-
Notifications
You must be signed in to change notification settings - Fork 13.8k
Open
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsD-papercutDiagnostics: An error or lint that needs small tweaks.Diagnostics: An error or lint that needs small tweaks.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
From one of our tests:
fn parse_type(iter: Box<dyn Iterator<Item=&str>+'static>) -> &str { iter.next() }
produces the following error:
error[E0106]: missing lifetime specifier
--> src/lib.rs:1:62
|
1 | fn parse_type(iter: Box<dyn Iterator<Item=&str>+'static>) -> &str { iter.next() }
| ------------------------------------ ^ expected named lifetime parameter
|
= help: this function's return type contains a borrowed value, but the signature does not say which one of `iter`'s 2 lifetimes it is borrowed from
help: consider introducing a named lifetime parameter
|
1 | fn parse_type<'a>(iter: Box<dyn Iterator<Item=&'a str>+'static>) -> &'a str { iter.next() }
| ++++ ++ ++
error[E0308]: mismatched types
--> src/lib.rs:1:69
|
1 | fn parse_type(iter: Box<dyn Iterator<Item=&str>+'static>) -> &str { iter.next() }
| ---- ^^^^^^^^^^^ expected `&str`, found enum `Option`
| |
| expected `&'static str` because of return type
|
= note: expected reference `&'static str`
found enum `Option<&str>`
Note how in the mismatched types error we’re seing two spans disagreeing with each other on what the lifetime of &str
ought to be. This can come across as pretty weird.
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsD-papercutDiagnostics: An error or lint that needs small tweaks.Diagnostics: An error or lint that needs small tweaks.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.