Skip to content

Commit 9e6d80d

Browse files
committed
Auto merge of #161338 - jhpratt:rollup-gDOZoei, r=jhpratt
Rollup of 18 pull requests Successful merges: - rust-lang/rust#154210 (fix: fix the capture behavior of `if let` in closures) - rust-lang/rust#156176 (Initial implementation of `FnPtr` trait) - rust-lang/rust#160767 (Unify E0117 foreign-trait label for ADT/primitive types with existing Slice/Array/Tuple handling) - rust-lang/rust#161297 (std: use UNIX's `Instant` and `SystemTime` on Hermit) - rust-lang/rust#160489 (Adding diagnostic item markers for multiple fs functions and structs) - rust-lang/rust#160643 (Require windowed (and exception) for Xtensa ABI) - rust-lang/rust#161088 (suppress projection errors already covered by a trait error) - rust-lang/rust#161114 (Remove fields from TypeKind: Struct, Enum, Union and Tuple) - rust-lang/rust#161115 (Assorted allocator nitpicks) - rust-lang/rust#161220 (bootstrap: Allow `./x fix --allow-dirty`) - rust-lang/rust#161296 (Enable overflow checks in `rustc_thread_pool`) - rust-lang/rust#161298 (remove rustc_error_messages dependency) - rust-lang/rust#161304 (Rename test so it matches the issue) - rust-lang/rust#161309 (`allow(non_camel_case_types)` in `minicore.rs`) - rust-lang/rust#161315 (Relax codgen test variable regex) - rust-lang/rust#161318 (Doc: clarify how `Read::bytes` handling Interrupted errors) - rust-lang/rust#161321 (Update books) - rust-lang/rust#161335 ([compiletest] Use the correct rustc lib directory for query_rustc_output)
2 parents 9b37613 + 5c8c843 commit 9e6d80d

4 files changed

Lines changed: 90 additions & 0 deletions

File tree

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// This test serves to document the change in semantics introduced by
2+
// rust-lang/rust#138961, extended to `if let` closure captures.
3+
//
4+
// A corollary of partial-pattern.rs: while the tuple access testcase makes
5+
// it clear why these semantics are useful, it is actually the dereference
6+
// being performed by the pattern that matters.
7+
//
8+
// Before rust-lang/rust#154210, `if let` in closures captured all of `x`, so
9+
// this test did not fail because the closure is never called.
10+
//@normalize-stderr-test: "constructing invalid value of type [^:]+:" -> "constructing invalid value:"
11+
12+
#![allow(irrefutable_let_patterns)]
13+
14+
fn main() {
15+
// the inner reference is dangling
16+
let x: &&u32 = unsafe {
17+
let x: u32 = 42;
18+
&&*&raw const x
19+
};
20+
21+
//~v ERROR: encountered a dangling reference
22+
let _ = || {
23+
if let &&_y = x {}
24+
};
25+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
error: Undefined Behavior: constructing invalid value: encountered a dangling reference (use-after-free)
2+
--> tests/fail/match/closures/if-let-deref-in-pattern.rs:LL:CC
3+
|
4+
LL | let _ = || {
5+
| _____________^
6+
LL | | if let &&_y = x {}
7+
LL | | };
8+
| |_____^ Undefined Behavior occurred here
9+
|
10+
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
11+
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
12+
13+
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
14+
15+
error: aborting due to 1 previous error
16+
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// This test serves to document the change in semantics introduced by
2+
// rust-lang/rust#138961, extended to `if let` closure captures.
3+
//
4+
// Previously, the closure would capture the entirety of x, and access *(*x).0
5+
// when called. Now, the closure only captures *(*x).0, which means that
6+
// a &*(*x).0 reborrow happens when the closure is constructed.
7+
//
8+
// Hence, if one of the references is dangling, this constitutes newly introduced UB
9+
// in the case where the closure doesn't get called. This isn't a big deal,
10+
// because while opsem only now considers this to be UB, the unsafe code
11+
// guidelines have long recommended against any handling of dangling references.
12+
//
13+
// Before rust-lang/rust#154210, `if let` in closures captured all of `x`, so
14+
// this test did not fail because the closure is never called.
15+
//@normalize-stderr-test: "constructing invalid value of type [^:]+:" -> "constructing invalid value:"
16+
17+
#![allow(irrefutable_let_patterns)]
18+
19+
fn main() {
20+
// the inner references are dangling
21+
let x: &(&u32, &u32) = unsafe {
22+
let a = 21;
23+
let b = 37;
24+
let ra = &*&raw const a;
25+
let rb = &*&raw const b;
26+
&(ra, rb)
27+
};
28+
29+
//~v ERROR: encountered a dangling reference
30+
let _ = || {
31+
if let &(&_y, _) = x {}
32+
};
33+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
error: Undefined Behavior: constructing invalid value: encountered a dangling reference (use-after-free)
2+
--> tests/fail/match/closures/if-let-partial-pattern.rs:LL:CC
3+
|
4+
LL | let _ = || {
5+
| _____________^
6+
LL | | if let &(&_y, _) = x {}
7+
LL | | };
8+
| |_____^ Undefined Behavior occurred here
9+
|
10+
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
11+
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
12+
13+
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
14+
15+
error: aborting due to 1 previous error
16+

0 commit comments

Comments
 (0)