Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"these two types are declared with different lifetimes..." not triggering within structs #44508

Closed
nikomatsakis opened this issue Sep 11, 2017 · 0 comments · Fixed by #44549
Closed
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@nikomatsakis
Copy link
Contributor

This example:

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

fn foo<'a, 'b>(mut x: Vec<Ref<'a>>, y: Ref<'b>)  {
    x.push(y);
}

fn main() { }

currently prints an old-school and crappy error:

error[E0308]: mismatched types
 --> src/main.rs:4:12
  |
4 |     x.push(y);
  |            ^ lifetime mismatch
  |
  = note: expected type `Ref<'a>`
             found type `Ref<'b>`
note: the lifetime 'b as defined on the function body at 3:1...
 --> src/main.rs:3:1
  |
3 | / fn foo<'a, 'b>(mut x: Vec<Ref<'a>>, y: Ref<'b>)  {
4 | |     x.push(y);
5 | | }
  | |_^
note: ...does not necessarily outlive the lifetime 'a as defined on the function body at 3:1
 --> src/main.rs:3:1
  |
3 | / fn foo<'a, 'b>(mut x: Vec<Ref<'a>>, y: Ref<'b>)  {
4 | |     x.push(y);
5 | | }
  | |_^

It should print something like:

error[E0623]: lifetime mismatch
 --> src/main.rs:2:12
  |
1 | fn foo<'a, 'b>(mut x: Vec<Ref<'a, u32>>, y: Ref<'b, u32>)  {
  |                           ------------      ------------ these two types are declared with different lifetimes...
2 |     x.push(y);
  |            ^ ...but data from `y` flows into `x` here
@nikomatsakis nikomatsakis added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 11, 2017
alexcrichton added a commit to alexcrichton/rust that referenced this issue Sep 16, 2017
extend E0623 for earlybound and latebound for structs

This fixes rust-lang#44508

r? @nikomatsakis
frewsxcv added a commit to frewsxcv/rust that referenced this issue Sep 16, 2017
extend E0623 for earlybound and latebound for structs

This fixes rust-lang#44508

r? @nikomatsakis
TimNN added a commit to TimNN/rust that referenced this issue Sep 17, 2017
extend E0623 for earlybound and latebound for structs

This fixes rust-lang#44508

r? @nikomatsakis
TimNN added a commit to TimNN/rust that referenced this issue Sep 17, 2017
extend E0623 for earlybound and latebound for structs

This fixes rust-lang#44508

r? @nikomatsakis
TimNN added a commit to TimNN/rust that referenced this issue Sep 17, 2017
extend E0623 for earlybound and latebound for structs

This fixes rust-lang#44508

r? @nikomatsakis
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant