-
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
rustc: fixed regionck for owned trait casts. #13129
Conversation
Looks like something for @nikomatsakis to review. |
Does this fix #10751 too? If not, I guess it probably could. |
It doesn't - from the look of it, #10751 seems similar to #12470, probably happens for the same reason: trait stores not being considered when inferring variance, which leads to respective regions not being related in a cast (please see #12828 for details). |
I've had a more thorough look at #10751 and i think it's happening because type bounds declared in trait impl just aren't taken into account when matching the type being cast to a trait and the type that the trait is implemented for (vtable.rs:361-372), so i think that is also not a bug i tried to fix here. |
cc me |
let source_ty = rcx.fcx.expr_ty(expr); | ||
constrain_regions_in_type(rcx, trait_region, | ||
infer::RelateObjectBound(expr.span), source_ty); | ||
ty::AutoObject(ast::BorrowedSigil, Some(trait_region), _, _, _, ref substs) => { |
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.
nit: could you use just maybe_region
to keep it consistent in style with the next arm?
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.
Done - i've squashed those two arms together actually, as they both do the same thing.
Travis failures are because of #13079 and should go away with the next snapshot. |
@bors: retry |
The tests need to be fixed for windows. The run-pass tests added need to have |
Sorry, not for windows, but for the check-fast target in the makefiles. |
@alexcrichton ah, thanks! I somehow only saw "interrupted" everywhere and thought it was spurious. |
Sadly the |
Have pushed an update - this passes both fast-check and check locally. |
r? @cmr, @alexcrichton ? |
I don't consider myself qualified enough to review this portion of the compiler, I think @pnkfelix or @nikomatsakis would be more appropriate. There's some introductions of lifetimes which don't quite make sense to me, but perhaps it's more sound now... |
@alexcrichton Ah, sorry then. It's just that this was r+'ed by @cmr earlier and failed in fast-check on windows due to non-pub fn main and i thought that it won't require another full-blown review. |
Regionck didn't do any checks for casts/coercions to an owned trait, which resulted in lifetimes of the source pointer to be ignored in the result of such cast. This fix constraints all regions of the source type of the cast/coercion to be superregions of each region of the target type (if target trait definition has some lifetime params), or of 'static lifetime (if there're no lifetime params in target trait's definition). Closes rust-lang#5723 Closes rust-lang#9745 Closes rust-lang#11971
This code is headed in the right direction, but the details are off. There is really a general notion of a type being bounded by a lifetime L (meaning: all borrowed data reachable by the type has lifetime L or longer). The code doesn't really handle these cases correctly, leading to the bugs. I've been wanting to go in and refactor this for a while and your patch is definitely in the correct direction. What is perhaps surprising is that this bound has nothing to do with the lifetime parameters of the trait type. So, for example, if you have: To see what I mean, consider this example:
Here the type In any case, I think limiting the check to the trait bound is in the right direction and would be enough for this patch. But when I tried to modify your branch locally I got some other compilation errors for the owned-ptr-static-bound test that I don't fully understand. I'll investigate tomorrow. |
Thanks for the thorough explanation! As i understand, The solution with constraining casts to I guess the one possible 'correct' solution would be to actually allow one to write |
Closing due to inactivity, but feel free to reopen with a rebase! Also, perhaps some of this work will be enabled by #13898? |
I've actually started moving in the general direction of my previous comment, having changed libsyntax to allow arbitrary lifetimes in bounds (i.e. roughly the same thing #13898 does). Got sidetracked by another project, but i'm still interested in implementing a proper fix for this. Does it make sense for me to continue here (rebasing my changes atop #13898), or is it better to find something else to work on, now that @nikomatsakis is working on this? |
I know that @nikomatsakis is deep in a number of large changes right now, so I would coordinate with him if you'd like to work on this area. |
@dmski sorry for being incommunicative, I am about ... oh, I don't know, 90% of the way through enabling a more general notion of bounds. I agree this is the proper fix. |
@nikomatsakis Thanks for letting me know. I'll keep an eye on PRs for this then. |
…xFrednet Add xFrednet back to Clippy's reviewer roulette What the title says. --- cc: rust-lang/rust-clippy#12947 changelog: none r? `@ghost`
Regionck didn't do any checks for casts/coercions to an owned trait,
which resulted in lifetimes of the source pointer
to be ignored in the result of such cast.
This fix constraints all regions of the source type of the cast/coercion to be superregions
of each region of the target type (if target trait definition has some lifetime params),
or of 'static lifetime (if there're no lifetime params in target trait's definition).
Closes #5723
Closes #9745
Closes #11971