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

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

Lines changed: 2 additions & 4 deletions
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

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

Lines changed: 2 additions & 2 deletions
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 {

compiler/rustc_borrowck/src/diagnostics/region_errors.rs

Lines changed: 5 additions & 2 deletions
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 {

compiler/rustc_const_eval/src/interpret/projection.rs

Lines changed: 2 additions & 0 deletions
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.

compiler/rustc_const_eval/src/interpret/visitor.rs

Lines changed: 10 additions & 0 deletions
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

compiler/rustc_const_eval/src/transform/check_consts/mod.rs

Lines changed: 3 additions & 4 deletions
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
}

compiler/rustc_hir/src/hir.rs

Lines changed: 1 addition & 1 deletion
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> {

compiler/rustc_hir_analysis/src/astconv/mod.rs

Lines changed: 1 addition & 3 deletions
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));

compiler/rustc_hir_analysis/src/collect.rs

Lines changed: 2 additions & 5 deletions
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(

compiler/rustc_hir_analysis/src/collect/generics_of.rs

Lines changed: 2 additions & 2 deletions
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

0 commit comments

Comments
 (0)