-
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
In-band lifetimes stop working when in a nested function #52532
Comments
The diagnostics ("use of undeclared lifetime name") are bad, but this indeed must be an error because the inner |
Hm, I don't think that's quite what I'd expect: previously using fn main() {}
struct Bar<'a>(&'a u32);
impl<'a> Bar<'a> {
fn foo() {
fn foo<'a>(_: &'a u32) { }
}
} |
(In the second example there's an explicit definition that shadows the previous definition for following uses, in the first example there's no second definition, only use) |
I see that this is in the RFC, but I think I more or less disagree with the reasoning given. Disallowing the use of inband lifetimes when nesting function seems arbitrary and not entirely helpful; it also makes a mechanical change from "old" to "new" more difficult because shadowing is visible only based on indent levels. |
IMO it should be an error, with a helpful note like the one you get when writing |
The distinction is that inband lifetime's selling point is that you don't need to declare lifetimes. If we say that, and then clarify it with "except" then I think the feature feels incomplete. Inband lifetimes confusion does not increase with permitting this, IMO. |
The problem is if it's allowed, then impl Foo<'a> { fn foo(_: &'a u32) } has a different meaning than fn foo(_: &'a u32) { fn foo(_: &'a u32) {} } This seems unfortunate and confusing. Even unergonomic if I may say so. There's no way that the distinction between |
Well, somewhat, but not really. Nothing outside of imports/definitions inherits into the inner function, unlike the impl where there is a history and multiple things which inherit ( |
…-impl-lifetime, r=cramertj use `ParamName` to track in-scope lifetimes instead of Ident Also, clear in-scope lifetimes when visiting nested items. Fixes rust-lang#63500. Fixes rust-lang#63225. Fixes rust-lang#52532. r? @cramertj
…-impl-lifetime, r=cramertj use `ParamName` to track in-scope lifetimes instead of Ident Also, clear in-scope lifetimes when visiting nested items. Fixes rust-lang#63500. Fixes rust-lang#63225. Fixes rust-lang#52532. r? @cramertj
https://play.rust-lang.org/?gist=d2b32bc0947a05fa0830a0d244dcb4fa&version=nightly&mode=debug&edition=2015
The text was updated successfully, but these errors were encountered: