forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#108333 - compiler-errors:new-solver-object-…
…sound, r=lcnr Make object bound candidates sound in the new trait solver r? `@lcnr`
- Loading branch information
Showing
9 changed files
with
309 additions
and
3 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
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
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
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
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,17 @@ | ||
// compile-flags: -Ztrait-solver=next | ||
// check-pass | ||
|
||
trait Trait<'a> { | ||
type Item: for<'b> Trait2<'b>; | ||
} | ||
|
||
trait Trait2<'a> {} | ||
impl Trait2<'_> for () {} | ||
|
||
fn needs_trait(_: Box<impl for<'a> Trait<'a> + ?Sized>) {} | ||
|
||
fn foo(x: Box<dyn for<'a> Trait<'a, Item = ()>>) { | ||
needs_trait(x); | ||
} | ||
|
||
fn main() {} |
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,27 @@ | ||
// compile-flags: -Ztrait-solver=next | ||
// From #80800 | ||
|
||
trait SuperTrait { | ||
type A; | ||
type B; | ||
} | ||
|
||
trait Trait: SuperTrait<A = <Self as SuperTrait>::B> {} | ||
|
||
fn transmute<A, B>(x: A) -> B { | ||
foo::<A, B, dyn Trait<A = A, B = B>>(x) | ||
//~^ ERROR type annotations needed: cannot satisfy `dyn Trait<A = A, B = B>: Trait` | ||
} | ||
|
||
fn foo<A, B, T: ?Sized>(x: T::A) -> B | ||
where | ||
T: Trait<B = B>, | ||
{ | ||
x | ||
} | ||
|
||
static X: u8 = 0; | ||
fn main() { | ||
let x = transmute::<&u8, &[u8; 1_000_000]>(&X); | ||
println!("{:?}", x[100_000]); | ||
} |
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,19 @@ | ||
error[E0283]: type annotations needed: cannot satisfy `dyn Trait<A = A, B = B>: Trait` | ||
--> $DIR/more-object-bound.rs:12:5 | ||
| | ||
LL | foo::<A, B, dyn Trait<A = A, B = B>>(x) | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: cannot satisfy `dyn Trait<A = A, B = B>: Trait` | ||
note: required by a bound in `foo` | ||
--> $DIR/more-object-bound.rs:18:8 | ||
| | ||
LL | fn foo<A, B, T: ?Sized>(x: T::A) -> B | ||
| --- required by a bound in this function | ||
LL | where | ||
LL | T: Trait<B = B>, | ||
| ^^^^^^^^^^^^ required by this bound in `foo` | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0283`. |
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,20 @@ | ||
// compile-flags: -Ztrait-solver=next | ||
|
||
trait Setup { | ||
type From: Copy; | ||
} | ||
|
||
fn copy<U: Setup + ?Sized>(from: &U::From) -> U::From { | ||
*from | ||
} | ||
|
||
pub fn copy_any<T>(t: &T) -> T { | ||
copy::<dyn Setup<From=T>>(t) | ||
//~^ ERROR the trait bound `dyn Setup<From = T>: Setup` is not satisfied | ||
} | ||
|
||
fn main() { | ||
let x = String::from("Hello, world"); | ||
let y = copy_any(&x); | ||
println!("{y}"); | ||
} |
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,19 @@ | ||
error[E0277]: the trait bound `dyn Setup<From = T>: Setup` is not satisfied | ||
--> $DIR/object-unsafety.rs:12:12 | ||
| | ||
LL | copy::<dyn Setup<From=T>>(t) | ||
| ^^^^^^^^^^^^^^^^^ the trait `Setup` is not implemented for `dyn Setup<From = T>` | ||
| | ||
note: required by a bound in `copy` | ||
--> $DIR/object-unsafety.rs:7:12 | ||
| | ||
LL | fn copy<U: Setup + ?Sized>(from: &U::From) -> U::From { | ||
| ^^^^^ required by this bound in `copy` | ||
help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement | ||
| | ||
LL | pub fn copy_any<T>(t: &T) -> T where dyn Setup<From = T>: Setup { | ||
| ++++++++++++++++++++++++++++++++ | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0277`. |