Rust: Improve case with one named, one anonymous lifetime parameter - SubSupConflict Errors

Created on 16 Jun 2017  路  7Comments  路  Source: rust-lang/rust

Currently in #42669, we are handling only ConcreteFailure RegionResolution Errors. We need to detect and improve the error message for SubSupConflict Error as well.

struct Foo {
  field: i32
}
impl Foo{

  fn foo2<'a>(&self, x: &'a i32) -> &'a i32 {
    if true { &self.field } else { x }
  }
}

cc @nikomatsakis

A-diagnostics C-enhancement E-needs-mentor WG-compiler-errors

Most helpful comment

@cengizIO expressed some interest in taking a look at this. @cengizIO, here are some rough instructions for what would have to be done. Currently, when reporting region errors, we check for the special case of a "named-anon conflict". If you look into this function, you'll see that it first tests for ConcreteFailure. The basic task here is to extend that also work for SubSupConflict. I think, in this case, that is probably as easy as extracting the sub and sup regions involved (as well as the "main span") and returning them, and then checking what impact that has on the tests involved and making sure everything still looks ok. It's a good opportunity though to read over the code and understand what it does.

All 7 comments

I'd like to start working on this if noone else is assigned.

@cengizIO expressed some interest in taking a look at this. @cengizIO, here are some rough instructions for what would have to be done. Currently, when reporting region errors, we check for the special case of a "named-anon conflict". If you look into this function, you'll see that it first tests for ConcreteFailure. The basic task here is to extend that also work for SubSupConflict. I think, in this case, that is probably as easy as extracting the sub and sup regions involved (as well as the "main span") and returning them, and then checking what impact that has on the tests involved and making sure everything still looks ok. It's a good opportunity though to read over the code and understand what it does.

You can read up my blogs here. I hope they will be of help :)

Ping: I was busy with other stuff since I've signed up to this. Now that they are over, I'm diving into it.

I think this is a good test case:

struct Foo {
    field: i32,
}

fn foo2<'a>(a: &'a Foo, x: &i32) -> &'a i32 {
    if true {
        let p: &i32 = &a.field;
        &*p
    } else {
        &*x
    }
}

fn main() { }

Hello @gaurikholkar I was in LOA during last week, just returned. Will revise my PR tomorrow.

I've removed the redundant test case and updated the sample input with the provided one up in https://github.com/rust-lang/rust/issues/42701#issuecomment-326091615

Was this page helpful?
0 / 5 - 0 ratings

Related issues

withoutboats picture withoutboats  路  308Comments

nikomatsakis picture nikomatsakis  路  274Comments

aturon picture aturon  路  417Comments

nikomatsakis picture nikomatsakis  路  236Comments

nikomatsakis picture nikomatsakis  路  210Comments