Skip to content

[NLL] Bad higher ranked subtype errorΒ #57374

Open
@matthewjasper

Description

@matthewjasper

With the removal of the leak check the MIR type checker is now responsible for reporting higher-ranked lifetime errors in full NLL mode. The error messages are not currently very helpful, since they weren't user visible until now.

The following code (play):

#![feature(nll)]

fn main() {
    let x: fn(&'static ()) = |_| {};
    let y: for<'a> fn(&'a ()) = x;
}

gives the following output

error: higher-ranked subtype error
  --> <source>:19:12
   |
19 |     let x: fn(&'static ()) = |_| {};
   |            ^^^^^^^^^^^^^^^
error: aborting due to previous error
Compiler returned: 1

In migrate mode or with AST borrowck the error is much clearer:

error[E0308]: mismatched types
  --> <source>:20:33
   |
20 |     let y: for<'a> fn(&'a ()) = x;
   |                                 ^ one type is more general than the other
   |
   = note: expected type `for<'a> fn(&'a ())`
              found type `fn(&'static ())`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0308`.
Compiler returned: 1

cc @rust-lang/wg-compiler-nll

Metadata

Metadata

Labels

A-NLLArea: Non-lexical lifetimes (NLL)A-diagnosticsArea: Messages for errors, warnings, and lintsA-higher-rankedArea: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs)NLL-diagnosticsWorking towards the "diagnostic parity" goalP-mediumMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions