Skip to content

Commit 0c609a4

Browse files
committed
Change enclosing_body_owner to return LocalDefId
Signed-off-by: Miguel Guarniz <[email protected]>
1 parent 16513d6 commit 0c609a4

File tree

7 files changed

+13
-14
lines changed

7 files changed

+13
-14
lines changed

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -853,7 +853,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
853853
let closure_id = self.mir_hir_id();
854854
let fn_call_id = hir.get_parent_node(closure_id);
855855
let node = hir.get(fn_call_id);
856-
let item_id = hir.enclosing_body_owner(fn_call_id);
856+
let def_id = hir.enclosing_body_owner(fn_call_id);
857857
let mut look_at_return = true;
858858
// If we can detect the expression to be an `fn` call where the closure was an argument,
859859
// we point at the `fn` definition argument...
@@ -864,7 +864,6 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
864864
.filter(|(_, arg)| arg.hir_id == closure_id)
865865
.map(|(pos, _)| pos)
866866
.next();
867-
let def_id = hir.local_def_id(item_id);
868867
let tables = self.infcx.tcx.typeck(def_id);
869868
if let Some(ty::FnDef(def_id, _)) =
870869
tables.node_type_opt(func.hir_id).as_ref().map(|ty| ty.kind())

compiler/rustc_middle/src/hir/map/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -396,10 +396,10 @@ impl<'hir> Map<'hir> {
396396
}
397397
}
398398

399-
pub fn enclosing_body_owner(self, hir_id: HirId) -> HirId {
399+
pub fn enclosing_body_owner(self, hir_id: HirId) -> LocalDefId {
400400
for (parent, _) in self.parent_iter(hir_id) {
401-
if let Some(local_did) = parent.as_owner() && let Some(body) = self.maybe_body_owned_by(local_did) {
402-
return self.body_owner(body);
401+
if let Some(body) = self.find(parent).map(associated_body).flatten() {
402+
return self.body_owner_def_id(body);
403403
}
404404
}
405405

@@ -671,7 +671,7 @@ impl<'hir> Map<'hir> {
671671
/// Whether the expression pointed at by `hir_id` belongs to a `const` evaluation context.
672672
/// Used exclusively for diagnostics, to avoid suggestion function calls.
673673
pub fn is_inside_const_context(self, hir_id: HirId) -> bool {
674-
self.body_const_context(self.local_def_id(self.enclosing_body_owner(hir_id))).is_some()
674+
self.body_const_context(self.enclosing_body_owner(hir_id)).is_some()
675675
}
676676

677677
/// Retrieves the `HirId` for `id`'s enclosing method, unless there's a

compiler/rustc_mir_build/src/check_unsafety.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ pub fn check_unsafety<'tcx>(tcx: TyCtxt<'tcx>, def: ty::WithOptConstParam<LocalD
626626
if tcx.is_closure(def.did.to_def_id()) {
627627
let hir = tcx.hir();
628628
let owner = hir.enclosing_body_owner(hir.local_def_id_to_hir_id(def.did));
629-
tcx.ensure().thir_check_unsafety(hir.local_def_id(owner));
629+
tcx.ensure().thir_check_unsafety(owner);
630630
return;
631631
}
632632

compiler/rustc_typeck/src/check/expr.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -766,10 +766,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
766766

767767
// If this didn't hold, we would not have to report an error in
768768
// the first place.
769-
assert_ne!(hir::HirId::make_owner(encl_item_id), encl_body_owner_id);
769+
assert_ne!(encl_item_id, encl_body_owner_id);
770770

771-
let encl_body_id =
772-
self.tcx.hir().body_owned_by(self.tcx.hir().local_def_id(encl_body_owner_id));
771+
let encl_body_id = self.tcx.hir().body_owned_by(encl_body_owner_id);
773772
let encl_body = self.tcx.hir().body(encl_body_id);
774773

775774
err.encl_body_span = Some(encl_body.value.span);

compiler/rustc_typeck/src/check/fn_ctxt/checks.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
5858
debug!("FnCtxt::check_asm: {} deferred checks", deferred_asm_checks.len());
5959
for (asm, hir_id) in deferred_asm_checks.drain(..) {
6060
let enclosing_id = self.tcx.hir().enclosing_body_owner(hir_id);
61-
InlineAsmCtxt::new_in_fn(self).check_asm(asm, enclosing_id);
61+
InlineAsmCtxt::new_in_fn(self)
62+
.check_asm(asm, self.tcx.hir().local_def_id_to_hir_id(enclosing_id));
6263
}
6364
}
6465

compiler/rustc_typeck/src/collect/type_of.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ pub(super) fn opt_const_param_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<
100100
ExprKind::MethodCall(segment, ..) | ExprKind::Path(QPath::TypeRelative(_, segment)),
101101
..
102102
}) => {
103-
let body_owner = tcx.hir().local_def_id(tcx.hir().enclosing_body_owner(hir_id));
103+
let body_owner = tcx.hir().enclosing_body_owner(hir_id);
104104
let tables = tcx.typeck(body_owner);
105105
// This may fail in case the method/path does not actually exist.
106106
// 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<
134134
| ExprKind::Struct(&QPath::Resolved(_, path), ..),
135135
..
136136
}) => {
137-
let body_owner = tcx.hir().local_def_id(tcx.hir().enclosing_body_owner(hir_id));
137+
let body_owner = tcx.hir().enclosing_body_owner(hir_id);
138138
let _tables = tcx.typeck(body_owner);
139139
&*path
140140
}

src/tools/clippy/clippy_utils/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1353,7 +1353,7 @@ pub fn is_integer_const(cx: &LateContext<'_>, e: &Expr<'_>, value: u128) -> bool
13531353
if is_integer_literal(e, value) {
13541354
return true;
13551355
}
1356-
let enclosing_body = cx.tcx.hir().local_def_id(cx.tcx.hir().enclosing_body_owner(e.hir_id));
1356+
let enclosing_body = cx.tcx.hir().enclosing_body_owner(e.hir_id);
13571357
if let Some((Constant::Int(v), _)) = constant(cx, cx.tcx.typeck(enclosing_body), e) {
13581358
return value == v;
13591359
}

0 commit comments

Comments
 (0)