-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
correctly dedup ExistentialPredicate
s
#73815
Conversation
#![feature(trait_alias)] | ||
|
||
trait I32Iterator = Iterator<Item = i32>; | ||
|
||
fn main() { | ||
let _: &dyn I32Iterator<Item = u32> = &vec![42].into_iter(); | ||
//~^ ERROR type mismatch |
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 think this test changes because ExistentialPredicate::stable_cmp
doesn't actually look at its substs. This seems kind of incorrect to me 🤔
src/librustc_typeck/astconv.rs
Outdated
@@ -1814,7 +1815,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { | |||
) |
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 think here we need to look for conflicting existential_projections
and emit an error like E0271. I think the change to dedup
below makes it consider two projections on the same associated type but with different values to be the same.
I would also imagine that if you try this code out you will also get a "successful" compilation.
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 would also imagine that if you try this code out you will also get a "successful" compilation.
That code compiles correctly errors, added it as a test. I still fear that the current dedup ends up being unsound though 🤔
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 see what's happening. In the type
test that is now passing we probably shouldn't allow people to override the type params that are set in the type
, and error when that happens. @nikomatsakis might have better insight on what we should continue to do, but the more I look at how we treat type aliases the more I want to revamp them.
(I failed to publish this back on the 28th)
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.
Why do you think it's unsound?
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.
List<ExistentialPredicate>
for dyn A + B
previously was [Trait(A), Trait(B)]
and this PR changes this to just [Trait(A)]
. This made me slightly worried as I wasn't sure how we handle wf for trait objects.
I spend a bit more time looking at this and strongly believe that this PR is not concerning here
as we emit the errors before using stable_cmp
, so anything we may "incorrectly" dedup here
already caused an error.
Added a comment summarizing my current understanding
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.
Huh, I guess I better look at how stable_cmp
is defined.
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.
OK, yeah, this seems like not what I expected. =)
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.
Okay, so I've rebased this, I think the current state is sound, if somewhat 👻 spooky 👻 Not
sure what's the least invasive way to clean this up though...
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.
Sorry, I'll try to give useful feedback as soon as I can ...
93a48f6
to
7d09fdb
Compare
☔ The latest upstream changes (presumably #73924) made this pull request unmergeable. Please resolve the merge conflicts. |
☔ The latest upstream changes (presumably #74073) made this pull request unmergeable. Please resolve the merge conflicts. |
☔ The latest upstream changes (presumably #75797) made this pull request unmergeable. Please resolve the merge conflicts. |
Ping from triage, there's merge conflicts now. |
0f5e9f3
to
9818bda
Compare
This is the only relevant test which fails if we check that // check-pass
trait Service {
type S;
}
trait Framing {
type F;
}
impl Framing for () {
type F = ();
}
trait HttpService<F: Framing>: Service<S = F::F> {}
type BoxService = Box<dyn HttpService<(), S = ()>>;
fn build_server<F: FnOnce() -> BoxService>(_: F) {}
fn make_server<F: Framing>() -> Box<dyn HttpService<F, S = F::F>> {
unimplemented!()
}
fn main() {
build_server(|| make_server())
} It fails with
i.e. one of the predicates is not normalized enough. Tbh I think that we should slowly start to emit a future compat lint and then error here, as IMO we are getting dangerously close to being unsound here: trait Foo {
type F;
}
impl<T> Foo for T {
type F = T;
}
trait Bar: Foo<F = u32> {}
impl<T: Foo<F = u32>> Bar for T {}
fn main() {
let y: i32 = 7;
let z: Box<dyn Bar<F = i32>> = Box::new(y);
} luckily results in
|
☔ The latest upstream changes (presumably #76964) made this pull request unmergeable. Please resolve the merge conflicts. Note that reviewers usually do not review pull requests until merge conflicts are resolved! Once you resolve the conflicts, you should change the labels applied by bors to indicate that your PR is ready for review. Post this as a comment to change the labels:
|
closing this for now, I feel like we probably should instead try to change the way existential types are handled in a more fundamental way which means that keeping this PR open isn't really too helpful. |
fixes the underlying issue of the regression in #59326 and removes the stopgap added in #73485.
r? @nikomatsakis cc @estebank