Add nofallback tests
This commit is contained in:
parent
078e3fd4ba
commit
c4c5fc8c4c
11 changed files with 95 additions and 23 deletions
|
@ -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<dyn Error> 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`.
|
|
@ -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: T) -> *mut T {
|
|||
|
||||
fn foo(x: !) -> Box<dyn Error> {
|
||||
/* *mut $0 is coerced to Box<dyn Error> 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 {
|
||||
|
|
|
@ -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 <https://github.com/rust-lang/rust/issues/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: ImplementedForUnitButNotNever>(_t: T) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `foo`
|
|
@ -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: ImplementedForUnitButNotNever>(_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() {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 <https://github.com/rust-lang/rust/issues/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: Test>(_: T) {}
|
||||
| ^^^^ required by this bound in `unconstrained_arg`
|
|
@ -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: Test>(_: 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
|
||||
}
|
||||
|
|
|
@ -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() {}
|
||||
|
||||
|
|
17
src/test/ui/never_type/fallback-closure-wrap.fallback.stderr
Normal file
17
src/test/ui/never_type/fallback-closure-wrap.fallback.stderr
Normal file
|
@ -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<dyn FnMut()>);
|
||||
| |______^ 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`.
|
|
@ -0,0 +1,17 @@
|
|||
error[E0277]: the trait bound `E: From<()>` is not satisfied
|
||||
--> $DIR/never-value-fallback-issue-66757.rs:27:5
|
||||
|
|
||||
LL | <E as From<_>>::from(never);
|
||||
| ^^^^^^^^^^^^^^^^^^^^ the trait `From<()>` is not implemented for `E`
|
||||
|
|
||||
= help: the following implementations were found:
|
||||
<E as From<!>>
|
||||
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`.
|
|
@ -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: !) {
|
||||
<E as From<!>>::from(never); // Ok
|
||||
<E as From<_>>::from(never); // Inference fails here
|
||||
<E as From<_>>::from(never); //[nofallback]~ ERROR trait bound `E: From<()>` is not satisfied
|
||||
}
|
||||
|
||||
fn main() { }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue