From c4c5fc8c4ce976387b3c7bc012ac274b4559b8ef Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Fri, 17 Sep 2021 09:59:50 -0400 Subject: [PATCH] Add nofallback tests --- ...ce-issue-49593-box-never.nofallback.stderr | 19 ++++++++++++++++++ .../coercion/coerce-issue-49593-box-never.rs | 10 ++++++++-- ...r => defaulted-never-note.fallback.stderr} | 4 ++-- .../ui/never_type/defaulted-never-note.rs | 20 +++++++++++-------- .../diverging-fallback-control-flow.rs | 3 ++- ...iverging-fallback-no-leak.fallback.stderr} | 4 ++-- .../never_type/diverging-fallback-no-leak.rs | 10 +++++++--- ...diverging-fallback-unconstrained-return.rs | 5 ++++- .../fallback-closure-wrap.fallback.stderr | 17 ++++++++++++++++ ...lue-fallback-issue-66757.nofallback.stderr | 17 ++++++++++++++++ .../never-value-fallback-issue-66757.rs | 9 +++++---- 11 files changed, 95 insertions(+), 23 deletions(-) create mode 100644 src/test/ui/coercion/coerce-issue-49593-box-never.nofallback.stderr rename src/test/ui/never_type/{defaulted-never-note.stderr => defaulted-never-note.fallback.stderr} (90%) rename src/test/ui/never_type/{diverging-fallback-no-leak.stderr => diverging-fallback-no-leak.fallback.stderr} (88%) create mode 100644 src/test/ui/never_type/fallback-closure-wrap.fallback.stderr create mode 100644 src/test/ui/never_type/never-value-fallback-issue-66757.nofallback.stderr diff --git a/src/test/ui/coercion/coerce-issue-49593-box-never.nofallback.stderr b/src/test/ui/coercion/coerce-issue-49593-box-never.nofallback.stderr new file mode 100644 index 000000000000..fbaa874792a0 --- /dev/null +++ b/src/test/ui/coercion/coerce-issue-49593-box-never.nofallback.stderr @@ -0,0 +1,19 @@ +error[E0277]: the trait bound `(): std::error::Error` is not satisfied + --> $DIR/coerce-issue-49593-box-never.rs:17:53 + | +LL | /* *mut $0 is coerced to Box here */ Box::<_ /* ! */>::new(x) + | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::error::Error` is not implemented for `()` + | + = note: required for the cast to the object type `dyn std::error::Error` + +error[E0277]: the trait bound `(): std::error::Error` is not satisfied + --> $DIR/coerce-issue-49593-box-never.rs:22:49 + | +LL | /* *mut $0 is coerced to *mut Error here */ raw_ptr_box::<_ /* ! */>(x) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::error::Error` is not implemented for `()` + | + = note: required for the cast to the object type `(dyn std::error::Error + 'static)` + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/coercion/coerce-issue-49593-box-never.rs b/src/test/ui/coercion/coerce-issue-49593-box-never.rs index 0824ce8cd585..7a4324bd5adc 100644 --- a/src/test/ui/coercion/coerce-issue-49593-box-never.rs +++ b/src/test/ui/coercion/coerce-issue-49593-box-never.rs @@ -1,5 +1,9 @@ -// check-pass -#![feature(never_type, never_type_fallback)] +// revisions: nofallback fallback +//[fallback] check-pass +//[nofallback] check-fail + +#![feature(never_type)] +#![cfg_attr(fallback, feature(never_type_fallback))] #![allow(unreachable_code)] use std::error::Error; @@ -11,10 +15,12 @@ fn raw_ptr_box(t: T) -> *mut T { fn foo(x: !) -> Box { /* *mut $0 is coerced to Box here */ Box::<_ /* ! */>::new(x) + //[nofallback]~^ 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 { diff --git a/src/test/ui/never_type/defaulted-never-note.stderr b/src/test/ui/never_type/defaulted-never-note.fallback.stderr similarity index 90% rename from src/test/ui/never_type/defaulted-never-note.stderr rename to src/test/ui/never_type/defaulted-never-note.fallback.stderr index 109a81a5ca04..588d644c77b0 100644 --- a/src/test/ui/never_type/defaulted-never-note.stderr +++ b/src/test/ui/never_type/defaulted-never-note.fallback.stderr @@ -1,5 +1,5 @@ error[E0277]: the trait bound `!: ImplementedForUnitButNotNever` is not satisfied - --> $DIR/defaulted-never-note.rs:26:5 + --> $DIR/defaulted-never-note.rs:30:5 | LL | foo(_x); | ^^^ the trait `ImplementedForUnitButNotNever` is not implemented for `!` @@ -8,7 +8,7 @@ LL | foo(_x); = note: this error might have been caused by changes to Rust's type-inference algorithm (see issue #48950 for more information). = help: did you intend to use the type `()` here instead? note: required by a bound in `foo` - --> $DIR/defaulted-never-note.rs:21:11 + --> $DIR/defaulted-never-note.rs:25:11 | LL | fn foo(_t: T) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `foo` diff --git a/src/test/ui/never_type/defaulted-never-note.rs b/src/test/ui/never_type/defaulted-never-note.rs index 70333c5f324f..54f551759cb3 100644 --- a/src/test/ui/never_type/defaulted-never-note.rs +++ b/src/test/ui/never_type/defaulted-never-note.rs @@ -1,6 +1,10 @@ +// revisions: nofallback fallback +//[nofallback] run-pass +//[fallback] check-fail + // We need to opt into the `never_type_fallback` feature // to trigger the requirement that this is testing. -#![feature(never_type, never_type_fallback)] +#![cfg_attr(fallback, feature(never_type, never_type_fallback))] #![allow(unused)] @@ -19,16 +23,16 @@ trait ImplementedForUnitButNotNever {} impl ImplementedForUnitButNotNever for () {} fn foo(_t: T) {} -//~^ NOTE required by this bound in `foo` -//~| NOTE required by a bound in `foo` +//[fallback]~^ NOTE required by this bound in `foo` +//[fallback]~| NOTE required by a bound in `foo` fn smeg() { let _x = return; foo(_x); - //~^ ERROR the trait bound - //~| NOTE the trait `ImplementedForUnitButNotNever` is not implemented - //~| NOTE this trait is implemented for `()` - //~| NOTE this error might have been caused - //~| HELP did you intend + //[fallback]~^ ERROR the trait bound + //[fallback]~| NOTE the trait `ImplementedForUnitButNotNever` is not implemented + //[fallback]~| NOTE this trait is implemented for `()` + //[fallback]~| NOTE this error might have been caused + //[fallback]~| HELP did you intend } fn main() { diff --git a/src/test/ui/never_type/diverging-fallback-control-flow.rs b/src/test/ui/never_type/diverging-fallback-control-flow.rs index f323f40ba31c..45a3362fa6d8 100644 --- a/src/test/ui/never_type/diverging-fallback-control-flow.rs +++ b/src/test/ui/never_type/diverging-fallback-control-flow.rs @@ -1,3 +1,4 @@ +// revisions: nofallback fallback // run-pass #![allow(dead_code)] @@ -8,7 +9,7 @@ // to fallback based on control-flow. In all of these cases, // the type variable winds up being the target of both a `!` coercion // and a coercion from a non-`!` variable, and hence falls back to `()`. -#![feature(never_type, never_type_fallback)] +#![cfg_attr(fallback, feature(never_type, never_type_fallback))] trait UnitDefault { fn default() -> Self; diff --git a/src/test/ui/never_type/diverging-fallback-no-leak.stderr b/src/test/ui/never_type/diverging-fallback-no-leak.fallback.stderr similarity index 88% rename from src/test/ui/never_type/diverging-fallback-no-leak.stderr rename to src/test/ui/never_type/diverging-fallback-no-leak.fallback.stderr index 27615fe4e77e..3a5b602f1118 100644 --- a/src/test/ui/never_type/diverging-fallback-no-leak.stderr +++ b/src/test/ui/never_type/diverging-fallback-no-leak.fallback.stderr @@ -1,5 +1,5 @@ error[E0277]: the trait bound `!: Test` is not satisfied - --> $DIR/diverging-fallback-no-leak.rs:14:5 + --> $DIR/diverging-fallback-no-leak.rs:17:5 | LL | unconstrained_arg(return); | ^^^^^^^^^^^^^^^^^ the trait `Test` is not implemented for `!` @@ -8,7 +8,7 @@ LL | unconstrained_arg(return); = note: this error might have been caused by changes to Rust's type-inference algorithm (see issue #48950 for more information). = help: did you intend to use the type `()` here instead? note: required by a bound in `unconstrained_arg` - --> $DIR/diverging-fallback-no-leak.rs:9:25 + --> $DIR/diverging-fallback-no-leak.rs:12:25 | LL | fn unconstrained_arg(_: T) {} | ^^^^ required by this bound in `unconstrained_arg` diff --git a/src/test/ui/never_type/diverging-fallback-no-leak.rs b/src/test/ui/never_type/diverging-fallback-no-leak.rs index a3a15f0ed885..03478e19ddcd 100644 --- a/src/test/ui/never_type/diverging-fallback-no-leak.rs +++ b/src/test/ui/never_type/diverging-fallback-no-leak.rs @@ -1,4 +1,7 @@ -#![feature(never_type_fallback)] +// revisions: nofallback fallback +//[nofallback] check-pass + +#![cfg_attr(fallback, feature(never_type, never_type_fallback))] fn make_unit() {} @@ -10,6 +13,7 @@ fn unconstrained_arg(_: T) {} fn main() { // Here the type variable falls back to `!`, - // and hence we get a type error: - unconstrained_arg(return); //~ ERROR trait bound `!: Test` is not satisfied + // and hence we get a type error. + unconstrained_arg(return); + //[fallback]~^ ERROR trait bound `!: Test` is not satisfied } diff --git a/src/test/ui/never_type/diverging-fallback-unconstrained-return.rs b/src/test/ui/never_type/diverging-fallback-unconstrained-return.rs index 9a6c965cefb0..7ea97126f89c 100644 --- a/src/test/ui/never_type/diverging-fallback-unconstrained-return.rs +++ b/src/test/ui/never_type/diverging-fallback-unconstrained-return.rs @@ -6,7 +6,10 @@ // // check-pass -#![feature(never_type_fallback)] +// revisions: nofallback fallback + +#![cfg_attr(fallback, feature(never_type, never_type_fallback))] + fn make_unit() {} diff --git a/src/test/ui/never_type/fallback-closure-wrap.fallback.stderr b/src/test/ui/never_type/fallback-closure-wrap.fallback.stderr new file mode 100644 index 000000000000..78d1a3caf4a3 --- /dev/null +++ b/src/test/ui/never_type/fallback-closure-wrap.fallback.stderr @@ -0,0 +1,17 @@ +error[E0271]: type mismatch resolving `<[closure@$DIR/fallback-closure-wrap.rs:18:40: 21:6] as FnOnce<()>>::Output == ()` + --> $DIR/fallback-closure-wrap.rs:18:31 + | +LL | let error = Closure::wrap(Box::new(move || { + | _______________________________^ +LL | | +LL | | panic!("Can't connect to server."); +LL | | }) as Box); + | |______^ expected `()`, found `!` + | + = note: expected unit type `()` + found type `!` + = note: required for the cast to the object type `dyn FnMut()` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0271`. diff --git a/src/test/ui/never_type/never-value-fallback-issue-66757.nofallback.stderr b/src/test/ui/never_type/never-value-fallback-issue-66757.nofallback.stderr new file mode 100644 index 000000000000..f374266626bc --- /dev/null +++ b/src/test/ui/never_type/never-value-fallback-issue-66757.nofallback.stderr @@ -0,0 +1,17 @@ +error[E0277]: the trait bound `E: From<()>` is not satisfied + --> $DIR/never-value-fallback-issue-66757.rs:27:5 + | +LL | >::from(never); + | ^^^^^^^^^^^^^^^^^^^^ the trait `From<()>` is not implemented for `E` + | + = help: the following implementations were found: + > +note: required by `from` + --> $SRC_DIR/core/src/convert/mod.rs:LL:COL + | +LL | fn from(_: T) -> Self; + | ^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/never_type/never-value-fallback-issue-66757.rs b/src/test/ui/never_type/never-value-fallback-issue-66757.rs index f2e9e087307d..6dc7e6ad2d93 100644 --- a/src/test/ui/never_type/never-value-fallback-issue-66757.rs +++ b/src/test/ui/never_type/never-value-fallback-issue-66757.rs @@ -4,12 +4,13 @@ // never) and an uninferred variable (here the argument to `From`) it // doesn't fallback to `()` but rather `!`. // -// run-pass +// revisions: nofallback fallback +//[fallback] run-pass +//[nofallback] check-fail #![feature(never_type)] -// FIXME(#67225) -- this should be true even without the fallback gate. -#![feature(never_type_fallback)] +#![cfg_attr(fallback, feature(never_type_fallback))] struct E; @@ -23,7 +24,7 @@ impl From for E { #[allow(dead_code)] fn foo(never: !) { >::from(never); // Ok - >::from(never); // Inference fails here + >::from(never); //[nofallback]~ ERROR trait bound `E: From<()>` is not satisfied } fn main() { }