-
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
[nll] cast to raw pointer creates an "enduring" borrow #53123
Comments
OK, the problem here is due to the If we change to: #![feature(nll)]
#![allow(unused_variables)]
pub trait TryTransform {
fn try_transform<F>(self, f: F)
where
Self: Sized,
F: FnOnce(Self);
}
impl<'a, T> TryTransform for &'a mut T {
fn try_transform<F>(self, f: F)
where
// Self: Sized,
F: FnOnce(Self),
{
let this: *mut T = self as *mut T;
f(self);
}
}
fn main() {
} then the code compiles as expected. I'm actually not sure why the AST code avoids this problem. I guess because it just doesn't happen to try proving Probably the best fix is to special-case |
OK, so one possible fix is to hack in the trait system. Right now, we arbitrarily give where-clauses higher priority than impls. We could tweak this by hacking on rust/src/librustc/traits/select.rs Lines 2019 to 2029 in 18925de
The implications are...not entirely obvious, but still, I can't see much harm in modifying that function to give |
cc @matthewjasper — I know you're familiar with this code, though you've already got a lot of branches. Thoughts? |
@nikomatsakis built in traits used to be more special cased than they are now, so it might be worth checking if I changed something here. The proposed solution sounds good, although I suspect it might break type inference in some obscure cases. |
Never say never, but the scenarios I can construct in my head are pretty obscure indeed. The other option is to special case this in MIR borrow check. In particular, we could skip proving rust/src/librustc_mir/borrow_check/nll/type_check/mod.rs Lines 902 to 906 in 39e9516
That is a total hack but seems obviously "fine". That said, the tweak to select just might also fix #53156, hard to say. |
NLL - Prevent where clauses from extending the lifetime of bindings Fixes #53123 r? @nikomatsakis
The following program (extracted from
try_transform_mut
v0.1.0) fails to compile with MIR-based borrow check:The error is:
I'm not entirely sure what is going on here, but it seems strange. I would not consider the
self as _
to be a "borrow" ofself
really.The text was updated successfully, but these errors were encountered: