Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 15b663e

Browse files
committedNov 23, 2024
Auto merge of rust-lang#133379 - jieyouxu:rollup-00jxo71, r=jieyouxu
Rollup of 4 pull requests Successful merges: - rust-lang#133217 ([AIX] Add option -X32_64 to the "strip" command) - rust-lang#133237 (Minimally constify `Add`) - rust-lang#133355 (Add language tests for aggregate types) - rust-lang#133374 (show abi_unsupported_vector_types lint in future breakage reports) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 386a7c7 + f5cfb90 commit 15b663e

23 files changed

+922
-90
lines changed
 

‎compiler/rustc_codegen_ssa/src/back/link.rs

+12-10
Original file line numberDiff line numberDiff line change
@@ -1117,14 +1117,14 @@ fn link_natively(
11171117
let stripcmd = "rust-objcopy";
11181118
match (strip, crate_type) {
11191119
(Strip::Debuginfo, _) => {
1120-
strip_symbols_with_external_utility(sess, stripcmd, out_filename, Some("-S"))
1120+
strip_symbols_with_external_utility(sess, stripcmd, out_filename, &["-S"])
11211121
}
11221122
// Per the manpage, `-x` is the maximum safe strip level for dynamic libraries. (#93988)
11231123
(Strip::Symbols, CrateType::Dylib | CrateType::Cdylib | CrateType::ProcMacro) => {
1124-
strip_symbols_with_external_utility(sess, stripcmd, out_filename, Some("-x"))
1124+
strip_symbols_with_external_utility(sess, stripcmd, out_filename, &["-x"])
11251125
}
11261126
(Strip::Symbols, _) => {
1127-
strip_symbols_with_external_utility(sess, stripcmd, out_filename, None)
1127+
strip_symbols_with_external_utility(sess, stripcmd, out_filename, &[])
11281128
}
11291129
(Strip::None, _) => {}
11301130
}
@@ -1141,7 +1141,7 @@ fn link_natively(
11411141
match strip {
11421142
// Always preserve the symbol table (-x).
11431143
Strip::Debuginfo => {
1144-
strip_symbols_with_external_utility(sess, stripcmd, out_filename, Some("-x"))
1144+
strip_symbols_with_external_utility(sess, stripcmd, out_filename, &["-x"])
11451145
}
11461146
// Strip::Symbols is handled via the --strip-all linker option.
11471147
Strip::Symbols => {}
@@ -1158,11 +1158,15 @@ fn link_natively(
11581158
match strip {
11591159
Strip::Debuginfo => {
11601160
// FIXME: AIX's strip utility only offers option to strip line number information.
1161-
strip_symbols_with_external_utility(sess, stripcmd, out_filename, Some("-l"))
1161+
strip_symbols_with_external_utility(sess, stripcmd, out_filename, &[
1162+
"-X32_64", "-l",
1163+
])
11621164
}
11631165
Strip::Symbols => {
11641166
// Must be noted this option might remove symbol __aix_rust_metadata and thus removes .info section which contains metadata.
1165-
strip_symbols_with_external_utility(sess, stripcmd, out_filename, Some("-r"))
1167+
strip_symbols_with_external_utility(sess, stripcmd, out_filename, &[
1168+
"-X32_64", "-r",
1169+
])
11661170
}
11671171
Strip::None => {}
11681172
}
@@ -1181,12 +1185,10 @@ fn strip_symbols_with_external_utility(
11811185
sess: &Session,
11821186
util: &str,
11831187
out_filename: &Path,
1184-
option: Option<&str>,
1188+
options: &[&str],
11851189
) {
11861190
let mut cmd = Command::new(util);
1187-
if let Some(option) = option {
1188-
cmd.arg(option);
1189-
}
1191+
cmd.args(options);
11901192

11911193
let mut new_path = sess.get_tools_search_paths(false);
11921194
if let Some(path) = env::var_os("PATH") {

‎compiler/rustc_lint_defs/src/builtin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5173,7 +5173,7 @@ declare_lint! {
51735173
Warn,
51745174
"this function call or definition uses a vector type which is not enabled",
51755175
@future_incompatible = FutureIncompatibleInfo {
5176-
reason: FutureIncompatibilityReason::FutureReleaseErrorDontReportInDeps,
5176+
reason: FutureIncompatibilityReason::FutureReleaseErrorReportInDeps,
51775177
reference: "issue #116558 <https://github.com/rust-lang/rust/issues/116558>",
51785178
};
51795179
}

‎compiler/rustc_passes/src/stability.rs

+1-10
Original file line numberDiff line numberDiff line change
@@ -590,16 +590,7 @@ impl<'tcx> MissingStabilityAnnotations<'tcx> {
590590
}
591591

592592
fn check_missing_const_stability(&self, def_id: LocalDefId, span: Span) {
593-
// if the const impl is derived using the `derive_const` attribute,
594-
// then it would be "stable" at least for the impl.
595-
// We gate usages of it using `feature(const_trait_impl)` anyways
596-
// so there is no unstable leakage
597-
if self.tcx.is_automatically_derived(def_id.to_def_id()) {
598-
return;
599-
}
600-
601-
let is_const = self.tcx.is_const_fn(def_id.to_def_id())
602-
|| self.tcx.is_const_trait_impl(def_id.to_def_id());
593+
let is_const = self.tcx.is_const_fn(def_id.to_def_id());
603594

604595
// Reachable const fn must have a stability attribute.
605596
if is_const

‎library/core/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@
174174
#![feature(const_is_char_boundary)]
175175
#![feature(const_precise_live_drops)]
176176
#![feature(const_str_split_at)]
177+
#![feature(const_trait_impl)]
177178
#![feature(decl_macro)]
178179
#![feature(deprecated_suggestion)]
179180
#![feature(doc_cfg)]

‎library/core/src/ops/arith.rs

+13
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
append_const_msg
7474
)]
7575
#[doc(alias = "+")]
76+
#[cfg_attr(not(bootstrap), const_trait)]
7677
pub trait Add<Rhs = Self> {
7778
/// The resulting type after applying the `+` operator.
7879
#[stable(feature = "rust1", since = "1.0.0")]
@@ -94,6 +95,7 @@ pub trait Add<Rhs = Self> {
9495
macro_rules! add_impl {
9596
($($t:ty)*) => ($(
9697
#[stable(feature = "rust1", since = "1.0.0")]
98+
#[cfg(bootstrap)]
9799
impl Add for $t {
98100
type Output = $t;
99101

@@ -103,6 +105,17 @@ macro_rules! add_impl {
103105
fn add(self, other: $t) -> $t { self + other }
104106
}
105107

108+
#[stable(feature = "rust1", since = "1.0.0")]
109+
#[cfg(not(bootstrap))]
110+
impl const Add for $t {
111+
type Output = $t;
112+
113+
#[inline]
114+
#[track_caller]
115+
#[rustc_inherit_overflow_checks]
116+
fn add(self, other: $t) -> $t { self + other }
117+
}
118+
106119
forward_ref_binop! { impl Add, add for $t, $t }
107120
)*)
108121
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//@ run-pass
2+
//@ reference: layout.aggregate.struct-size-align
3+
//@ edition: 2018
4+
5+
#[repr(align(64))]
6+
#[derive(Copy, Clone)]
7+
#[allow(dead_code)]
8+
pub struct Overaligned(u8);
9+
10+
#[allow(dead_code)]
11+
struct ReprRustStruct {
12+
x: i32,
13+
y: [u32; 4],
14+
z: f32,
15+
a: u128,
16+
b: Overaligned,
17+
}
18+
19+
fn test_alignment_contains_all_fields() {
20+
assert!(core::mem::align_of::<ReprRustStruct>() >= core::mem::align_of::<i32>());
21+
assert!(core::mem::align_of::<ReprRustStruct>() >= core::mem::align_of::<[u32; 4]>());
22+
assert!(core::mem::align_of::<ReprRustStruct>() >= core::mem::align_of::<f32>());
23+
assert!(core::mem::align_of::<ReprRustStruct>() >= core::mem::align_of::<u128>());
24+
assert!(core::mem::align_of::<ReprRustStruct>() >= core::mem::align_of::<Overaligned>());
25+
}
26+
27+
fn main() {
28+
test_alignment_contains_all_fields();
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
//@ run-pass
2+
//@ reference: layout.aggregate.struct-offsets
3+
//@ edition: 2018
4+
5+
#[repr(align(64))]
6+
#[derive(Copy, Clone)]
7+
#[allow(dead_code)]
8+
pub struct Overaligned(u8);
9+
10+
#[allow(dead_code)]
11+
struct ReprRustStruct {
12+
x: i32,
13+
y: [u32; 4],
14+
z: f32,
15+
a: u128,
16+
b: Overaligned,
17+
}
18+
19+
macro_rules! span_of {
20+
($ty:ty , $field:tt) => {{
21+
let __field = unsafe { ::core::mem::zeroed::<$ty>() };
22+
23+
(
24+
core::mem::offset_of!($ty, $field),
25+
core::mem::offset_of!($ty, $field) + core::mem::size_of_val(&__field.$field),
26+
)
27+
}};
28+
}
29+
30+
fn test_fields_make_sense(a: &(usize, usize)) {
31+
assert!(a.0 <= a.1);
32+
}
33+
34+
// order is `begin, end`
35+
fn test_non_overlapping(a: &(usize, usize), b: &(usize, usize)) {
36+
assert!((a.1 <= b.0) || (b.1 <= a.0));
37+
}
38+
39+
fn test_fields_non_overlapping() {
40+
let fields = [
41+
span_of!(ReprRustStruct, x),
42+
span_of!(ReprRustStruct, y),
43+
span_of!(ReprRustStruct, z),
44+
span_of!(ReprRustStruct, a),
45+
span_of!(ReprRustStruct, b),
46+
];
47+
48+
test_fields_make_sense(&fields[0]);
49+
test_fields_make_sense(&fields[1]);
50+
test_fields_make_sense(&fields[2]);
51+
test_fields_make_sense(&fields[3]);
52+
test_fields_make_sense(&fields[4]);
53+
54+
test_non_overlapping(&fields[0], &fields[1]);
55+
test_non_overlapping(&fields[0], &fields[2]);
56+
test_non_overlapping(&fields[0], &fields[3]);
57+
test_non_overlapping(&fields[0], &fields[4]);
58+
test_non_overlapping(&fields[1], &fields[2]);
59+
test_non_overlapping(&fields[2], &fields[3]);
60+
test_non_overlapping(&fields[2], &fields[4]);
61+
test_non_overlapping(&fields[3], &fields[4]);
62+
}
63+
64+
fn test_fields_aligned() {
65+
assert_eq!((core::mem::offset_of!(ReprRustStruct, x) % (core::mem::align_of::<i32>())), 0);
66+
assert_eq!((core::mem::offset_of!(ReprRustStruct, y) % (core::mem::align_of::<[u32; 4]>())), 0);
67+
assert_eq!((core::mem::offset_of!(ReprRustStruct, z) % (core::mem::align_of::<f32>())), 0);
68+
assert_eq!((core::mem::offset_of!(ReprRustStruct, a) % (core::mem::align_of::<u128>())), 0);
69+
assert_eq!(
70+
(core::mem::offset_of!(ReprRustStruct, b) % (core::mem::align_of::<Overaligned>())),
71+
0
72+
);
73+
}
74+
75+
fn main() {
76+
test_fields_non_overlapping();
77+
test_fields_aligned();
78+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
//@ run-pass
2+
//@ reference: layout.aggregate.struct-size-align
3+
//@ edition: 2018
4+
5+
#[allow(dead_code)]
6+
struct ReprRustStruct {
7+
x: i32,
8+
y: [u32; 4],
9+
z: f32,
10+
a: u128,
11+
}
12+
13+
fn test_size_contains_all_types() {
14+
assert!(
15+
core::mem::size_of::<ReprRustStruct>()
16+
>= (core::mem::size_of::<i32>()
17+
+ core::mem::size_of::<[u32; 4]>()
18+
+ core::mem::size_of::<f32>()
19+
+ core::mem::size_of::<u128>())
20+
);
21+
}
22+
23+
fn test_size_contains_all_fields() {
24+
assert!(
25+
(core::mem::offset_of!(ReprRustStruct, x) + core::mem::size_of::<i32>())
26+
<= core::mem::size_of::<ReprRustStruct>()
27+
);
28+
assert!(
29+
(core::mem::offset_of!(ReprRustStruct, y) + core::mem::size_of::<[u32; 4]>())
30+
<= core::mem::size_of::<ReprRustStruct>()
31+
);
32+
assert!(
33+
(core::mem::offset_of!(ReprRustStruct, z) + core::mem::size_of::<f32>())
34+
<= core::mem::size_of::<ReprRustStruct>()
35+
);
36+
assert!(
37+
(core::mem::offset_of!(ReprRustStruct, a) + core::mem::size_of::<u128>())
38+
<= core::mem::size_of::<ReprRustStruct>()
39+
);
40+
}
41+
42+
fn test_size_modulo_align() {
43+
assert_eq!(core::mem::size_of::<ReprRustStruct>() % core::mem::align_of::<ReprRustStruct>(), 0);
44+
}
45+
46+
fn main() {
47+
test_size_contains_all_fields();
48+
test_size_contains_all_types();
49+
test_size_modulo_align();
50+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//@ run-pass
2+
//@ reference: layout.aggregate.struct-size-align
3+
//@ edition: 2018
4+
5+
#[repr(align(64))]
6+
#[derive(Copy, Clone)]
7+
#[allow(dead_code)]
8+
pub struct Overaligned(u8);
9+
10+
#[allow(dead_code)]
11+
union ReprRustUnion {
12+
x: i32,
13+
y: [u32; 4],
14+
z: f32,
15+
a: u128,
16+
b: Overaligned,
17+
}
18+
19+
fn test_alignment_contains_all_fields() {
20+
assert!(core::mem::align_of::<ReprRustUnion>() >= core::mem::align_of::<i32>());
21+
assert!(core::mem::align_of::<ReprRustUnion>() >= core::mem::align_of::<[u32; 4]>());
22+
assert!(core::mem::align_of::<ReprRustUnion>() >= core::mem::align_of::<f32>());
23+
assert!(core::mem::align_of::<ReprRustUnion>() >= core::mem::align_of::<u128>());
24+
assert!(core::mem::align_of::<ReprRustUnion>() >= core::mem::align_of::<Overaligned>());
25+
}
26+
27+
fn main() {
28+
test_alignment_contains_all_fields();
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//@ run-pass
2+
//@ reference: layout.aggregate.struct-offsets
3+
//@ edition: 2018
4+
5+
#[repr(align(64))]
6+
#[derive(Copy, Clone)]
7+
#[allow(dead_code)]
8+
pub struct Overaligned(u8);
9+
10+
#[allow(dead_code)]
11+
union ReprRustUnion {
12+
x: i32,
13+
y: [u32; 4],
14+
z: f32,
15+
a: u128,
16+
b: Overaligned,
17+
}
18+
19+
fn test_fields_aligned() {
20+
assert_eq!((core::mem::offset_of!(ReprRustUnion, x) % (core::mem::align_of::<i32>())), 0);
21+
assert_eq!((core::mem::offset_of!(ReprRustUnion, y) % (core::mem::align_of::<[u32; 4]>())), 0);
22+
assert_eq!((core::mem::offset_of!(ReprRustUnion, z) % (core::mem::align_of::<f32>())), 0);
23+
assert_eq!((core::mem::offset_of!(ReprRustUnion, a) % (core::mem::align_of::<u128>())), 0);
24+
assert_eq!(
25+
(core::mem::offset_of!(ReprRustUnion, b) % (core::mem::align_of::<Overaligned>())),
26+
0
27+
);
28+
}
29+
30+
fn main() {
31+
test_fields_aligned();
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
//@ run-pass
2+
//@ reference: layout.aggregate.struct-size-align
3+
//@ edition: 2018
4+
5+
#[allow(dead_code)]
6+
union ReprRustUnion {
7+
x: i32,
8+
y: [u32; 4],
9+
z: f32,
10+
a: u128,
11+
}
12+
13+
fn test_size_contains_each_type() {
14+
assert!(core::mem::size_of::<i32>() <= core::mem::size_of::<ReprRustUnion>());
15+
assert!(core::mem::size_of::<[u32; 4]>() <= core::mem::size_of::<ReprRustUnion>());
16+
assert!(core::mem::size_of::<f32>() <= core::mem::size_of::<ReprRustUnion>());
17+
assert!(core::mem::size_of::<u128>() <= core::mem::size_of::<ReprRustUnion>());
18+
}
19+
20+
fn test_size_contains_all_fields() {
21+
assert!(
22+
(core::mem::offset_of!(ReprRustUnion, x) + core::mem::size_of::<i32>())
23+
<= core::mem::size_of::<ReprRustUnion>()
24+
);
25+
assert!(
26+
(core::mem::offset_of!(ReprRustUnion, y) + core::mem::size_of::<[u32; 4]>())
27+
<= core::mem::size_of::<ReprRustUnion>()
28+
);
29+
assert!(
30+
(core::mem::offset_of!(ReprRustUnion, z) + core::mem::size_of::<f32>())
31+
<= core::mem::size_of::<ReprRustUnion>()
32+
);
33+
assert!(
34+
(core::mem::offset_of!(ReprRustUnion, a) + core::mem::size_of::<u128>())
35+
<= core::mem::size_of::<ReprRustUnion>()
36+
);
37+
}
38+
39+
fn test_size_modulo_align() {
40+
assert_eq!(core::mem::size_of::<ReprRustUnion>() % core::mem::align_of::<ReprRustUnion>(), 0);
41+
}
42+
43+
fn main() {
44+
test_size_contains_each_type();
45+
test_size_contains_all_fields();
46+
test_size_modulo_align();
47+
}
There was a problem loading the remainder of the diff.

0 commit comments

Comments
 (0)
Failed to load comments.