Add a query for CapturedPlace::to_symbol
This commit is contained in:
parent
0cb6f07ef2
commit
cf5eda1b4d
5 changed files with 39 additions and 9 deletions
|
@ -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 }
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue