Skip to content

[NLL] Poor spans for mismatched types #95686

Closed

Description

@jackh726

The src/test/ui/rfc1623.rs test currently gives objectively worse output spans under NLL. Specifically, without NLL, we point to the specific field that isn't general enough. With NLL, we point at the outer struct creation.

Relevant excerpt with error labels:

struct SomeStruct<'x, 'y, 'z: 'x> {
    foo: &'x Foo<'z>,
    bar: &'x Bar<'z>,
    f: &'y dyn for<'a, 'b> Fn(&'a Foo<'b>) -> &'a Foo<'b>,
}
fn id<T>(t: T) -> T {
    t
}
static SOME_STRUCT: &SomeStruct = &SomeStruct {
    //[nll]~^ ERROR mismatched types
    //[nll]~| ERROR mismatched types
    //[nll]~| ERROR implementation of `FnOnce` is not general enough
    //[nll]~| ERROR implementation of `FnOnce` is not general enough
    foo: &Foo { bools: &[false, true] },
    bar: &Bar { bools: &[true, true] },
    f: &id,
    //[base]~^ ERROR implementation of `FnOnce` is not general enough
};

Activity

  1. added
    A-diagnosticsArea: Messages for errors, warnings, and lints
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    A-NLLArea: Non-lexical lifetimes (NLL)
    NLL-diagnosticsWorking towards the "diagnostic parity" goal
    on Apr 5, 2022
  2. self-assigned this
    on Apr 19, 2022
  3. Aaron1011 commented on Apr 20, 2022

    @Aaron1011
    Contributor

    This is caused by the way that we handle region constraints for promoteds. We change the location of all constraints to point to the location of the promoted:

    let locations = location.to_locations();
    for constraint in constraints.outlives().iter() {
    let mut constraint = constraint.clone();
    constraint.locations = locations;

    However, the location is used for both borrow-checking and diagnostics. As a result, any errors that get 'blamed' on a promoted will have the span of the entire promoted. We should track the span separately from the location, so that we can adjust the (semantic) location and diagnostic span separately.

  4. jackh726 commented on May 21, 2022

    @jackh726
    MemberAuthor

    Span here is better thanks to #96236. Now just a nearly duplicate error, which we can track in #96211.

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

Metadata

Metadata

Assignees

Labels

A-NLLArea: Non-lexical lifetimes (NLL)A-diagnosticsArea: Messages for errors, warnings, and lintsNLL-diagnosticsWorking towards the "diagnostic parity" goalT-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