Auto merge of #51321 - zackmdavis:hiridification_generations, r=eddyb
HirId-ification, continued Another incremental step towards the vision of #50928 (previously: #50929). r? @michaelwoerister
This commit is contained in:
commit
b58b721921
@ -319,7 +319,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
|
|||||||
let fn_body_scope_r =
|
let fn_body_scope_r =
|
||||||
self.tcx().mk_region(ty::ReScope(region::Scope::Node(body.value.hir_id.local_id)));
|
self.tcx().mk_region(ty::ReScope(region::Scope::Node(body.value.hir_id.local_id)));
|
||||||
let arg_cmt = Rc::new(self.mc.cat_rvalue(
|
let arg_cmt = Rc::new(self.mc.cat_rvalue(
|
||||||
arg.id,
|
arg.hir_id,
|
||||||
arg.pat.span,
|
arg.pat.span,
|
||||||
fn_body_scope_r, // Args live only as long as the fn body.
|
fn_body_scope_r, // Args live only as long as the fn body.
|
||||||
arg_ty));
|
arg_ty));
|
||||||
@ -860,7 +860,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
|
|||||||
// Each match binding is effectively an assignment to the
|
// Each match binding is effectively an assignment to the
|
||||||
// binding being produced.
|
// binding being produced.
|
||||||
let def = Def::Local(canonical_id);
|
let def = Def::Local(canonical_id);
|
||||||
if let Ok(ref binding_cmt) = mc.cat_def(pat.id, pat.span, pat_ty, def) {
|
if let Ok(ref binding_cmt) = mc.cat_def(pat.hir_id, pat.span, pat_ty, def) {
|
||||||
delegate.mutate(pat.id, pat.span, binding_cmt, MutateMode::Init);
|
delegate.mutate(pat.id, pat.span, binding_cmt, MutateMode::Init);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -923,7 +923,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
|
|||||||
closure_expr_id: closure_def_id.to_local(),
|
closure_expr_id: closure_def_id.to_local(),
|
||||||
};
|
};
|
||||||
let upvar_capture = self.mc.tables.upvar_capture(upvar_id);
|
let upvar_capture = self.mc.tables.upvar_capture(upvar_id);
|
||||||
let cmt_var = return_if_err!(self.cat_captured_var(closure_expr.id,
|
let cmt_var = return_if_err!(self.cat_captured_var(closure_expr.hir_id,
|
||||||
fn_decl_span,
|
fn_decl_span,
|
||||||
freevar));
|
freevar));
|
||||||
match upvar_capture {
|
match upvar_capture {
|
||||||
@ -948,7 +948,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn cat_captured_var(&mut self,
|
fn cat_captured_var(&mut self,
|
||||||
closure_id: ast::NodeId,
|
closure_hir_id: hir::HirId,
|
||||||
closure_span: Span,
|
closure_span: Span,
|
||||||
upvar: &hir::Freevar)
|
upvar: &hir::Freevar)
|
||||||
-> mc::McResult<mc::cmt_<'tcx>> {
|
-> mc::McResult<mc::cmt_<'tcx>> {
|
||||||
@ -956,7 +956,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
|
|||||||
// caller's perspective
|
// caller's perspective
|
||||||
let var_hir_id = self.tcx().hir.node_to_hir_id(upvar.var_id());
|
let var_hir_id = self.tcx().hir.node_to_hir_id(upvar.var_id());
|
||||||
let var_ty = self.mc.node_ty(var_hir_id)?;
|
let var_ty = self.mc.node_ty(var_hir_id)?;
|
||||||
self.mc.cat_def(closure_id, closure_span, var_ty, upvar.def)
|
self.mc.cat_def(closure_hir_id, closure_span, var_ty, upvar.def)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -179,17 +179,21 @@ pub enum Note {
|
|||||||
// and how it is located, as well as the mutability of the memory in
|
// and how it is located, as well as the mutability of the memory in
|
||||||
// which the value is stored.
|
// which the value is stored.
|
||||||
//
|
//
|
||||||
// *WARNING* The field `cmt.ty` is NOT necessarily the same as the
|
// *WARNING* The field `cmt.type` is NOT necessarily the same as the
|
||||||
// result of `node_id_to_type(cmt.id)`. This is because the `id` is
|
// result of `node_id_to_type(cmt.id)`.
|
||||||
// always the `id` of the node producing the type; in an expression
|
//
|
||||||
// like `*x`, the type of this deref node is the deref'd type (`T`),
|
// (FIXME: rewrite the following comment given that `@x` managed
|
||||||
// but in a pattern like `@x`, the `@x` pattern is again a
|
// pointers have been obsolete for quite some time.)
|
||||||
// dereference, but its type is the type *before* the dereference
|
//
|
||||||
// (`@T`). So use `cmt.ty` to find the type of the value in a consistent
|
// This is because the `id` is always the `id` of the node producing the
|
||||||
// fashion. For more details, see the method `cat_pattern`
|
// type; in an expression like `*x`, the type of this deref node is the
|
||||||
|
// deref'd type (`T`), but in a pattern like `@x`, the `@x` pattern is
|
||||||
|
// again a dereference, but its type is the type *before* the
|
||||||
|
// dereference (`@T`). So use `cmt.ty` to find the type of the value in
|
||||||
|
// a consistent fashion. For more details, see the method `cat_pattern`
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
pub struct cmt_<'tcx> {
|
pub struct cmt_<'tcx> {
|
||||||
pub id: ast::NodeId, // id of expr/pat producing this value
|
pub hir_id: hir::HirId, // HIR id of expr/pat producing this value
|
||||||
pub span: Span, // span of same expr/pat
|
pub span: Span, // span of same expr/pat
|
||||||
pub cat: Categorization<'tcx>, // categorization of expr
|
pub cat: Categorization<'tcx>, // categorization of expr
|
||||||
pub mutbl: MutabilityCategory, // mutability of expr as place
|
pub mutbl: MutabilityCategory, // mutability of expr as place
|
||||||
@ -271,18 +275,18 @@ impl<'tcx> cmt_<'tcx> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait ast_node {
|
pub trait HirNode {
|
||||||
fn id(&self) -> ast::NodeId;
|
fn hir_id(&self) -> hir::HirId;
|
||||||
fn span(&self) -> Span;
|
fn span(&self) -> Span;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ast_node for hir::Expr {
|
impl HirNode for hir::Expr {
|
||||||
fn id(&self) -> ast::NodeId { self.id }
|
fn hir_id(&self) -> hir::HirId { self.hir_id }
|
||||||
fn span(&self) -> Span { self.span }
|
fn span(&self) -> Span { self.span }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ast_node for hir::Pat {
|
impl HirNode for hir::Pat {
|
||||||
fn id(&self) -> ast::NodeId { self.id }
|
fn hir_id(&self) -> hir::HirId { self.hir_id }
|
||||||
fn span(&self) -> Span { self.span }
|
fn span(&self) -> Span { self.span }
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -610,7 +614,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
|
|||||||
ty: target,
|
ty: target,
|
||||||
mutbl: deref.mutbl,
|
mutbl: deref.mutbl,
|
||||||
});
|
});
|
||||||
self.cat_rvalue_node(expr.id, expr.span, ref_ty)
|
self.cat_rvalue_node(expr.hir_id, expr.span, ref_ty)
|
||||||
} else {
|
} else {
|
||||||
previous()?
|
previous()?
|
||||||
});
|
});
|
||||||
@ -625,7 +629,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
|
|||||||
adjustment::Adjust::Borrow(_) |
|
adjustment::Adjust::Borrow(_) |
|
||||||
adjustment::Adjust::Unsize => {
|
adjustment::Adjust::Unsize => {
|
||||||
// Result is an rvalue.
|
// Result is an rvalue.
|
||||||
Ok(self.cat_rvalue_node(expr.id, expr.span, target))
|
Ok(self.cat_rvalue_node(expr.hir_id, expr.span, target))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -670,7 +674,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
|
|||||||
|
|
||||||
hir::ExprPath(ref qpath) => {
|
hir::ExprPath(ref qpath) => {
|
||||||
let def = self.tables.qpath_def(qpath, expr.hir_id);
|
let def = self.tables.qpath_def(qpath, expr.hir_id);
|
||||||
self.cat_def(expr.id, expr.span, expr_ty, def)
|
self.cat_def(expr.hir_id, expr.span, expr_ty, def)
|
||||||
}
|
}
|
||||||
|
|
||||||
hir::ExprType(ref e, _) => {
|
hir::ExprType(ref e, _) => {
|
||||||
@ -688,35 +692,35 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
|
|||||||
hir::ExprLit(..) | hir::ExprBreak(..) |
|
hir::ExprLit(..) | hir::ExprBreak(..) |
|
||||||
hir::ExprContinue(..) | hir::ExprStruct(..) | hir::ExprRepeat(..) |
|
hir::ExprContinue(..) | hir::ExprStruct(..) | hir::ExprRepeat(..) |
|
||||||
hir::ExprInlineAsm(..) | hir::ExprBox(..) => {
|
hir::ExprInlineAsm(..) | hir::ExprBox(..) => {
|
||||||
Ok(self.cat_rvalue_node(expr.id(), expr.span(), expr_ty))
|
Ok(self.cat_rvalue_node(expr.hir_id, expr.span, expr_ty))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn cat_def(&self,
|
pub fn cat_def(&self,
|
||||||
id: ast::NodeId,
|
hir_id: hir::HirId,
|
||||||
span: Span,
|
span: Span,
|
||||||
expr_ty: Ty<'tcx>,
|
expr_ty: Ty<'tcx>,
|
||||||
def: Def)
|
def: Def)
|
||||||
-> McResult<cmt_<'tcx>> {
|
-> McResult<cmt_<'tcx>> {
|
||||||
debug!("cat_def: id={} expr={:?} def={:?}",
|
debug!("cat_def: id={:?} expr={:?} def={:?}",
|
||||||
id, expr_ty, def);
|
hir_id, expr_ty, def);
|
||||||
|
|
||||||
match def {
|
match def {
|
||||||
Def::StructCtor(..) | Def::VariantCtor(..) | Def::Const(..) |
|
Def::StructCtor(..) | Def::VariantCtor(..) | Def::Const(..) |
|
||||||
Def::AssociatedConst(..) | Def::Fn(..) | Def::Method(..) => {
|
Def::AssociatedConst(..) | Def::Fn(..) | Def::Method(..) => {
|
||||||
Ok(self.cat_rvalue_node(id, span, expr_ty))
|
Ok(self.cat_rvalue_node(hir_id, span, expr_ty))
|
||||||
}
|
}
|
||||||
|
|
||||||
Def::Static(def_id, mutbl) => {
|
Def::Static(def_id, mutbl) => {
|
||||||
// `#[thread_local]` statics may not outlive the current function.
|
// `#[thread_local]` statics may not outlive the current function.
|
||||||
for attr in &self.tcx.get_attrs(def_id)[..] {
|
for attr in &self.tcx.get_attrs(def_id)[..] {
|
||||||
if attr.check_name("thread_local") {
|
if attr.check_name("thread_local") {
|
||||||
return Ok(self.cat_rvalue_node(id, span, expr_ty));
|
return Ok(self.cat_rvalue_node(hir_id, span, expr_ty));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(cmt_ {
|
Ok(cmt_ {
|
||||||
id:id,
|
hir_id,
|
||||||
span:span,
|
span:span,
|
||||||
cat:Categorization::StaticItem,
|
cat:Categorization::StaticItem,
|
||||||
mutbl: if mutbl { McDeclared } else { McImmutable},
|
mutbl: if mutbl { McDeclared } else { McImmutable},
|
||||||
@ -726,12 +730,12 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Def::Upvar(var_id, _, fn_node_id) => {
|
Def::Upvar(var_id, _, fn_node_id) => {
|
||||||
self.cat_upvar(id, span, var_id, fn_node_id)
|
self.cat_upvar(hir_id, span, var_id, fn_node_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
Def::Local(vid) => {
|
Def::Local(vid) => {
|
||||||
Ok(cmt_ {
|
Ok(cmt_ {
|
||||||
id,
|
hir_id,
|
||||||
span,
|
span,
|
||||||
cat: Categorization::Local(vid),
|
cat: Categorization::Local(vid),
|
||||||
mutbl: MutabilityCategory::from_local(self.tcx, self.tables, vid),
|
mutbl: MutabilityCategory::from_local(self.tcx, self.tables, vid),
|
||||||
@ -747,7 +751,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
|
|||||||
// Categorize an upvar, complete with invisible derefs of closure
|
// Categorize an upvar, complete with invisible derefs of closure
|
||||||
// environment and upvar reference as appropriate.
|
// environment and upvar reference as appropriate.
|
||||||
fn cat_upvar(&self,
|
fn cat_upvar(&self,
|
||||||
id: ast::NodeId,
|
hir_id: hir::HirId,
|
||||||
span: Span,
|
span: Span,
|
||||||
var_id: ast::NodeId,
|
var_id: ast::NodeId,
|
||||||
fn_node_id: ast::NodeId)
|
fn_node_id: ast::NodeId)
|
||||||
@ -814,7 +818,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
|
|||||||
// from the environment (perhaps we should eventually desugar
|
// from the environment (perhaps we should eventually desugar
|
||||||
// this field further, but it will do for now).
|
// this field further, but it will do for now).
|
||||||
let cmt_result = cmt_ {
|
let cmt_result = cmt_ {
|
||||||
id,
|
hir_id,
|
||||||
span,
|
span,
|
||||||
cat: Categorization::Upvar(Upvar {id: upvar_id, kind: kind}),
|
cat: Categorization::Upvar(Upvar {id: upvar_id, kind: kind}),
|
||||||
mutbl: var_mutbl,
|
mutbl: var_mutbl,
|
||||||
@ -830,10 +834,10 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
|
|||||||
cmt_result
|
cmt_result
|
||||||
}
|
}
|
||||||
ty::ClosureKind::FnMut => {
|
ty::ClosureKind::FnMut => {
|
||||||
self.env_deref(id, span, upvar_id, var_mutbl, ty::MutBorrow, cmt_result)
|
self.env_deref(hir_id, span, upvar_id, var_mutbl, ty::MutBorrow, cmt_result)
|
||||||
}
|
}
|
||||||
ty::ClosureKind::Fn => {
|
ty::ClosureKind::Fn => {
|
||||||
self.env_deref(id, span, upvar_id, var_mutbl, ty::ImmBorrow, cmt_result)
|
self.env_deref(hir_id, span, upvar_id, var_mutbl, ty::ImmBorrow, cmt_result)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -848,7 +852,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
|
|||||||
ty::UpvarCapture::ByRef(upvar_borrow) => {
|
ty::UpvarCapture::ByRef(upvar_borrow) => {
|
||||||
let ptr = BorrowedPtr(upvar_borrow.kind, upvar_borrow.region);
|
let ptr = BorrowedPtr(upvar_borrow.kind, upvar_borrow.region);
|
||||||
cmt_ {
|
cmt_ {
|
||||||
id,
|
hir_id,
|
||||||
span,
|
span,
|
||||||
cat: Categorization::Deref(Rc::new(cmt_result), ptr),
|
cat: Categorization::Deref(Rc::new(cmt_result), ptr),
|
||||||
mutbl: MutabilityCategory::from_borrow_kind(upvar_borrow.kind),
|
mutbl: MutabilityCategory::from_borrow_kind(upvar_borrow.kind),
|
||||||
@ -864,7 +868,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn env_deref(&self,
|
fn env_deref(&self,
|
||||||
id: ast::NodeId,
|
hir_id: hir::HirId,
|
||||||
span: Span,
|
span: Span,
|
||||||
upvar_id: ty::UpvarId,
|
upvar_id: ty::UpvarId,
|
||||||
upvar_mutbl: MutabilityCategory,
|
upvar_mutbl: MutabilityCategory,
|
||||||
@ -908,7 +912,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let ret = cmt_ {
|
let ret = cmt_ {
|
||||||
id,
|
hir_id,
|
||||||
span,
|
span,
|
||||||
cat: Categorization::Deref(Rc::new(cmt_result), env_ptr),
|
cat: Categorization::Deref(Rc::new(cmt_result), env_ptr),
|
||||||
mutbl: deref_mutbl,
|
mutbl: deref_mutbl,
|
||||||
@ -932,17 +936,16 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn cat_rvalue_node(&self,
|
pub fn cat_rvalue_node(&self,
|
||||||
id: ast::NodeId,
|
hir_id: hir::HirId,
|
||||||
span: Span,
|
span: Span,
|
||||||
expr_ty: Ty<'tcx>)
|
expr_ty: Ty<'tcx>)
|
||||||
-> cmt_<'tcx> {
|
-> cmt_<'tcx> {
|
||||||
debug!(
|
debug!(
|
||||||
"cat_rvalue_node(id={:?}, span={:?}, expr_ty={:?})",
|
"cat_rvalue_node(id={:?}, span={:?}, expr_ty={:?})",
|
||||||
id,
|
hir_id,
|
||||||
span,
|
span,
|
||||||
expr_ty,
|
expr_ty,
|
||||||
);
|
);
|
||||||
let hir_id = self.tcx.hir.node_to_hir_id(id);
|
|
||||||
let promotable = self.rvalue_promotable_map.as_ref().map(|m| m.contains(&hir_id.local_id))
|
let promotable = self.rvalue_promotable_map.as_ref().map(|m| m.contains(&hir_id.local_id))
|
||||||
.unwrap_or(false);
|
.unwrap_or(false);
|
||||||
|
|
||||||
@ -970,18 +973,18 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
|
|||||||
} else {
|
} else {
|
||||||
self.temporary_scope(hir_id.local_id)
|
self.temporary_scope(hir_id.local_id)
|
||||||
};
|
};
|
||||||
let ret = self.cat_rvalue(id, span, re, expr_ty);
|
let ret = self.cat_rvalue(hir_id, span, re, expr_ty);
|
||||||
debug!("cat_rvalue_node ret {:?}", ret);
|
debug!("cat_rvalue_node ret {:?}", ret);
|
||||||
ret
|
ret
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn cat_rvalue(&self,
|
pub fn cat_rvalue(&self,
|
||||||
cmt_id: ast::NodeId,
|
cmt_hir_id: hir::HirId,
|
||||||
span: Span,
|
span: Span,
|
||||||
temp_scope: ty::Region<'tcx>,
|
temp_scope: ty::Region<'tcx>,
|
||||||
expr_ty: Ty<'tcx>) -> cmt_<'tcx> {
|
expr_ty: Ty<'tcx>) -> cmt_<'tcx> {
|
||||||
let ret = cmt_ {
|
let ret = cmt_ {
|
||||||
id:cmt_id,
|
hir_id: cmt_hir_id,
|
||||||
span:span,
|
span:span,
|
||||||
cat:Categorization::Rvalue(temp_scope),
|
cat:Categorization::Rvalue(temp_scope),
|
||||||
mutbl:McDeclared,
|
mutbl:McDeclared,
|
||||||
@ -992,7 +995,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
|
|||||||
ret
|
ret
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn cat_field<N:ast_node>(&self,
|
pub fn cat_field<N: HirNode>(&self,
|
||||||
node: &N,
|
node: &N,
|
||||||
base_cmt: cmt<'tcx>,
|
base_cmt: cmt<'tcx>,
|
||||||
f_index: usize,
|
f_index: usize,
|
||||||
@ -1000,7 +1003,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
|
|||||||
f_ty: Ty<'tcx>)
|
f_ty: Ty<'tcx>)
|
||||||
-> cmt_<'tcx> {
|
-> cmt_<'tcx> {
|
||||||
let ret = cmt_ {
|
let ret = cmt_ {
|
||||||
id: node.id(),
|
hir_id: node.hir_id(),
|
||||||
span: node.span(),
|
span: node.span(),
|
||||||
mutbl: base_cmt.mutbl.inherit(),
|
mutbl: base_cmt.mutbl.inherit(),
|
||||||
cat: Categorization::Interior(base_cmt,
|
cat: Categorization::Interior(base_cmt,
|
||||||
@ -1042,13 +1045,13 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
|
|||||||
mutbl,
|
mutbl,
|
||||||
});
|
});
|
||||||
|
|
||||||
let base_cmt = Rc::new(self.cat_rvalue_node(expr.id, expr.span, ref_ty));
|
let base_cmt = Rc::new(self.cat_rvalue_node(expr.hir_id, expr.span, ref_ty));
|
||||||
self.cat_deref(expr, base_cmt, note)
|
self.cat_deref(expr, base_cmt, note)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn cat_deref(
|
pub fn cat_deref(
|
||||||
&self,
|
&self,
|
||||||
node: &impl ast_node,
|
node: &impl HirNode,
|
||||||
base_cmt: cmt<'tcx>,
|
base_cmt: cmt<'tcx>,
|
||||||
note: Note,
|
note: Note,
|
||||||
) -> McResult<cmt_<'tcx>> {
|
) -> McResult<cmt_<'tcx>> {
|
||||||
@ -1074,7 +1077,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
|
|||||||
ref ty => bug!("unexpected type in cat_deref: {:?}", ty)
|
ref ty => bug!("unexpected type in cat_deref: {:?}", ty)
|
||||||
};
|
};
|
||||||
let ret = cmt_ {
|
let ret = cmt_ {
|
||||||
id: node.id(),
|
hir_id: node.hir_id(),
|
||||||
span: node.span(),
|
span: node.span(),
|
||||||
// For unique ptrs, we inherit mutability from the owning reference.
|
// For unique ptrs, we inherit mutability from the owning reference.
|
||||||
mutbl: MutabilityCategory::from_pointer_kind(base_cmt.mutbl, ptr),
|
mutbl: MutabilityCategory::from_pointer_kind(base_cmt.mutbl, ptr),
|
||||||
@ -1086,7 +1089,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
|
|||||||
Ok(ret)
|
Ok(ret)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cat_index<N:ast_node>(&self,
|
fn cat_index<N: HirNode>(&self,
|
||||||
elt: &N,
|
elt: &N,
|
||||||
base_cmt: cmt<'tcx>,
|
base_cmt: cmt<'tcx>,
|
||||||
element_ty: Ty<'tcx>,
|
element_ty: Ty<'tcx>,
|
||||||
@ -1106,7 +1109,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
|
|||||||
//! presuming that `base_cmt` is not of fixed-length type.
|
//! presuming that `base_cmt` is not of fixed-length type.
|
||||||
//!
|
//!
|
||||||
//! # Parameters
|
//! # Parameters
|
||||||
//! - `elt`: the AST node being indexed
|
//! - `elt`: the HIR node being indexed
|
||||||
//! - `base_cmt`: the cmt of `elt`
|
//! - `base_cmt`: the cmt of `elt`
|
||||||
|
|
||||||
let interior_elem = InteriorElement(context);
|
let interior_elem = InteriorElement(context);
|
||||||
@ -1115,14 +1118,14 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
|
|||||||
return Ok(ret);
|
return Ok(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn cat_imm_interior<N:ast_node>(&self,
|
pub fn cat_imm_interior<N:HirNode>(&self,
|
||||||
node: &N,
|
node: &N,
|
||||||
base_cmt: cmt<'tcx>,
|
base_cmt: cmt<'tcx>,
|
||||||
interior_ty: Ty<'tcx>,
|
interior_ty: Ty<'tcx>,
|
||||||
interior: InteriorKind)
|
interior: InteriorKind)
|
||||||
-> cmt_<'tcx> {
|
-> cmt_<'tcx> {
|
||||||
let ret = cmt_ {
|
let ret = cmt_ {
|
||||||
id: node.id(),
|
hir_id: node.hir_id(),
|
||||||
span: node.span(),
|
span: node.span(),
|
||||||
mutbl: base_cmt.mutbl.inherit(),
|
mutbl: base_cmt.mutbl.inherit(),
|
||||||
cat: Categorization::Interior(base_cmt, interior),
|
cat: Categorization::Interior(base_cmt, interior),
|
||||||
@ -1133,7 +1136,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
|
|||||||
ret
|
ret
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn cat_downcast_if_needed<N:ast_node>(&self,
|
pub fn cat_downcast_if_needed<N:HirNode>(&self,
|
||||||
node: &N,
|
node: &N,
|
||||||
base_cmt: cmt<'tcx>,
|
base_cmt: cmt<'tcx>,
|
||||||
variant_did: DefId)
|
variant_did: DefId)
|
||||||
@ -1143,7 +1146,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
|
|||||||
if self.tcx.adt_def(base_did).variants.len() != 1 {
|
if self.tcx.adt_def(base_did).variants.len() != 1 {
|
||||||
let base_ty = base_cmt.ty;
|
let base_ty = base_cmt.ty;
|
||||||
let ret = Rc::new(cmt_ {
|
let ret = Rc::new(cmt_ {
|
||||||
id: node.id(),
|
hir_id: node.hir_id(),
|
||||||
span: node.span(),
|
span: node.span(),
|
||||||
mutbl: base_cmt.mutbl.inherit(),
|
mutbl: base_cmt.mutbl.inherit(),
|
||||||
cat: Categorization::Downcast(base_cmt, variant_did),
|
cat: Categorization::Downcast(base_cmt, variant_did),
|
||||||
@ -1193,6 +1196,8 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
|
|||||||
// value, and I consider them to produce the value that was
|
// value, and I consider them to produce the value that was
|
||||||
// matched. So if you have something like:
|
// matched. So if you have something like:
|
||||||
//
|
//
|
||||||
|
// (FIXME: `@@3` is not legal code anymore!)
|
||||||
|
//
|
||||||
// let x = @@3;
|
// let x = @@3;
|
||||||
// match x {
|
// match x {
|
||||||
// @@y { ... }
|
// @@y { ... }
|
||||||
|
@ -459,7 +459,7 @@ struct RegionResolutionVisitor<'a, 'tcx: 'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct ExprLocatorVisitor {
|
struct ExprLocatorVisitor {
|
||||||
id: ast::NodeId,
|
hir_id: hir::HirId,
|
||||||
result: Option<usize>,
|
result: Option<usize>,
|
||||||
expr_and_pat_count: usize,
|
expr_and_pat_count: usize,
|
||||||
}
|
}
|
||||||
@ -476,7 +476,7 @@ impl<'tcx> Visitor<'tcx> for ExprLocatorVisitor {
|
|||||||
|
|
||||||
self.expr_and_pat_count += 1;
|
self.expr_and_pat_count += 1;
|
||||||
|
|
||||||
if pat.id == self.id {
|
if pat.hir_id == self.hir_id {
|
||||||
self.result = Some(self.expr_and_pat_count);
|
self.result = Some(self.expr_and_pat_count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -494,7 +494,7 @@ impl<'tcx> Visitor<'tcx> for ExprLocatorVisitor {
|
|||||||
self.expr_and_pat_count,
|
self.expr_and_pat_count,
|
||||||
expr);
|
expr);
|
||||||
|
|
||||||
if expr.id == self.id {
|
if expr.hir_id == self.hir_id {
|
||||||
self.result = Some(self.expr_and_pat_count);
|
self.result = Some(self.expr_and_pat_count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -778,11 +778,11 @@ impl<'tcx> ScopeTree {
|
|||||||
/// `scope` must be inside the body.
|
/// `scope` must be inside the body.
|
||||||
pub fn yield_in_scope_for_expr(&self,
|
pub fn yield_in_scope_for_expr(&self,
|
||||||
scope: Scope,
|
scope: Scope,
|
||||||
expr: ast::NodeId,
|
expr_hir_id: hir::HirId,
|
||||||
body: &'tcx hir::Body) -> Option<Span> {
|
body: &'tcx hir::Body) -> Option<Span> {
|
||||||
self.yield_in_scope(scope).and_then(|(span, count)| {
|
self.yield_in_scope(scope).and_then(|(span, count)| {
|
||||||
let mut visitor = ExprLocatorVisitor {
|
let mut visitor = ExprLocatorVisitor {
|
||||||
id: expr,
|
hir_id: expr_hir_id,
|
||||||
result: None,
|
result: None,
|
||||||
expr_and_pat_count: 0,
|
expr_and_pat_count: 0,
|
||||||
};
|
};
|
||||||
|
@ -168,8 +168,7 @@ impl<'a, 'tcx> euv::Delegate<'tcx> for CheckLoanCtxt<'a, 'tcx> {
|
|||||||
// have to be *FULLY* initialized, but we still
|
// have to be *FULLY* initialized, but we still
|
||||||
// must be careful lest it contains derefs of
|
// must be careful lest it contains derefs of
|
||||||
// pointers.
|
// pointers.
|
||||||
let hir_id = self.tcx().hir.node_to_hir_id(assignee_cmt.id);
|
self.check_if_assigned_path_is_moved(assignee_cmt.hir_id.local_id,
|
||||||
self.check_if_assigned_path_is_moved(hir_id.local_id,
|
|
||||||
assignment_span,
|
assignment_span,
|
||||||
MovedInUse,
|
MovedInUse,
|
||||||
&lp);
|
&lp);
|
||||||
@ -178,8 +177,7 @@ impl<'a, 'tcx> euv::Delegate<'tcx> for CheckLoanCtxt<'a, 'tcx> {
|
|||||||
// In a case like `path += 1`, then path must be
|
// In a case like `path += 1`, then path must be
|
||||||
// fully initialized, since we will read it before
|
// fully initialized, since we will read it before
|
||||||
// we write it.
|
// we write it.
|
||||||
let hir_id = self.tcx().hir.node_to_hir_id(assignee_cmt.id);
|
self.check_if_path_is_moved(assignee_cmt.hir_id.local_id,
|
||||||
self.check_if_path_is_moved(hir_id.local_id,
|
|
||||||
assignment_span,
|
assignment_span,
|
||||||
MovedInUse,
|
MovedInUse,
|
||||||
&lp);
|
&lp);
|
||||||
@ -448,7 +446,7 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
|
|||||||
if let Some(yield_span) = self.bccx
|
if let Some(yield_span) = self.bccx
|
||||||
.region_scope_tree
|
.region_scope_tree
|
||||||
.yield_in_scope_for_expr(scope,
|
.yield_in_scope_for_expr(scope,
|
||||||
cmt.id,
|
cmt.hir_id,
|
||||||
self.bccx.body) {
|
self.bccx.body) {
|
||||||
self.bccx.cannot_borrow_across_generator_yield(borrow_span,
|
self.bccx.cannot_borrow_across_generator_yield(borrow_span,
|
||||||
yield_span,
|
yield_span,
|
||||||
|
@ -283,7 +283,7 @@ impl<'a, 'tcx> GatherLoanCtxt<'a, 'tcx> {
|
|||||||
.local_id,
|
.local_id,
|
||||||
assignment_span,
|
assignment_span,
|
||||||
lp,
|
lp,
|
||||||
self.bccx.tcx.hir.node_to_hir_id(cmt.id).local_id,
|
cmt.hir_id.local_id,
|
||||||
mode);
|
mode);
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
|
@ -112,15 +112,15 @@ fn group_errors_with_same_origin<'tcx>(errors: &Vec<MoveError<'tcx>>)
|
|||||||
|
|
||||||
fn append_to_grouped_errors<'tcx>(grouped_errors: &mut Vec<GroupedMoveErrors<'tcx>>,
|
fn append_to_grouped_errors<'tcx>(grouped_errors: &mut Vec<GroupedMoveErrors<'tcx>>,
|
||||||
error: &MoveError<'tcx>) {
|
error: &MoveError<'tcx>) {
|
||||||
let move_from_id = error.move_from.id;
|
let move_from_id = error.move_from.hir_id;
|
||||||
debug!("append_to_grouped_errors(move_from_id={})", move_from_id);
|
debug!("append_to_grouped_errors(move_from_id={:?})", move_from_id);
|
||||||
let move_to = if error.move_to.is_some() {
|
let move_to = if error.move_to.is_some() {
|
||||||
vec![error.move_to.clone().unwrap()]
|
vec![error.move_to.clone().unwrap()]
|
||||||
} else {
|
} else {
|
||||||
Vec::new()
|
Vec::new()
|
||||||
};
|
};
|
||||||
for ge in &mut *grouped_errors {
|
for ge in &mut *grouped_errors {
|
||||||
if move_from_id == ge.move_from.id && error.move_to.is_some() {
|
if move_from_id == ge.move_from.hir_id && error.move_to.is_some() {
|
||||||
debug!("appending move_to to list");
|
debug!("appending move_to to list");
|
||||||
ge.move_to_places.extend(move_to);
|
ge.move_to_places.extend(move_to);
|
||||||
return
|
return
|
||||||
|
@ -899,7 +899,11 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
self.note_and_explain_mutbl_error(&mut db, &err, &error_span);
|
self.note_and_explain_mutbl_error(&mut db, &err, &error_span);
|
||||||
self.note_immutability_blame(&mut db, err.cmt.immutability_blame(), err.cmt.id);
|
self.note_immutability_blame(
|
||||||
|
&mut db,
|
||||||
|
err.cmt.immutability_blame(),
|
||||||
|
self.tcx.hir.hir_to_node_id(err.cmt.hir_id)
|
||||||
|
);
|
||||||
db.emit();
|
db.emit();
|
||||||
}
|
}
|
||||||
err_out_of_scope(super_scope, sub_scope, cause) => {
|
err_out_of_scope(super_scope, sub_scope, cause) => {
|
||||||
@ -1105,7 +1109,11 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
|
|||||||
Origin::Ast)
|
Origin::Ast)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
self.note_immutability_blame(&mut err, blame, cmt.id);
|
self.note_immutability_blame(
|
||||||
|
&mut err,
|
||||||
|
blame,
|
||||||
|
self.tcx.hir.hir_to_node_id(cmt.hir_id)
|
||||||
|
);
|
||||||
|
|
||||||
if is_closure {
|
if is_closure {
|
||||||
err.help("closures behind references must be called via `&mut`");
|
err.help("closures behind references must be called via `&mut`");
|
||||||
|
@ -1018,7 +1018,7 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> {
|
|||||||
let arg_ty = self.node_ty(arg.hir_id);
|
let arg_ty = self.node_ty(arg.hir_id);
|
||||||
let re_scope = self.tcx.mk_region(ty::ReScope(body_scope));
|
let re_scope = self.tcx.mk_region(ty::ReScope(body_scope));
|
||||||
let arg_cmt = self.with_mc(|mc| {
|
let arg_cmt = self.with_mc(|mc| {
|
||||||
Rc::new(mc.cat_rvalue(arg.id, arg.pat.span, re_scope, arg_ty))
|
Rc::new(mc.cat_rvalue(arg.hir_id, arg.pat.span, re_scope, arg_ty))
|
||||||
});
|
});
|
||||||
debug!("arg_ty={:?} arg_cmt={:?} arg={:?}",
|
debug!("arg_ty={:?} arg_cmt={:?} arg={:?}",
|
||||||
arg_ty,
|
arg_ty,
|
||||||
|
Loading…
Reference in New Issue
Block a user