-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Double check that hidden types match the expected hidden type #113661
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @compiler-errors (or someone else) soon. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
|
Some changes occurred to the core trait solver cc @rust-lang/initiative-trait-system-refactor |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
"{}, {}", | ||
tcx.type_of(key.def_id).subst(tcx, key.substs), | ||
ty.hidden_type.ty | ||
); |
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 feel like we should hit this bug? 🤔 or do we avoid it because we have OpaqueCast
everywhere we would assign to/from opaques?
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 was surprised, too, but I didn't debug it.
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.
do we run the validator before optimizations by default 😅 iirc we only do it with -Zvalidate-mir
🤔
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.
#114121 :D
92e7e6d
to
7c75895
Compare
This comment has been minimized.
This comment has been minimized.
fa82e44
to
82fa94e
Compare
This comment has been minimized.
This comment has been minimized.
/// // desugared to | ||
/// | ||
/// // hidden type is `&'bDup ()` | ||
/// // During wfcheck the hidden type of `Inner` is `&'a ()`, but |
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.
/// // During wfcheck the hidden type of `Inner` is `&'a ()`, but | |
/// // During wfcheck the hidden type of `Inner` is `&'b ()`, but |
i feel like it is a bit weird to talk about 'bDup
if it is unclear where 'b
comes from. I prefer using 'a
and 'aDup
everywhere
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.
well... unless I double confused myself, your diff is wrong, so it's good that I made it explicit 😆
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.
how can the inner type in wf
check be 'a
if we wf check in the scope of the opaque type which does not have a 'a
in scope? 😅
also, "During wfcheck of Outer
...", would make this clearer I think
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.
because RPITs aren't desugerable currently (ok I guess that's what you meant by "unclear where 'b
comes from"), they only work by construction and are cheating. I rewrote the example to be more like how it actually works, is that clearer?
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.
r=me after final comment nits
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.
accurately documenting the desugaring is messy (because the desugaring is messy :3)
because RPITs aren't desugerable currently (ok I guess that's what you meant by "unclear where 'b comes from"), they only work by construction and are cheating. I rewrote the example to be more like how it actually works, is that clearer?
idk 😅 i don't know how much of my nits are "the actual impl is a mess" and how much is "the comment is wrong/incomplete"
@@ -545,17 +545,23 @@ fn sanity_check_found_hidden_type<'tcx>( | |||
/// } | |||
/// fn func<'a>(x: &'a ()) -> impl Id<Assoc = impl Sized + 'a> { x } | |||
/// // desugared to | |||
/// fn func<'a>(x: &'a () -> Outer<'a, Assoc = Inner<'a>> { |
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.
/// fn func<'a>(x: &'a () -> Outer<'a, Assoc = Inner<'a>> { | |
/// fn func<'a>(x: &'a () -> Outer<'a, 'a> { |
? 🤔
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.
yea... I don't know how to represent the fact that we walk the item bounds of Outer
/// // hidden type is `&'cDup ()` | ||
/// type Inner<'c, 'cDup> = impl Sized + 'cDup; | ||
/// fn func<'a>(x: &'a () -> Outer<'static, 'a> { x } | ||
/// // hidden type is `&'aDupOuter ()` |
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.
This feels wrong, if the hidden type of Outer
is &'aDupOuter ()
, shouldn't wf check of Outer
define the hidden type of Inner
to be <&'aDupOuter () as Id>::Assoc
which is &'aDupOuter ()
, so this should worK?
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.
No, because we figure out the hidden type of Inner
anew during wf check of Outer
, we don't get it from type_of
. We get the hidden type of Outer
, which is &'a ()
, so the id projection is also &'a ()
/// // So we walk the signature of `func` to find the use of `Inner<'a>` | ||
/// // and then use that to replace the lifetimes in the hidden type, obtaining | ||
/// // `&'a ()`. | ||
/// type Outer<'aDupOuter> = impl Id<Assoc = Inner<'aDupOuter>>; |
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.
is the 'a
param of Inner
'a
or 'aDupOuter
here?
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.
'a
, it is inherited from the function.
@bors r=lcnr |
⌛ Testing commit df4bfd9 with merge 50bb51b2201e3aa6ca651a9446f62088ca32d9f0... |
💔 Test failed - checks-actions |
@bors retry nothing failed? Not sure what happened |
…iaskrgr Rollup of 5 pull requests Successful merges: - rust-lang#112995 (Check for `<&NotClone as Clone>::clone()` calls and suggest to add Clone trait appropriately) - rust-lang#113578 (Don't say that a type is uncallable if its fn signature has errors in it) - rust-lang#113661 (Double check that hidden types match the expected hidden type) - rust-lang#114044 (factor out more stable impls) - rust-lang#114062 (CI: split nested GHA groups instead of panicking) r? `@ghost` `@rustbot` modify labels: rollup
… r=jackh726 Paper over an accidental regression r? types cc rust-lang#115781 (do not close issue until beta backport has been performed) The PR reasons are explained with comments in the source. In order to keep the diff simple, this PR effectively reverts rust-lang#113661, but only for RPITs. I will submit a follow up PR that fixes this correctly instead of just disabling the newly added check for RPITs. This PR should be significantly easier to review for beta backport
Rollup merge of rust-lang#115844 - oli-obk:opaque_lifetime_ambiguity, r=jackh726 Paper over an accidental regression r? types cc rust-lang#115781 (do not close issue until beta backport has been performed) The PR reasons are explained with comments in the source. In order to keep the diff simple, this PR effectively reverts rust-lang#113661, but only for RPITs. I will submit a follow up PR that fixes this correctly instead of just disabling the newly added check for RPITs. This PR should be significantly easier to review for beta backport
Fixes #113278 specifically, but I left a TODO for where we should also add some hardening.
It feels a bit like papering over the issue, but at least this way we don't get unsoundness, but just surprising errors. Errors will be improved and given spans before this PR lands.
r? @compiler-errors @lcnr