Skip to content

Commit e737bb8

Browse files
committed
Auto merge of #150118 - JonathanBrouwer:rollup-w6cit7x, r=JonathanBrouwer
Rollup of 5 pull requests Successful merges: - #145933 (Expand `str_as_str` to more types) - #148849 (Set -Cpanic=abort in windows-msvc stack protector tests) - #150048 (std_detect: AArch64 Darwin: expose SME F16F16 and B16B16 features) - #150083 (tests/run-make-cargo/same-crate-name-and-macro-name: New regression test) - #150102 (Fixed ICE for EII with multiple defaults due to duplicate definition in nameres) r? `@ghost` `@rustbot` modify labels: rollup
2 parents ed0006a + 118c181 commit e737bb8

File tree

21 files changed

+294
-62
lines changed

21 files changed

+294
-62
lines changed

compiler/rustc_passes/src/eii.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ pub(crate) fn check_externally_implementable_items<'tcx>(tcx: TyCtxt<'tcx>, ():
116116
}
117117

118118
if default_impls.len() > 1 {
119-
panic!("multiple not supported right now");
119+
let decl_span = tcx.def_ident_span(decl_did).unwrap();
120+
tcx.dcx().span_delayed_bug(decl_span, "multiple not supported right now");
120121
}
121122

122123
let (local_impl, is_default) =

library/core/src/bstr/mod.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,30 @@ impl ByteStr {
6868
ByteStr::from_bytes(bytes.as_ref())
6969
}
7070

71+
/// Returns the same string as `&ByteStr`.
72+
///
73+
/// This method is redundant when used directly on `&ByteStr`, but
74+
/// it helps dereferencing other "container" types,
75+
/// for example `Box<ByteStr>` or `Arc<ByteStr>`.
76+
#[inline]
77+
// #[unstable(feature = "str_as_str", issue = "130366")]
78+
#[unstable(feature = "bstr", issue = "134915")]
79+
pub const fn as_byte_str(&self) -> &ByteStr {
80+
self
81+
}
82+
83+
/// Returns the same string as `&mut ByteStr`.
84+
///
85+
/// This method is redundant when used directly on `&mut ByteStr`, but
86+
/// it helps dereferencing other "container" types,
87+
/// for example `Box<ByteStr>` or `MutexGuard<ByteStr>`.
88+
#[inline]
89+
// #[unstable(feature = "str_as_str", issue = "130366")]
90+
#[unstable(feature = "bstr", issue = "134915")]
91+
pub const fn as_mut_byte_str(&mut self) -> &mut ByteStr {
92+
self
93+
}
94+
7195
#[doc(hidden)]
7296
#[unstable(feature = "bstr_internals", issue = "none")]
7397
#[inline]

library/core/src/ffi/c_str.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,17 @@ impl CStr {
648648
pub fn display(&self) -> impl fmt::Display {
649649
crate::bstr::ByteStr::from_bytes(self.to_bytes())
650650
}
651+
652+
/// Returns the same string as a string slice `&CStr`.
653+
///
654+
/// This method is redundant when used directly on `&CStr`, but
655+
/// it helps dereferencing other string-like types to string slices,
656+
/// for example references to `Box<CStr>` or `Arc<CStr>`.
657+
#[inline]
658+
#[unstable(feature = "str_as_str", issue = "130366")]
659+
pub const fn as_c_str(&self) -> &CStr {
660+
self
661+
}
651662
}
652663

653664
#[stable(feature = "c_string_eq_c_str", since = "1.90.0")]

library/core/src/slice/mod.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4908,6 +4908,28 @@ impl<T> [T] {
49084908

49094909
if start <= self.len() && end <= self.len() { Some(start..end) } else { None }
49104910
}
4911+
4912+
/// Returns the same slice `&[T]`.
4913+
///
4914+
/// This method is redundant when used directly on `&[T]`, but
4915+
/// it helps dereferencing other "container" types to slices,
4916+
/// for example `Box<[T]>` or `Arc<[T]>`.
4917+
#[inline]
4918+
#[unstable(feature = "str_as_str", issue = "130366")]
4919+
pub const fn as_slice(&self) -> &[T] {
4920+
self
4921+
}
4922+
4923+
/// Returns the same slice `&mut [T]`.
4924+
///
4925+
/// This method is redundant when used directly on `&mut [T]`, but
4926+
/// it helps dereferencing other "container" types to slices,
4927+
/// for example `Box<[T]>` or `MutexGuard<[T]>`.
4928+
#[inline]
4929+
#[unstable(feature = "str_as_str", issue = "130366")]
4930+
pub const fn as_mut_slice(&mut self) -> &mut [T] {
4931+
self
4932+
}
49114933
}
49124934

49134935
impl<T> [MaybeUninit<T>] {

library/std/src/ffi/os_str.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1278,6 +1278,17 @@ impl OsStr {
12781278
pub fn display(&self) -> Display<'_> {
12791279
Display { os_str: self }
12801280
}
1281+
1282+
/// Returns the same string as a string slice `&OsStr`.
1283+
///
1284+
/// This method is redundant when used directly on `&OsStr`, but
1285+
/// it helps dereferencing other string-like types to string slices,
1286+
/// for example references to `Box<OsStr>` or `Arc<OsStr>`.
1287+
#[inline]
1288+
#[unstable(feature = "str_as_str", issue = "130366")]
1289+
pub const fn as_os_str(&self) -> &OsStr {
1290+
self
1291+
}
12811292
}
12821293

12831294
#[stable(feature = "box_from_os_str", since = "1.17.0")]

library/std/src/path.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3206,6 +3206,17 @@ impl Path {
32063206
Display { inner: self.inner.display() }
32073207
}
32083208

3209+
/// Returns the same path as `&Path`.
3210+
///
3211+
/// This method is redundant when used directly on `&Path`, but
3212+
/// it helps dereferencing other `PathBuf`-like types to `Path`s,
3213+
/// for example references to `Box<Path>` or `Arc<Path>`.
3214+
#[inline]
3215+
#[unstable(feature = "str_as_str", issue = "130366")]
3216+
pub const fn as_path(&self) -> &Path {
3217+
self
3218+
}
3219+
32093220
/// Queries the file system to get information about a file, directory, etc.
32103221
///
32113222
/// This function will traverse symbolic links to query information about the

library/std_detect/src/detect/os/darwin/aarch64.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ pub(crate) fn detect_features() -> cache::Initializer {
7676
let sme = _sysctlbyname(c"hw.optional.arm.FEAT_SME");
7777
let sme2 = _sysctlbyname(c"hw.optional.arm.FEAT_SME2");
7878
let sme2p1 = _sysctlbyname(c"hw.optional.arm.FEAT_SME2p1");
79+
let sme_b16b16 = _sysctlbyname(c"hw.optional.arm.FEAT_SME_B16B16");
80+
let sme_f16f16 = _sysctlbyname(c"hw.optional.arm.FEAT_SME_F16F16");
7981
let sme_f64f64 = _sysctlbyname(c"hw.optional.arm.FEAT_SME_F64F64");
8082
let sme_i16i64 = _sysctlbyname(c"hw.optional.arm.FEAT_SME_I16I64");
8183
let ssbs = _sysctlbyname(c"hw.optional.arm.FEAT_SSBS");
@@ -153,6 +155,8 @@ pub(crate) fn detect_features() -> cache::Initializer {
153155
enable_feature(Feature::sme, sme);
154156
enable_feature(Feature::sme2, sme2);
155157
enable_feature(Feature::sme2p1, sme2p1);
158+
enable_feature(Feature::sme_b16b16, sme_b16b16);
159+
enable_feature(Feature::sme_f16f16, sme_f16f16);
156160
enable_feature(Feature::sme_f64f64, sme_f64f64);
157161
enable_feature(Feature::sme_i16i64, sme_i16i64);
158162
enable_feature(Feature::ssbs, ssbs);

tests/assembly-llvm/stack-protector/stack-protector-heuristics-effect-windows-32bit.rs

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
//@ [strong] compile-flags: -Z stack-protector=strong
88
//@ [basic] compile-flags: -Z stack-protector=basic
99
//@ [none] compile-flags: -Z stack-protector=none
10-
//@ compile-flags: -C opt-level=2 -Z merge-functions=disabled
10+
//@ compile-flags: -C opt-level=2 -Z merge-functions=disabled -Cpanic=abort -Cdebuginfo=1
1111

1212
#![crate_type = "lib"]
1313
#![allow(internal_features)]
@@ -39,6 +39,8 @@ pub fn array_char(f: fn(*const char)) {
3939
// basic: __security_check_cookie
4040
// none-NOT: __security_check_cookie
4141
// missing-NOT: __security_check_cookie
42+
43+
// CHECK-DAG: .cv_fpo_endproc
4244
}
4345

4446
// CHECK-LABEL: array_u8_1
@@ -55,6 +57,8 @@ pub fn array_u8_1(f: fn(*const u8)) {
5557
// basic-NOT: __security_check_cookie
5658
// none-NOT: __security_check_cookie
5759
// missing-NOT: __security_check_cookie
60+
61+
// CHECK-DAG: .cv_fpo_endproc
5862
}
5963

6064
// CHECK-LABEL: array_u8_small:
@@ -72,6 +76,8 @@ pub fn array_u8_small(f: fn(*const u8)) {
7276
// basic-NOT: __security_check_cookie
7377
// none-NOT: __security_check_cookie
7478
// missing-NOT: __security_check_cookie
79+
80+
// CHECK-DAG: .cv_fpo_endproc
7581
}
7682

7783
// CHECK-LABEL: array_u8_large:
@@ -88,6 +94,8 @@ pub fn array_u8_large(f: fn(*const u8)) {
8894
// basic: __security_check_cookie
8995
// none-NOT: __security_check_cookie
9096
// missing-NOT: __security_check_cookie
97+
98+
// CHECK-DAG: .cv_fpo_endproc
9199
}
92100

93101
#[derive(Copy, Clone)]
@@ -107,6 +115,8 @@ pub fn array_bytesizednewtype_9(f: fn(*const ByteSizedNewtype)) {
107115
// basic: __security_check_cookie
108116
// none-NOT: __security_check_cookie
109117
// missing-NOT: __security_check_cookie
118+
119+
// CHECK-DAG: .cv_fpo_endproc
110120
}
111121

112122
// CHECK-LABEL: local_var_addr_used_indirectly
@@ -134,6 +144,8 @@ pub fn local_var_addr_used_indirectly(f: fn(bool)) {
134144
// basic-NOT: __security_check_cookie
135145
// none-NOT: __security_check_cookie
136146
// missing-NOT: __security_check_cookie
147+
148+
// CHECK-DAG: .cv_fpo_endproc
137149
}
138150

139151
// CHECK-LABEL: local_string_addr_taken
@@ -143,28 +155,15 @@ pub fn local_string_addr_taken(f: fn(&String)) {
143155
f(&x);
144156

145157
// Taking the address of the local variable `x` leads to stack smash
146-
// protection with the `strong` heuristic, but not with the `basic`
147-
// heuristic. It does not matter that the reference is not mut.
148-
//
149-
// An interesting note is that a similar function in C++ *would* be
150-
// protected by the `basic` heuristic, because `std::string` has a char
151-
// array internally as a small object optimization:
152-
// ```
153-
// cat <<EOF | clang++ -O2 -fstack-protector -S -x c++ - -o - | grep stack_chk
154-
// #include <string>
155-
// void f(void (*g)(const std::string&)) {
156-
// std::string x;
157-
// g(x);
158-
// }
159-
// EOF
160-
// ```
161-
//
158+
// protection. It does not matter that the reference is not mut.
162159

163160
// all: __security_check_cookie
164-
// strong-NOT: __security_check_cookie
165-
// basic-NOT: __security_check_cookie
161+
// strong: __security_check_cookie
162+
// basic: __security_check_cookie
166163
// none-NOT: __security_check_cookie
167164
// missing-NOT: __security_check_cookie
165+
166+
// CHECK-DAG: .cv_fpo_endproc
168167
}
169168

170169
pub trait SelfByRef {
@@ -194,6 +193,8 @@ pub fn local_var_addr_taken_used_locally_only(factory: fn() -> i32, sink: fn(i32
194193
// basic-NOT: __security_check_cookie
195194
// none-NOT: __security_check_cookie
196195
// missing-NOT: __security_check_cookie
196+
197+
// CHECK-DAG: .cv_fpo_endproc
197198
}
198199

199200
pub struct Gigastruct {
@@ -231,6 +232,8 @@ pub fn local_large_var_moved(f: fn(Gigastruct)) {
231232
// basic: __security_check_cookie
232233
// none-NOT: __security_check_cookie
233234
// missing-NOT: __security_check_cookie
235+
236+
// CHECK-DAG: .cv_fpo_endproc
234237
}
235238

236239
// CHECK-LABEL: local_large_var_cloned
@@ -260,6 +263,8 @@ pub fn local_large_var_cloned(f: fn(Gigastruct)) {
260263
// basic: __security_check_cookie
261264
// none-NOT: __security_check_cookie
262265
// missing-NOT: __security_check_cookie
266+
267+
// CHECK-DAG: .cv_fpo_endproc
263268
}
264269

265270
extern "C" {
@@ -300,6 +305,8 @@ pub fn alloca_small_compile_time_constant_arg(f: fn(*mut ())) {
300305
// basic-NOT: __security_check_cookie
301306
// none-NOT: __security_check_cookie
302307
// missing-NOT: __security_check_cookie
308+
309+
// CHECK-DAG: .cv_fpo_endproc
303310
}
304311

305312
// CHECK-LABEL: alloca_large_compile_time_constant_arg
@@ -312,6 +319,8 @@ pub fn alloca_large_compile_time_constant_arg(f: fn(*mut ())) {
312319
// basic-NOT: __security_check_cookie
313320
// none-NOT: __security_check_cookie
314321
// missing-NOT: __security_check_cookie
322+
323+
// CHECK-DAG: .cv_fpo_endproc
315324
}
316325

317326
// CHECK-LABEL: alloca_dynamic_arg
@@ -324,14 +333,14 @@ pub fn alloca_dynamic_arg(f: fn(*mut ()), n: usize) {
324333
// basic-NOT: __security_check_cookie
325334
// none-NOT: __security_check_cookie
326335
// missing-NOT: __security_check_cookie
336+
337+
// CHECK-DAG: .cv_fpo_endproc
327338
}
328339

329340
// The question then is: in what ways can Rust code generate array-`alloca`
330341
// LLVM instructions? This appears to only be generated by
331342
// rustc_codegen_ssa::traits::Builder::array_alloca() through
332-
// rustc_codegen_ssa::mir::operand::OperandValue::store_unsized(). FWICT
333-
// this is support for the "unsized locals" unstable feature:
334-
// https://doc.rust-lang.org/unstable-book/language-features/unsized-locals.html.
343+
// rustc_codegen_ssa::mir::operand::OperandValue::store_unsized().
335344

336345
// CHECK-LABEL: unsized_fn_param
337346
#[no_mangle]
@@ -346,14 +355,11 @@ pub fn unsized_fn_param(s: [u8], l: bool, f: fn([u8])) {
346355
// alloca, and is therefore not protected by the `strong` or `basic`
347356
// heuristics.
348357

349-
// We should have a __security_check_cookie call in `all` and `strong` modes but
350-
// LLVM does not support generating stack protectors in functions with funclet
351-
// based EH personalities.
352-
// https://github.com/llvm/llvm-project/blob/37fd3c96b917096d8a550038f6e61cdf0fc4174f/llvm/lib/CodeGen/StackProtector.cpp#L103C1-L109C4
353358
// all-NOT: __security_check_cookie
354359
// strong-NOT: __security_check_cookie
355-
356360
// basic-NOT: __security_check_cookie
357361
// none-NOT: __security_check_cookie
358362
// missing-NOT: __security_check_cookie
363+
364+
// CHECK-DAG: .cv_fpo_endproc
359365
}

0 commit comments

Comments
 (0)