Skip to content
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

Lifetimes should be inferred in simple cases #762

Closed
steveklabnik opened this issue Jan 29, 2015 · 1 comment
Closed

Lifetimes should be inferred in simple cases #762

steveklabnik opened this issue Jan 29, 2015 · 1 comment
Labels
T-lang Relevant to the language team, which will review and decide on the RFC.

Comments

@steveklabnik
Copy link
Member

Issue by mhart
Tuesday Nov 04, 2014 at 18:07 GMT

For earlier discussion, see rust-lang/rust#18620

This issue was labelled with: in the Rust repository


Rust newbie here. This is very probably a dupe, but my GH foo failed me.

The following fails to compile:

fn my_fn<T>(items: T) where T: Iterator<&str> {
    println!("hello")
}

With:

<anon>:5:41: 5:45 error: missing lifetime specifier [E0106]
<anon>:5 fn my_fn<T>(items: T) where T: Iterator<&str> {
                                                 ^~~~

But it's unclear to me why the compiler can't just infer the lifetime here?

Shouldn't this be the default choice?

fn my_fn<'a, T>(items: T) where T: Iterator<&'a str> {
    println!("hello")
}

Edit: So it could also be 'static, but I wouldn't have thought that would be the default (or encouraged) case. If you did want it to be static, then you could declare it explicitly. Similar to how variables are immutable by default (without needing an explicit declaration), yet if you want them to be mutable you declare it.

@petrochenkov petrochenkov added the T-lang Relevant to the language team, which will review and decide on the RFC. label Jan 29, 2018
@Centril
Copy link
Contributor

Centril commented Oct 7, 2018

Closing in favor of #1352.

@Centril Centril closed this as completed Oct 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-lang Relevant to the language team, which will review and decide on the RFC.
Projects
None yet
Development

No branches or pull requests

3 participants