Skip to content

Nightly regression: Incorrect "parameter type may not live long enough" warning #29048

Closed
@eefriedman

Description

@eefriedman

Testcase:

use std::marker::PhantomData;
pub struct WebDriverHttpApi<U> {
    _routes: PhantomData<U>,
}
impl <U> WebDriverHttpApi<U> {
    pub fn new(extension_routes:Vec<(&str, U)>) -> WebDriverHttpApi<U> {
        for &(ref _url, ref _extension_route) in extension_routes.iter() {}
        unimplemented!()
    }
}
fn main(){}
<anon>:7:67: 7:73 warning: the parameter type `U` may not live long enough [E0311]
<anon>:7         for &(ref _url, ref _extension_route) in extension_routes.iter() {}
                                                                           ^~~~~~
<anon>:7:67: 7:73 help: consider adding an explicit lifetime bound for `U`
<anon>:6:72: 9:6 note: the parameter type `U` must be valid for the anonymous lifetime #1 defined on the block at 6:71...
<anon>:6     pub fn new(extension_routes:Vec<(&str, U)>) -> WebDriverHttpApi<U> {
<anon>:7         for &(ref _url, ref _extension_route) in extension_routes.iter() {}
<anon>:8         unimplemented!()
<anon>:9     }
<anon>:7:67: 7:73 note: this warning results from recent bug fixes and clarifications; it will become a HARD ERROR in the next release. See RFC 1214 for details.
<anon>:7         for &(ref _url, ref _extension_route) in extension_routes.iter() {}
                                                                           ^~~~~~
<anon>:7:67: 7:73 note: ...so that the reference type `&collections::vec::Vec<(&str, U)>` does not outlive the data it points at
<anon>:7         for &(ref _url, ref _extension_route) in extension_routes.iter() {}
                                                                           ^~~~~~
<anon>:7:67: 7:73 warning: the parameter type `U` may not live long enough [E0311]
<anon>:7         for &(ref _url, ref _extension_route) in extension_routes.iter() {}
                                                                           ^~~~~~
<anon>:7:67: 7:73 help: consider adding an explicit lifetime bound for `U`
<anon>:6:72: 9:6 note: the parameter type `U` must be valid for the anonymous lifetime #1 defined on the block at 6:71...
<anon>:6     pub fn new(extension_routes:Vec<(&str, U)>) -> WebDriverHttpApi<U> {
<anon>:7         for &(ref _url, ref _extension_route) in extension_routes.iter() {}
<anon>:8         unimplemented!()
<anon>:9     }
<anon>:7:67: 7:73 note: this warning results from recent bug fixes and clarifications; it will become a HARD ERROR in the next release. See RFC 1214 for details.
<anon>:7         for &(ref _url, ref _extension_route) in extension_routes.iter() {}
                                                                           ^~~~~~
<anon>:7:67: 7:73 note: ...so that the reference type `&[(&str, U)]` does not outlive the data it points at
<anon>:7         for &(ref _url, ref _extension_route) in extension_routes.iter() {}
                                                                           ^~~~~~

This gives no warnings on beta or stable.

Metadata

Metadata

Assignees

Labels

A-lifetimesArea: Lifetimes / regionsP-highHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language team, which will review and decide on the PR/issue.regression-from-stable-to-nightlyPerformance or correctness regression from stable to nightly.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions