Skip to content

Commit c4c5fc8

Browse files
Add nofallback tests
1 parent 078e3fd commit c4c5fc8

11 files changed

+95
-23
lines changed
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:17:53
3+
|
4+
LL | /* *mut $0 is coerced to Box<dyn Error> here */ Box::<_ /* ! */>::new(x)
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::error::Error` is not implemented for `()`
6+
|
7+
= note: required for the cast to the object type `dyn std::error::Error`
8+
9+
error[E0277]: the trait bound `(): std::error::Error` is not satisfied
10+
--> $DIR/coerce-issue-49593-box-never.rs:22:49
11+
|
12+
LL | /* *mut $0 is coerced to *mut Error here */ raw_ptr_box::<_ /* ! */>(x)
13+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::error::Error` is not implemented for `()`
14+
|
15+
= note: required for the cast to the object type `(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`.

Diff for: src/test/ui/coercion/coerce-issue-49593-box-never.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
// check-pass
2-
#![feature(never_type, never_type_fallback)]
1+
// revisions: nofallback fallback
2+
//[fallback] check-pass
3+
//[nofallback] check-fail
4+
5+
#![feature(never_type)]
6+
#![cfg_attr(fallback, feature(never_type_fallback))]
37
#![allow(unreachable_code)]
48

59
use std::error::Error;
@@ -11,10 +15,12 @@ fn raw_ptr_box<T>(t: T) -> *mut T {
1115

1216
fn foo(x: !) -> Box<dyn Error> {
1317
/* *mut $0 is coerced to Box<dyn Error> here */ Box::<_ /* ! */>::new(x)
18+
//[nofallback]~^ ERROR trait bound `(): std::error::Error` is not satisfied
1419
}
1520

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

2026
fn no_coercion(d: *mut dyn Error) -> *mut dyn Error {

Diff for: src/test/ui/never_type/defaulted-never-note.stderr renamed to src/test/ui/never_type/defaulted-never-note.fallback.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0277]: the trait bound `!: ImplementedForUnitButNotNever` is not satisfied
2-
--> $DIR/defaulted-never-note.rs:26:5
2+
--> $DIR/defaulted-never-note.rs:30:5
33
|
44
LL | foo(_x);
55
| ^^^ the trait `ImplementedForUnitButNotNever` is not implemented for `!`
@@ -8,7 +8,7 @@ LL | foo(_x);
88
= note: this error might have been caused by changes to Rust's type-inference algorithm (see issue #48950 <https://github.com/rust-lang/rust/issues/48950> for more information).
99
= help: did you intend to use the type `()` here instead?
1010
note: required by a bound in `foo`
11-
--> $DIR/defaulted-never-note.rs:21:11
11+
--> $DIR/defaulted-never-note.rs:25:11
1212
|
1313
LL | fn foo<T: ImplementedForUnitButNotNever>(_t: T) {}
1414
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `foo`

Diff for: src/test/ui/never_type/defaulted-never-note.rs

+12-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
// revisions: nofallback fallback
2+
//[nofallback] run-pass
3+
//[fallback] check-fail
4+
15
// We need to opt into the `never_type_fallback` feature
26
// to trigger the requirement that this is testing.
3-
#![feature(never_type, never_type_fallback)]
7+
#![cfg_attr(fallback, feature(never_type, never_type_fallback))]
48

59
#![allow(unused)]
610

@@ -19,16 +23,16 @@ trait ImplementedForUnitButNotNever {}
1923
impl ImplementedForUnitButNotNever for () {}
2024

2125
fn foo<T: ImplementedForUnitButNotNever>(_t: T) {}
22-
//~^ NOTE required by this bound in `foo`
23-
//~| NOTE required by a bound in `foo`
26+
//[fallback]~^ NOTE required by this bound in `foo`
27+
//[fallback]~| NOTE required by a bound in `foo`
2428
fn smeg() {
2529
let _x = return;
2630
foo(_x);
27-
//~^ ERROR the trait bound
28-
//~| NOTE the trait `ImplementedForUnitButNotNever` is not implemented
29-
//~| NOTE this trait is implemented for `()`
30-
//~| NOTE this error might have been caused
31-
//~| HELP did you intend
31+
//[fallback]~^ ERROR the trait bound
32+
//[fallback]~| NOTE the trait `ImplementedForUnitButNotNever` is not implemented
33+
//[fallback]~| NOTE this trait is implemented for `()`
34+
//[fallback]~| NOTE this error might have been caused
35+
//[fallback]~| HELP did you intend
3236
}
3337

3438
fn main() {

Diff for: src/test/ui/never_type/diverging-fallback-control-flow.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// revisions: nofallback fallback
12
// run-pass
23

34
#![allow(dead_code)]
@@ -8,7 +9,7 @@
89
// to fallback based on control-flow. In all of these cases,
910
// the type variable winds up being the target of both a `!` coercion
1011
// and a coercion from a non-`!` variable, and hence falls back to `()`.
11-
#![feature(never_type, never_type_fallback)]
12+
#![cfg_attr(fallback, feature(never_type, never_type_fallback))]
1213

1314
trait UnitDefault {
1415
fn default() -> Self;

Diff for: src/test/ui/never_type/diverging-fallback-no-leak.stderr renamed to src/test/ui/never_type/diverging-fallback-no-leak.fallback.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0277]: the trait bound `!: Test` is not satisfied
2-
--> $DIR/diverging-fallback-no-leak.rs:14:5
2+
--> $DIR/diverging-fallback-no-leak.rs:17:5
33
|
44
LL | unconstrained_arg(return);
55
| ^^^^^^^^^^^^^^^^^ the trait `Test` is not implemented for `!`
@@ -8,7 +8,7 @@ LL | unconstrained_arg(return);
88
= note: this error might have been caused by changes to Rust's type-inference algorithm (see issue #48950 <https://github.com/rust-lang/rust/issues/48950> for more information).
99
= help: did you intend to use the type `()` here instead?
1010
note: required by a bound in `unconstrained_arg`
11-
--> $DIR/diverging-fallback-no-leak.rs:9:25
11+
--> $DIR/diverging-fallback-no-leak.rs:12:25
1212
|
1313
LL | fn unconstrained_arg<T: Test>(_: T) {}
1414
| ^^^^ required by this bound in `unconstrained_arg`

Diff for: src/test/ui/never_type/diverging-fallback-no-leak.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
#![feature(never_type_fallback)]
1+
// revisions: nofallback fallback
2+
//[nofallback] check-pass
3+
4+
#![cfg_attr(fallback, feature(never_type, never_type_fallback))]
25

36
fn make_unit() {}
47

@@ -10,6 +13,7 @@ fn unconstrained_arg<T: Test>(_: T) {}
1013

1114
fn main() {
1215
// Here the type variable falls back to `!`,
13-
// and hence we get a type error:
14-
unconstrained_arg(return); //~ ERROR trait bound `!: Test` is not satisfied
16+
// and hence we get a type error.
17+
unconstrained_arg(return);
18+
//[fallback]~^ ERROR trait bound `!: Test` is not satisfied
1519
}

Diff for: src/test/ui/never_type/diverging-fallback-unconstrained-return.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
//
77
// check-pass
88

9-
#![feature(never_type_fallback)]
9+
// revisions: nofallback fallback
10+
11+
#![cfg_attr(fallback, feature(never_type, never_type_fallback))]
12+
1013

1114
fn make_unit() {}
1215

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error[E0271]: type mismatch resolving `<[closure@$DIR/fallback-closure-wrap.rs:18:40: 21:6] as FnOnce<()>>::Output == ()`
2+
--> $DIR/fallback-closure-wrap.rs:18:31
3+
|
4+
LL | let error = Closure::wrap(Box::new(move || {
5+
| _______________________________^
6+
LL | |
7+
LL | | panic!("Can't connect to server.");
8+
LL | | }) as Box<dyn FnMut()>);
9+
| |______^ expected `()`, found `!`
10+
|
11+
= note: expected unit type `()`
12+
found type `!`
13+
= note: required for the cast to the object type `dyn FnMut()`
14+
15+
error: aborting due to previous error
16+
17+
For more information about this error, try `rustc --explain E0271`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error[E0277]: the trait bound `E: From<()>` is not satisfied
2+
--> $DIR/never-value-fallback-issue-66757.rs:27:5
3+
|
4+
LL | <E as From<_>>::from(never);
5+
| ^^^^^^^^^^^^^^^^^^^^ the trait `From<()>` is not implemented for `E`
6+
|
7+
= help: the following implementations were found:
8+
<E as From<!>>
9+
note: required by `from`
10+
--> $SRC_DIR/core/src/convert/mod.rs:LL:COL
11+
|
12+
LL | fn from(_: T) -> Self;
13+
| ^^^^^^^^^^^^^^^^^^^^^^
14+
15+
error: aborting due to previous error
16+
17+
For more information about this error, try `rustc --explain E0277`.

Diff for: src/test/ui/never_type/never-value-fallback-issue-66757.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44
// never) and an uninferred variable (here the argument to `From`) it
55
// doesn't fallback to `()` but rather `!`.
66
//
7-
// run-pass
7+
// revisions: nofallback fallback
8+
//[fallback] run-pass
9+
//[nofallback] check-fail
810

911
#![feature(never_type)]
1012

11-
// FIXME(#67225) -- this should be true even without the fallback gate.
12-
#![feature(never_type_fallback)]
13+
#![cfg_attr(fallback, feature(never_type_fallback))]
1314

1415
struct E;
1516

@@ -23,7 +24,7 @@ impl From<!> for E {
2324
#[allow(dead_code)]
2425
fn foo(never: !) {
2526
<E as From<!>>::from(never); // Ok
26-
<E as From<_>>::from(never); // Inference fails here
27+
<E as From<_>>::from(never); //[nofallback]~ ERROR trait bound `E: From<()>` is not satisfied
2728
}
2829

2930
fn main() { }

0 commit comments

Comments
 (0)