Skip to content

Commit

Permalink
Change enclosing_body_owner to return LocalDefId
Browse files Browse the repository at this point in the history
Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>
  • Loading branch information
kckeiks committed Jul 29, 2022
1 parent 16513d6 commit 0c609a4
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 14 deletions.
3 changes: 1 addition & 2 deletions compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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...
Expand All @@ -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())
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_middle/src/hir/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_build/src/check_unsafety.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_typeck/src/check/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_typeck/src/check/fn_ctxt/checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_typeck/src/collect/type_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/clippy_utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 0c609a4

Please sign in to comment.