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.
fix trait objects with a Self-having projection va
This follows ALT2 in the issue. Fixes rust-lang#56288.
- Loading branch information
1 parent
e5126cf
commit 5524250
Showing
5 changed files
with
103 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
22 changes: 22 additions & 0 deletions
22
src/test/ui/traits/trait-object-with-self-in-projection-output-bad.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,22 @@ | ||
trait Base { | ||
type Output; | ||
} | ||
|
||
trait Helper: Base<Output=<Self as Helper>::Target> { | ||
type Target; | ||
} | ||
|
||
impl Base for u32 | ||
{ | ||
type Output = i32; | ||
} | ||
|
||
impl Helper for u32 | ||
{ | ||
type Target = i32; | ||
} | ||
|
||
fn main() { | ||
let _x: Box<dyn Helper<Target=i32>> = Box::new(2u32); | ||
//~^ ERROR the value of the associated type `Output` (from the trait `Base`) must be specified | ||
} |
12 changes: 12 additions & 0 deletions
12
src/test/ui/traits/trait-object-with-self-in-projection-output-bad.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,12 @@ | ||
error[E0191]: the value of the associated type `Output` (from the trait `Base`) must be specified | ||
--> $DIR/trait-object-with-self-in-projection-output-bad.rs:20:17 | ||
| | ||
LL | type Output; | ||
| ------------ `Output` defined here | ||
... | ||
LL | let _x: Box<dyn Helper<Target=i32>> = Box::new(2u32); | ||
| ^^^^^^^^^^^^^^^^^^^^^^ associated type `Output` must be specified | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0191`. |
23 changes: 23 additions & 0 deletions
23
src/test/ui/traits/trait-object-with-self-in-projection-output-good.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,23 @@ | ||
// compile-pass | ||
|
||
trait Base { | ||
type Output; | ||
} | ||
|
||
trait Helper: Base<Output=<Self as Helper>::Target> { | ||
type Target; | ||
} | ||
|
||
impl Base for u32 | ||
{ | ||
type Output = i32; | ||
} | ||
|
||
impl Helper for u32 | ||
{ | ||
type Target = i32; | ||
} | ||
|
||
fn main() { | ||
let _x: Box<dyn Helper<Target=i32, Output=i32>> = Box::new(2u32); | ||
} |