-
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
Regression with NLL and RefCell #47224
Comments
@matthewjasper, is there a fundamental reason the OP example shouldn’t work? Is the issue that the fixes also make this case not work, but not necessarily intentionally so to speak? |
the foo.deref_mut().v.push(foo.deref().b); Unless the deref method has any other treatment than a regular method call, it's not possible to allow this this code, because Reading One class of programs NLL wants to fix is the (with |
It seems like the problem could be solved by inlining the call to Is that a feasible solution to the problem? |
@stjepang I don't think it's feasible to depend on inlined inner behavior of other functions for borrow checking of an outside function. We might know I mean, a type is literally allowed to do anything inside I don't think it's reasonable to introduce this to rust now. So far, we've had everything that type / borrow checking can rely on encoded in function signatures. It would be nice if things stayed this way. |
Maybe there could be some sort of annotation on |
|
Given how prevalent |
@vitalyd it's worth noting that doing these kind of things is possible with RefCell, and the restrictions aren't new to NLL. It just can't be made into a nice example as other NLL examples can. For instance, this does work (replacing fn f(foo: RefCell<Foo>) {
let mut foo = &mut *foo.borrow_mut();
foo.v.push(foo.b);
} I agree that "pure" deref may be desirable, maybe as an unsafe trait, or maybe as some kind of function and/or trait modifier, but I don't think it should be tied to NLL. It would be useful outside of using non-lexical lifetimes, and NLL is useful without it. |
This is indeed expected in the absence of |
Seems like this is "not a bug — behaving as designed", so I'm going to close the issue. Thanks all. |
Hi,
I have some code similar to the one below that compiled fine up until nightly-2018-01-03, but stopped compiling starting with nightly-2018-01-04:
The error I now get is
I was able to work around it by coercing
RefMut<T>
to a&mut T
usinglet foo = &mut *foo.borrow_mut()
, and normal nll rules work as expected. But since it used to work withRefMut
, I suppose it still should?The text was updated successfully, but these errors were encountered: