Skip to content

Commit

Permalink
Add nofallback tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark-Simulacrum committed Sep 17, 2021
1 parent 078e3fd commit c4c5fc8
Show file tree
Hide file tree
Showing 11 changed files with 95 additions and 23 deletions.
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: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`.
10 changes: 8 additions & 2 deletions src/test/ui/coercion/coerce-issue-49593-box-never.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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 `!`
Expand All @@ -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`
Expand Down
20 changes: 12 additions & 8 deletions src/test/ui/never_type/defaulted-never-note.rs
Original file line number Diff line number Diff line change
@@ -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)]

Expand All @@ -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() {
Expand Down
3 changes: 2 additions & 1 deletion src/test/ui/never_type/diverging-fallback-control-flow.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// revisions: nofallback fallback
// run-pass

#![allow(dead_code)]
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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 `!`
Expand All @@ -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`
Expand Down
10 changes: 7 additions & 3 deletions src/test/ui/never_type/diverging-fallback-no-leak.rs
Original file line number Diff line number Diff line change
@@ -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() {}

Expand All @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}

Expand Down
17 changes: 17 additions & 0 deletions src/test/ui/never_type/fallback-closure-wrap.fallback.stderr
Original file line number Diff line number Diff line change
@@ -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`.
Original file line number Diff line number Diff line change
@@ -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`.
9 changes: 5 additions & 4 deletions src/test/ui/never_type/never-value-fallback-issue-66757.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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() { }

0 comments on commit c4c5fc8

Please sign in to comment.