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

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

Closed
eefriedman opened this issue Oct 14, 2015 · 12 comments · Fixed by #29188
Closed

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

eefriedman opened this issue Oct 14, 2015 · 12 comments · Fixed by #29188
Assignees
Labels
A-lifetimes Area: Lifetimes / regions P-high High priority regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team, which will review and decide on the PR/issue.

Comments

@eefriedman
Copy link
Contributor

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.

@pnkfelix pnkfelix added regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. A-lifetimes Area: Lifetimes / regions labels Oct 14, 2015
@pnkfelix
Copy link
Member

(this may be a compiler issue or a lang issue; tagging with both teams until that Q is resolved)

@pnkfelix pnkfelix added T-lang Relevant to the language team, which will review and decide on the PR/issue. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 14, 2015
@eefriedman
Copy link
Contributor Author

Another testcase, which I think is the same issue:

pub struct Chan;
pub struct ChanSelect<'c, T> {
    chans: Vec<(&'c Chan, T)>,
}
impl<'c, T> ChanSelect<'c, T> {
    pub fn add_recv_ret(&mut self, chan: &'c Chan, ret: T)
    {
        self.chans.push((chan, ret));
    }
}
fn main() {}

@alexcrichton
Copy link
Member

triage: I-nominated

@nikomatsakis
Copy link
Contributor

I've not fully investigated, but problem is almost certainly a missing call to outlives, similar to #29006

@nikomatsakis
Copy link
Contributor

Hmm, problem seems to be related to a late-bound region instantiated during the probing phase. We wind up adding a region obligation. I will continue investigating, but definitely the fact that probe leaks variables is worrisome (I may also be getting a bit confused).

(As an aside, I wonder if rewriting region inference isn't part of the fix here; the current contraction behavior isn't really doing anyone any favors, and there are many other known deficiencies.)

@arielb1
Copy link
Contributor

arielb1 commented Oct 15, 2015

I think this would be fixed by #26324 - I should try to check.

@nikomatsakis
Copy link
Contributor

triage: P-high

Assigning to myself. The problem has to do with a lifetime parameter being created as part of the autoderef loop during method probing. Best fix might be to isolate probing, if we can, but there are other workarounds we could put in place. Improving region compilation would be good too. Not sure what I think is the preferred fix just now.

@nikomatsakis nikomatsakis self-assigned this Oct 15, 2015
@rust-highfive rust-highfive added P-high High priority and removed I-nominated labels Oct 15, 2015
@arielb1
Copy link
Contributor

arielb1 commented Oct 15, 2015

Annoyingly, the problem variables aren't used in a stack-like way, so #26324 etc. can't really work, unless we refactor method probing.

@arielb1
Copy link
Contributor

arielb1 commented Oct 15, 2015

Maybe refactor method::probe to use a select-commit approach and combine this with #26324 (or @jroesch's version of it).

@nikomatsakis
Copy link
Contributor

So I tend to agree that a transactional approach is the right thing here (and, indeed, method::probe and method::commit were intended to be be a select-commit model, to aid with caching). That said, another way to address this particular regression is by modifying region inference so that it works on a more traditional dataflow model, where all inference variables begin as empty and just get bigger (removing the notion of contracting variables). I'm writing up a short discuss post outlining some related thoughts on this topic. This carries a certain element of danger as the current behavior tends to flush bugs, but it also causes incorrect regressions as here. My main thought there is that we should be moving to doing a "validating" typeck on MIR, which would probably be much simpler and even more effective at catching invalid region inference results.

@nikomatsakis
Copy link
Contributor

But given that @jroesch's PR got stalled, perhaps landing #26324 in the meantime (and using it to fix this problem) is prudent. I am currently experimenting with converting region inference as described in previous comment, which ought (in principle) to be simple.

@nikomatsakis
Copy link
Contributor

OK, I've verified that modifying the region inference scheme does indeed solve the regression, though I agree that it's sort of a workaround, in that we really ought not to be solving these constraints in the first place.

nikomatsakis added a commit to nikomatsakis/rust that referenced this issue Oct 28, 2015
empty region, and they complicate region inference to no particular end.
They also lead in some cases to spurious errors like rust-lang#29048 (though in
some cases these errors are helpful in tracking down missing
constraints).
nikomatsakis added a commit to nikomatsakis/rust that referenced this issue Oct 28, 2015
bors added a commit that referenced this issue Oct 29, 2015
This fixes #29048 (though I think adding better transactional support would be a better fix for that issue, but that is more difficult). It also simplifies region inference and changes the model to a pure data flow one, as discussed in [this internals thread](https://internals.rust-lang.org/t/rough-thoughts-on-the-impl-of-region-inference-mir-etc/2800). I am not 100% sure though if this PR is the right thing to do -- or at least maybe not at this moment, so thoughts on that would be appreciated.

r? @pnkfelix 
cc @arielb1
brson pushed a commit to brson/rust that referenced this issue Nov 4, 2015
empty region, and they complicate region inference to no particular end.
They also lead in some cases to spurious errors like rust-lang#29048 (though in
some cases these errors are helpful in tracking down missing
constraints).
brson pushed a commit to brson/rust that referenced this issue Nov 4, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lifetimes Area: Lifetimes / regions P-high High priority regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants