Skip to content

improve case with both anonymous lifetime parameters in Structs #43275

Closed
@gaurikholkar-zz

Description

@gaurikholkar-zz

Generate error message for the case where , for structs, we have missing lifetime parameters.
For e.g. a sample error message

struct Ref<'a> { x: &'a u32 }

fn foo(mut x: Vec<Ref>, y: Ref) {
                  ---      --- must have the same lifetime
  x.push(y);
|            ^ data from `y` flows into `x` here

}

There are cases where more than one lifetime parameters come into play.

struct Ref<'a, 'b> { a: &'a u32, b: &'b u32 }

fn foo(mut x: Ref, y: Ref) {
              ---     --- 2nd lifetime parameter on `Ref` must match
              2nd lifetime parameter on `Ref` must match
  x.b = y.b;
}

struct Ref<'a, 'b> { a: &'a u32, b: &'b u32 }

fn foo<'x1, 'x2, 'y1>(mut x: Ref<'x1, 'x2>, y: Ref<'y1, 'y2>) {
  x.b = y.b;
}

cc @nikomatsakis

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-lifetimesArea: Lifetimes / regionsC-enhancementCategory: An issue proposing an enhancement or a PR with one.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions