Skip to content

Commit 54f47f8

Browse files
committed
Auto merge of rust-lang#137199 - Zalathar:rollup-18ux22s, r=Zalathar
Rollup of 8 pull requests Successful merges: - rust-lang#135767 (Future incompatibility warning `unsupported_fn_ptr_calling_conventions`: Also warn in dependencies) - rust-lang#136457 (Expose algebraic floating point intrinsics) - rust-lang#136985 (Do not ignore uninhabited types for function-call ABI purposes. (Remove BackendRepr::Uninhabited)) - rust-lang#137000 (Deeply normalize item bounds in new solver) - rust-lang#137151 (Install more signal stack trace handlers) - rust-lang#137155 (Organize `OsString`/`OsStr` shims) - rust-lang#137161 (Pattern Migration 2024: fix incorrect messages/suggestions when errors arise in macro expansions) - rust-lang#137162 (Move methods from `Map` to `TyCtxt`, part 2.) r? `@ghost` `@rustbot` modify labels: rollup
2 parents de91711 + 2807d0a commit 54f47f8

File tree

201 files changed

+2323
-741
lines changed

Some content is hidden

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

201 files changed

+2323
-741
lines changed

Diff for: compiler/rustc_abi/src/callconv.rs

-2
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ impl<'a, Ty> TyAndLayout<'a, Ty> {
6565
Ty: TyAbiInterface<'a, C> + Copy,
6666
{
6767
match self.backend_repr {
68-
BackendRepr::Uninhabited => Err(Heterogeneous),
69-
7068
// The primitive for this algorithm.
7169
BackendRepr::Scalar(scalar) => {
7270
let kind = match scalar.primitive() {

Diff for: compiler/rustc_abi/src/layout.rs

+12-11
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
130130
},
131131
backend_repr: BackendRepr::ScalarPair(a, b),
132132
largest_niche,
133+
uninhabited: false,
133134
align,
134135
size,
135136
max_repr_align: None,
@@ -221,8 +222,9 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
221222
LayoutData {
222223
variants: Variants::Empty,
223224
fields: FieldsShape::Primitive,
224-
backend_repr: BackendRepr::Uninhabited,
225+
backend_repr: BackendRepr::Memory { sized: true },
225226
largest_niche: None,
227+
uninhabited: true,
226228
align: dl.i8_align,
227229
size: Size::ZERO,
228230
max_repr_align: None,
@@ -400,6 +402,7 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
400402
fields: FieldsShape::Union(union_field_count),
401403
backend_repr: abi,
402404
largest_niche: None,
405+
uninhabited: false,
403406
align,
404407
size: size.align_to(align.abi),
405408
max_repr_align,
@@ -447,7 +450,6 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
447450
Scalar::Union { .. } => {}
448451
};
449452
match &mut st.backend_repr {
450-
BackendRepr::Uninhabited => {}
451453
BackendRepr::Scalar(scalar) => hide_niches(scalar),
452454
BackendRepr::ScalarPair(a, b) => {
453455
hide_niches(a);
@@ -639,9 +641,8 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
639641
let same_size = size == variant_layouts[largest_variant_index].size;
640642
let same_align = align == variant_layouts[largest_variant_index].align;
641643

642-
let abi = if variant_layouts.iter().all(|v| v.is_uninhabited()) {
643-
BackendRepr::Uninhabited
644-
} else if same_size && same_align && others_zst {
644+
let uninhabited = variant_layouts.iter().all(|v| v.is_uninhabited());
645+
let abi = if same_size && same_align && others_zst {
645646
match variant_layouts[largest_variant_index].backend_repr {
646647
// When the total alignment and size match, we can use the
647648
// same ABI as the scalar variant with the reserved niche.
@@ -683,6 +684,7 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
683684
},
684685
backend_repr: abi,
685686
largest_niche,
687+
uninhabited,
686688
size,
687689
align,
688690
max_repr_align,
@@ -853,9 +855,8 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
853855
};
854856
let mut abi = BackendRepr::Memory { sized: true };
855857

856-
if layout_variants.iter().all(|v| v.is_uninhabited()) {
857-
abi = BackendRepr::Uninhabited;
858-
} else if tag.size(dl) == size {
858+
let uninhabited = layout_variants.iter().all(|v| v.is_uninhabited());
859+
if tag.size(dl) == size {
859860
// Make sure we only use scalar layout when the enum is entirely its
860861
// own tag (i.e. it has no padding nor any non-ZST variant fields).
861862
abi = BackendRepr::Scalar(tag);
@@ -995,6 +996,7 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
995996
memory_index: [0].into(),
996997
},
997998
largest_niche,
999+
uninhabited,
9981000
backend_repr: abi,
9991001
align,
10001002
size,
@@ -1355,9 +1357,7 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
13551357
_ => {}
13561358
}
13571359
}
1358-
if fields.iter().any(|f| f.is_uninhabited()) {
1359-
abi = BackendRepr::Uninhabited;
1360-
}
1360+
let uninhabited = fields.iter().any(|f| f.is_uninhabited());
13611361

13621362
let unadjusted_abi_align = if repr.transparent() {
13631363
match layout_of_single_non_zst_field {
@@ -1378,6 +1378,7 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
13781378
fields: FieldsShape::Arbitrary { offsets, memory_index },
13791379
backend_repr: abi,
13801380
largest_niche,
1381+
uninhabited,
13811382
align,
13821383
size,
13831384
max_repr_align,

Diff for: compiler/rustc_abi/src/lib.rs

+16-19
Original file line numberDiff line numberDiff line change
@@ -1404,7 +1404,6 @@ impl AddressSpace {
14041404
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
14051405
#[cfg_attr(feature = "nightly", derive(HashStable_Generic))]
14061406
pub enum BackendRepr {
1407-
Uninhabited,
14081407
Scalar(Scalar),
14091408
ScalarPair(Scalar, Scalar),
14101409
Vector {
@@ -1423,10 +1422,9 @@ impl BackendRepr {
14231422
#[inline]
14241423
pub fn is_unsized(&self) -> bool {
14251424
match *self {
1426-
BackendRepr::Uninhabited
1427-
| BackendRepr::Scalar(_)
1428-
| BackendRepr::ScalarPair(..)
1429-
| BackendRepr::Vector { .. } => false,
1425+
BackendRepr::Scalar(_) | BackendRepr::ScalarPair(..) | BackendRepr::Vector { .. } => {
1426+
false
1427+
}
14301428
BackendRepr::Memory { sized } => !sized,
14311429
}
14321430
}
@@ -1445,12 +1443,6 @@ impl BackendRepr {
14451443
}
14461444
}
14471445

1448-
/// Returns `true` if this is an uninhabited type
1449-
#[inline]
1450-
pub fn is_uninhabited(&self) -> bool {
1451-
matches!(*self, BackendRepr::Uninhabited)
1452-
}
1453-
14541446
/// Returns `true` if this is a scalar type
14551447
#[inline]
14561448
pub fn is_scalar(&self) -> bool {
@@ -1471,7 +1463,7 @@ impl BackendRepr {
14711463
BackendRepr::Vector { element, count } => {
14721464
cx.data_layout().vector_align(element.size(cx) * count)
14731465
}
1474-
BackendRepr::Uninhabited | BackendRepr::Memory { .. } => return None,
1466+
BackendRepr::Memory { .. } => return None,
14751467
})
14761468
}
14771469

@@ -1492,7 +1484,7 @@ impl BackendRepr {
14921484
// to make the size a multiple of align (e.g. for vectors of size 3).
14931485
(element.size(cx) * count).align_to(self.inherent_align(cx)?.abi)
14941486
}
1495-
BackendRepr::Uninhabited | BackendRepr::Memory { .. } => return None,
1487+
BackendRepr::Memory { .. } => return None,
14961488
})
14971489
}
14981490

@@ -1506,9 +1498,7 @@ impl BackendRepr {
15061498
BackendRepr::Vector { element, count } => {
15071499
BackendRepr::Vector { element: element.to_union(), count }
15081500
}
1509-
BackendRepr::Uninhabited | BackendRepr::Memory { .. } => {
1510-
BackendRepr::Memory { sized: true }
1511-
}
1501+
BackendRepr::Memory { .. } => BackendRepr::Memory { sized: true },
15121502
}
15131503
}
15141504

@@ -1704,6 +1694,11 @@ pub struct LayoutData<FieldIdx: Idx, VariantIdx: Idx> {
17041694
/// The leaf scalar with the largest number of invalid values
17051695
/// (i.e. outside of its `valid_range`), if it exists.
17061696
pub largest_niche: Option<Niche>,
1697+
/// Is this type known to be uninhabted?
1698+
///
1699+
/// This is separate from BackendRepr because uninhabited return types can affect ABI,
1700+
/// especially in the case of by-pointer struct returns, which allocate stack even when unused.
1701+
pub uninhabited: bool,
17071702

17081703
pub align: AbiAndPrefAlign,
17091704
pub size: Size,
@@ -1735,14 +1730,14 @@ impl<FieldIdx: Idx, VariantIdx: Idx> LayoutData<FieldIdx, VariantIdx> {
17351730
/// Returns `true` if this is an aggregate type (including a ScalarPair!)
17361731
pub fn is_aggregate(&self) -> bool {
17371732
match self.backend_repr {
1738-
BackendRepr::Uninhabited | BackendRepr::Scalar(_) | BackendRepr::Vector { .. } => false,
1733+
BackendRepr::Scalar(_) | BackendRepr::Vector { .. } => false,
17391734
BackendRepr::ScalarPair(..) | BackendRepr::Memory { .. } => true,
17401735
}
17411736
}
17421737

17431738
/// Returns `true` if this is an uninhabited type
17441739
pub fn is_uninhabited(&self) -> bool {
1745-
self.backend_repr.is_uninhabited()
1740+
self.uninhabited
17461741
}
17471742

17481743
pub fn scalar<C: HasDataLayout>(cx: &C, scalar: Scalar) -> Self {
@@ -1778,6 +1773,7 @@ impl<FieldIdx: Idx, VariantIdx: Idx> LayoutData<FieldIdx, VariantIdx> {
17781773
fields: FieldsShape::Primitive,
17791774
backend_repr: BackendRepr::Scalar(scalar),
17801775
largest_niche,
1776+
uninhabited: false,
17811777
size,
17821778
align,
17831779
max_repr_align: None,
@@ -1802,6 +1798,7 @@ where
18021798
backend_repr,
18031799
fields,
18041800
largest_niche,
1801+
uninhabited,
18051802
variants,
18061803
max_repr_align,
18071804
unadjusted_abi_align,
@@ -1813,6 +1810,7 @@ where
18131810
.field("abi", backend_repr)
18141811
.field("fields", fields)
18151812
.field("largest_niche", largest_niche)
1813+
.field("uninhabited", uninhabited)
18161814
.field("variants", variants)
18171815
.field("max_repr_align", max_repr_align)
18181816
.field("unadjusted_abi_align", unadjusted_abi_align)
@@ -1877,7 +1875,6 @@ impl<FieldIdx: Idx, VariantIdx: Idx> LayoutData<FieldIdx, VariantIdx> {
18771875
BackendRepr::Scalar(_) | BackendRepr::ScalarPair(..) | BackendRepr::Vector { .. } => {
18781876
false
18791877
}
1880-
BackendRepr::Uninhabited => self.size.bytes() == 0,
18811878
BackendRepr::Memory { sized } => sized && self.size.bytes() == 0,
18821879
}
18831880
}

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

+8-8
Original file line numberDiff line numberDiff line change
@@ -386,8 +386,9 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
386386
hir::intravisit::walk_pat(self, p);
387387
}
388388
}
389+
let tcx = self.infcx.tcx;
389390
let hir = self.infcx.tcx.hir();
390-
if let Some(body) = hir.maybe_body_owned_by(self.mir_def_id()) {
391+
if let Some(body) = tcx.hir_maybe_body_owned_by(self.mir_def_id()) {
391392
let expr = body.value;
392393
let place = &self.move_data.move_paths[mpi].place;
393394
let span = place.as_local().map(|local| self.body.local_decls[local].source_info.span);
@@ -396,7 +397,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
396397
expr: None,
397398
pat: None,
398399
parent_pat: None,
399-
tcx: self.infcx.tcx,
400+
tcx,
400401
};
401402
finder.visit_expr(expr);
402403
if let Some(span) = span
@@ -782,9 +783,9 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
782783

783784
// We use the statements were the binding was initialized, and inspect the HIR to look
784785
// for the branching codepaths that aren't covered, to point at them.
785-
let map = self.infcx.tcx.hir();
786-
let body = map.body_owned_by(self.mir_def_id());
787-
let mut visitor = ConditionVisitor { tcx: self.infcx.tcx, spans, name, errors: vec![] };
786+
let tcx = self.infcx.tcx;
787+
let body = tcx.hir_body_owned_by(self.mir_def_id());
788+
let mut visitor = ConditionVisitor { tcx, spans, name, errors: vec![] };
788789
visitor.visit_body(&body);
789790
let spans = visitor.spans;
790791

@@ -2443,7 +2444,6 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
24432444
) {
24442445
let &UseSpans::ClosureUse { capture_kind_span, .. } = issued_spans else { return };
24452446
let tcx = self.infcx.tcx;
2446-
let hir = tcx.hir();
24472447

24482448
// Get the type of the local that we are trying to borrow
24492449
let local = borrowed_place.local;
@@ -2522,7 +2522,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
25222522

25232523
// Find the first argument with a matching type, get its name
25242524
let Some((_, this_name)) =
2525-
params.iter().zip(hir.body_param_names(closure.body)).find(|(param_ty, name)| {
2525+
params.iter().zip(tcx.hir_body_param_names(closure.body)).find(|(param_ty, name)| {
25262526
// FIXME: also support deref for stuff like `Rc` arguments
25272527
param_ty.peel_refs() == local_ty && name != &Ident::empty()
25282528
})
@@ -4178,7 +4178,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
41784178
debug!("annotate_fn_sig: did={:?} sig={:?}", did, sig);
41794179
let is_closure = self.infcx.tcx.is_closure_like(did.to_def_id());
41804180
let fn_hir_id = self.infcx.tcx.local_def_id_to_hir_id(did);
4181-
let fn_decl = self.infcx.tcx.hir().fn_decl_by_hir_id(fn_hir_id)?;
4181+
let fn_decl = self.infcx.tcx.hir_fn_decl_by_hir_id(fn_hir_id)?;
41824182

41834183
// We need to work out which arguments to highlight. We do this by looking
41844184
// at the return type, where there are three cases:

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -777,12 +777,12 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
777777
}
778778
let Some(pat_span) = pat_span else { return };
779779

780-
let hir = self.infcx.tcx.hir();
781-
let Some(body) = hir.maybe_body_owned_by(self.mir_def_id()) else { return };
780+
let tcx = self.infcx.tcx;
781+
let Some(body) = tcx.hir_maybe_body_owned_by(self.mir_def_id()) else { return };
782782
let typeck_results = self.infcx.tcx.typeck(self.mir_def_id());
783783
let mut finder = BindingFinder {
784784
typeck_results,
785-
tcx: self.infcx.tcx,
785+
tcx,
786786
pat_span,
787787
binding_spans,
788788
found_pat: false,

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

+10-13
Original file line numberDiff line numberDiff line change
@@ -648,10 +648,9 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
648648
}
649649
}
650650
}
651-
let hir_map = self.infcx.tcx.hir();
652651
let def_id = self.body.source.def_id();
653652
let Some(local_def_id) = def_id.as_local() else { return };
654-
let Some(body) = hir_map.maybe_body_owned_by(local_def_id) else { return };
653+
let Some(body) = self.infcx.tcx.hir_maybe_body_owned_by(local_def_id) else { return };
655654

656655
let mut v = SuggestIndexOperatorAlternativeVisitor {
657656
assign_span: span,
@@ -749,7 +748,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
749748
// `fn foo(&x: &i32)` -> `fn foo(&(mut x): &i32)`
750749
let def_id = self.body.source.def_id();
751750
if let Some(local_def_id) = def_id.as_local()
752-
&& let Some(body) = self.infcx.tcx.hir().maybe_body_owned_by(local_def_id)
751+
&& let Some(body) = self.infcx.tcx.hir_maybe_body_owned_by(local_def_id)
753752
&& let Some(hir_id) = (BindingFinder { span: pat_span }).visit_body(&body).break_value()
754753
&& let node = self.infcx.tcx.hir_node(hir_id)
755754
&& let hir::Node::LetStmt(hir::LetStmt {
@@ -856,7 +855,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
856855
use hir::ExprKind::{AddrOf, Block, Call, MethodCall};
857856
use hir::{BorrowKind, Expr};
858857

859-
let hir_map = self.infcx.tcx.hir();
858+
let tcx = self.infcx.tcx;
860859
struct Finder {
861860
span: Span,
862861
}
@@ -871,7 +870,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
871870
}
872871
}
873872
}
874-
if let Some(body) = hir_map.maybe_body_owned_by(self.mir_def_id())
873+
if let Some(body) = tcx.hir_maybe_body_owned_by(self.mir_def_id())
875874
&& let Block(block, _) = body.value.kind
876875
{
877876
// `span` corresponds to the expression being iterated, find the `for`-loop desugared
@@ -884,17 +883,15 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
884883
MethodCall(path_segment, _, _, span) => {
885884
// We have `for _ in iter.read_only_iter()`, try to
886885
// suggest `for _ in iter.mutable_iter()` instead.
887-
let opt_suggestions = self
888-
.infcx
889-
.tcx
886+
let opt_suggestions = tcx
890887
.typeck(path_segment.hir_id.owner.def_id)
891888
.type_dependent_def_id(expr.hir_id)
892-
.and_then(|def_id| self.infcx.tcx.impl_of_method(def_id))
893-
.map(|def_id| self.infcx.tcx.associated_items(def_id))
889+
.and_then(|def_id| tcx.impl_of_method(def_id))
890+
.map(|def_id| tcx.associated_items(def_id))
894891
.map(|assoc_items| {
895892
assoc_items
896893
.in_definition_order()
897-
.map(|assoc_item_def| assoc_item_def.ident(self.infcx.tcx))
894+
.map(|assoc_item_def| assoc_item_def.ident(tcx))
898895
.filter(|&ident| {
899896
let original_method_ident = path_segment.ident;
900897
original_method_ident != ident
@@ -942,7 +939,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
942939
let closure_span = tcx.def_span(self.mir_def_id());
943940
let fn_call_id = tcx.parent_hir_id(closure_id);
944941
let node = tcx.hir_node(fn_call_id);
945-
let def_id = hir.enclosing_body_owner(fn_call_id);
942+
let def_id = tcx.hir_enclosing_body_owner(fn_call_id);
946943
let mut look_at_return = true;
947944

948945
// If the HIR node is a function or method call gets the def ID
@@ -1275,7 +1272,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
12751272
}) => {
12761273
let def_id = self.body.source.def_id();
12771274
let hir_id = if let Some(local_def_id) = def_id.as_local()
1278-
&& let Some(body) = self.infcx.tcx.hir().maybe_body_owned_by(local_def_id)
1275+
&& let Some(body) = self.infcx.tcx.hir_maybe_body_owned_by(local_def_id)
12791276
{
12801277
BindingFinder { span: err_label_span }.visit_body(&body).break_value()
12811278
} else {

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -1169,8 +1169,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
11691169

11701170
#[allow(rustc::diagnostic_outside_of_impl)]
11711171
fn suggest_move_on_borrowing_closure(&self, diag: &mut Diag<'_>) {
1172-
let map = self.infcx.tcx.hir();
1173-
let body = map.body_owned_by(self.mir_def_id());
1172+
let body = self.infcx.tcx.hir_body_owned_by(self.mir_def_id());
11741173
let expr = &body.value.peel_blocks();
11751174
let mut closure_span = None::<rustc_span::Span>;
11761175
match expr.kind {

0 commit comments

Comments
 (0)