Skip to content

Commit 120c25c

Browse files
authored
Unrolled build for #149541
Rollup merge of #149541 - WaffleLapkin:never-test, r=lcnr Various never type test improvements I want to make sure that the never type ui tests are actually sensible, and to do so I'm trying to clean them up. This mainly adds comments explaining test purposes and removes outdated stuff. I imagine best reviewed commit-by-commit, I tried to write useful descriptions and group things into small commits. cc `@lcnr` (I removed `fallback`/`nofallback` terminology in b5f82d4)
2 parents 568b117 + cb5318d commit 120c25c

File tree

65 files changed

+515
-727
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+515
-727
lines changed

tests/ui/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -941,6 +941,8 @@ Contains a single test. It imports a massive amount of very similar types from a
941941

942942
## `tests/ui/never_type/`
943943

944+
Tests relating to the never type. Most tests are specifically about the never type fallback behavior.
945+
944946
See [Tracking issue for promoting `!` to a type (RFC 1216) #35121](https://github.com/rust-lang/rust/issues/35121).
945947

946948
## `tests/ui/new-range/`
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
error[E0277]: the trait bound `(): std::error::Error` is not satisfied
2+
--> $DIR/coerce-issue-49593-box-never.rs:28:5
3+
|
4+
LL | Box::new(x)
5+
| ^^^^^^^^^^^ the trait `std::error::Error` is not implemented for `()`
6+
|
7+
= note: required for the cast from `Box<()>` to `Box<(dyn std::error::Error + 'static)>`
8+
9+
error[E0277]: the trait bound `(): std::error::Error` is not satisfied
10+
--> $DIR/coerce-issue-49593-box-never.rs:33:5
11+
|
12+
LL | raw_ptr(x)
13+
| ^^^^^^^^^^ the trait `std::error::Error` is not implemented for `()`
14+
|
15+
= note: required for the cast from `*mut ()` to `*mut (dyn std::error::Error + 'static)`
16+
17+
error: aborting due to 2 previous errors
18+
19+
For more information about this error, try `rustc --explain E0277`.
Lines changed: 21 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,37 @@
1-
//@ revisions: nofallback fallback
2-
//@[fallback] edition: 2024
3-
//@[fallback] check-pass
1+
// Regression test for <https://github.com/rust-lang/rust/issues/49593>.
2+
//
3+
// This checks that we can construct `Box<dyn Error>` by calling `Box::new`
4+
// with a value of the never type. And similarly for raw pointers.
5+
//
6+
// This used to fail because we tried to coerce `! -> dyn Error`, which then
7+
// failed because we were trying to pass an unsized value by value, etc.
8+
//
9+
// On edition <= 2021 this currently fails because of never type fallback to
10+
// unit.
11+
//
12+
//@ revisions: e2021 e2024
13+
//@[e2021] edition: 2021
14+
//@[e2024] edition: 2024
15+
//
16+
//@[e2024] check-pass
417

518
#![feature(never_type)]
619

720
use std::error::Error;
821
use std::mem;
922

10-
fn raw_ptr_box<T>(t: T) -> *mut T {
23+
fn raw_ptr<T>(t: T) -> *mut T {
1124
panic!()
1225
}
1326

1427
fn foo(x: !) -> Box<dyn Error> {
15-
// Method resolution will generate new inference vars and relate them.
16-
// Thus fallback will not fall back to `!`, but `()` instead.
17-
Box::<_ /* ! */>::new(x)
18-
//[nofallback]~^ ERROR trait bound `(): std::error::Error` is not satisfied
28+
Box::new(x)
29+
//[e2021]~^ ERROR trait bound `(): std::error::Error` is not satisfied
1930
}
2031

2132
fn foo_raw_ptr(x: !) -> *mut dyn Error {
22-
/* *mut $0 is coerced to *mut Error here */
23-
raw_ptr_box::<_ /* ! */>(x)
24-
//[nofallback]~^ ERROR trait bound `(): std::error::Error` is not satisfied
25-
}
26-
27-
fn no_coercion(d: *mut dyn Error) -> *mut dyn Error {
28-
/* an unsize coercion won't compile here, and it is indeed not used
29-
because there is nothing requiring the _ to be Sized */
30-
d as *mut _
31-
}
32-
33-
trait Xyz {}
34-
struct S;
35-
struct T;
36-
impl Xyz for S {}
37-
impl Xyz for T {}
38-
39-
fn foo_no_never() {
40-
let mut x /* : Option<S> */ = None;
41-
let mut first_iter = false;
42-
loop {
43-
if !first_iter {
44-
let y: Box<dyn Xyz>
45-
= /* Box<$0> is coerced to Box<Xyz> here */ Box::new(x.unwrap());
46-
}
47-
48-
x = Some(S);
49-
first_iter = true;
50-
}
51-
52-
let mut y: Option<S> = None;
53-
// assert types are equal
54-
mem::swap(&mut x, &mut y);
33+
raw_ptr(x)
34+
//[e2021]~^ ERROR trait bound `(): std::error::Error` is not satisfied
5535
}
5636

5737
fn main() {}

tests/ui/coercion/coerce-to-bang.rs

Lines changed: 0 additions & 79 deletions
This file was deleted.

tests/ui/coercion/coerce-to-bang.stderr

Lines changed: 0 additions & 130 deletions
This file was deleted.

tests/ui/editions/never-type-fallback-breaking.e2021.fixed

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// This is a test for various ways in which the change to the never type
2+
// fallback can break things and for the `dependency_on_unit_never_type_fallback`
3+
// lint.
4+
//
15
//@ revisions: e2021 e2024
26
//
37
//@[e2021] edition: 2021

0 commit comments

Comments
 (0)