-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Make borrowed-to-unsafe coercions introduce minimum region constraints #20423
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
Nominating for 1.0. This is strictly speaking a backwards incompat change in that some programs could start failing borrow checker but I wouldn't expect much impact. |
What does this mean for code? |
@huonw I believe that you could recover the old behavior with an explicit cast in that case, the reborrow, if I remember correctly, was only with automatic coercions. For example: fn foo(a: *mut int, b: *mut int) {}
foo(&mut x, &mut x); // error
foor(&mut x, &mut x as *mut int); // error
foor(&mut x as *mut int, &mut x); // ok |
This seems like a relatively benign change. Although perhaps very confusing the first time you run into it. |
Slightly backwwards incompat. could possibly be a post-1.0 bugfix |
cc me |
cc me |
So, it's far past 1.0. How are we feeling about this change? Is this the kind of back-incompat-change that's still worth it? |
I think we can close this in favor of rust-lang/rfcs#1447. In any case, I've come to think that this particular change is not the right approach -- we ought to be making rules that are not based on the results of region inference in any way, since those are so unpredictable. |
This is an idea that @alexcrichton and I had some time back but I think it was generally lost in the shuffle of things to do. The idea is that whenever a
&T
(resp.&mut T
) is coerced to a*const T
(resp.*const T
or*mut T
), we should treat that as a reborrow for the enclosing temporary scope. This would ensure that the borrow checker treats the&T
(resp.&mut T
) as borrowed for the enclosing temporary scope. This means that users can be sure that it is safe to use*
pointer so long as it does not outlive the enclosing temporary scope. Longer than that the rules get trickier.Some notes from IRC that pretty much say the same thing:
cc #19733
The text was updated successfully, but these errors were encountered: