Add a query for CapturedPlace::to_symbol
This commit is contained in:
@@ -162,7 +162,7 @@ impl CapturedPlace<'tcx> {
|
||||
}
|
||||
|
||||
/// Returns a symbol of the captured upvar, which looks like `name__field1__field2`.
|
||||
pub fn to_symbol(&self, tcx: TyCtxt<'tcx>) -> Symbol {
|
||||
fn to_symbol(&self, tcx: TyCtxt<'tcx>) -> Symbol {
|
||||
let hir_id = match self.place.base {
|
||||
HirPlaceBase::Upvar(upvar_id) => upvar_id.var_path.hir_id,
|
||||
base => bug!("Expected an upvar, found {:?}", base),
|
||||
@@ -248,6 +248,15 @@ impl CapturedPlace<'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
fn symbols_for_closure_captures<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
def_id: (LocalDefId, DefId),
|
||||
) -> Vec<Symbol> {
|
||||
let typeck_results = tcx.typeck(def_id.0);
|
||||
let captures = typeck_results.closure_min_captures_flattened(def_id.1);
|
||||
captures.into_iter().map(|captured_place| captured_place.to_symbol(tcx)).collect()
|
||||
}
|
||||
|
||||
/// Return true if the `proj_possible_ancestor` represents an ancestor path
|
||||
/// to `proj_capture` or `proj_possible_ancestor` is same as `proj_capture`,
|
||||
/// assuming they both start off of the same root variable.
|
||||
@@ -432,3 +441,7 @@ impl BorrowKind {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn provide(providers: &mut ty::query::Providers) {
|
||||
*providers = ty::query::Providers { symbols_for_closure_captures, ..*providers }
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@ pub use self::IntVarValue::*;
|
||||
pub use self::Variance::*;
|
||||
pub use adt::*;
|
||||
pub use assoc::*;
|
||||
pub use closure::*;
|
||||
pub use generics::*;
|
||||
pub use vtable::*;
|
||||
|
||||
@@ -55,6 +54,12 @@ pub use rustc_type_ir::*;
|
||||
|
||||
pub use self::binding::BindingMode;
|
||||
pub use self::binding::BindingMode::*;
|
||||
pub use self::closure::{
|
||||
is_ancestor_or_same_capture, place_to_string_for_capture, BorrowKind, CaptureInfo,
|
||||
CapturedPlace, ClosureKind, MinCaptureInformationMap, MinCaptureList,
|
||||
RootVariableMinCaptureList, UpvarBorrow, UpvarCapture, UpvarCaptureMap, UpvarId, UpvarListMap,
|
||||
UpvarPath, CAPTURE_STRUCT_LOCAL,
|
||||
};
|
||||
pub use self::consts::{Const, ConstInt, ConstKind, InferConst, ScalarInt, Unevaluated, ValTree};
|
||||
pub use self::context::{
|
||||
tls, CanonicalUserType, CanonicalUserTypeAnnotation, CanonicalUserTypeAnnotations,
|
||||
@@ -1979,6 +1984,7 @@ pub fn ast_uint_ty(uty: UintTy) -> ast::UintTy {
|
||||
}
|
||||
|
||||
pub fn provide(providers: &mut ty::query::Providers) {
|
||||
closure::provide(providers);
|
||||
context::provide(providers);
|
||||
erase_regions::provide(providers);
|
||||
layout::provide(providers);
|
||||
|
||||
Reference in New Issue
Block a user