Skip to content

Commit b48576b

Browse files
committed
Auto merge of rust-lang#138831 - matthiaskrgr:rollup-3t0dqiz, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - rust-lang#138609 (Add stack overflow handler for cygwin) - rust-lang#138639 (Clean UI tests 2 of n) - rust-lang#138773 (catch_unwind intrinsic: document return value) - rust-lang#138782 (test(ui): add tuple-struct-where-clause-suggestion ui test for rust-lang#91520) - rust-lang#138794 (expand: Do not report `cfg_attr` traces on macros as unused attributes) - rust-lang#138801 (triagebot: add autolabel rules for D-* and L-*) - rust-lang#138804 (Allow inlining for `Atomic*::from_ptr`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents d93f678 + 2644500 commit b48576b

17 files changed

+226
-86
lines changed

compiler/rustc_expand/src/expand.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1941,7 +1941,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
19411941
let attr_name = attr.ident().unwrap().name;
19421942
// `#[cfg]` and `#[cfg_attr]` are special - they are
19431943
// eagerly evaluated.
1944-
if attr_name != sym::cfg && attr_name != sym::cfg_attr {
1944+
if attr_name != sym::cfg && attr_name != sym::cfg_attr_trace {
19451945
self.cx.sess.psess.buffer_lint(
19461946
UNUSED_ATTRIBUTES,
19471947
attr.span,

library/core/src/intrinsics/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3002,6 +3002,7 @@ pub const fn discriminant_value<T>(v: &T) -> <T as DiscriminantKind>::Discrimina
30023002

30033003
/// Rust's "try catch" construct for unwinding. Invokes the function pointer `try_fn` with the
30043004
/// data pointer `data`, and calls `catch_fn` if unwinding occurs while `try_fn` runs.
3005+
/// Returns `1` if unwinding occurred and `catch_fn` was called; returns `0` otherwise.
30053006
///
30063007
/// `catch_fn` must not unwind.
30073008
///

library/core/src/sync/atomic.rs

+3
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,7 @@ impl AtomicBool {
469469
///
470470
/// [valid]: crate::ptr#safety
471471
/// [Memory model for atomic accesses]: self#memory-model-for-atomic-accesses
472+
#[inline]
472473
#[stable(feature = "atomic_from_ptr", since = "1.75.0")]
473474
#[rustc_const_stable(feature = "const_atomic_from_ptr", since = "1.84.0")]
474475
pub const unsafe fn from_ptr<'a>(ptr: *mut bool) -> &'a AtomicBool {
@@ -1389,6 +1390,7 @@ impl<T> AtomicPtr<T> {
13891390
///
13901391
/// [valid]: crate::ptr#safety
13911392
/// [Memory model for atomic accesses]: self#memory-model-for-atomic-accesses
1393+
#[inline]
13921394
#[stable(feature = "atomic_from_ptr", since = "1.75.0")]
13931395
#[rustc_const_stable(feature = "const_atomic_from_ptr", since = "1.84.0")]
13941396
pub const unsafe fn from_ptr<'a>(ptr: *mut *mut T) -> &'a AtomicPtr<T> {
@@ -2525,6 +2527,7 @@ macro_rules! atomic_int {
25252527
///
25262528
/// [valid]: crate::ptr#safety
25272529
/// [Memory model for atomic accesses]: self#memory-model-for-atomic-accesses
2530+
#[inline]
25282531
#[stable(feature = "atomic_from_ptr", since = "1.75.0")]
25292532
#[rustc_const_stable(feature = "const_atomic_from_ptr", since = "1.84.0")]
25302533
pub const unsafe fn from_ptr<'a>(ptr: *mut $int_type) -> &'a $atomic_type {

library/std/src/sys/pal/unix/stack_overflow.rs

+87
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,7 @@ mod imp {
585585
target_os = "openbsd",
586586
target_os = "solaris",
587587
target_os = "illumos",
588+
target_os = "cygwin",
588589
)))]
589590
mod imp {
590591
pub unsafe fn init() {}
@@ -597,3 +598,89 @@ mod imp {
597598

598599
pub unsafe fn drop_handler(_data: *mut libc::c_void) {}
599600
}
601+
602+
#[cfg(target_os = "cygwin")]
603+
mod imp {
604+
mod c {
605+
pub type PVECTORED_EXCEPTION_HANDLER =
606+
Option<unsafe extern "system" fn(exceptioninfo: *mut EXCEPTION_POINTERS) -> i32>;
607+
pub type NTSTATUS = i32;
608+
pub type BOOL = i32;
609+
610+
unsafe extern "system" {
611+
pub fn AddVectoredExceptionHandler(
612+
first: u32,
613+
handler: PVECTORED_EXCEPTION_HANDLER,
614+
) -> *mut core::ffi::c_void;
615+
pub fn SetThreadStackGuarantee(stacksizeinbytes: *mut u32) -> BOOL;
616+
}
617+
618+
pub const EXCEPTION_STACK_OVERFLOW: NTSTATUS = 0xC00000FD_u32 as _;
619+
pub const EXCEPTION_CONTINUE_SEARCH: i32 = 1i32;
620+
621+
#[repr(C)]
622+
#[derive(Clone, Copy)]
623+
pub struct EXCEPTION_POINTERS {
624+
pub ExceptionRecord: *mut EXCEPTION_RECORD,
625+
// We don't need this field here
626+
// pub Context: *mut CONTEXT,
627+
}
628+
#[repr(C)]
629+
#[derive(Clone, Copy)]
630+
pub struct EXCEPTION_RECORD {
631+
pub ExceptionCode: NTSTATUS,
632+
pub ExceptionFlags: u32,
633+
pub ExceptionRecord: *mut EXCEPTION_RECORD,
634+
pub ExceptionAddress: *mut core::ffi::c_void,
635+
pub NumberParameters: u32,
636+
pub ExceptionInformation: [usize; 15],
637+
}
638+
}
639+
640+
/// Reserve stack space for use in stack overflow exceptions.
641+
fn reserve_stack() {
642+
let result = unsafe { c::SetThreadStackGuarantee(&mut 0x5000) };
643+
// Reserving stack space is not critical so we allow it to fail in the released build of libstd.
644+
// We still use debug assert here so that CI will test that we haven't made a mistake calling the function.
645+
debug_assert_ne!(result, 0, "failed to reserve stack space for exception handling");
646+
}
647+
648+
unsafe extern "system" fn vectored_handler(ExceptionInfo: *mut c::EXCEPTION_POINTERS) -> i32 {
649+
// SAFETY: It's up to the caller (which in this case is the OS) to ensure that `ExceptionInfo` is valid.
650+
unsafe {
651+
let rec = &(*(*ExceptionInfo).ExceptionRecord);
652+
let code = rec.ExceptionCode;
653+
654+
if code == c::EXCEPTION_STACK_OVERFLOW {
655+
crate::thread::with_current_name(|name| {
656+
let name = name.unwrap_or("<unknown>");
657+
rtprintpanic!("\nthread '{name}' has overflowed its stack\n");
658+
});
659+
}
660+
c::EXCEPTION_CONTINUE_SEARCH
661+
}
662+
}
663+
664+
pub unsafe fn init() {
665+
// SAFETY: `vectored_handler` has the correct ABI and is safe to call during exception handling.
666+
unsafe {
667+
let result = c::AddVectoredExceptionHandler(0, Some(vectored_handler));
668+
// Similar to the above, adding the stack overflow handler is allowed to fail
669+
// but a debug assert is used so CI will still test that it normally works.
670+
debug_assert!(!result.is_null(), "failed to install exception handler");
671+
}
672+
// Set the thread stack guarantee for the main thread.
673+
reserve_stack();
674+
}
675+
676+
pub unsafe fn cleanup() {}
677+
678+
pub unsafe fn make_handler(main_thread: bool) -> super::Handler {
679+
if !main_thread {
680+
reserve_stack();
681+
}
682+
super::Handler::null()
683+
}
684+
685+
pub unsafe fn drop_handler(_data: *mut libc::c_void) {}
686+
}

src/tools/tidy/src/issues.txt

-3
Original file line numberDiff line numberDiff line change
@@ -2000,7 +2000,6 @@ ui/issues/issue-28586.rs
20002000
ui/issues/issue-28600.rs
20012001
ui/issues/issue-28625.rs
20022002
ui/issues/issue-28776.rs
2003-
ui/issues/issue-28777.rs
20042003
ui/issues/issue-28828.rs
20052004
ui/issues/issue-28839.rs
20062005
ui/issues/issue-28936.rs
@@ -2063,7 +2062,6 @@ ui/issues/issue-3091.rs
20632062
ui/issues/issue-31011.rs
20642063
ui/issues/issue-3109.rs
20652064
ui/issues/issue-3121.rs
2066-
ui/issues/issue-31260.rs
20672065
ui/issues/issue-31267-additional.rs
20682066
ui/issues/issue-31267.rs
20692067
ui/issues/issue-31299.rs
@@ -2608,7 +2606,6 @@ ui/issues/issue-9243.rs
26082606
ui/issues/issue-9249.rs
26092607
ui/issues/issue-9259.rs
26102608
ui/issues/issue-92741.rs
2611-
ui/issues/issue-9382.rs
26122609
ui/issues/issue-9446.rs
26132610
ui/issues/issue-9719.rs
26142611
ui/issues/issue-9725.rs

src/tools/tidy/src/ui_tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use ignore::Walk;
1717
const ENTRY_LIMIT: u32 = 901;
1818
// FIXME: The following limits should be reduced eventually.
1919

20-
const ISSUES_ENTRY_LIMIT: u32 = 1634;
20+
const ISSUES_ENTRY_LIMIT: u32 = 1631;
2121

2222
const EXPECTED_TEST_FILE_EXTENSIONS: &[&str] = &[
2323
"rs", // test source files
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//! Regression test that ensures struct field literals can be coerced into slice and `Box` types
2+
3+
//@ check-pass
4+
5+
struct Thing1<'a> {
6+
baz: &'a [Box<isize>],
7+
bar: Box<u64>,
8+
}
9+
10+
struct Thing2<'a> {
11+
baz: &'a [Box<isize>],
12+
bar: u64,
13+
}
14+
15+
pub fn main() {
16+
let _a = Thing1 { baz: &[], bar: Box::new(32) };
17+
let _b = Thing1 { baz: &Vec::new(), bar: Box::new(32) };
18+
let _c = Thing2 { baz: &[], bar: 32 };
19+
let _d = Thing2 { baz: &Vec::new(), bar: 32 };
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//! Regression test to check that literal expressions in a struct field can be coerced to the
2+
//! expected field type, including block expressions.
3+
//!
4+
//! Issue: <https://github.com/rust-lang/rust/issues/31260>
5+
6+
//@ check-pass
7+
8+
pub struct Struct<K: 'static> {
9+
pub field: K,
10+
}
11+
12+
static STRUCT: Struct<&'static [u8]> = Struct { field: { &[1] } };
13+
14+
static STRUCT2: Struct<&'static [u8]> = Struct { field: &[1] };
15+
16+
fn main() {}

tests/ui/issues/issue-28777.rs

-22
This file was deleted.

tests/ui/issues/issue-31260.rs

-15
This file was deleted.

tests/ui/issues/issue-9382.rs

-37
This file was deleted.

tests/ui/lint/inert-attr-macro.rs

+7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//@ check-pass
22

3+
#![feature(cfg_boolean_literals)]
34
#![warn(unused)]
45

56
macro_rules! foo {
@@ -17,4 +18,10 @@ fn main() {
1718
// This does work, since the attribute is on a parent
1819
// of the macro invocation.
1920
#[allow(warnings)] { #[inline] foo!(); }
21+
22+
// Ok, `cfg` and `cfg_attr` are expanded eagerly and do not warn.
23+
#[cfg(true)] foo!();
24+
#[cfg(false)] foo!();
25+
#[cfg_attr(true, cfg(true))] foo!();
26+
#[cfg_attr(false, nonexistent)] foo!();
2027
}

tests/ui/lint/inert-attr-macro.stderr

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,41 @@
11
warning: unused attribute `inline`
2-
--> $DIR/inert-attr-macro.rs:10:5
2+
--> $DIR/inert-attr-macro.rs:11:5
33
|
44
LL | #[inline] foo!();
55
| ^^^^^^^^^
66
|
77
note: the built-in attribute `inline` will be ignored, since it's applied to the macro invocation `foo`
8-
--> $DIR/inert-attr-macro.rs:10:15
8+
--> $DIR/inert-attr-macro.rs:11:15
99
|
1010
LL | #[inline] foo!();
1111
| ^^^
1212
note: the lint level is defined here
13-
--> $DIR/inert-attr-macro.rs:3:9
13+
--> $DIR/inert-attr-macro.rs:4:9
1414
|
1515
LL | #![warn(unused)]
1616
| ^^^^^^
1717
= note: `#[warn(unused_attributes)]` implied by `#[warn(unused)]`
1818

1919
warning: unused attribute `allow`
20-
--> $DIR/inert-attr-macro.rs:14:5
20+
--> $DIR/inert-attr-macro.rs:15:5
2121
|
2222
LL | #[allow(warnings)] #[inline] foo!();
2323
| ^^^^^^^^^^^^^^^^^^
2424
|
2525
note: the built-in attribute `allow` will be ignored, since it's applied to the macro invocation `foo`
26-
--> $DIR/inert-attr-macro.rs:14:34
26+
--> $DIR/inert-attr-macro.rs:15:34
2727
|
2828
LL | #[allow(warnings)] #[inline] foo!();
2929
| ^^^
3030

3131
warning: unused attribute `inline`
32-
--> $DIR/inert-attr-macro.rs:14:24
32+
--> $DIR/inert-attr-macro.rs:15:24
3333
|
3434
LL | #[allow(warnings)] #[inline] foo!();
3535
| ^^^^^^^^^
3636
|
3737
note: the built-in attribute `inline` will be ignored, since it's applied to the macro invocation `foo`
38-
--> $DIR/inert-attr-macro.rs:14:34
38+
--> $DIR/inert-attr-macro.rs:15:34
3939
|
4040
LL | #[allow(warnings)] #[inline] foo!();
4141
| ^^^
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//! Regression test for ensuring that operator precedence is correctly handled in the presence of
2+
//! braces
3+
//!
4+
//! Issue: <https://github.com/rust-lang/rust/issues/28777>
5+
6+
//@ run-pass
7+
8+
#[allow(unused_braces)]
9+
fn main() {
10+
let v1 = { 1 + { 2 } * { 3 } };
11+
let v2 = 1 + { 2 } * { 3 };
12+
13+
assert_eq!(7, v1);
14+
assert_eq!(7, v2);
15+
16+
let v3;
17+
v3 = { 1 + { 2 } * { 3 } };
18+
let v4;
19+
v4 = 1 + { 2 } * { 3 };
20+
assert_eq!(7, v3);
21+
assert_eq!(7, v4);
22+
23+
let v5 = { 1 + { 2 } * 3 };
24+
assert_eq!(7, v5);
25+
26+
let v9 = { 1 + if 1 > 2 { 1 } else { 2 } * { 3 } };
27+
assert_eq!(7, v9);
28+
}

0 commit comments

Comments
 (0)