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

NLL regression: lifetime 'static required #58127

Closed
timvermeulen opened this issue Feb 3, 2019 · 1 comment
Closed

NLL regression: lifetime 'static required #58127

timvermeulen opened this issue Feb 3, 2019 · 1 comment
Assignees
Labels
A-NLL Area: Non-lexical lifetimes (NLL) NLL-complete Working towards the "valid code works" goal P-high High priority

Comments

@timvermeulen
Copy link
Contributor

NLL causes compilation to fail here:

fn f(s: &str) {
    g(s, |x| h(x));
}

fn g<T, F>(_: T, _: F)
where F: Fn(&mut (&(T, T), T)) {}

fn h<T>(_: &mut (&(T, T), T)) {}
error[E0621]: explicit lifetime required in the type of `s`
 --> src/lib.rs:2:5
  |
1 | fn f(s: &str) {
  |         ---- help: add explicit lifetime `'static` to the type of `s`: `&'static str`
2 |     g(s, |x| h(x));
  |     ^^^^^^^^^^^^^^ lifetime `'static` required

error: aborting due to previous error

For more information about this error, try `rustc --explain E0621`.

Oddly, it does compile if I replace g(s, |x| h(x)) by g(s, h). Alternatively, if I give &str an explicit lifetime 'a, the compiler says that s escapes the function body:

warning[E0521]: borrowed data escapes outside of function
 --> src/lib.rs:2:5
  |
1 | fn f<'a>(s: &'a str) {
  |          - `s` is a reference that is only valid in the function body
2 |     g(s, |x| h(x));
  |     ^^^^^^^^^^^^^^ `s` escapes the function body here
  |
  = warning: this error has been downgraded to a warning for backwards compatibility with previous releases
  = warning: this represents potential undefined behavior in your code and this warning will become a hard error in the future
@matthewjasper matthewjasper added A-NLL Area: Non-lexical lifetimes (NLL) NLL-complete Working towards the "valid code works" goal labels Feb 4, 2019
@matthewjasper matthewjasper self-assigned this Feb 4, 2019
@matthewjasper
Copy link
Contributor

relevant code (cc @nikomatsakis):

// In case we find more than one, reduce to one for
// convenience. This is to prevent us from generating more
// complex constraints, but it will cause spurious errors.
let post_dom = relation
.mutual_immediate_postdominator(external_parents)
.cloned();

@matthewjasper matthewjasper added the P-high High priority label Feb 5, 2019
Centril added a commit to Centril/rust that referenced this issue Feb 14, 2019
… r=pnkfelix

Closure bounds fixes

* Ensures that "nice region errors" are buffered so that they are sorted and migrated correctly.
* Propagates fewer constraints for closures (cc rust-lang#58178)
* Propagate constraints from closures more precisely (rust-lang#58127)

Closes rust-lang#58127

r? @nikomatsakis
Centril added a commit to Centril/rust that referenced this issue Feb 14, 2019
… r=pnkfelix

Closure bounds fixes

* Ensures that "nice region errors" are buffered so that they are sorted and migrated correctly.
* Propagates fewer constraints for closures (cc rust-lang#58178)
* Propagate constraints from closures more precisely (rust-lang#58127)

Closes rust-lang#58127

r? @nikomatsakis
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-NLL Area: Non-lexical lifetimes (NLL) NLL-complete Working towards the "valid code works" goal P-high High priority
Projects
None yet
Development

No branches or pull requests

2 participants