Skip to content

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

Description

@pnkfelix

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-NLLArea: Non-lexical lifetimes (NLL)NLL-diagnosticsWorking towards the "diagnostic parity" goal

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions