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 injects type infer failures in presence of subsequently-masked lifetime errors #51172

Closed
pnkfelix opened this issue May 29, 2018 · 3 comments · Fixed by #53129
Closed

NLL injects type infer failures in presence of subsequently-masked lifetime errors #51172

pnkfelix opened this issue May 29, 2018 · 3 comments · Fixed by #53129
Labels
A-NLL Area: Non-lexical lifetimes (NLL) NLL-diagnostics Working towards the "diagnostic parity" goal

Comments

@pnkfelix
Copy link
Member

Look at https://github.com/rust-lang/rust/blob/master/src/test/ui/lifetime-errors/ex2a-push-one-existing-name-early-bound.rs

trait Foo<'a> {}
impl<'a, T> Foo<'a> for T {}

fn baz<'a, 'b, T>(x: &mut Vec<&'a T>, y: &T)
    where i32: Foo<'a>,
          u32: Foo<'b>
{
    x.push(y); //~ ERROR explicit lifetime required
}
fn main() {
let x = baz;
}

its expected error output is (https://github.com/rust-lang/rust/blob/master/src/test/ui/lifetime-errors/ex2a-push-one-existing-name-early-bound.stderr)

error[E0621]: explicit lifetime required in the type of `y`
  --> $DIR/ex2a-push-one-existing-name-early-bound.rs:17:12
   |
LL | fn baz<'a, 'b, T>(x: &mut Vec<&'a T>, y: &T)
   |                                       - consider changing the type of `y` to `&'a T`
...
LL |     x.push(y); //~ ERROR explicit lifetime required
| ^ lifetime `'a` required

but under NLL it yields (https://github.com/rust-lang/rust/blob/master/src/test/ui/lifetime-errors/ex2a-push-one-existing-name-early-bound.nll.stderr):

warning: not reporting region error due to nll
  --> $DIR/ex2a-push-one-existing-name-early-bound.rs:17:12
   |
LL |     x.push(y); //~ ERROR explicit lifetime required
   |            ^

error[E0282]: type annotations needed
  --> $DIR/ex2a-push-one-existing-name-early-bound.rs:20:9
   |
LL | let x = baz;
   |     -   ^^^ cannot infer type for `T`
   |     |
   |     consider giving `x` a type

error: aborting due to previous error

The latter is amazingly different from the former.

@pnkfelix pnkfelix added A-NLL Area: Non-lexical lifetimes (NLL) NLL-diagnostics Working towards the "diagnostic parity" goal WG-compiler-nll labels May 29, 2018
@nikomatsakis
Copy link
Contributor

Hmm. We actually do try to give the nicer errors, but for whatever reason the heuristics we use to decide what is the "main error" to report are failing here. Seems like an interesting case to dig into a bit.

@nikomatsakis
Copy link
Contributor

But I'll mark it as a sub-issue of #51169

@nikomatsakis
Copy link
Contributor

OK so -- the problem here I think is the TEST. In particular, the let x = baz line serves no purpose. It does however cause typeck to fail and hence we never get to MIR borrowck. If you remove that line and enable #![feature(nll)], we get the same error message.

@nikomatsakis nikomatsakis self-assigned this Aug 6, 2018
cramertj added a commit to cramertj/rust that referenced this issue Aug 8, 2018
…, r=pnkfelix

remove `let x = baz` which was obscuring the real error

fixes rust-lang#51172
cramertj added a commit to cramertj/rust that referenced this issue Aug 8, 2018
…, r=pnkfelix

remove `let x = baz` which was obscuring the real error

fixes rust-lang#51172
kennytm added a commit to kennytm/rust that referenced this issue Aug 28, 2018
…, r=pnkfelix

remove `let x = baz` which was obscuring the real error

fixes rust-lang#51172
Mark-Simulacrum added a commit to Mark-Simulacrum/rust that referenced this issue Aug 28, 2018
…, r=pnkfelix

remove `let x = baz` which was obscuring the real error

fixes rust-lang#51172
@nikomatsakis nikomatsakis removed their assignment Aug 29, 2018
pietroalbini added a commit to pietroalbini/rust that referenced this issue Aug 29, 2018
…, r=pnkfelix

remove `let x = baz` which was obscuring the real error

fixes rust-lang#51172
pietroalbini added a commit to pietroalbini/rust that referenced this issue Aug 29, 2018
…, r=pnkfelix

remove `let x = baz` which was obscuring the real error

fixes rust-lang#51172
pietroalbini added a commit to pietroalbini/rust that referenced this issue Aug 30, 2018
…, r=pnkfelix

remove `let x = baz` which was obscuring the real error

fixes rust-lang#51172
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-diagnostics Working towards the "diagnostic parity" goal
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants