-
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
Owned trait objects are erroneously permitted to contain references #11971
Comments
Actually, I misspoke on IRC: it's In any case, |
Yeah, I should have seen that myself—the span does show the error as the |
cc me |
In some way this is related to #5121. I think what we want is to support |
still reproduces. Updating description with concrete test case. |
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
assigning 1.0 milestone, P-backcompat-lang. |
Nominating for closing as a dupe of #5723. |
Rustup r? `@ghost` changelog: none
(pnkfelix: Here is a test case. This behavior is not sound.)
Transcript of a run:
Original bug report follows
Consider the errors you get with trying to use references inside a managed trait object such as
@Any:
(remove the:
and you get a'static
bound failure error plus the same error):Now, the problem: owned trait objects do not have this contains-references check.
With the default constraints,
~&2 as ~Any
does not compile, because something with references is notSend
. This is good and proper.On the other hand,
~&2 as ~Any:
does compile successfully. (Complete example:fn main() { ~&2 as ~Any:; }
, should not compile.) This is unsound and should be forbidden in the same way that@T:
forbids references.The text was updated successfully, but these errors were encountered: