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
20 changes: 20 additions & 0 deletions tests/ui/never_type/try-block-never-type-fallback.e2021.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
error[E0277]: the trait bound `!: From<()>` is not satisfied
--> $DIR/try-block-never-type-fallback.rs:20:9
|
LL | bar(try { x? });
| --- ^^^^^^^^^^ the trait `From<()>` is not implemented for `!`
| |
| required by a bound introduced by this call
|
= note: this error might have been caused by changes to Rust's type-inference algorithm (see issue #148922 <https://github.com/rust-lang/rust/issues/148922> for more information)
= help: you might have intended to use the type `()` here instead
= note: required for `()` to implement `Into<!>`
note: required by a bound in `bar`
--> $DIR/try-block-never-type-fallback.rs:15:23
|
LL | fn bar(_: Result<impl Into<!>, u32>) {
| ^^^^^^^ required by this bound in `bar`

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0277`.
25 changes: 25 additions & 0 deletions tests/ui/never_type/try-block-never-type-fallback.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//@ revisions: e2021 e2024
//@[e2021] edition: 2021
//@[e2024] edition: 2024
//@[e2024] check-pass

// Issue #125364: Bad interaction between never_type, try_blocks, and From/Into
//
// In edition 2021, the never type in try blocks falls back to (),
// causing a type error (since (): Into<!> does not hold).
// In edition 2024, it falls back to !, allowing the code to compile correctly.

#![feature(never_type)]
#![feature(try_blocks)]

fn bar(_: Result<impl Into<!>, u32>) {
unimplemented!()
}

fn foo(x: Result<!, u32>) {
bar(try { x? });
//[e2021]~^ ERROR the trait bound `!: From<()>` is not satisfied
}

fn main() {
}
Loading