Use ItemLocalId as key for TypeckTables::pat_binding_modes.
This commit is contained in:
parent
7f2423eede
commit
e777189b4a
@ -642,7 +642,7 @@ for ty::TypeckTables<'gcx> {
|
||||
ich::hash_stable_itemlocalmap(hcx, hasher, node_types);
|
||||
ich::hash_stable_itemlocalmap(hcx, hasher, node_substs);
|
||||
ich::hash_stable_itemlocalmap(hcx, hasher, adjustments);
|
||||
ich::hash_stable_nodemap(hcx, hasher, pat_binding_modes);
|
||||
ich::hash_stable_itemlocalmap(hcx, hasher, pat_binding_modes);
|
||||
ich::hash_stable_hashmap(hcx, hasher, upvar_capture_map, |hcx, up_var_id| {
|
||||
let ty::UpvarId {
|
||||
var_id,
|
||||
|
@ -797,7 +797,8 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
|
||||
pat);
|
||||
return_if_err!(self.mc.cat_pattern(cmt_discr, pat, |cmt_pat, pat| {
|
||||
if let PatKind::Binding(..) = pat.node {
|
||||
let bm = *self.mc.tables.pat_binding_modes.get(&pat.id)
|
||||
self.mc.tables.validate_hir_id(pat.hir_id);
|
||||
let bm = *self.mc.tables.pat_binding_modes.get(&pat.hir_id.local_id)
|
||||
.expect("missing binding mode");
|
||||
match bm {
|
||||
ty::BindByReference(..) =>
|
||||
@ -823,7 +824,9 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
|
||||
return_if_err!(mc.cat_pattern(cmt_discr.clone(), pat, |cmt_pat, pat| {
|
||||
if let PatKind::Binding(_, def_id, ..) = pat.node {
|
||||
debug!("binding cmt_pat={:?} pat={:?} match_mode={:?}", cmt_pat, pat, match_mode);
|
||||
let bm = *mc.tables.pat_binding_modes.get(&pat.id).expect("missing binding mode");
|
||||
mc.tables.validate_hir_id(pat.hir_id);
|
||||
let bm = *mc.tables.pat_binding_modes.get(&pat.hir_id.local_id)
|
||||
.expect("missing binding mode");
|
||||
|
||||
// pat_ty: the type of the binding being produced.
|
||||
let pat_ty = return_if_err!(mc.node_ty(pat.hir_id));
|
||||
|
@ -334,7 +334,11 @@ impl MutabilityCategory {
|
||||
let ret = match tcx.hir.get(id) {
|
||||
hir_map::NodeLocal(p) => match p.node {
|
||||
PatKind::Binding(..) => {
|
||||
let bm = *tables.pat_binding_modes.get(&p.id).expect("missing binding mode");
|
||||
|
||||
tables.validate_hir_id(p.hir_id);
|
||||
let bm = *tables.pat_binding_modes
|
||||
.get(&p.hir_id.local_id)
|
||||
.expect("missing binding mode");
|
||||
if bm == ty::BindByValue(hir::MutMutable) {
|
||||
McDeclared
|
||||
} else {
|
||||
@ -481,7 +485,12 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
|
||||
// fundamental fix to this conflated use of the node id.
|
||||
let ret_ty = match pat.node {
|
||||
PatKind::Binding(..) => {
|
||||
let bm = *self.tables.pat_binding_modes.get(&pat.id).expect("missing binding mode");
|
||||
self.tables.validate_hir_id(pat.hir_id);
|
||||
let bm = *self.tables
|
||||
.pat_binding_modes
|
||||
.get(&pat.hir_id.local_id)
|
||||
.expect("missing binding mode");
|
||||
|
||||
if let ty::BindByReference(_) = bm {
|
||||
// a bind-by-ref means that the base_ty will be the type of the ident itself,
|
||||
// but what we want here is the type of the underlying value being borrowed.
|
||||
|
@ -230,7 +230,7 @@ pub struct TypeckTables<'tcx> {
|
||||
pub adjustments: ItemLocalMap<Vec<ty::adjustment::Adjustment<'tcx>>>,
|
||||
|
||||
// Stores the actual binding mode for all instances of hir::BindingAnnotation.
|
||||
pub pat_binding_modes: NodeMap<BindingMode>,
|
||||
pub pat_binding_modes: ItemLocalMap<BindingMode>,
|
||||
|
||||
/// Borrows
|
||||
pub upvar_capture_map: ty::UpvarCaptureMap<'tcx>,
|
||||
@ -281,7 +281,7 @@ impl<'tcx> TypeckTables<'tcx> {
|
||||
node_types: ItemLocalMap(),
|
||||
node_substs: ItemLocalMap(),
|
||||
adjustments: ItemLocalMap(),
|
||||
pat_binding_modes: NodeMap(),
|
||||
pat_binding_modes: ItemLocalMap(),
|
||||
upvar_capture_map: FxHashMap(),
|
||||
closure_tys: NodeMap(),
|
||||
closure_kinds: NodeMap(),
|
||||
|
@ -899,8 +899,13 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
|
||||
};
|
||||
|
||||
match pat.node {
|
||||
hir::PatKind::Binding(..) =>
|
||||
*self.tables.pat_binding_modes.get(&pat.id).expect("missing binding mode"),
|
||||
hir::PatKind::Binding(..) => {
|
||||
self.tables.validate_hir_id(pat.hir_id);
|
||||
*self.tables
|
||||
.pat_binding_modes
|
||||
.get(&pat.hir_id.local_id)
|
||||
.expect("missing binding mode")
|
||||
}
|
||||
_ => bug!("local is not a binding: {:?}", pat)
|
||||
}
|
||||
}
|
||||
|
@ -269,7 +269,12 @@ impl<'a, 'tcx> MatchVisitor<'a, 'tcx> {
|
||||
fn check_for_bindings_named_the_same_as_variants(cx: &MatchVisitor, pat: &Pat) {
|
||||
pat.walk(|p| {
|
||||
if let PatKind::Binding(_, _, name, None) = p.node {
|
||||
let bm = *cx.tables.pat_binding_modes.get(&p.id).expect("missing binding mode");
|
||||
cx.tables.validate_hir_id(p.hir_id);
|
||||
let bm = *cx.tables
|
||||
.pat_binding_modes
|
||||
.get(&p.hir_id.local_id)
|
||||
.expect("missing binding mode");
|
||||
|
||||
if bm != ty::BindByValue(hir::MutImmutable) {
|
||||
// Nothing to check.
|
||||
return true;
|
||||
@ -458,7 +463,12 @@ fn check_legality_of_move_bindings(cx: &MatchVisitor,
|
||||
let mut by_ref_span = None;
|
||||
for pat in pats {
|
||||
pat.each_binding(|_, id, span, _path| {
|
||||
let bm = *cx.tables.pat_binding_modes.get(&id).expect("missing binding mode");
|
||||
let hir_id = cx.tcx.hir.node_to_hir_id(id);
|
||||
cx.tables.validate_hir_id(hir_id);
|
||||
let bm = *cx.tables
|
||||
.pat_binding_modes
|
||||
.get(&hir_id.local_id)
|
||||
.expect("missing binding mode");
|
||||
if let ty::BindByReference(..) = bm {
|
||||
by_ref_span = Some(span);
|
||||
}
|
||||
@ -491,7 +501,11 @@ fn check_legality_of_move_bindings(cx: &MatchVisitor,
|
||||
for pat in pats {
|
||||
pat.walk(|p| {
|
||||
if let PatKind::Binding(_, _, _, ref sub) = p.node {
|
||||
let bm = *cx.tables.pat_binding_modes.get(&p.id).expect("missing binding mode");
|
||||
cx.tables.validate_hir_id(p.hir_id);
|
||||
let bm = *cx.tables
|
||||
.pat_binding_modes
|
||||
.get(&p.hir_id.local_id)
|
||||
.expect("missing binding mode");
|
||||
match bm {
|
||||
ty::BindByValue(..) => {
|
||||
let pat_ty = cx.tables.node_id_to_type(p.hir_id);
|
||||
|
@ -381,7 +381,7 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> {
|
||||
ty::TyRef(r, _) => Some(r),
|
||||
_ => None,
|
||||
};
|
||||
let bm = *self.tables.pat_binding_modes.get(&pat.id)
|
||||
let bm = *self.tables.pat_binding_modes.get(&pat.hir_id.local_id)
|
||||
.expect("missing binding mode");
|
||||
let (mutability, mode) = match bm {
|
||||
ty::BindByValue(hir::MutMutable) =>
|
||||
|
@ -45,7 +45,9 @@ impl UnusedMut {
|
||||
let mut mutables = FxHashMap();
|
||||
for p in pats {
|
||||
p.each_binding(|_, id, span, path1| {
|
||||
let bm = match cx.tables.pat_binding_modes.get(&id) {
|
||||
let hir_id = cx.tcx.hir.node_to_hir_id(id);
|
||||
cx.tables.validate_hir_id(hir_id);
|
||||
let bm = match cx.tables.pat_binding_modes.get(&hir_id.local_id) {
|
||||
Some(&bm) => bm,
|
||||
None => span_bug!(span, "missing binding mode"),
|
||||
};
|
||||
|
@ -118,8 +118,11 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||
// identical to what could be scraped from the HIR, but this will change with
|
||||
// default binding modes (#42640).
|
||||
let bm = ty::BindingMode::convert(ba);
|
||||
self.inh.tables.borrow_mut().pat_binding_modes.insert(pat.id, bm);
|
||||
|
||||
{
|
||||
let mut inh_tables = self.inh.tables.borrow_mut();
|
||||
inh_tables.validate_hir_id(pat.hir_id);
|
||||
inh_tables.pat_binding_modes.insert(pat.hir_id.local_id, bm);
|
||||
}
|
||||
let typ = self.local_ty(pat.span, pat.id);
|
||||
match bm {
|
||||
ty::BindByReference(mutbl) => {
|
||||
|
@ -1205,7 +1205,8 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> {
|
||||
match sub_pat.node {
|
||||
// `ref x` pattern
|
||||
PatKind::Binding(..) => {
|
||||
let bm = *mc.tables.pat_binding_modes.get(&sub_pat.id)
|
||||
mc.tables.validate_hir_id(sub_pat.hir_id);
|
||||
let bm = *mc.tables.pat_binding_modes.get(&sub_pat.hir_id.local_id)
|
||||
.expect("missing binding mode");
|
||||
if let ty::BindByReference(mutbl) = bm {
|
||||
self.link_region_from_node_type(sub_pat.span, sub_pat.hir_id,
|
||||
|
@ -186,9 +186,14 @@ impl<'cx, 'gcx, 'tcx> Visitor<'gcx> for WritebackCx<'cx, 'gcx, 'tcx> {
|
||||
fn visit_pat(&mut self, p: &'gcx hir::Pat) {
|
||||
match p.node {
|
||||
hir::PatKind::Binding(..) => {
|
||||
let bm = *self.fcx.tables.borrow().pat_binding_modes.get(&p.id)
|
||||
.expect("missing binding mode");
|
||||
self.tables.pat_binding_modes.insert(p.id, bm);
|
||||
let bm = {
|
||||
let fcx_tables = self.fcx.tables.borrow();
|
||||
fcx_tables.validate_hir_id(p.hir_id);
|
||||
*fcx_tables.pat_binding_modes.get(&p.hir_id.local_id)
|
||||
.expect("missing binding mode")
|
||||
};
|
||||
self.tables.validate_hir_id(p.hir_id);
|
||||
self.tables.pat_binding_modes.insert(p.hir_id.local_id, bm);
|
||||
}
|
||||
_ => {}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user