forked from rust-lang/rust
-
-
Notifications
You must be signed in to change notification settings - Fork 0
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#107245 - compiler-errors:new-solver-unsizin…
…g, r=lcnr Implement unsizing in the new trait solver This makes hello world compile! Ignore the first commit, that's just rust-lang#107146 which is waiting on merge. I'll leave some comments inline about design choices that might be debatable. r? `@lcnr` (until we have a new trait solver reviewer group...)
- Loading branch information
Showing
8 changed files
with
307 additions
and
5 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,25 @@ | ||
// compile-flags: -Ztrait-solver=next | ||
// check-pass | ||
|
||
#![feature(unsized_tuple_coercion)] | ||
|
||
trait Foo {} | ||
|
||
impl Foo for i32 {} | ||
|
||
fn main() { | ||
// Unsizing via struct | ||
let _: Box<dyn Foo> = Box::new(1i32); | ||
|
||
// Slice unsizing | ||
let y = [1, 2, 3]; | ||
let _: &[i32] = &y; | ||
|
||
// Tuple unsizing | ||
let hi = (1i32,); | ||
let _: &(dyn Foo,) = &hi; | ||
|
||
// Dropping auto traits | ||
let a: &(dyn Foo + Send) = &1; | ||
let _: &dyn Foo = a; | ||
} |
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,14 @@ | ||
// compile-flags: -Ztrait-solver=next | ||
// check-pass | ||
|
||
#![feature(trait_upcasting)] | ||
|
||
trait Foo: Bar<i32> + Bar<u32> {} | ||
|
||
trait Bar<T> {} | ||
|
||
fn main() { | ||
let x: &dyn Foo = todo!(); | ||
let y: &dyn Bar<i32> = x; | ||
let z: &dyn Bar<u32> = x; | ||
} |
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,13 @@ | ||
// compile-flags: -Ztrait-solver=next | ||
|
||
#![feature(trait_upcasting)] | ||
|
||
trait Foo: Bar<i32> + Bar<u32> {} | ||
|
||
trait Bar<T> {} | ||
|
||
fn main() { | ||
let x: &dyn Foo = todo!(); | ||
let y: &dyn Bar<usize> = x; | ||
//~^ ERROR mismatched types | ||
} |
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,14 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/upcast-wrong-substs.rs:11:30 | ||
| | ||
LL | let y: &dyn Bar<usize> = x; | ||
| --------------- ^ expected trait `Bar`, found trait `Foo` | ||
| | | ||
| expected due to this | ||
| | ||
= note: expected reference `&dyn Bar<usize>` | ||
found reference `&dyn Foo` | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0308`. |