-
Notifications
You must be signed in to change notification settings - Fork 12.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rustc_middle: Pretty-print negative bounds correctly
- Loading branch information
Showing
5 changed files
with
195 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
tests/ui/traits/negative-bounds/opaque-type-unsatisfied-bound.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// compile-flags: -Znext-solver | ||
|
||
#![feature(negative_bounds, negative_impls)] | ||
//~^ WARN the feature `negative_bounds` is incomplete and may not be safe to use and/or cause compiler crashes | ||
|
||
trait Trait {} | ||
impl !Trait for () {} | ||
|
||
fn produce() -> impl !Trait {} | ||
fn consume(_: impl Trait) {} | ||
|
||
fn main() { | ||
consume(produce()); //~ ERROR the trait bound `impl !Trait: Trait` is not satisfied | ||
} | ||
|
||
fn weird0() -> impl Sized + !Sized {} | ||
//~^ ERROR mismatched types | ||
//~| ERROR type mismatch resolving `() == impl !Sized` | ||
fn weird1() -> impl Sized + !Sized {} | ||
//~^ ERROR mismatched types | ||
//~| ERROR type mismatch resolving `() == impl !Sized` | ||
fn weird2() -> impl !Sized + Sized {} | ||
//~^ ERROR mismatched types | ||
//~| ERROR type mismatch resolving `() == impl !Sized` |
77 changes: 77 additions & 0 deletions
77
tests/ui/traits/negative-bounds/opaque-type-unsatisfied-bound.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
warning: the feature `negative_bounds` is incomplete and may not be safe to use and/or cause compiler crashes | ||
--> $DIR/opaque-type-unsatisfied-bound.rs:3:12 | ||
| | ||
LL | #![feature(negative_bounds, negative_impls)] | ||
| ^^^^^^^^^^^^^^^ | ||
| | ||
= note: `#[warn(incomplete_features)]` on by default | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/opaque-type-unsatisfied-bound.rs:16:36 | ||
| | ||
LL | fn weird0() -> impl Sized + !Sized {} | ||
| ------------------- ^^ types differ | ||
| | | ||
| the expected opaque type | ||
| | ||
= note: expected opaque type `impl !Sized` | ||
found unit type `()` | ||
|
||
error[E0271]: type mismatch resolving `() == impl !Sized` | ||
--> $DIR/opaque-type-unsatisfied-bound.rs:16:16 | ||
| | ||
LL | fn weird0() -> impl Sized + !Sized {} | ||
| ^^^^^^^^^^^^^^^^^^^ types differ | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/opaque-type-unsatisfied-bound.rs:19:36 | ||
| | ||
LL | fn weird1() -> impl Sized + !Sized {} | ||
| ------------------- ^^ types differ | ||
| | | ||
| the expected opaque type | ||
| | ||
= note: expected opaque type `impl !Sized` | ||
found unit type `()` | ||
|
||
error[E0271]: type mismatch resolving `() == impl !Sized` | ||
--> $DIR/opaque-type-unsatisfied-bound.rs:19:16 | ||
| | ||
LL | fn weird1() -> impl Sized + !Sized {} | ||
| ^^^^^^^^^^^^^^^^^^^ types differ | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/opaque-type-unsatisfied-bound.rs:22:36 | ||
| | ||
LL | fn weird2() -> impl !Sized + Sized {} | ||
| ------------------- ^^ types differ | ||
| | | ||
| the expected opaque type | ||
| | ||
= note: expected opaque type `impl !Sized` | ||
found unit type `()` | ||
|
||
error[E0271]: type mismatch resolving `() == impl !Sized` | ||
--> $DIR/opaque-type-unsatisfied-bound.rs:22:16 | ||
| | ||
LL | fn weird2() -> impl !Sized + Sized {} | ||
| ^^^^^^^^^^^^^^^^^^^ types differ | ||
|
||
error[E0277]: the trait bound `impl !Trait: Trait` is not satisfied | ||
--> $DIR/opaque-type-unsatisfied-bound.rs:13:13 | ||
| | ||
LL | consume(produce()); | ||
| ------- ^^^^^^^^^ the trait `Trait` is not implemented for `impl !Trait` | ||
| | | ||
| required by a bound introduced by this call | ||
| | ||
note: required by a bound in `consume` | ||
--> $DIR/opaque-type-unsatisfied-bound.rs:10:20 | ||
| | ||
LL | fn consume(_: impl Trait) {} | ||
| ^^^^^ required by this bound in `consume` | ||
|
||
error: aborting due to 7 previous errors; 1 warning emitted | ||
|
||
Some errors have detailed explanations: E0271, E0277, E0308. | ||
For more information about an error, try `rustc --explain E0271`. |
10 changes: 10 additions & 0 deletions
10
tests/ui/traits/negative-bounds/opaque-type-unsatisfied-fn-bound.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// compile-flags: -Znext-solver | ||
|
||
#![feature(negative_bounds, unboxed_closures)] | ||
//~^ WARN the feature `negative_bounds` is incomplete and may not be safe to use and/or cause compiler crashes | ||
|
||
fn produce() -> impl !Fn<(u32,)> {} | ||
//~^ ERROR mismatched types | ||
//~| ERROR type mismatch resolving `() == impl !Fn<(u32,)>` | ||
|
||
fn main() {} |
29 changes: 29 additions & 0 deletions
29
tests/ui/traits/negative-bounds/opaque-type-unsatisfied-fn-bound.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
warning: the feature `negative_bounds` is incomplete and may not be safe to use and/or cause compiler crashes | ||
--> $DIR/opaque-type-unsatisfied-fn-bound.rs:3:12 | ||
| | ||
LL | #![feature(negative_bounds, unboxed_closures)] | ||
| ^^^^^^^^^^^^^^^ | ||
| | ||
= note: `#[warn(incomplete_features)]` on by default | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/opaque-type-unsatisfied-fn-bound.rs:6:34 | ||
| | ||
LL | fn produce() -> impl !Fn<(u32,)> {} | ||
| ---------------- ^^ types differ | ||
| | | ||
| the expected opaque type | ||
| | ||
= note: expected opaque type `impl !Fn<(u32,)>` | ||
found unit type `()` | ||
|
||
error[E0271]: type mismatch resolving `() == impl !Fn<(u32,)>` | ||
--> $DIR/opaque-type-unsatisfied-fn-bound.rs:6:17 | ||
| | ||
LL | fn produce() -> impl !Fn<(u32,)> {} | ||
| ^^^^^^^^^^^^^^^^ types differ | ||
|
||
error: aborting due to 2 previous errors; 1 warning emitted | ||
|
||
Some errors have detailed explanations: E0271, E0308. | ||
For more information about an error, try `rustc --explain E0271`. |