Skip to content

Commit eb33b43

Browse files
committed
Auto merge of rust-lang#129978 - matthiaskrgr:rollup-a7ryoox, r=matthiaskrgr
Rollup of 10 pull requests Successful merges: - rust-lang#101339 (enable -Zrandomize-layout in debug CI builds ) - rust-lang#120736 (rustdoc: add header map to the table of contents) - rust-lang#127021 (Add target support for RTEMS Arm) - rust-lang#128928 (CI: rfl: add more tools and steps) - rust-lang#129584 (warn the user if the upstream master branch is old) - rust-lang#129664 (Arbitrary self types v2: pointers feature gate.) - rust-lang#129752 (Make supertrait and implied predicates queries defaulted) - rust-lang#129918 (Update docs of `missing_abi` lint) - rust-lang#129919 (Stabilize `waker_getters`) - rust-lang#129925 (remove deprecated option `rust.split-debuginfo`) Failed merges: - rust-lang#129789 (rustdoc: use strategic boxing to shrink `clean::Item`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 009e738 + 3190521 commit eb33b43

File tree

106 files changed

+1549
-284
lines changed

Some content is hidden

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

106 files changed

+1549
-284
lines changed

Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -3569,6 +3569,7 @@ dependencies = [
35693569
"rustc_hir_pretty",
35703570
"rustc_hir_typeck",
35713571
"rustc_incremental",
3572+
"rustc_index",
35723573
"rustc_infer",
35733574
"rustc_interface",
35743575
"rustc_lint",

compiler/rustc/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,6 @@ features = ['unprefixed_malloc_on_supported_platforms']
3030
jemalloc = ['dep:jemalloc-sys']
3131
llvm = ['rustc_driver_impl/llvm']
3232
max_level_info = ['rustc_driver_impl/max_level_info']
33+
rustc_randomized_layouts = ['rustc_driver_impl/rustc_randomized_layouts']
3334
rustc_use_parallel_compiler = ['rustc_driver_impl/rustc_use_parallel_compiler']
3435
# tidy-alphabetical-end

compiler/rustc_abi/src/layout.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -968,8 +968,8 @@ fn univariant<
968968
let mut align = if pack.is_some() { dl.i8_align } else { dl.aggregate_align };
969969
let mut max_repr_align = repr.align;
970970
let mut inverse_memory_index: IndexVec<u32, FieldIdx> = fields.indices().collect();
971-
let optimize = !repr.inhibit_struct_field_reordering();
972-
if optimize && fields.len() > 1 {
971+
let optimize_field_order = !repr.inhibit_struct_field_reordering();
972+
if optimize_field_order && fields.len() > 1 {
973973
let end = if let StructKind::MaybeUnsized = kind { fields.len() - 1 } else { fields.len() };
974974
let optimizing = &mut inverse_memory_index.raw[..end];
975975
let fields_excluding_tail = &fields.raw[..end];
@@ -1176,7 +1176,7 @@ fn univariant<
11761176
// If field 5 has offset 0, offsets[0] is 5, and memory_index[5] should be 0.
11771177
// Field 5 would be the first element, so memory_index is i:
11781178
// Note: if we didn't optimize, it's already right.
1179-
let memory_index = if optimize {
1179+
let memory_index = if optimize_field_order {
11801180
inverse_memory_index.invert_bijective_mapping()
11811181
} else {
11821182
debug_assert!(inverse_memory_index.iter().copied().eq(fields.indices()));
@@ -1189,6 +1189,9 @@ fn univariant<
11891189
}
11901190
let mut layout_of_single_non_zst_field = None;
11911191
let mut abi = Abi::Aggregate { sized };
1192+
1193+
let optimize_abi = !repr.inhibit_newtype_abi_optimization();
1194+
11921195
// Try to make this a Scalar/ScalarPair.
11931196
if sized && size.bytes() > 0 {
11941197
// We skip *all* ZST here and later check if we are good in terms of alignment.
@@ -1205,7 +1208,7 @@ fn univariant<
12051208
match field.abi {
12061209
// For plain scalars, or vectors of them, we can't unpack
12071210
// newtypes for `#[repr(C)]`, as that affects C ABIs.
1208-
Abi::Scalar(_) | Abi::Vector { .. } if optimize => {
1211+
Abi::Scalar(_) | Abi::Vector { .. } if optimize_abi => {
12091212
abi = field.abi;
12101213
}
12111214
// But scalar pairs are Rust-specific and get

compiler/rustc_abi/src/lib.rs

+11-4
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,17 @@ bitflags! {
4343
const IS_SIMD = 1 << 1;
4444
const IS_TRANSPARENT = 1 << 2;
4545
// Internal only for now. If true, don't reorder fields.
46+
// On its own it does not prevent ABI optimizations.
4647
const IS_LINEAR = 1 << 3;
47-
// If true, the type's layout can be randomized using
48-
// the seed stored in `ReprOptions.field_shuffle_seed`
48+
// If true, the type's crate has opted into layout randomization.
49+
// Other flags can still inhibit reordering and thus randomization.
50+
// The seed stored in `ReprOptions.field_shuffle_seed`.
4951
const RANDOMIZE_LAYOUT = 1 << 4;
5052
// Any of these flags being set prevent field reordering optimisation.
51-
const IS_UNOPTIMISABLE = ReprFlags::IS_C.bits()
53+
const FIELD_ORDER_UNOPTIMIZABLE = ReprFlags::IS_C.bits()
5254
| ReprFlags::IS_SIMD.bits()
5355
| ReprFlags::IS_LINEAR.bits();
56+
const ABI_UNOPTIMIZABLE = ReprFlags::IS_C.bits() | ReprFlags::IS_SIMD.bits();
5457
}
5558
}
5659

@@ -139,10 +142,14 @@ impl ReprOptions {
139142
self.c() || self.int.is_some()
140143
}
141144

145+
pub fn inhibit_newtype_abi_optimization(&self) -> bool {
146+
self.flags.intersects(ReprFlags::ABI_UNOPTIMIZABLE)
147+
}
148+
142149
/// Returns `true` if this `#[repr()]` guarantees a fixed field order,
143150
/// e.g. `repr(C)` or `repr(<int>)`.
144151
pub fn inhibit_struct_field_reordering(&self) -> bool {
145-
self.flags.intersects(ReprFlags::IS_UNOPTIMISABLE) || self.int.is_some()
152+
self.flags.intersects(ReprFlags::FIELD_ORDER_UNOPTIMIZABLE) || self.int.is_some()
146153
}
147154

148155
/// Returns `true` if this type is valid for reordering and `-Z randomize-layout`

compiler/rustc_driver_impl/Cargo.toml

+5
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ rustc_hir_analysis = { path = "../rustc_hir_analysis" }
2323
rustc_hir_pretty = { path = "../rustc_hir_pretty" }
2424
rustc_hir_typeck = { path = "../rustc_hir_typeck" }
2525
rustc_incremental = { path = "../rustc_incremental" }
26+
rustc_index = { path = "../rustc_index" }
2627
rustc_infer = { path = "../rustc_infer" }
2728
rustc_interface = { path = "../rustc_interface" }
2829
rustc_lint = { path = "../rustc_lint" }
@@ -72,6 +73,10 @@ ctrlc = "3.4.4"
7273
# tidy-alphabetical-start
7374
llvm = ['rustc_interface/llvm']
7475
max_level_info = ['rustc_log/max_level_info']
76+
rustc_randomized_layouts = [
77+
'rustc_index/rustc_randomized_layouts',
78+
'rustc_middle/rustc_randomized_layouts'
79+
]
7580
rustc_use_parallel_compiler = [
7681
'rustc_data_structures/rustc_use_parallel_compiler',
7782
'rustc_interface/rustc_use_parallel_compiler',

compiler/rustc_feature/src/unstable.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -349,8 +349,10 @@ declare_features! (
349349
(unstable, adt_const_params, "1.56.0", Some(95174)),
350350
/// Allows defining an `#[alloc_error_handler]`.
351351
(unstable, alloc_error_handler, "1.29.0", Some(51540)),
352-
/// Allows trait methods with arbitrary self types.
352+
/// Allows inherent and trait methods with arbitrary self types.
353353
(unstable, arbitrary_self_types, "1.23.0", Some(44874)),
354+
/// Allows inherent and trait methods with arbitrary self types that are raw pointers.
355+
(unstable, arbitrary_self_types_pointers, "CURRENT_RUSTC_VERSION", Some(44874)),
354356
/// Enables experimental inline assembly support for additional architectures.
355357
(unstable, asm_experimental_arch, "1.58.0", Some(93335)),
356358
/// Allows using `label` operands in inline assembly.

compiler/rustc_hir_analysis/src/check/wfcheck.rs

+63-19
Original file line numberDiff line numberDiff line change
@@ -1652,6 +1652,13 @@ fn check_fn_or_method<'tcx>(
16521652
}
16531653
}
16541654

1655+
/// The `arbitrary_self_types_pointers` feature implies `arbitrary_self_types`.
1656+
#[derive(Clone, Copy, PartialEq)]
1657+
enum ArbitrarySelfTypesLevel {
1658+
Basic, // just arbitrary_self_types
1659+
WithPointers, // both arbitrary_self_types and arbitrary_self_types_pointers
1660+
}
1661+
16551662
#[instrument(level = "debug", skip(wfcx))]
16561663
fn check_method_receiver<'tcx>(
16571664
wfcx: &WfCheckingCtxt<'_, 'tcx>,
@@ -1684,40 +1691,77 @@ fn check_method_receiver<'tcx>(
16841691
return Ok(());
16851692
}
16861693

1687-
if tcx.features().arbitrary_self_types {
1688-
if !receiver_is_valid(wfcx, span, receiver_ty, self_ty, true) {
1689-
// Report error; `arbitrary_self_types` was enabled.
1690-
return Err(tcx.dcx().emit_err(errors::InvalidReceiverTy { span, receiver_ty }));
1691-
}
1694+
let arbitrary_self_types_level = if tcx.features().arbitrary_self_types_pointers {
1695+
Some(ArbitrarySelfTypesLevel::WithPointers)
1696+
} else if tcx.features().arbitrary_self_types {
1697+
Some(ArbitrarySelfTypesLevel::Basic)
16921698
} else {
1693-
if !receiver_is_valid(wfcx, span, receiver_ty, self_ty, false) {
1694-
return Err(if receiver_is_valid(wfcx, span, receiver_ty, self_ty, true) {
1699+
None
1700+
};
1701+
1702+
if !receiver_is_valid(wfcx, span, receiver_ty, self_ty, arbitrary_self_types_level) {
1703+
return Err(match arbitrary_self_types_level {
1704+
// Wherever possible, emit a message advising folks that the features
1705+
// `arbitrary_self_types` or `arbitrary_self_types_pointers` might
1706+
// have helped.
1707+
None if receiver_is_valid(
1708+
wfcx,
1709+
span,
1710+
receiver_ty,
1711+
self_ty,
1712+
Some(ArbitrarySelfTypesLevel::Basic),
1713+
) =>
1714+
{
16951715
// Report error; would have worked with `arbitrary_self_types`.
16961716
feature_err(
16971717
&tcx.sess,
16981718
sym::arbitrary_self_types,
16991719
span,
17001720
format!(
17011721
"`{receiver_ty}` cannot be used as the type of `self` without \
1702-
the `arbitrary_self_types` feature",
1722+
the `arbitrary_self_types` feature",
17031723
),
17041724
)
17051725
.with_help(fluent::hir_analysis_invalid_receiver_ty_help)
17061726
.emit()
1707-
} else {
1708-
// Report error; would not have worked with `arbitrary_self_types`.
1727+
}
1728+
None | Some(ArbitrarySelfTypesLevel::Basic)
1729+
if receiver_is_valid(
1730+
wfcx,
1731+
span,
1732+
receiver_ty,
1733+
self_ty,
1734+
Some(ArbitrarySelfTypesLevel::WithPointers),
1735+
) =>
1736+
{
1737+
// Report error; would have worked with `arbitrary_self_types_pointers`.
1738+
feature_err(
1739+
&tcx.sess,
1740+
sym::arbitrary_self_types_pointers,
1741+
span,
1742+
format!(
1743+
"`{receiver_ty}` cannot be used as the type of `self` without \
1744+
the `arbitrary_self_types_pointers` feature",
1745+
),
1746+
)
1747+
.with_help(fluent::hir_analysis_invalid_receiver_ty_help)
1748+
.emit()
1749+
}
1750+
_ =>
1751+
// Report error; would not have worked with `arbitrary_self_types[_pointers]`.
1752+
{
17091753
tcx.dcx().emit_err(errors::InvalidReceiverTy { span, receiver_ty })
1710-
});
1711-
}
1754+
}
1755+
});
17121756
}
17131757
Ok(())
17141758
}
17151759

17161760
/// Returns whether `receiver_ty` would be considered a valid receiver type for `self_ty`. If
17171761
/// `arbitrary_self_types` is enabled, `receiver_ty` must transitively deref to `self_ty`, possibly
1718-
/// through a `*const/mut T` raw pointer. If the feature is not enabled, the requirements are more
1719-
/// strict: `receiver_ty` must implement `Receiver` and directly implement
1720-
/// `Deref<Target = self_ty>`.
1762+
/// through a `*const/mut T` raw pointer if `arbitrary_self_types_pointers` is also enabled.
1763+
/// If neither feature is enabled, the requirements are more strict: `receiver_ty` must implement
1764+
/// `Receiver` and directly implement `Deref<Target = self_ty>`.
17211765
///
17221766
/// N.B., there are cases this function returns `true` but causes an error to be emitted,
17231767
/// particularly when `receiver_ty` derefs to a type that is the same as `self_ty` but has the
@@ -1727,7 +1771,7 @@ fn receiver_is_valid<'tcx>(
17271771
span: Span,
17281772
receiver_ty: Ty<'tcx>,
17291773
self_ty: Ty<'tcx>,
1730-
arbitrary_self_types_enabled: bool,
1774+
arbitrary_self_types_enabled: Option<ArbitrarySelfTypesLevel>,
17311775
) -> bool {
17321776
let infcx = wfcx.infcx;
17331777
let tcx = wfcx.tcx();
@@ -1745,8 +1789,8 @@ fn receiver_is_valid<'tcx>(
17451789

17461790
let mut autoderef = Autoderef::new(infcx, wfcx.param_env, wfcx.body_def_id, span, receiver_ty);
17471791

1748-
// The `arbitrary_self_types` feature allows raw pointer receivers like `self: *const Self`.
1749-
if arbitrary_self_types_enabled {
1792+
// The `arbitrary_self_types_pointers` feature allows raw pointer receivers like `self: *const Self`.
1793+
if arbitrary_self_types_enabled == Some(ArbitrarySelfTypesLevel::WithPointers) {
17501794
autoderef = autoderef.include_raw_pointers();
17511795
}
17521796

@@ -1772,7 +1816,7 @@ fn receiver_is_valid<'tcx>(
17721816

17731817
// Without `feature(arbitrary_self_types)`, we require that each step in the
17741818
// deref chain implement `receiver`.
1775-
if !arbitrary_self_types_enabled {
1819+
if arbitrary_self_types_enabled.is_none() {
17761820
if !receiver_is_implemented(
17771821
wfcx,
17781822
receiver_trait_def_id,

compiler/rustc_hir_typeck/src/method/probe.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
403403
mode,
404404
}));
405405
} else if bad_ty.reached_raw_pointer
406-
&& !self.tcx.features().arbitrary_self_types
406+
&& !self.tcx.features().arbitrary_self_types_pointers
407407
&& !self.tcx.sess.at_least_rust_2018()
408408
{
409409
// this case used to be allowed by the compiler,

compiler/rustc_index/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,5 @@ nightly = [
2020
"dep:rustc_macros",
2121
"rustc_index_macros/nightly",
2222
]
23+
rustc_randomized_layouts = []
2324
# tidy-alphabetical-end

compiler/rustc_index/src/lib.rs

+11
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,19 @@ pub use vec::IndexVec;
3333
///
3434
/// </div>
3535
#[macro_export]
36+
#[cfg(not(feature = "rustc_randomized_layouts"))]
3637
macro_rules! static_assert_size {
3738
($ty:ty, $size:expr) => {
3839
const _: [(); $size] = [(); ::std::mem::size_of::<$ty>()];
3940
};
4041
}
42+
43+
#[macro_export]
44+
#[cfg(feature = "rustc_randomized_layouts")]
45+
macro_rules! static_assert_size {
46+
($ty:ty, $size:expr) => {
47+
// no effect other than using the statements.
48+
// struct sizes are not deterministic under randomized layouts
49+
const _: (usize, usize) = ($size, ::std::mem::size_of::<$ty>());
50+
};
51+
}

compiler/rustc_lint_defs/src/builtin.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -3706,7 +3706,7 @@ declare_lint_pass!(UnusedDocComment => [UNUSED_DOC_COMMENTS]);
37063706

37073707
declare_lint! {
37083708
/// The `missing_abi` lint detects cases where the ABI is omitted from
3709-
/// extern declarations.
3709+
/// `extern` declarations.
37103710
///
37113711
/// ### Example
37123712
///
@@ -3720,10 +3720,12 @@ declare_lint! {
37203720
///
37213721
/// ### Explanation
37223722
///
3723-
/// Historically, Rust implicitly selected C as the ABI for extern
3724-
/// declarations. We expect to add new ABIs, like `C-unwind`, in the future,
3725-
/// though this has not yet happened, and especially with their addition
3726-
/// seeing the ABI easily will make code review easier.
3723+
/// For historic reasons, Rust implicitly selects `C` as the default ABI for
3724+
/// `extern` declarations. [Other ABIs] like `C-unwind` and `system` have
3725+
/// been added since then, and especially with their addition seeing the ABI
3726+
/// easily makes code review easier.
3727+
///
3728+
/// [Other ABIs]: https://doc.rust-lang.org/reference/items/external-blocks.html#abi
37273729
pub MISSING_ABI,
37283730
Allow,
37293731
"No declared ABI for extern declaration"

compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,8 @@ provide! { tcx, def_id, other, cdata,
247247
explicit_predicates_of => { table }
248248
generics_of => { table }
249249
inferred_outlives_of => { table_defaulted_array }
250-
explicit_super_predicates_of => { table }
251-
explicit_implied_predicates_of => { table }
250+
explicit_super_predicates_of => { table_defaulted_array }
251+
explicit_implied_predicates_of => { table_defaulted_array }
252252
type_of => { table }
253253
type_alias_is_lazy => { table_direct }
254254
variances_of => { table }

compiler/rustc_metadata/src/rmeta/encoder.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1443,9 +1443,9 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
14431443
}
14441444
if let DefKind::Trait = def_kind {
14451445
record!(self.tables.trait_def[def_id] <- self.tcx.trait_def(def_id));
1446-
record_array!(self.tables.explicit_super_predicates_of[def_id] <-
1446+
record_defaulted_array!(self.tables.explicit_super_predicates_of[def_id] <-
14471447
self.tcx.explicit_super_predicates_of(def_id).skip_binder());
1448-
record_array!(self.tables.explicit_implied_predicates_of[def_id] <-
1448+
record_defaulted_array!(self.tables.explicit_implied_predicates_of[def_id] <-
14491449
self.tcx.explicit_implied_predicates_of(def_id).skip_binder());
14501450

14511451
let module_children = self.tcx.module_children_local(local_id);
@@ -1454,9 +1454,9 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
14541454
}
14551455
if let DefKind::TraitAlias = def_kind {
14561456
record!(self.tables.trait_def[def_id] <- self.tcx.trait_def(def_id));
1457-
record_array!(self.tables.explicit_super_predicates_of[def_id] <-
1457+
record_defaulted_array!(self.tables.explicit_super_predicates_of[def_id] <-
14581458
self.tcx.explicit_super_predicates_of(def_id).skip_binder());
1459-
record_array!(self.tables.explicit_implied_predicates_of[def_id] <-
1459+
record_defaulted_array!(self.tables.explicit_implied_predicates_of[def_id] <-
14601460
self.tcx.explicit_implied_predicates_of(def_id).skip_binder());
14611461
}
14621462
if let DefKind::Trait | DefKind::Impl { .. } = def_kind {

compiler/rustc_metadata/src/rmeta/mod.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,8 @@ define_tables! {
390390
explicit_item_bounds: Table<DefIndex, LazyArray<(ty::Clause<'static>, Span)>>,
391391
explicit_item_super_predicates: Table<DefIndex, LazyArray<(ty::Clause<'static>, Span)>>,
392392
inferred_outlives_of: Table<DefIndex, LazyArray<(ty::Clause<'static>, Span)>>,
393+
explicit_super_predicates_of: Table<DefIndex, LazyArray<(ty::Clause<'static>, Span)>>,
394+
explicit_implied_predicates_of: Table<DefIndex, LazyArray<(ty::Clause<'static>, Span)>>,
393395
inherent_impls: Table<DefIndex, LazyArray<DefIndex>>,
394396
associated_types_for_impl_traits_in_associated_fn: Table<DefIndex, LazyArray<DefId>>,
395397
associated_type_for_effects: Table<DefIndex, Option<LazyValue<DefId>>>,
@@ -419,10 +421,6 @@ define_tables! {
419421
lookup_deprecation_entry: Table<DefIndex, LazyValue<attr::Deprecation>>,
420422
explicit_predicates_of: Table<DefIndex, LazyValue<ty::GenericPredicates<'static>>>,
421423
generics_of: Table<DefIndex, LazyValue<ty::Generics>>,
422-
explicit_super_predicates_of: Table<DefIndex, LazyArray<(ty::Clause<'static>, Span)>>,
423-
// As an optimization, we only store this for trait aliases,
424-
// since it's identical to explicit_super_predicates_of for traits.
425-
explicit_implied_predicates_of: Table<DefIndex, LazyArray<(ty::Clause<'static>, Span)>>,
426424
type_of: Table<DefIndex, LazyValue<ty::EarlyBinder<'static, Ty<'static>>>>,
427425
variances_of: Table<DefIndex, LazyArray<ty::Variance>>,
428426
fn_sig: Table<DefIndex, LazyValue<ty::EarlyBinder<'static, ty::PolyFnSig<'static>>>>,

compiler/rustc_middle/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,6 @@ tracing = "0.1"
4040

4141
[features]
4242
# tidy-alphabetical-start
43+
rustc_randomized_layouts = []
4344
rustc_use_parallel_compiler = ["dep:rustc-rayon-core"]
4445
# tidy-alphabetical-end

compiler/rustc_middle/src/query/plumbing.rs

+1
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ macro_rules! define_callbacks {
337337
// Ensure that values grow no larger than 64 bytes by accident.
338338
// Increase this limit if necessary, but do try to keep the size low if possible
339339
#[cfg(target_pointer_width = "64")]
340+
#[cfg(not(feature = "rustc_randomized_layouts"))]
340341
const _: () = {
341342
if mem::size_of::<Value<'static>>() > 64 {
342343
panic!("{}", concat!(

0 commit comments

Comments
 (0)