rustc: remove Res::Upvar.
This commit is contained in:
parent
340b91e2ff
commit
ed1bbbb545
12 changed files with 61 additions and 84 deletions
|
@ -139,7 +139,6 @@ pub enum Res<Id = hir::HirId> {
|
||||||
// Value namespace
|
// Value namespace
|
||||||
SelfCtor(DefId /* impl */), // `DefId` refers to the impl
|
SelfCtor(DefId /* impl */), // `DefId` refers to the impl
|
||||||
Local(Id),
|
Local(Id),
|
||||||
Upvar(Id),
|
|
||||||
|
|
||||||
// Macro namespace
|
// Macro namespace
|
||||||
NonMacroAttr(NonMacroAttrKind), // e.g., `#[inline]` or `#[rustfmt::skip]`
|
NonMacroAttr(NonMacroAttrKind), // e.g., `#[inline]` or `#[rustfmt::skip]`
|
||||||
|
@ -345,7 +344,6 @@ impl<Id> Res<Id> {
|
||||||
Res::Def(_, id) => Some(id),
|
Res::Def(_, id) => Some(id),
|
||||||
|
|
||||||
Res::Local(..) |
|
Res::Local(..) |
|
||||||
Res::Upvar(..) |
|
|
||||||
Res::PrimTy(..) |
|
Res::PrimTy(..) |
|
||||||
Res::SelfTy(..) |
|
Res::SelfTy(..) |
|
||||||
Res::SelfCtor(..) |
|
Res::SelfCtor(..) |
|
||||||
|
@ -372,7 +370,6 @@ impl<Id> Res<Id> {
|
||||||
Res::SelfCtor(..) => "self constructor",
|
Res::SelfCtor(..) => "self constructor",
|
||||||
Res::PrimTy(..) => "builtin type",
|
Res::PrimTy(..) => "builtin type",
|
||||||
Res::Local(..) => "local variable",
|
Res::Local(..) => "local variable",
|
||||||
Res::Upvar(..) => "closure capture",
|
|
||||||
Res::SelfTy(..) => "self type",
|
Res::SelfTy(..) => "self type",
|
||||||
Res::ToolMod => "tool module",
|
Res::ToolMod => "tool module",
|
||||||
Res::NonMacroAttr(attr_kind) => attr_kind.descr(),
|
Res::NonMacroAttr(attr_kind) => attr_kind.descr(),
|
||||||
|
@ -395,7 +392,6 @@ impl<Id> Res<Id> {
|
||||||
Res::SelfCtor(id) => Res::SelfCtor(id),
|
Res::SelfCtor(id) => Res::SelfCtor(id),
|
||||||
Res::PrimTy(id) => Res::PrimTy(id),
|
Res::PrimTy(id) => Res::PrimTy(id),
|
||||||
Res::Local(id) => Res::Local(map(id)),
|
Res::Local(id) => Res::Local(map(id)),
|
||||||
Res::Upvar(id) => Res::Upvar(map(id)),
|
|
||||||
Res::SelfTy(a, b) => Res::SelfTy(a, b),
|
Res::SelfTy(a, b) => Res::SelfTy(a, b),
|
||||||
Res::ToolMod => Res::ToolMod,
|
Res::ToolMod => Res::ToolMod,
|
||||||
Res::NonMacroAttr(attr_kind) => Res::NonMacroAttr(attr_kind),
|
Res::NonMacroAttr(attr_kind) => Res::NonMacroAttr(attr_kind),
|
||||||
|
|
|
@ -1409,7 +1409,6 @@ impl Expr {
|
||||||
ExprKind::Path(QPath::Resolved(_, ref path)) => {
|
ExprKind::Path(QPath::Resolved(_, ref path)) => {
|
||||||
match path.res {
|
match path.res {
|
||||||
Res::Local(..)
|
Res::Local(..)
|
||||||
| Res::Upvar(..)
|
|
||||||
| Res::Def(DefKind::Static, _)
|
| Res::Def(DefKind::Static, _)
|
||||||
| Res::Err => true,
|
| Res::Err => true,
|
||||||
_ => false,
|
_ => false,
|
||||||
|
|
|
@ -78,7 +78,7 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
_ if self.in_pat => {},
|
_ if self.in_pat => {},
|
||||||
Res::PrimTy(..) | Res::SelfTy(..) | Res::SelfCtor(..) |
|
Res::PrimTy(..) | Res::SelfTy(..) | Res::SelfCtor(..) |
|
||||||
Res::Local(..) | Res::Upvar(..) => {}
|
Res::Local(..) => {}
|
||||||
Res::Def(DefKind::Ctor(CtorOf::Variant, ..), ctor_def_id) => {
|
Res::Def(DefKind::Ctor(CtorOf::Variant, ..), ctor_def_id) => {
|
||||||
let variant_id = self.tcx.parent(ctor_def_id).unwrap();
|
let variant_id = self.tcx.parent(ctor_def_id).unwrap();
|
||||||
let enum_id = self.tcx.parent(variant_id).unwrap();
|
let enum_id = self.tcx.parent(variant_id).unwrap();
|
||||||
|
|
|
@ -968,14 +968,9 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
|
||||||
var_id: hir::HirId)
|
var_id: hir::HirId)
|
||||||
-> mc::McResult<mc::cmt_<'tcx>> {
|
-> mc::McResult<mc::cmt_<'tcx>> {
|
||||||
// Create the cmt for the variable being borrowed, from the
|
// Create the cmt for the variable being borrowed, from the
|
||||||
// caller's perspective
|
// perspective of the creator (parent) of the closure.
|
||||||
let res = if self.mc.upvars.map_or(false, |upvars| upvars.contains_key(&var_id)) {
|
|
||||||
Res::Upvar(var_id)
|
|
||||||
} else {
|
|
||||||
Res::Local(var_id)
|
|
||||||
};
|
|
||||||
let var_ty = self.mc.node_ty(var_id)?;
|
let var_ty = self.mc.node_ty(var_id)?;
|
||||||
self.mc.cat_res(closure_hir_id, closure_span, var_ty, res)
|
self.mc.cat_res(closure_hir_id, closure_span, var_ty, Res::Local(var_id))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -474,9 +474,12 @@ fn visit_expr<'a, 'tcx>(ir: &mut IrMaps<'a, 'tcx>, expr: &'tcx Expr) {
|
||||||
// live nodes required for uses or definitions of variables:
|
// live nodes required for uses or definitions of variables:
|
||||||
hir::ExprKind::Path(hir::QPath::Resolved(_, ref path)) => {
|
hir::ExprKind::Path(hir::QPath::Resolved(_, ref path)) => {
|
||||||
debug!("expr {}: path that leads to {:?}", expr.hir_id, path.res);
|
debug!("expr {}: path that leads to {:?}", expr.hir_id, path.res);
|
||||||
if let Res::Local(..) = path.res {
|
if let Res::Local(var_hir_id) = path.res {
|
||||||
|
let upvars = ir.tcx.upvars(ir.body_owner);
|
||||||
|
if !upvars.map_or(false, |upvars| upvars.contains_key(&var_hir_id)) {
|
||||||
ir.add_live_node_for_node(expr.hir_id, ExprNode(expr.span));
|
ir.add_live_node_for_node(expr.hir_id, ExprNode(expr.span));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
intravisit::walk_expr(ir, expr);
|
intravisit::walk_expr(ir, expr);
|
||||||
}
|
}
|
||||||
hir::ExprKind::Closure(..) => {
|
hir::ExprKind::Closure(..) => {
|
||||||
|
@ -1338,8 +1341,13 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
|
||||||
-> LiveNode {
|
-> LiveNode {
|
||||||
match path.res {
|
match path.res {
|
||||||
Res::Local(hid) => {
|
Res::Local(hid) => {
|
||||||
|
let upvars = self.ir.tcx.upvars(self.ir.body_owner);
|
||||||
|
if !upvars.map_or(false, |upvars| upvars.contains_key(&hid)) {
|
||||||
let nid = self.ir.tcx.hir().hir_to_node_id(hid);
|
let nid = self.ir.tcx.hir().hir_to_node_id(hid);
|
||||||
self.access_var(hir_id, nid, succ, acc, path.span)
|
self.access_var(hir_id, nid, succ, acc, path.span)
|
||||||
|
} else {
|
||||||
|
succ
|
||||||
|
}
|
||||||
}
|
}
|
||||||
_ => succ
|
_ => succ
|
||||||
}
|
}
|
||||||
|
@ -1531,6 +1539,8 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
|
||||||
match expr.node {
|
match expr.node {
|
||||||
hir::ExprKind::Path(hir::QPath::Resolved(_, ref path)) => {
|
hir::ExprKind::Path(hir::QPath::Resolved(_, ref path)) => {
|
||||||
if let Res::Local(var_hid) = path.res {
|
if let Res::Local(var_hid) = path.res {
|
||||||
|
let upvars = self.ir.tcx.upvars(self.ir.body_owner);
|
||||||
|
if !upvars.map_or(false, |upvars| upvars.contains_key(&var_hid)) {
|
||||||
// Assignment to an immutable variable or argument: only legal
|
// Assignment to an immutable variable or argument: only legal
|
||||||
// if there is no later assignment. If this local is actually
|
// if there is no later assignment. If this local is actually
|
||||||
// mutable, then check for a reassignment to flag the mutability
|
// mutable, then check for a reassignment to flag the mutability
|
||||||
|
@ -1540,6 +1550,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
|
||||||
self.warn_about_dead_assign(expr.span, expr.hir_id, ln, var);
|
self.warn_about_dead_assign(expr.span, expr.hir_id, ln, var);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
_ => {
|
_ => {
|
||||||
// For other kinds of places, no checks are required,
|
// For other kinds of places, no checks are required,
|
||||||
// and any embedded expressions are actually rvalues
|
// and any embedded expressions are actually rvalues
|
||||||
|
|
|
@ -746,15 +746,11 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
|
||||||
self.cat_upvar(hir_id, span, var_nid)
|
|
||||||
}
|
|
||||||
|
|
||||||
Res::Local(var_id) => {
|
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);
|
let var_nid = self.tcx.hir().hir_to_node_id(var_id);
|
||||||
|
if self.upvars.map_or(false, |upvars| upvars.contains_key(&var_id)) {
|
||||||
|
self.cat_upvar(hir_id, span, var_nid)
|
||||||
|
} else {
|
||||||
Ok(cmt_ {
|
Ok(cmt_ {
|
||||||
hir_id,
|
hir_id,
|
||||||
span,
|
span,
|
||||||
|
@ -764,6 +760,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
|
||||||
note: NoteNone
|
note: NoteNone
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
def => span_bug!(span, "unexpected definition in memory categorization: {:?}", def)
|
def => span_bug!(span, "unexpected definition in memory categorization: {:?}", def)
|
||||||
}
|
}
|
||||||
|
|
|
@ -104,7 +104,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ReachableContext<'a, 'tcx> {
|
||||||
};
|
};
|
||||||
|
|
||||||
match res {
|
match res {
|
||||||
Some(Res::Local(hir_id)) | Some(Res::Upvar(hir_id, ..)) => {
|
Some(Res::Local(hir_id)) => {
|
||||||
self.reachable_symbols.insert(hir_id);
|
self.reachable_symbols.insert(hir_id);
|
||||||
}
|
}
|
||||||
Some(res) => {
|
Some(res) => {
|
||||||
|
|
|
@ -960,18 +960,7 @@ fn convert_path_expr<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
|
||||||
|
|
||||||
Res::Def(DefKind::Static, id) => ExprKind::StaticRef { id },
|
Res::Def(DefKind::Static, id) => ExprKind::StaticRef { id },
|
||||||
|
|
||||||
Res::Local(var_hir_id) => {
|
Res::Local(var_hir_id) => convert_var(cx, expr, 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)
|
|
||||||
}
|
|
||||||
|
|
||||||
_ => span_bug!(expr.span, "res `{:?}` not yet implemented", res),
|
_ => span_bug!(expr.span, "res `{:?}` not yet implemented", res),
|
||||||
}
|
}
|
||||||
|
|
|
@ -612,7 +612,6 @@ impl<'a> PathSource<'a> {
|
||||||
| Res::Def(DefKind::Const, _)
|
| Res::Def(DefKind::Const, _)
|
||||||
| Res::Def(DefKind::Static, _)
|
| Res::Def(DefKind::Static, _)
|
||||||
| Res::Local(..)
|
| Res::Local(..)
|
||||||
| Res::Upvar(..)
|
|
||||||
| Res::Def(DefKind::Fn, _)
|
| Res::Def(DefKind::Fn, _)
|
||||||
| Res::Def(DefKind::Method, _)
|
| Res::Def(DefKind::Method, _)
|
||||||
| Res::Def(DefKind::AssocConst, _)
|
| Res::Def(DefKind::AssocConst, _)
|
||||||
|
@ -2204,7 +2203,7 @@ impl<'a> Resolver<'a> {
|
||||||
if let Some(res) = self.ribs[ns][i].bindings.get(&ident).cloned() {
|
if let Some(res) = self.ribs[ns][i].bindings.get(&ident).cloned() {
|
||||||
// The ident resolves to a type parameter or local variable.
|
// The ident resolves to a type parameter or local variable.
|
||||||
return Some(LexicalScopeBinding::Res(
|
return Some(LexicalScopeBinding::Res(
|
||||||
self.adjust_local_res(ns, i, res, record_used, path_span)
|
self.validate_res_from_ribs(ns, i, res, record_used, path_span),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4006,14 +4005,16 @@ impl<'a> Resolver<'a> {
|
||||||
diag);
|
diag);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Resolve a local definition, potentially adjusting for closures.
|
// Validate a local resolution (from ribs), potentially recording closure upvars.
|
||||||
fn adjust_local_res(&mut self,
|
fn validate_res_from_ribs(
|
||||||
|
&mut self,
|
||||||
ns: Namespace,
|
ns: Namespace,
|
||||||
rib_index: usize,
|
rib_index: usize,
|
||||||
mut res: Res,
|
res: Res,
|
||||||
record_used: bool,
|
record_used: bool,
|
||||||
span: Span) -> Res {
|
span: Span,
|
||||||
debug!("adjust_local_res");
|
) -> Res {
|
||||||
|
debug!("validate_res_from_ribs({:?})", res);
|
||||||
let ribs = &self.ribs[ns][rib_index + 1..];
|
let ribs = &self.ribs[ns][rib_index + 1..];
|
||||||
|
|
||||||
// An invalid forward use of a type parameter from a previous default.
|
// An invalid forward use of a type parameter from a previous default.
|
||||||
|
@ -4035,9 +4036,6 @@ impl<'a> Resolver<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
match res {
|
match res {
|
||||||
Res::Upvar(..) => {
|
|
||||||
span_bug!(span, "unexpected {:?} in bindings", res)
|
|
||||||
}
|
|
||||||
Res::Local(var_id) => {
|
Res::Local(var_id) => {
|
||||||
use ResolutionError::*;
|
use ResolutionError::*;
|
||||||
let mut res_err = None;
|
let mut res_err = None;
|
||||||
|
@ -4049,14 +4047,9 @@ impl<'a> Resolver<'a> {
|
||||||
// Nothing to do. Continue.
|
// Nothing to do. Continue.
|
||||||
}
|
}
|
||||||
ClosureRibKind(function_id) => {
|
ClosureRibKind(function_id) => {
|
||||||
res = Res::Upvar(var_id);
|
|
||||||
match self.upvars.entry(function_id).or_default().entry(var_id) {
|
|
||||||
indexmap::map::Entry::Occupied(_) => continue,
|
|
||||||
indexmap::map::Entry::Vacant(entry) => {
|
|
||||||
if record_used {
|
if record_used {
|
||||||
entry.insert(Upvar { span });
|
self.upvars.entry(function_id).or_default()
|
||||||
}
|
.entry(var_id).or_insert(Upvar { span });
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ItemRibKind | FnItemRibKind | AssocItemRibKind => {
|
ItemRibKind | FnItemRibKind | AssocItemRibKind => {
|
||||||
|
|
|
@ -702,7 +702,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
|
||||||
let span = self.span_from_span(span);
|
let span = self.span_from_span(span);
|
||||||
|
|
||||||
match res {
|
match res {
|
||||||
Res::Upvar(id, ..) | Res::Local(id) => {
|
Res::Local(id) => {
|
||||||
Some(Ref {
|
Some(Ref {
|
||||||
kind: RefKind::Variable,
|
kind: RefKind::Variable,
|
||||||
span,
|
span,
|
||||||
|
|
|
@ -350,7 +350,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
|
|
||||||
let def_span = match def {
|
let def_span = match def {
|
||||||
Res::Err => None,
|
Res::Err => None,
|
||||||
Res::Local(id) | Res::Upvar(id, ..) => {
|
Res::Local(id) => {
|
||||||
Some(self.tcx.hir().span_by_hir_id(id))
|
Some(self.tcx.hir().span_by_hir_id(id))
|
||||||
},
|
},
|
||||||
_ => def
|
_ => def
|
||||||
|
|
|
@ -5264,7 +5264,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
Err(ErrorReported) => return (tcx.types.err, res),
|
Err(ErrorReported) => return (tcx.types.err, res),
|
||||||
};
|
};
|
||||||
let path_segs = match res {
|
let path_segs = match res {
|
||||||
Res::Local(_) | Res::Upvar(..) => Vec::new(),
|
Res::Local(_) => vec![],
|
||||||
Res::Def(kind, def_id) =>
|
Res::Def(kind, def_id) =>
|
||||||
AstConv::def_ids_for_value_path_segments(self, segments, self_ty, kind, def_id),
|
AstConv::def_ids_for_value_path_segments(self, segments, self_ty, kind, def_id),
|
||||||
_ => bug!("instantiate_value_path on {:?}", res),
|
_ => bug!("instantiate_value_path on {:?}", res),
|
||||||
|
@ -5325,15 +5325,12 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
match res {
|
if let Res::Local(hid) = res {
|
||||||
Res::Local(hid) | Res::Upvar(hid, ..) => {
|
|
||||||
let ty = self.local_ty(span, hid).decl_ty;
|
let ty = self.local_ty(span, hid).decl_ty;
|
||||||
let ty = self.normalize_associated_types_in(span, &ty);
|
let ty = self.normalize_associated_types_in(span, &ty);
|
||||||
self.write_ty(hir_id, ty);
|
self.write_ty(hir_id, ty);
|
||||||
return (ty, res);
|
return (ty, res);
|
||||||
}
|
}
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
|
|
||||||
if generics_has_err {
|
if generics_has_err {
|
||||||
// Don't try to infer type parameters when prohibited generic arguments were given.
|
// Don't try to infer type parameters when prohibited generic arguments were given.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue