rustc: remove closure ID from Res::Upvar.
This commit is contained in:
parent
1768030791
commit
b13d0407d4
5 changed files with 30 additions and 26 deletions
|
@ -139,8 +139,7 @@ pub enum Res<Id = hir::HirId> {
|
|||
// Value namespace
|
||||
SelfCtor(DefId /* impl */), // `DefId` refers to the impl
|
||||
Local(Id),
|
||||
Upvar(Id, // `HirId` of closed over local
|
||||
ast::NodeId), // expr node that creates the closure
|
||||
Upvar(Id),
|
||||
|
||||
// Macro namespace
|
||||
NonMacroAttr(NonMacroAttrKind), // e.g., `#[inline]` or `#[rustfmt::skip]`
|
||||
|
@ -396,7 +395,7 @@ impl<Id> Res<Id> {
|
|||
Res::SelfCtor(id) => Res::SelfCtor(id),
|
||||
Res::PrimTy(id) => Res::PrimTy(id),
|
||||
Res::Local(id) => Res::Local(map(id)),
|
||||
Res::Upvar(id, closure) => Res::Upvar(map(id), closure),
|
||||
Res::Upvar(id) => Res::Upvar(map(id)),
|
||||
Res::SelfTy(a, b) => Res::SelfTy(a, b),
|
||||
Res::ToolMod => Res::ToolMod,
|
||||
Res::NonMacroAttr(attr_kind) => Res::NonMacroAttr(attr_kind),
|
||||
|
|
|
@ -971,15 +971,13 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
|
|||
-> mc::McResult<mc::cmt_<'tcx>> {
|
||||
// Create the cmt for the variable being borrowed, from the
|
||||
// caller's perspective
|
||||
if upvar.has_parent {
|
||||
let closure_def_id = self.tcx().hir().local_def_id_from_hir_id(closure_hir_id);
|
||||
assert_eq!(self.mc.body_owner, self.tcx().parent(closure_def_id).unwrap());
|
||||
let var_nid = self.tcx().hir().hir_to_node_id(var_id);
|
||||
self.mc.cat_upvar(closure_hir_id, closure_span, var_nid)
|
||||
let res = if upvar.has_parent {
|
||||
Res::Upvar(var_id)
|
||||
} else {
|
||||
Res::Local(var_id)
|
||||
};
|
||||
let var_ty = self.mc.node_ty(var_id)?;
|
||||
self.mc.cat_res(closure_hir_id, closure_span, var_ty, Res::Local(var_id))
|
||||
}
|
||||
self.mc.cat_res(closure_hir_id, closure_span, var_ty, res)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -78,6 +78,7 @@ use syntax_pos::Span;
|
|||
use std::borrow::Cow;
|
||||
use std::fmt;
|
||||
use std::hash::{Hash, Hasher};
|
||||
use rustc_data_structures::fx::FxIndexMap;
|
||||
use rustc_data_structures::indexed_vec::Idx;
|
||||
use std::rc::Rc;
|
||||
use crate::util::nodemap::ItemLocalSet;
|
||||
|
@ -289,6 +290,7 @@ impl HirNode for hir::Pat {
|
|||
pub struct MemCategorizationContext<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
|
||||
pub tcx: TyCtxt<'a, 'gcx, 'tcx>,
|
||||
pub body_owner: DefId,
|
||||
pub upvars: Option<&'tcx FxIndexMap<hir::HirId, hir::Upvar>>,
|
||||
pub region_scope_tree: &'a region::ScopeTree,
|
||||
pub tables: &'a ty::TypeckTables<'tcx>,
|
||||
rvalue_promotable_map: Option<&'tcx ItemLocalSet>,
|
||||
|
@ -407,6 +409,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx, 'tcx> {
|
|||
MemCategorizationContext {
|
||||
tcx,
|
||||
body_owner,
|
||||
upvars: tcx.upvars(body_owner),
|
||||
region_scope_tree,
|
||||
tables,
|
||||
rvalue_promotable_map,
|
||||
|
@ -441,6 +444,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
|
|||
MemCategorizationContext {
|
||||
tcx,
|
||||
body_owner,
|
||||
upvars: tcx.upvars(body_owner),
|
||||
region_scope_tree,
|
||||
tables,
|
||||
rvalue_promotable_map,
|
||||
|
@ -742,21 +746,20 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
|
|||
})
|
||||
}
|
||||
|
||||
Res::Upvar(var_id, closure_node_id) => {
|
||||
Res::Upvar(var_id) => {
|
||||
assert!(self.upvars.map_or(false, |upvars| upvars.contains_key(&var_id)));
|
||||
let var_nid = self.tcx.hir().hir_to_node_id(var_id);
|
||||
let closure_def_id = self.tcx.hir().local_def_id(closure_node_id);
|
||||
assert_eq!(self.body_owner, closure_def_id);
|
||||
|
||||
self.cat_upvar(hir_id, span, var_nid)
|
||||
}
|
||||
|
||||
Res::Local(vid) => {
|
||||
let vnid = self.tcx.hir().hir_to_node_id(vid);
|
||||
Res::Local(var_id) => {
|
||||
assert!(!self.upvars.map_or(false, |upvars| upvars.contains_key(&var_id)));
|
||||
let var_nid = self.tcx.hir().hir_to_node_id(var_id);
|
||||
Ok(cmt_ {
|
||||
hir_id,
|
||||
span,
|
||||
cat: Categorization::Local(vid),
|
||||
mutbl: MutabilityCategory::from_local(self.tcx, self.tables, vnid),
|
||||
cat: Categorization::Local(var_id),
|
||||
mutbl: MutabilityCategory::from_local(self.tcx, self.tables, var_nid),
|
||||
ty: expr_ty,
|
||||
note: NoteNone
|
||||
})
|
||||
|
@ -768,7 +771,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
|
|||
|
||||
// Categorize an upvar, complete with invisible derefs of closure
|
||||
// environment and upvar reference as appropriate.
|
||||
pub fn cat_upvar(
|
||||
fn cat_upvar(
|
||||
&self,
|
||||
hir_id: hir::HirId,
|
||||
span: Span,
|
||||
|
|
|
@ -960,11 +960,15 @@ fn convert_path_expr<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
|
|||
|
||||
Res::Def(DefKind::Static, id) => ExprKind::StaticRef { id },
|
||||
|
||||
Res::Local(var_hir_id) => convert_var(cx, expr, var_hir_id),
|
||||
Res::Upvar(var_hir_id, closure_node_id) => {
|
||||
let closure_def_id = cx.tcx.hir().local_def_id(closure_node_id);
|
||||
assert_eq!(cx.body_owner, closure_def_id);
|
||||
assert!(cx.tables().upvar_list[&cx.body_owner].contains_key(&var_hir_id));
|
||||
Res::Local(var_hir_id) => {
|
||||
assert!(!cx.tables().upvar_list.get(&cx.body_owner)
|
||||
.map_or(false, |upvars| upvars.contains_key(&var_hir_id)));
|
||||
|
||||
convert_var(cx, expr, var_hir_id)
|
||||
}
|
||||
Res::Upvar(var_hir_id) => {
|
||||
assert!(cx.tables().upvar_list.get(&cx.body_owner)
|
||||
.map_or(false, |upvars| upvars.contains_key(&var_hir_id)));
|
||||
|
||||
convert_var(cx, expr, var_hir_id)
|
||||
}
|
||||
|
|
|
@ -4053,7 +4053,7 @@ impl<'a> Resolver<'a> {
|
|||
Res::Upvar(..) => true,
|
||||
_ => false,
|
||||
};
|
||||
res = Res::Upvar(var_id, function_id);
|
||||
res = Res::Upvar(var_id);
|
||||
|
||||
match self.upvars.entry(function_id).or_default().entry(var_id) {
|
||||
indexmap::map::Entry::Occupied(_) => continue,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue