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
|
||||
SelfCtor(DefId /* impl */), // `DefId` refers to the impl
|
||||
Local(Id),
|
||||
Upvar(Id),
|
||||
|
||||
// Macro namespace
|
||||
NonMacroAttr(NonMacroAttrKind), // e.g., `#[inline]` or `#[rustfmt::skip]`
|
||||
|
@ -345,7 +344,6 @@ impl<Id> Res<Id> {
|
|||
Res::Def(_, id) => Some(id),
|
||||
|
||||
Res::Local(..) |
|
||||
Res::Upvar(..) |
|
||||
Res::PrimTy(..) |
|
||||
Res::SelfTy(..) |
|
||||
Res::SelfCtor(..) |
|
||||
|
@ -372,7 +370,6 @@ impl<Id> Res<Id> {
|
|||
Res::SelfCtor(..) => "self constructor",
|
||||
Res::PrimTy(..) => "builtin type",
|
||||
Res::Local(..) => "local variable",
|
||||
Res::Upvar(..) => "closure capture",
|
||||
Res::SelfTy(..) => "self type",
|
||||
Res::ToolMod => "tool module",
|
||||
Res::NonMacroAttr(attr_kind) => attr_kind.descr(),
|
||||
|
@ -395,7 +392,6 @@ 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) => Res::Upvar(map(id)),
|
||||
Res::SelfTy(a, b) => Res::SelfTy(a, b),
|
||||
Res::ToolMod => Res::ToolMod,
|
||||
Res::NonMacroAttr(attr_kind) => Res::NonMacroAttr(attr_kind),
|
||||
|
|
|
@ -1409,7 +1409,6 @@ impl Expr {
|
|||
ExprKind::Path(QPath::Resolved(_, ref path)) => {
|
||||
match path.res {
|
||||
Res::Local(..)
|
||||
| Res::Upvar(..)
|
||||
| Res::Def(DefKind::Static, _)
|
||||
| Res::Err => true,
|
||||
_ => false,
|
||||
|
|
|
@ -78,7 +78,7 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
|
|||
}
|
||||
_ if self.in_pat => {},
|
||||
Res::PrimTy(..) | Res::SelfTy(..) | Res::SelfCtor(..) |
|
||||
Res::Local(..) | Res::Upvar(..) => {}
|
||||
Res::Local(..) => {}
|
||||
Res::Def(DefKind::Ctor(CtorOf::Variant, ..), ctor_def_id) => {
|
||||
let variant_id = self.tcx.parent(ctor_def_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)
|
||||
-> mc::McResult<mc::cmt_<'tcx>> {
|
||||
// Create the cmt for the variable being borrowed, from the
|
||||
// caller's perspective
|
||||
let res = if self.mc.upvars.map_or(false, |upvars| upvars.contains_key(&var_id)) {
|
||||
Res::Upvar(var_id)
|
||||
} else {
|
||||
Res::Local(var_id)
|
||||
};
|
||||
// perspective of the creator (parent) of the closure.
|
||||
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:
|
||||
hir::ExprKind::Path(hir::QPath::Resolved(_, ref path)) => {
|
||||
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));
|
||||
}
|
||||
}
|
||||
intravisit::walk_expr(ir, expr);
|
||||
}
|
||||
hir::ExprKind::Closure(..) => {
|
||||
|
@ -1338,8 +1341,13 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
|
|||
-> LiveNode {
|
||||
match path.res {
|
||||
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);
|
||||
self.access_var(hir_id, nid, succ, acc, path.span)
|
||||
} else {
|
||||
succ
|
||||
}
|
||||
}
|
||||
_ => succ
|
||||
}
|
||||
|
@ -1531,6 +1539,8 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
|
|||
match expr.node {
|
||||
hir::ExprKind::Path(hir::QPath::Resolved(_, ref path)) => {
|
||||
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
|
||||
// if there is no later assignment. If this local is actually
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
// For other kinds of places, no checks are required,
|
||||
// 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) => {
|
||||
assert!(!self.upvars.map_or(false, |upvars| upvars.contains_key(&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_ {
|
||||
hir_id,
|
||||
span,
|
||||
|
@ -764,6 +760,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
|
|||
note: NoteNone
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
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 {
|
||||
Some(Res::Local(hir_id)) | Some(Res::Upvar(hir_id, ..)) => {
|
||||
Some(Res::Local(hir_id)) => {
|
||||
self.reachable_symbols.insert(hir_id);
|
||||
}
|
||||
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::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)
|
||||
}
|
||||
Res::Local(var_hir_id) => convert_var(cx, expr, var_hir_id),
|
||||
|
||||
_ => span_bug!(expr.span, "res `{:?}` not yet implemented", res),
|
||||
}
|
||||
|
|
|
@ -612,7 +612,6 @@ impl<'a> PathSource<'a> {
|
|||
| Res::Def(DefKind::Const, _)
|
||||
| Res::Def(DefKind::Static, _)
|
||||
| Res::Local(..)
|
||||
| Res::Upvar(..)
|
||||
| Res::Def(DefKind::Fn, _)
|
||||
| Res::Def(DefKind::Method, _)
|
||||
| Res::Def(DefKind::AssocConst, _)
|
||||
|
@ -2204,7 +2203,7 @@ impl<'a> Resolver<'a> {
|
|||
if let Some(res) = self.ribs[ns][i].bindings.get(&ident).cloned() {
|
||||
// The ident resolves to a type parameter or local variable.
|
||||
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);
|
||||
}
|
||||
|
||||
// Resolve a local definition, potentially adjusting for closures.
|
||||
fn adjust_local_res(&mut self,
|
||||
// Validate a local resolution (from ribs), potentially recording closure upvars.
|
||||
fn validate_res_from_ribs(
|
||||
&mut self,
|
||||
ns: Namespace,
|
||||
rib_index: usize,
|
||||
mut res: Res,
|
||||
res: Res,
|
||||
record_used: bool,
|
||||
span: Span) -> Res {
|
||||
debug!("adjust_local_res");
|
||||
span: Span,
|
||||
) -> Res {
|
||||
debug!("validate_res_from_ribs({:?})", res);
|
||||
let ribs = &self.ribs[ns][rib_index + 1..];
|
||||
|
||||
// An invalid forward use of a type parameter from a previous default.
|
||||
|
@ -4035,9 +4036,6 @@ impl<'a> Resolver<'a> {
|
|||
}
|
||||
|
||||
match res {
|
||||
Res::Upvar(..) => {
|
||||
span_bug!(span, "unexpected {:?} in bindings", res)
|
||||
}
|
||||
Res::Local(var_id) => {
|
||||
use ResolutionError::*;
|
||||
let mut res_err = None;
|
||||
|
@ -4049,14 +4047,9 @@ impl<'a> Resolver<'a> {
|
|||
// Nothing to do. Continue.
|
||||
}
|
||||
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 {
|
||||
entry.insert(Upvar { span });
|
||||
}
|
||||
}
|
||||
self.upvars.entry(function_id).or_default()
|
||||
.entry(var_id).or_insert(Upvar { span });
|
||||
}
|
||||
}
|
||||
ItemRibKind | FnItemRibKind | AssocItemRibKind => {
|
||||
|
|
|
@ -702,7 +702,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
|
|||
let span = self.span_from_span(span);
|
||||
|
||||
match res {
|
||||
Res::Upvar(id, ..) | Res::Local(id) => {
|
||||
Res::Local(id) => {
|
||||
Some(Ref {
|
||||
kind: RefKind::Variable,
|
||||
span,
|
||||
|
|
|
@ -350,7 +350,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
|||
|
||||
let def_span = match def {
|
||||
Res::Err => None,
|
||||
Res::Local(id) | Res::Upvar(id, ..) => {
|
||||
Res::Local(id) => {
|
||||
Some(self.tcx.hir().span_by_hir_id(id))
|
||||
},
|
||||
_ => def
|
||||
|
|
|
@ -5264,7 +5264,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
|||
Err(ErrorReported) => return (tcx.types.err, res),
|
||||
};
|
||||
let path_segs = match res {
|
||||
Res::Local(_) | Res::Upvar(..) => Vec::new(),
|
||||
Res::Local(_) => vec![],
|
||||
Res::Def(kind, def_id) =>
|
||||
AstConv::def_ids_for_value_path_segments(self, segments, self_ty, kind, def_id),
|
||||
_ => bug!("instantiate_value_path on {:?}", res),
|
||||
|
@ -5325,15 +5325,12 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
|||
}
|
||||
}));
|
||||
|
||||
match res {
|
||||
Res::Local(hid) | Res::Upvar(hid, ..) => {
|
||||
if let Res::Local(hid) = res {
|
||||
let ty = self.local_ty(span, hid).decl_ty;
|
||||
let ty = self.normalize_associated_types_in(span, &ty);
|
||||
self.write_ty(hir_id, ty);
|
||||
return (ty, res);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
if generics_has_err {
|
||||
// Don't try to infer type parameters when prohibited generic arguments were given.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue