Skip to content

Commit

Permalink
Auto merge of #131320 - matthiaskrgr:rollup-tom15b3, r=matthiaskrgr
Browse files Browse the repository at this point in the history
Rollup of 5 pull requests

Successful merges:

 - #129392 (Do not consider match/let/ref of place that evaluates to `!` to diverge, disallow coercions from them too)
 - #131279 (update "build/host" symlink comment)
 - #131312 (On function and method calls in patterns, link to the book)
 - #131315 (bootstrap: add `std_features` config)
 - #131316 (Fix typo in primitive_docs.rs)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Oct 6, 2024
2 parents 42175d7 + 71df30e commit 62142cb
Showing 1 changed file with 49 additions and 2 deletions.
51 changes: 49 additions & 2 deletions tests/pass/underscore_pattern.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Various tests ensuring that underscore patterns really just construct the place, but don't check its contents.
#![feature(strict_provenance)]
#![feature(never_type)]

use std::ptr;

fn main() {
Expand All @@ -9,6 +11,7 @@ fn main() {
invalid_let();
dangling_let_type_annotation();
invalid_let_type_annotation();
never();
}

fn dangling_match() {
Expand All @@ -34,13 +37,25 @@ fn invalid_match() {
_ => {}
}
}

unsafe {
let x: Uninit<!> = Uninit { uninit: () };
match x.value {
_ => {}
}
}
}

fn dangling_let() {
unsafe {
let ptr = ptr::without_provenance::<bool>(0x40);
let _ = *ptr;
}

unsafe {
let ptr = ptr::without_provenance::<!>(0x40);
let _ = *ptr;
}
}

fn invalid_let() {
Expand All @@ -49,6 +64,12 @@ fn invalid_let() {
let ptr = ptr::addr_of!(val).cast::<bool>();
let _ = *ptr;
}

unsafe {
let val = 3u8;
let ptr = ptr::addr_of!(val).cast::<!>();
let _ = *ptr;
}
}

// Adding a type annotation used to change how MIR is generated, make sure we cover both cases.
Expand All @@ -57,6 +78,11 @@ fn dangling_let_type_annotation() {
let ptr = ptr::without_provenance::<bool>(0x40);
let _: bool = *ptr;
}

unsafe {
let ptr = ptr::without_provenance::<!>(0x40);
let _: ! = *ptr;
}
}

fn invalid_let_type_annotation() {
Expand All @@ -65,7 +91,28 @@ fn invalid_let_type_annotation() {
let ptr = ptr::addr_of!(val).cast::<bool>();
let _: bool = *ptr;
}

unsafe {
let val = 3u8;
let ptr = ptr::addr_of!(val).cast::<!>();
let _: ! = *ptr;
}
}

// FIXME: we should also test `!`, not just `bool` -- but that s currently buggy:
// https://github.com/rust-lang/rust/issues/117288
// Regression test from <https://github.com/rust-lang/rust/issues/117288>.
fn never() {
unsafe {
let x = 3u8;
let x: *const ! = &x as *const u8 as *const _;
let _: ! = *x;
}

// Without a type annotation, make sure we don't implicitly coerce `!` to `()`
// when we do the noop `*x` (as that would require a `!` *value*, creating
// which is UB).
unsafe {
let x = 3u8;
let x: *const ! = &x as *const u8 as *const _;
let _ = *x;
}
}

0 comments on commit 62142cb

Please sign in to comment.