-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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 rejects this code #48238
Comments
I'd like to work on this. |
Reduced version: #![feature(nll)]
fn main() {
let a = "Hello".to_string();
move || {
a.rsplit("")
};
} |
An even simpler reduction: #![feature(nll)]
fn use_val<'a>(val: &'a u8) -> &'a u8 {
val
}
fn main() {
let orig: u8 = 5;
move || {
use_val(&orig)
};
} |
Looking at this some more, I think the error is actually correct. The It seems to me that the error message itself could be improved, however. In the absence of explicit lifetime parameters, temporary lifetimes like |
This code compiles on stable, though. It's still a regression, right? @Aaron1011
Nevermind that, I realized what the code was doing. it's the closure inside the closure that's failing. Changing |
@daboross: Given that it's impossible to actually call the closure, I don't feel that this is really a regression. As written, the original example shouldn't be valid - NLL just gives the error 'earlier' than ast-borrowck. @nikomatsakis: Thoughts? |
@Aaron1011 is correct. If you try to think about the desugaring of the closure expression to the trait Fn<A> {
type Output;
fn call<'a>(&'a self, args: A) -> Self::Output;
} In particular, the return type we would need here is The AST-based type-checker has several known flaws in this area, so I'm not surprised to be uncovering bugs in this area. Seems like one we should add to #47366. |
Add test for issue-48238 Fixes rust-lang#48238 test case made from comments in rust-lang#48238
UPDATE: Turns out this code should not work, so we just need to add a negative test. See this comment but also the mentoring instructions in this tracking bug.
This code compiles, but it does not compile with nll enabled.
The text was updated successfully, but these errors were encountered: