For the HirIdification initiative #50928.
let fn_body_scope_r =
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 fn_body_scope_r =
self.tcx().mk_region(ty::ReScope(region::Scope::Node(body.value.hir_id.local_id)));
let arg_cmt = Rc::new(self.mc.cat_rvalue(
arg.pat.span,
fn_body_scope_r, // Args live only as long as the fn body.
arg_ty));
arg.pat.span,
fn_body_scope_r, // Args live only as long as the fn body.
arg_ty));
// Each match binding is effectively an assignment to the
// binding being produced.
let def = Def::Local(canonical_id);
// Each match binding is effectively an assignment to the
// binding being produced.
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);
}
closure_expr_id: closure_def_id.to_local(),
};
let upvar_capture = self.mc.tables.upvar_capture(upvar_id);
closure_expr_id: closure_def_id.to_local(),
};
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,
freevar));
match upvar_capture {
fn_decl_span,
freevar));
match upvar_capture {
}
fn cat_captured_var(&mut self,
}
fn cat_captured_var(&mut self,
- closure_id: ast::NodeId,
+ closure_hir_id: hir::HirId,
closure_span: Span,
upvar: &hir::Freevar)
-> mc::McResult<mc::cmt_<'tcx>> {
closure_span: Span,
upvar: &hir::Freevar)
-> mc::McResult<mc::cmt_<'tcx>> {
// caller's perspective
let var_hir_id = self.tcx().hir.node_to_hir_id(upvar.var_id());
let var_ty = self.mc.node_ty(var_hir_id)?;
// caller's perspective
let var_hir_id = self.tcx().hir.node_to_hir_id(upvar.var_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)
// fashion. For more details, see the method `cat_pattern`
#[derive(Clone, Debug, PartialEq)]
pub struct cmt_<'tcx> {
// fashion. For more details, see the method `cat_pattern`
#[derive(Clone, Debug, PartialEq)]
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 cat: Categorization<'tcx>, // categorization of expr
pub mutbl: MutabilityCategory, // mutability of expr as place
pub span: Span, // span of same expr/pat
pub cat: Categorization<'tcx>, // categorization of expr
pub mutbl: MutabilityCategory, // mutability of expr as place
-pub trait ast_node {
- fn id(&self) -> ast::NodeId;
+pub trait HirNode {
+ fn hir_id(&self) -> hir::HirId;
fn span(&self) -> Span;
}
fn span(&self) -> Span;
}
-impl ast_node for hir::Expr {
- fn id(&self) -> ast::NodeId { self.id }
+impl HirNode for hir::Expr {
+ 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 {
- fn id(&self) -> ast::NodeId { self.id }
+impl HirNode for hir::Pat {
+ fn hir_id(&self) -> hir::HirId { self.hir_id }
fn span(&self) -> Span { self.span }
}
fn span(&self) -> Span { self.span }
}
ty: target,
mutbl: deref.mutbl,
});
ty: target,
mutbl: deref.mutbl,
});
- self.cat_rvalue_node(expr.id, expr.span, ref_ty)
+ self.cat_rvalue_node(expr.hir_id, expr.span, ref_ty)
adjustment::Adjust::Borrow(_) |
adjustment::Adjust::Unsize => {
// Result is an rvalue.
adjustment::Adjust::Borrow(_) |
adjustment::Adjust::Unsize => {
// 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))
}
hir::ExprPath(ref qpath) => {
}
hir::ExprPath(ref qpath) => {
- let def = self.tables.qpath_def(qpath, expr.hir_id);
- self.cat_def(expr.id, expr.span, expr_ty, def)
+ let def = self.tables.qpath_def(qpath, expr.hir_id);
+ self.cat_def(expr.hir_id, expr.span, expr_ty, def)
}
hir::ExprType(ref e, _) => {
}
hir::ExprType(ref e, _) => {
hir::ExprLit(..) | hir::ExprBreak(..) |
hir::ExprContinue(..) | hir::ExprStruct(..) | hir::ExprRepeat(..) |
hir::ExprInlineAsm(..) | hir::ExprBox(..) => {
hir::ExprLit(..) | hir::ExprBreak(..) |
hir::ExprContinue(..) | hir::ExprStruct(..) | hir::ExprRepeat(..) |
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,
span: Span,
expr_ty: Ty<'tcx>,
def: Def)
-> McResult<cmt_<'tcx>> {
span: Span,
expr_ty: Ty<'tcx>,
def: Def)
-> McResult<cmt_<'tcx>> {
- debug!("cat_def: id={} expr={:?} def={:?}",
- id, expr_ty, def);
+ debug!("cat_def: id={:?} expr={:?} def={:?}",
+ hir_id, expr_ty, def);
match def {
Def::StructCtor(..) | Def::VariantCtor(..) | Def::Const(..) |
Def::AssociatedConst(..) | Def::Fn(..) | Def::Method(..) => {
match def {
Def::StructCtor(..) | Def::VariantCtor(..) | Def::Const(..) |
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) => {
// `#[thread_local]` statics may not outlive the current function.
for attr in &self.tcx.get_attrs(def_id)[..] {
if attr.check_name("thread_local") {
}
Def::Static(def_id, mutbl) => {
// `#[thread_local]` statics may not outlive the current function.
for attr in &self.tcx.get_attrs(def_id)[..] {
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));
span:span,
cat:Categorization::StaticItem,
mutbl: if mutbl { McDeclared } else { McImmutable},
span:span,
cat:Categorization::StaticItem,
mutbl: if mutbl { McDeclared } else { McImmutable},
}
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) => {
Ok(cmt_ {
}
Def::Local(vid) => {
Ok(cmt_ {
span,
cat: Categorization::Local(vid),
mutbl: MutabilityCategory::from_local(self.tcx, self.tables, vid),
span,
cat: Categorization::Local(vid),
mutbl: MutabilityCategory::from_local(self.tcx, self.tables, vid),
// Categorize an upvar, complete with invisible derefs of closure
// environment and upvar reference as appropriate.
fn cat_upvar(&self,
// Categorize an upvar, complete with invisible derefs of closure
// environment and upvar reference as appropriate.
fn cat_upvar(&self,
span: Span,
var_id: ast::NodeId,
fn_node_id: ast::NodeId)
span: Span,
var_id: ast::NodeId,
fn_node_id: ast::NodeId)
// from the environment (perhaps we should eventually desugar
// this field further, but it will do for now).
let cmt_result = cmt_ {
// from the environment (perhaps we should eventually desugar
// this field further, but it will do for now).
let cmt_result = cmt_ {
span,
cat: Categorization::Upvar(Upvar {id: upvar_id, kind: kind}),
mutbl: var_mutbl,
span,
cat: Categorization::Upvar(Upvar {id: upvar_id, kind: kind}),
mutbl: var_mutbl,
cmt_result
}
ty::ClosureKind::FnMut => {
cmt_result
}
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)
ty::UpvarCapture::ByRef(upvar_borrow) => {
let ptr = BorrowedPtr(upvar_borrow.kind, upvar_borrow.region);
cmt_ {
ty::UpvarCapture::ByRef(upvar_borrow) => {
let ptr = BorrowedPtr(upvar_borrow.kind, upvar_borrow.region);
cmt_ {
span,
cat: Categorization::Deref(Rc::new(cmt_result), ptr),
mutbl: MutabilityCategory::from_borrow_kind(upvar_borrow.kind),
span,
cat: Categorization::Deref(Rc::new(cmt_result), ptr),
mutbl: MutabilityCategory::from_borrow_kind(upvar_borrow.kind),
span: Span,
upvar_id: ty::UpvarId,
upvar_mutbl: MutabilityCategory,
span: Span,
upvar_id: ty::UpvarId,
upvar_mutbl: MutabilityCategory,
span,
cat: Categorization::Deref(Rc::new(cmt_result), env_ptr),
mutbl: deref_mutbl,
span,
cat: Categorization::Deref(Rc::new(cmt_result), env_ptr),
mutbl: deref_mutbl,
}
pub fn cat_rvalue_node(&self,
}
pub fn cat_rvalue_node(&self,
span: Span,
expr_ty: Ty<'tcx>)
-> cmt_<'tcx> {
debug!(
"cat_rvalue_node(id={:?}, span={:?}, expr_ty={:?})",
span: Span,
expr_ty: Ty<'tcx>)
-> cmt_<'tcx> {
debug!(
"cat_rvalue_node(id={:?}, span={:?}, 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))
.unwrap_or(false);
let promotable = self.rvalue_promotable_map.as_ref().map(|m| m.contains(&hir_id.local_id))
.unwrap_or(false);
} else {
self.temporary_scope(hir_id.local_id)
};
} else {
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);
ret
}
pub fn cat_rvalue(&self,
debug!("cat_rvalue_node ret {:?}", ret);
ret
}
pub fn cat_rvalue(&self,
+ cmt_hir_id: hir::HirId,
span: Span,
temp_scope: ty::Region<'tcx>,
expr_ty: Ty<'tcx>) -> cmt_<'tcx> {
let ret = cmt_ {
span: Span,
temp_scope: ty::Region<'tcx>,
expr_ty: Ty<'tcx>) -> cmt_<'tcx> {
let ret = cmt_ {
span:span,
cat:Categorization::Rvalue(temp_scope),
mutbl:McDeclared,
span:span,
cat:Categorization::Rvalue(temp_scope),
mutbl:McDeclared,
- pub fn cat_field<N:ast_node>(&self,
+ pub fn cat_field<N: HirNode>(&self,
node: &N,
base_cmt: cmt<'tcx>,
f_index: usize,
node: &N,
base_cmt: cmt<'tcx>,
f_index: usize,
f_ty: Ty<'tcx>)
-> cmt_<'tcx> {
let ret = cmt_ {
f_ty: Ty<'tcx>)
-> cmt_<'tcx> {
let ret = cmt_ {
span: node.span(),
mutbl: base_cmt.mutbl.inherit(),
cat: Categorization::Interior(base_cmt,
span: node.span(),
mutbl: base_cmt.mutbl.inherit(),
cat: Categorization::Interior(base_cmt,
- 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)
}
pub fn cat_deref(
&self,
self.cat_deref(expr, base_cmt, note)
}
pub fn cat_deref(
&self,
base_cmt: cmt<'tcx>,
note: Note,
) -> McResult<cmt_<'tcx>> {
base_cmt: cmt<'tcx>,
note: Note,
) -> McResult<cmt_<'tcx>> {
ref ty => bug!("unexpected type in cat_deref: {:?}", ty)
};
let ret = cmt_ {
ref ty => bug!("unexpected type in cat_deref: {:?}", ty)
};
let ret = cmt_ {
span: node.span(),
// For unique ptrs, we inherit mutability from the owning reference.
mutbl: MutabilityCategory::from_pointer_kind(base_cmt.mutbl, ptr),
span: node.span(),
// For unique ptrs, we inherit mutability from the owning reference.
mutbl: MutabilityCategory::from_pointer_kind(base_cmt.mutbl, ptr),
- fn cat_index<N:ast_node>(&self,
+ fn cat_index<N: HirNode>(&self,
elt: &N,
base_cmt: cmt<'tcx>,
element_ty: Ty<'tcx>,
elt: &N,
base_cmt: cmt<'tcx>,
element_ty: Ty<'tcx>,
//! presuming that `base_cmt` is not of fixed-length type.
//!
//! # Parameters
//! presuming that `base_cmt` is not of fixed-length type.
//!
//! # Parameters
- //! - `elt`: the AST node being indexed
+ //! - `elt`: the HIR node being indexed
//! - `base_cmt`: the cmt of `elt`
let interior_elem = InteriorElement(context);
//! - `base_cmt`: the cmt of `elt`
let interior_elem = InteriorElement(context);
- pub fn cat_imm_interior<N:ast_node>(&self,
+ pub fn cat_imm_interior<N:HirNode>(&self,
node: &N,
base_cmt: cmt<'tcx>,
interior_ty: Ty<'tcx>,
interior: InteriorKind)
-> cmt_<'tcx> {
let ret = cmt_ {
node: &N,
base_cmt: cmt<'tcx>,
interior_ty: Ty<'tcx>,
interior: InteriorKind)
-> cmt_<'tcx> {
let ret = cmt_ {
span: node.span(),
mutbl: base_cmt.mutbl.inherit(),
cat: Categorization::Interior(base_cmt, interior),
span: node.span(),
mutbl: base_cmt.mutbl.inherit(),
cat: Categorization::Interior(base_cmt, interior),
- pub fn cat_downcast_if_needed<N:ast_node>(&self,
+ pub fn cat_downcast_if_needed<N:HirNode>(&self,
node: &N,
base_cmt: cmt<'tcx>,
variant_did: DefId)
node: &N,
base_cmt: cmt<'tcx>,
variant_did: DefId)
if self.tcx.adt_def(base_did).variants.len() != 1 {
let base_ty = base_cmt.ty;
let ret = Rc::new(cmt_ {
if self.tcx.adt_def(base_did).variants.len() != 1 {
let base_ty = base_cmt.ty;
let ret = Rc::new(cmt_ {
span: node.span(),
mutbl: base_cmt.mutbl.inherit(),
cat: Categorization::Downcast(base_cmt, variant_did),
span: node.span(),
mutbl: base_cmt.mutbl.inherit(),
cat: Categorization::Downcast(base_cmt, variant_did),
}
struct ExprLocatorVisitor {
}
struct ExprLocatorVisitor {
result: Option<usize>,
expr_and_pat_count: usize,
}
result: Option<usize>,
expr_and_pat_count: usize,
}
self.expr_and_pat_count += 1;
self.expr_and_pat_count += 1;
+ if pat.hir_id == self.hir_id {
self.result = Some(self.expr_and_pat_count);
}
}
self.result = Some(self.expr_and_pat_count);
}
}
self.expr_and_pat_count,
expr);
self.expr_and_pat_count,
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);
}
}
/// `scope` must be inside the body.
pub fn yield_in_scope_for_expr(&self,
scope: Scope,
/// `scope` must be inside the body.
pub fn yield_in_scope_for_expr(&self,
scope: Scope,
+ expr_hir_id: hir::HirId,
body: &'tcx hir::Body) -> Option<Span> {
self.yield_in_scope(scope).and_then(|(span, count)| {
let mut visitor = ExprLocatorVisitor {
body: &'tcx hir::Body) -> Option<Span> {
self.yield_in_scope(scope).and_then(|(span, count)| {
let mut visitor = ExprLocatorVisitor {
result: None,
expr_and_pat_count: 0,
};
result: None,
expr_and_pat_count: 0,
};
// have to be *FULLY* initialized, but we still
// must be careful lest it contains derefs of
// pointers.
// have to be *FULLY* initialized, but we still
// must be careful lest it contains derefs of
// pointers.
- let hir_id = self.tcx().hir.node_to_hir_id(assignee_cmt.id);
- self.check_if_assigned_path_is_moved(hir_id.local_id,
+ self.check_if_assigned_path_is_moved(assignee_cmt.hir_id.local_id,
assignment_span,
MovedInUse,
&lp);
assignment_span,
MovedInUse,
&lp);
// In a case like `path += 1`, then path must be
// fully initialized, since we will read it before
// we write it.
// In a case like `path += 1`, then path must be
// fully initialized, since we will read it before
// we write it.
- let hir_id = self.tcx().hir.node_to_hir_id(assignee_cmt.id);
- self.check_if_path_is_moved(hir_id.local_id,
+ self.check_if_path_is_moved(assignee_cmt.hir_id.local_id,
assignment_span,
MovedInUse,
&lp);
assignment_span,
MovedInUse,
&lp);
if let Some(yield_span) = self.bccx
.region_scope_tree
.yield_in_scope_for_expr(scope,
if let Some(yield_span) = self.bccx
.region_scope_tree
.yield_in_scope_for_expr(scope,
self.bccx.body) {
self.bccx.cannot_borrow_across_generator_yield(borrow_span,
yield_span,
self.bccx.body) {
self.bccx.cannot_borrow_across_generator_yield(borrow_span,
yield_span,
.local_id,
assignment_span,
lp,
.local_id,
assignment_span,
lp,
- self.bccx.tcx.hir.node_to_hir_id(cmt.id).local_id,
fn append_to_grouped_errors<'tcx>(grouped_errors: &mut Vec<GroupedMoveErrors<'tcx>>,
error: &MoveError<'tcx>) {
fn append_to_grouped_errors<'tcx>(grouped_errors: &mut Vec<GroupedMoveErrors<'tcx>>,
error: &MoveError<'tcx>) {
- let move_from_id = error.move_from.id;
- debug!("append_to_grouped_errors(move_from_id={})", move_from_id);
+ let move_from_id = error.move_from.hir_id;
+ debug!("append_to_grouped_errors(move_from_id={:?})", move_from_id);
let move_to = if error.move_to.is_some() {
vec![error.move_to.clone().unwrap()]
} else {
Vec::new()
};
for ge in &mut *grouped_errors {
let move_to = if error.move_to.is_some() {
vec![error.move_to.clone().unwrap()]
} else {
Vec::new()
};
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");
ge.move_to_places.extend(move_to);
return
debug!("appending move_to to list");
ge.move_to_places.extend(move_to);
return
};
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();
}
err_out_of_scope(super_scope, sub_scope, cause) => {
db.emit();
}
err_out_of_scope(super_scope, sub_scope, cause) => {
- 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 {
err.help("closures behind references must be called via `&mut`");
if is_closure {
err.help("closures behind references must be called via `&mut`");
let arg_ty = self.node_ty(arg.hir_id);
let re_scope = self.tcx.mk_region(ty::ReScope(body_scope));
let arg_cmt = self.with_mc(|mc| {
let arg_ty = self.node_ty(arg.hir_id);
let re_scope = self.tcx.mk_region(ty::ReScope(body_scope));
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={:?}",
arg_ty,
});
debug!("arg_ty={:?} arg_cmt={:?} arg={:?}",
arg_ty,