Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions tests/ui/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,8 @@ Contains a single test. It imports a massive amount of very similar types from a

## `tests/ui/never_type/`

Tests relating to the never type. Most tests are specifically about the never type fallback behavior.

See [Tracking issue for promoting `!` to a type (RFC 1216) #35121](https://github.com/rust-lang/rust/issues/35121).

## `tests/ui/new-range/`
Expand Down
19 changes: 19 additions & 0 deletions tests/ui/coercion/coerce-issue-49593-box-never.e2021.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
error[E0277]: the trait bound `(): std::error::Error` is not satisfied
--> $DIR/coerce-issue-49593-box-never.rs:28:5
|
LL | Box::new(x)
| ^^^^^^^^^^^ the trait `std::error::Error` is not implemented for `()`
|
= note: required for the cast from `Box<()>` to `Box<(dyn std::error::Error + 'static)>`

error[E0277]: the trait bound `(): std::error::Error` is not satisfied
--> $DIR/coerce-issue-49593-box-never.rs:33:5
|
LL | raw_ptr(x)
| ^^^^^^^^^^ the trait `std::error::Error` is not implemented for `()`
|
= note: required for the cast from `*mut ()` to `*mut (dyn std::error::Error + 'static)`

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0277`.
62 changes: 21 additions & 41 deletions tests/ui/coercion/coerce-issue-49593-box-never.rs
Original file line number Diff line number Diff line change
@@ -1,57 +1,37 @@
//@ revisions: nofallback fallback
//@[fallback] edition: 2024
//@[fallback] check-pass
// Regression test for <https://github.com/rust-lang/rust/issues/49593>.
//
// This checks that we can construct `Box<dyn Error>` by calling `Box::new`
// with a value of the never type. And similarly for raw pointers.
//
// This used to fail because we tried to coerce `! -> dyn Error`, which then
// failed because we were trying to pass an unsized value by value, etc.
//
// On edition <= 2021 this currently fails because of never type fallback to
// unit.
//
//@ revisions: e2021 e2024
//@[e2021] edition: 2021
//@[e2024] edition: 2024
//
//@[e2024] check-pass

#![feature(never_type)]

use std::error::Error;
use std::mem;

fn raw_ptr_box<T>(t: T) -> *mut T {
fn raw_ptr<T>(t: T) -> *mut T {
panic!()
}

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

fn foo_raw_ptr(x: !) -> *mut dyn Error {
/* *mut $0 is coerced to *mut Error here */
raw_ptr_box::<_ /* ! */>(x)
//[nofallback]~^ ERROR trait bound `(): std::error::Error` is not satisfied
}

fn no_coercion(d: *mut dyn Error) -> *mut dyn Error {
/* an unsize coercion won't compile here, and it is indeed not used
because there is nothing requiring the _ to be Sized */
d as *mut _
}

trait Xyz {}
struct S;
struct T;
impl Xyz for S {}
impl Xyz for T {}

fn foo_no_never() {
let mut x /* : Option<S> */ = None;
let mut first_iter = false;
loop {
if !first_iter {
let y: Box<dyn Xyz>
= /* Box<$0> is coerced to Box<Xyz> here */ Box::new(x.unwrap());
}

x = Some(S);
first_iter = true;
}

let mut y: Option<S> = None;
// assert types are equal
mem::swap(&mut x, &mut y);
raw_ptr(x)
//[e2021]~^ ERROR trait bound `(): std::error::Error` is not satisfied
}

fn main() {}
79 changes: 0 additions & 79 deletions tests/ui/coercion/coerce-to-bang.rs

This file was deleted.

130 changes: 0 additions & 130 deletions tests/ui/coercion/coerce-to-bang.stderr

This file was deleted.

4 changes: 4 additions & 0 deletions tests/ui/editions/never-type-fallback-breaking.e2021.fixed
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// This is a test for various ways in which the change to the never type
// fallback can break things and for the `dependency_on_unit_never_type_fallback`
// lint.
//
//@ revisions: e2021 e2024
//
//@[e2021] edition: 2021
Expand Down
Loading
Loading