-
Notifications
You must be signed in to change notification settings - Fork 13k
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 soundness bug with type alias impl trait #82558
Conversation
src/test/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn.stderr
Outdated
Show resolved
Hide resolved
error: defining use generics `[B, A]` differ from previous defining use | ||
--> $DIR/multiple-def-uses-in-one-fn.rs:10:1 | ||
| | ||
LL | fn f<A, B: 'static>(a: &'static A, b: B) -> (X<A, B>, X<B, A>) { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
note: previous defining use with different generics `[A, B]` found here | ||
--> $DIR/multiple-def-uses-in-one-fn.rs:10:1 | ||
| | ||
LL | fn f<A, B: 'static>(a: &'static A, b: B) -> (X<A, B>, X<B, A>) { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 3 previous errors |
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 duplication is really odd.. we go through the TAIT logic (where I emit this diagnostic) twice. Once with the function as the body, once with the crate root as the body. I haven't been able to figure out the reason for that yet, but will investigate further.
This comment has been minimized.
This comment has been minimized.
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'd be ok with landing this either way (with or without the err ty) as long as we leave a ticket open to sometime fix this.
error: defining use generics `[B, A]` differ from previous defining use | ||
--> $DIR/multiple-def-uses-in-one-fn.rs:10:45 | ||
| | ||
LL | fn f<A, B: 'static>(a: &'static A, b: B) -> (X<A, B>, X<B, A>) { | ||
| ^^^^^^^^^^^^^^^^^^ | ||
| | ||
note: previous defining use with different generics `[A, B]` found here | ||
--> $DIR/multiple-def-uses-in-one-fn.rs:10:45 | ||
| | ||
LL | fn f<A, B: 'static>(a: &'static A, b: B) -> (X<A, B>, X<B, 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.
This is quite confusing to me :(
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 the spans could be better here: the error should have a span of X<B, A>
and the note should have a span of X<A, B>
src/test/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn.stderr
Outdated
Show resolved
Hide resolved
), | ||
) | ||
.span_note( | ||
opaque_defn.definition_span, |
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.
Can we check whether this and self.value_span
are the same, and if they are, emit a different note
or span_label
?
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 made a note of this, but it may become obsolete once I tackle all these spans in a more general manner.
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 approach makes sense to me, but I don't know much about this code, so someone else (@matthewjasper) can do the "real" review.
☔ The latest upstream changes (presumably #82898) made this pull request unmergeable. Please resolve the merge conflicts. |
…hin a single function
…ror must have been emitted already
dcd3dd2
to
93f3d08
Compare
@nikomatsakis any updates on this? |
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.
So, I think that this fix is sound, but it doesn't seem correct -- I think we can accommodate this sort of case without a real problem.
debug!("instantiate_opaque_types: returning concrete ty {:?}", opaque_defn.concrete_ty); | ||
return opaque_defn.concrete_ty; | ||
// than once in a function (e.g., if it's passed to a type alias). | ||
if let Some(opaque_defn) = self.opaque_types.get_mut(&def_id) { |
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 the right behavior here is to key by def-id+substs. We know that the substs are always universally quantified placeholders, right?
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.
The substs here are concrete types from the function. I don't understand what universally quantified placeholders mean 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.
Keying by DefId+substs makes sense though. We'll get two type variables, and then we can figure out whether they are compatible in the same pass that does it cross-function
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.
"Universally quantified placeholders" is jargon for the "generic parameters on the fn that we are type-checking". i.e., when we treat a parameter T
as a kind of placeholder for "some type". "universally quantified' is because there is a "forall" quantifier on the function.
opaque_defn.substs.push(substs); | ||
opaque_defn.concrete_ty = tcx.ty_error_with_message( | ||
self.value_span, | ||
"defining use generics differ from previous defining use", |
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.
(Just a note that I think we could say this in a clearer way; I doubt users know what a defining use is, etc)
☔ The latest upstream changes (presumably #85036) made this pull request unmergeable. Please resolve the merge conflicts. |
@spastorino is going to pick up this PR -- @spastorino do you plan to open a separate PR? Should we close this one? |
Yes, I can open a separate PR. |
cc @jackh726
fixes #73481 (only the first defining for a specific TAIT use within a function is handled at all, all others are not looked at at all)
r? @matthewjasper
I am fully aware the diagnostics aren't great, but they are ungreat in general around type alias impl trait, which is tracked in #63205