-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
compiler: report error when trait object type param reference self #139124
base: master
Are you sure you want to change the base?
Conversation
HIR ty lowering was modified cc @fmease |
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.
Please add a UI test.
Also, there's no explanation for why this fixes the issue? Specifically, I'm not convinced this is the right fix for the issue yet, since it doesn't really explain why this doesn't ICE for small permutations of the original reproducer like:
trait B<C> = Fn() -> Self;
type D<'a> = Vec<&'a dyn B<()>>;
And why this ends up fixing an ICE in the region solving code.
@rustbot author
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.
I thought more about this, and I think this may be the right fix, though currently it duplicates some code. Please add a test still, and it would be nice to add some sort of explanation about why this is necessary in the PR.
compiler/rustc_hir_analysis/src/hir_ty_lowering/dyn_compatibility.rs
Outdated
Show resolved
Hide resolved
However, when the type trait B<C> = Fn() -> Self;
type D = &'static dyn B<()>;
fn main() {
let a = D::new();
_ = a;
} (note that, the ICE from the above code is not the one in the issue but another one, ( I am not sure if |
53a3f72
to
0580faa
Compare
@rustbot review |
compiler/rustc_hir_analysis/src/hir_ty_lowering/dyn_compatibility.rs
Outdated
Show resolved
Hide resolved
One last requested change, sorry for the back and forth @rustbot author |
Reminder, once the PR becomes ready for a review, use |
Fixes rust-lang#139082. Emits an error when `Self` is found in the projection bounds of a trait object. In type aliases, `Self` has no meaning, so `type A = &'static dyn B` where `trait B = Fn() -> Self` will expands to `type A = &'static Fn() -> Self` which is illegal, causing the region solver to bail out when hitting the uninferred Self. Bug: rust-lang#139082 Signed-off-by: xtex <xtexchooser@duck.com>
@rustbot ready |
Fixes #139082.
Emits an error when
Self
is found in the projection bounds of a traitobject. In type aliases,
Self
has no meaning, sotype A = &'static dyn B
wheretrait B = Fn() -> Self
will expands totype A = &'static Fn() -> Self
which is illegal, causing the region solver to bail outwhen hitting the uninferred Self.
r? @compiler-errors @fee1-dead