mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-22 03:44:24 +00:00
Change enclosing_body_owner to return LocalDefId
Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>
This commit is contained in:
parent
16513d689e
commit
0c609a4c1f
@ -853,7 +853,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
||||
let closure_id = self.mir_hir_id();
|
||||
let fn_call_id = hir.get_parent_node(closure_id);
|
||||
let node = hir.get(fn_call_id);
|
||||
let item_id = hir.enclosing_body_owner(fn_call_id);
|
||||
let def_id = hir.enclosing_body_owner(fn_call_id);
|
||||
let mut look_at_return = true;
|
||||
// If we can detect the expression to be an `fn` call where the closure was an argument,
|
||||
// we point at the `fn` definition argument...
|
||||
@ -864,7 +864,6 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
||||
.filter(|(_, arg)| arg.hir_id == closure_id)
|
||||
.map(|(pos, _)| pos)
|
||||
.next();
|
||||
let def_id = hir.local_def_id(item_id);
|
||||
let tables = self.infcx.tcx.typeck(def_id);
|
||||
if let Some(ty::FnDef(def_id, _)) =
|
||||
tables.node_type_opt(func.hir_id).as_ref().map(|ty| ty.kind())
|
||||
|
@ -396,10 +396,10 @@ impl<'hir> Map<'hir> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn enclosing_body_owner(self, hir_id: HirId) -> HirId {
|
||||
pub fn enclosing_body_owner(self, hir_id: HirId) -> LocalDefId {
|
||||
for (parent, _) in self.parent_iter(hir_id) {
|
||||
if let Some(local_did) = parent.as_owner() && let Some(body) = self.maybe_body_owned_by(local_did) {
|
||||
return self.body_owner(body);
|
||||
if let Some(body) = self.find(parent).map(associated_body).flatten() {
|
||||
return self.body_owner_def_id(body);
|
||||
}
|
||||
}
|
||||
|
||||
@ -671,7 +671,7 @@ impl<'hir> Map<'hir> {
|
||||
/// Whether the expression pointed at by `hir_id` belongs to a `const` evaluation context.
|
||||
/// Used exclusively for diagnostics, to avoid suggestion function calls.
|
||||
pub fn is_inside_const_context(self, hir_id: HirId) -> bool {
|
||||
self.body_const_context(self.local_def_id(self.enclosing_body_owner(hir_id))).is_some()
|
||||
self.body_const_context(self.enclosing_body_owner(hir_id)).is_some()
|
||||
}
|
||||
|
||||
/// Retrieves the `HirId` for `id`'s enclosing method, unless there's a
|
||||
|
@ -626,7 +626,7 @@ pub fn check_unsafety<'tcx>(tcx: TyCtxt<'tcx>, def: ty::WithOptConstParam<LocalD
|
||||
if tcx.is_closure(def.did.to_def_id()) {
|
||||
let hir = tcx.hir();
|
||||
let owner = hir.enclosing_body_owner(hir.local_def_id_to_hir_id(def.did));
|
||||
tcx.ensure().thir_check_unsafety(hir.local_def_id(owner));
|
||||
tcx.ensure().thir_check_unsafety(owner);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -766,10 +766,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
|
||||
// If this didn't hold, we would not have to report an error in
|
||||
// the first place.
|
||||
assert_ne!(hir::HirId::make_owner(encl_item_id), encl_body_owner_id);
|
||||
assert_ne!(encl_item_id, encl_body_owner_id);
|
||||
|
||||
let encl_body_id =
|
||||
self.tcx.hir().body_owned_by(self.tcx.hir().local_def_id(encl_body_owner_id));
|
||||
let encl_body_id = self.tcx.hir().body_owned_by(encl_body_owner_id);
|
||||
let encl_body = self.tcx.hir().body(encl_body_id);
|
||||
|
||||
err.encl_body_span = Some(encl_body.value.span);
|
||||
|
@ -58,7 +58,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
debug!("FnCtxt::check_asm: {} deferred checks", deferred_asm_checks.len());
|
||||
for (asm, hir_id) in deferred_asm_checks.drain(..) {
|
||||
let enclosing_id = self.tcx.hir().enclosing_body_owner(hir_id);
|
||||
InlineAsmCtxt::new_in_fn(self).check_asm(asm, enclosing_id);
|
||||
InlineAsmCtxt::new_in_fn(self)
|
||||
.check_asm(asm, self.tcx.hir().local_def_id_to_hir_id(enclosing_id));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -100,7 +100,7 @@ pub(super) fn opt_const_param_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<
|
||||
ExprKind::MethodCall(segment, ..) | ExprKind::Path(QPath::TypeRelative(_, segment)),
|
||||
..
|
||||
}) => {
|
||||
let body_owner = tcx.hir().local_def_id(tcx.hir().enclosing_body_owner(hir_id));
|
||||
let body_owner = tcx.hir().enclosing_body_owner(hir_id);
|
||||
let tables = tcx.typeck(body_owner);
|
||||
// This may fail in case the method/path does not actually exist.
|
||||
// As there is no relevant param for `def_id`, we simply return
|
||||
@ -134,7 +134,7 @@ pub(super) fn opt_const_param_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<
|
||||
| ExprKind::Struct(&QPath::Resolved(_, path), ..),
|
||||
..
|
||||
}) => {
|
||||
let body_owner = tcx.hir().local_def_id(tcx.hir().enclosing_body_owner(hir_id));
|
||||
let body_owner = tcx.hir().enclosing_body_owner(hir_id);
|
||||
let _tables = tcx.typeck(body_owner);
|
||||
&*path
|
||||
}
|
||||
|
@ -1353,7 +1353,7 @@ pub fn is_integer_const(cx: &LateContext<'_>, e: &Expr<'_>, value: u128) -> bool
|
||||
if is_integer_literal(e, value) {
|
||||
return true;
|
||||
}
|
||||
let enclosing_body = cx.tcx.hir().local_def_id(cx.tcx.hir().enclosing_body_owner(e.hir_id));
|
||||
let enclosing_body = cx.tcx.hir().enclosing_body_owner(e.hir_id);
|
||||
if let Some((Constant::Int(v), _)) = constant(cx, cx.tcx.typeck(enclosing_body), e) {
|
||||
return value == v;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user