-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix trait objects with a Self-containing projection values #56863
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
} |
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`. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// compile-pass | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similarly a comment here would be good: Regression test related to #56288. Check that a supertrait projection (of |
||
|
||
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); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add a comment to this test:
Regression test for #56288. Checks that if a supertrait defines an associated type projection that references
Self
, then that associated type must still be explicitly specified in thedyn Trait
variant, since we don't know whatSelf
is anymore.