Skip to content

Commit 084ce5b

Browse files
committed
Auto merge of rust-lang#120951 - matthiaskrgr:rollup-0nnm7dv, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - rust-lang#110483 (Create try_new function for ThinBox) - rust-lang#120740 (Make cmath.rs a single file) - rust-lang#120872 (hir: Refactor getters for HIR parents) - rust-lang#120880 (add note on comparing vtables / function pointers) - rust-lang#120885 (interpret/visitor: ensure we only see normalized types) - rust-lang#120888 (assert_unsafe_precondition cleanup) - rust-lang#120897 (Encode `coroutine_for_closure` for foreign crates) - rust-lang#120937 ([docs] Update armv6k-nintendo-3ds platform docs for outdated info) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 520b0b2 + 9bd630a commit 084ce5b

File tree

98 files changed

+524
-534
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+524
-534
lines changed

Diff for: compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -403,8 +403,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
403403
}
404404
}
405405
let typeck = self.infcx.tcx.typeck(self.mir_def_id());
406-
let hir_id = hir.parent_id(expr.hir_id);
407-
let parent = self.infcx.tcx.hir_node(hir_id);
406+
let parent = self.infcx.tcx.parent_hir_node(expr.hir_id);
408407
let (def_id, args, offset) = if let hir::Node::Expr(parent_expr) = parent
409408
&& let hir::ExprKind::MethodCall(_, _, args, _) = parent_expr.kind
410409
&& let Some(def_id) = typeck.type_dependent_def_id(parent_expr.hir_id)
@@ -1660,8 +1659,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
16601659

16611660
// Check that the parent of the closure is a method call,
16621661
// with receiver matching with local's type (modulo refs)
1663-
let parent = hir.parent_id(closure_expr.hir_id);
1664-
if let hir::Node::Expr(parent) = tcx.hir_node(parent) {
1662+
if let hir::Node::Expr(parent) = tcx.parent_hir_node(closure_expr.hir_id) {
16651663
if let hir::ExprKind::MethodCall(_, recv, ..) = parent.kind {
16661664
let recv_ty = typeck_results.expr_ty(recv);
16671665

Diff for: compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -944,7 +944,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
944944
let hir = self.infcx.tcx.hir();
945945
let closure_id = self.mir_hir_id();
946946
let closure_span = self.infcx.tcx.def_span(self.mir_def_id());
947-
let fn_call_id = hir.parent_id(closure_id);
947+
let fn_call_id = self.infcx.tcx.parent_hir_id(closure_id);
948948
let node = self.infcx.tcx.hir_node(fn_call_id);
949949
let def_id = hir.enclosing_body_owner(fn_call_id);
950950
let mut look_at_return = true;
@@ -1034,7 +1034,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
10341034
if let InstanceDef::Item(def_id) = source.instance
10351035
&& let Some(Node::Expr(hir::Expr { hir_id, kind, .. })) = hir.get_if_local(def_id)
10361036
&& let ExprKind::Closure(hir::Closure { kind: hir::ClosureKind::Closure, .. }) = kind
1037-
&& let Some(Node::Expr(expr)) = hir.find_parent(*hir_id)
1037+
&& let Node::Expr(expr) = self.infcx.tcx.parent_hir_node(*hir_id)
10381038
{
10391039
let mut cur_expr = expr;
10401040
while let ExprKind::MethodCall(path_segment, recv, _, _) = cur_expr.kind {

Diff for: compiler/rustc_borrowck/src/diagnostics/region_errors.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,11 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
214214
if let Some(id) = placeholder.bound.kind.get_id()
215215
&& let Some(placeholder_id) = id.as_local()
216216
&& let gat_hir_id = self.infcx.tcx.local_def_id_to_hir_id(placeholder_id)
217-
&& let Some(generics_impl) =
218-
hir.get_parent(hir.parent_id(gat_hir_id)).generics()
217+
&& let Some(generics_impl) = self
218+
.infcx
219+
.tcx
220+
.parent_hir_node(self.infcx.tcx.parent_hir_id(gat_hir_id))
221+
.generics()
219222
{
220223
Some((gat_hir_id, generics_impl))
221224
} else {

Diff for: compiler/rustc_const_eval/src/interpret/projection.rs

+2
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ where
149149
"`field` projection called on a slice -- call `index` projection instead"
150150
);
151151
let offset = base.layout().fields.offset(field);
152+
// Computing the layout does normalization, so we get a normalized type out of this
153+
// even if the field type is non-normalized (possible e.g. via associated types).
152154
let field_layout = base.layout().field(self, field);
153155

154156
// Offset may need adjustment for unsized fields.

Diff for: compiler/rustc_const_eval/src/interpret/visitor.rs

+10
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,16 @@ pub trait ValueVisitor<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>>: Sized {
153153
// We visited all parts of this one.
154154
return Ok(());
155155
}
156+
157+
// Non-normalized types should never show up here.
158+
ty::Param(..)
159+
| ty::Alias(..)
160+
| ty::Bound(..)
161+
| ty::Placeholder(..)
162+
| ty::Infer(..)
163+
| ty::Error(..) => throw_inval!(TooGeneric),
164+
165+
// The rest is handled below.
156166
_ => {}
157167
};
158168

Diff for: compiler/rustc_const_eval/src/transform/check_consts/mod.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,10 @@ fn is_parent_const_stable_trait(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
131131
let local_def_id = def_id.expect_local();
132132
let hir_id = tcx.local_def_id_to_hir_id(local_def_id);
133133

134-
let Some(parent) = tcx.hir().opt_parent_id(hir_id) else { return false };
135-
136-
if !tcx.is_const_trait_impl_raw(parent.owner.def_id.to_def_id()) {
134+
let parent_owner_id = tcx.parent_hir_id(hir_id).owner;
135+
if !tcx.is_const_trait_impl_raw(parent_owner_id.to_def_id()) {
137136
return false;
138137
}
139138

140-
tcx.lookup_const_stability(parent.owner).is_some_and(|stab| stab.is_const_stable())
139+
tcx.lookup_const_stability(parent_owner_id).is_some_and(|stab| stab.is_const_stable())
141140
}

Diff for: compiler/rustc_hir/src/hir.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3508,7 +3508,7 @@ impl<'hir> Node<'hir> {
35083508
/// ```ignore (illustrative)
35093509
/// ctor
35103510
/// .ctor_hir_id()
3511-
/// .and_then(|ctor_id| tcx.hir().find_parent(ctor_id))
3511+
/// .map(|ctor_id| tcx.parent_hir_node(ctor_id))
35123512
/// .and_then(|parent| parent.ident())
35133513
/// ```
35143514
pub fn ident(&self) -> Option<Ident> {

Diff for: compiler/rustc_hir_analysis/src/astconv/mod.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -2749,14 +2749,12 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
27492749
arg_idx: Option<usize>,
27502750
) -> Option<Ty<'tcx>> {
27512751
let tcx = self.tcx();
2752-
let hir = tcx.hir();
2753-
27542752
let hir::Node::ImplItem(hir::ImplItem { kind: hir::ImplItemKind::Fn(..), ident, .. }) =
27552753
tcx.hir_node(fn_hir_id)
27562754
else {
27572755
return None;
27582756
};
2759-
let i = hir.get_parent(fn_hir_id).expect_item().expect_impl();
2757+
let i = tcx.parent_hir_node(fn_hir_id).expect_item().expect_impl();
27602758

27612759
let trait_ref =
27622760
self.instantiate_mono_trait_ref(i.of_trait.as_ref()?, self.ast_ty_to_ty(i.self_ty));

Diff for: compiler/rustc_hir_analysis/src/collect.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -224,11 +224,8 @@ pub(crate) fn placeholder_type_error_diag<'tcx>(
224224
is_fn = true;
225225

226226
// Check if parent is const or static
227-
let parent_id = tcx.hir().parent_id(hir_ty.hir_id);
228-
let parent_node = tcx.hir_node(parent_id);
229-
230227
is_const_or_static = matches!(
231-
parent_node,
228+
tcx.parent_hir_node(hir_ty.hir_id),
232229
Node::Item(&hir::Item {
233230
kind: hir::ItemKind::Const(..) | hir::ItemKind::Static(..),
234231
..
@@ -1085,7 +1082,7 @@ fn fn_sig(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<ty::PolyFnSig<
10851082

10861083
ImplItem(hir::ImplItem { kind: ImplItemKind::Fn(sig, _), generics, .. }) => {
10871084
// Do not try to infer the return type for a impl method coming from a trait
1088-
if let Item(hir::Item { kind: ItemKind::Impl(i), .. }) = tcx.hir().get_parent(hir_id)
1085+
if let Item(hir::Item { kind: ItemKind::Impl(i), .. }) = tcx.parent_hir_node(hir_id)
10891086
&& i.of_trait.is_some()
10901087
{
10911088
icx.astconv().ty_of_fn(

Diff for: compiler/rustc_hir_analysis/src/collect/generics_of.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
5151
// of a const parameter type, e.g. `struct Foo<const N: usize, const M: [u8; N]>` is not allowed.
5252
None
5353
} else if tcx.features().generic_const_exprs {
54-
let parent_node = tcx.hir().get_parent(hir_id);
54+
let parent_node = tcx.parent_hir_node(hir_id);
5555
if let Node::Variant(Variant { disr_expr: Some(constant), .. }) = parent_node
5656
&& constant.hir_id == hir_id
5757
{
@@ -113,7 +113,7 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
113113
Some(parent_def_id.to_def_id())
114114
}
115115
} else {
116-
let parent_node = tcx.hir().get_parent(hir_id);
116+
let parent_node = tcx.parent_hir_node(hir_id);
117117
match parent_node {
118118
// HACK(eddyb) this provides the correct generics for repeat
119119
// expressions' count (i.e. `N` in `[x; N]`), and explicit

Diff for: compiler/rustc_hir_analysis/src/collect/predicates_of.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
315315
// We create bi-directional Outlives predicates between the original
316316
// and the duplicated parameter, to ensure that they do not get out of sync.
317317
if let Node::Item(&Item { kind: ItemKind::OpaqueTy(..), .. }) = node {
318-
let opaque_ty_id = tcx.hir().parent_id(hir_id);
319-
let opaque_ty_node = tcx.hir_node(opaque_ty_id);
318+
let opaque_ty_node = tcx.parent_hir_node(hir_id);
320319
let Node::Ty(&Ty { kind: TyKind::OpaqueDef(_, lifetimes, _), .. }) = opaque_ty_node else {
321320
bug!("unexpected {opaque_ty_node:?}")
322321
};

Diff for: compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,7 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
732732
let Some(def_id) = def_id.as_local() else { continue };
733733
let hir_id = self.tcx.local_def_id_to_hir_id(def_id);
734734
// Ensure that the parent of the def is an item, not HRTB
735-
let parent_id = self.tcx.hir().parent_id(hir_id);
735+
let parent_id = self.tcx.parent_hir_id(hir_id);
736736
if !parent_id.is_owner() {
737737
struct_span_code_err!(
738738
self.tcx.dcx(),

Diff for: compiler/rustc_hir_analysis/src/collect/type_of.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ fn anon_const_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx> {
3030
);
3131
};
3232

33-
let parent_node_id = tcx.hir().parent_id(hir_id);
33+
let parent_node_id = tcx.parent_hir_id(hir_id);
3434
let parent_node = tcx.hir_node(parent_node_id);
3535

3636
let (generics, arg_idx) = match parent_node {
@@ -79,7 +79,7 @@ fn anon_const_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx> {
7979
}
8080

8181
Node::TypeBinding(binding @ &TypeBinding { hir_id: binding_id, .. })
82-
if let Node::TraitRef(trait_ref) = tcx.hir_node(tcx.hir().parent_id(binding_id)) =>
82+
if let Node::TraitRef(trait_ref) = tcx.parent_hir_node(binding_id) =>
8383
{
8484
let Some(trait_def_id) = trait_ref.trait_def_id() else {
8585
return Ty::new_error_with_message(

Diff for: compiler/rustc_hir_analysis/src/structured_errors/wrong_number_of_generic_args.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
135135
// Here we check if the reference to the generic type
136136
// is from the 'of_trait' field of the enclosing impl
137137

138-
let parent = self.tcx.hir().get_parent(self.path_segment.hir_id);
138+
let parent = self.tcx.parent_hir_node(self.path_segment.hir_id);
139139
let parent_item = self.tcx.hir_node_by_def_id(
140140
self.tcx.hir().get_parent_item(self.path_segment.hir_id).def_id,
141141
);
@@ -770,9 +770,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
770770
num = num_trait_generics_except_self,
771771
);
772772

773-
if let Some(parent_node) = self.tcx.hir().opt_parent_id(self.path_segment.hir_id)
774-
&& let hir::Node::Expr(expr) = self.tcx.hir_node(parent_node)
775-
{
773+
if let hir::Node::Expr(expr) = self.tcx.parent_hir_node(self.path_segment.hir_id) {
776774
match &expr.kind {
777775
hir::ExprKind::Path(qpath) => self
778776
.suggest_moving_args_from_assoc_fn_to_trait_for_qualified_path(

Diff for: compiler/rustc_hir_typeck/src/_match.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
287287
{
288288
// If this `if` expr is the parent's function return expr,
289289
// the cause of the type coercion is the return type, point at it. (#25228)
290-
let hir_id = self.tcx.hir().parent_id(self.tcx.hir().parent_id(then_expr.hir_id));
290+
let hir_id = self.tcx.parent_hir_id(self.tcx.parent_hir_id(then_expr.hir_id));
291291
let ret_reason = self.maybe_get_coercion_reason(hir_id, if_span);
292292
let cause = self.cause(if_span, ObligationCauseCode::IfExpressionWithNoElse);
293293
let mut error = false;
@@ -396,7 +396,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
396396
let node = self.tcx.hir_node(hir_id);
397397
if let hir::Node::Block(block) = node {
398398
// check that the body's parent is an fn
399-
let parent = self.tcx.hir().get_parent(self.tcx.hir().parent_id(block.hir_id));
399+
let parent = self.tcx.parent_hir_node(self.tcx.parent_hir_id(block.hir_id));
400400
if let (Some(expr), hir::Node::Item(hir::Item { kind: hir::ItemKind::Fn(..), .. })) =
401401
(&block.expr, parent)
402402
{

Diff for: compiler/rustc_hir_typeck/src/callee.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
361361
let fn_decl_span = if let hir::Node::Expr(hir::Expr {
362362
kind: hir::ExprKind::Closure(&hir::Closure { fn_decl_span, .. }),
363363
..
364-
}) = hir.get_parent(hir_id)
364+
}) = self.tcx.parent_hir_node(hir_id)
365365
{
366366
fn_decl_span
367367
} else if let Some((
@@ -383,11 +383,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
383383
{
384384
// Actually need to unwrap one more layer of HIR to get to
385385
// the _real_ closure...
386-
let async_closure = hir.parent_id(parent_hir_id);
387386
if let hir::Node::Expr(hir::Expr {
388387
kind: hir::ExprKind::Closure(&hir::Closure { fn_decl_span, .. }),
389388
..
390-
}) = self.tcx.hir_node(async_closure)
389+
}) = self.tcx.parent_hir_node(parent_hir_id)
391390
{
392391
fn_decl_span
393392
} else {
@@ -415,8 +414,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
415414
call_expr: &'tcx hir::Expr<'tcx>,
416415
callee_expr: &'tcx hir::Expr<'tcx>,
417416
) -> bool {
418-
let hir_id = self.tcx.hir().parent_id(call_expr.hir_id);
419-
let parent_node = self.tcx.hir_node(hir_id);
417+
let parent_node = self.tcx.parent_hir_node(call_expr.hir_id);
420418
if let (
421419
hir::Node::Expr(hir::Expr { kind: hir::ExprKind::Array(_), .. }),
422420
hir::ExprKind::Tup(exp),

Diff for: compiler/rustc_hir_typeck/src/coercion.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1594,7 +1594,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
15941594
err.span_label(cause.span, "return type is not `()`");
15951595
}
15961596
ObligationCauseCode::BlockTailExpression(blk_id, ..) => {
1597-
let parent_id = fcx.tcx.hir().parent_id(blk_id);
1597+
let parent_id = fcx.tcx.parent_hir_id(blk_id);
15981598
err = self.report_return_mismatched_types(
15991599
cause,
16001600
expected,
@@ -1785,7 +1785,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
17851785
) -> DiagnosticBuilder<'a> {
17861786
let mut err = fcx.err_ctxt().report_mismatched_types(cause, expected, found, ty_err);
17871787

1788-
let parent_id = fcx.tcx.hir().parent_id(id);
1788+
let parent_id = fcx.tcx.parent_hir_id(id);
17891789
let parent = fcx.tcx.hir_node(parent_id);
17901790
if let Some(expr) = expression
17911791
&& let hir::Node::Expr(hir::Expr {

0 commit comments

Comments
 (0)