Fix soundness bug with type alias impl trait#82558
Fix soundness bug with type alias impl trait#82558oli-obk wants to merge 6 commits intorust-lang:masterfrom
Conversation
src/test/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn.stderr
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
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.
estebank
left a comment
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
This is quite confusing to me :(
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
I made a note of this, but it may become obsolete once I tackle all these spans in a more general manner.
jackh726
left a comment
There was a problem hiding this comment.
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? |
nikomatsakis
left a comment
There was a problem hiding this comment.
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.
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.
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.
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.
"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.
(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