-
Notifications
You must be signed in to change notification settings - Fork 13.3k
diagnostics: avoid mismatch between variance index and hir generic #116045
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
Conversation
This happens because variances are constructed from ty generics, and ty generics are always constructed with lifetimes first. See compiler/rustc_hir_analysis/src/collect/generics_of.rs:248-269 Fixes rust-lang#83556
r? @cjgillot (rustbot has picked a reviewer for you, use r? to override) |
for hp in hir_generics.params { | ||
if hp.name.ident().name == ty_param.name { | ||
hir_param = hp; | ||
break; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we just silence the error? The program is invalid anyway, and we check that by delaying a bug.
for hp in hir_generics.params { | |
if hp.name.ident().name == ty_param.name { | |
hir_param = hp; | |
break; | |
} | |
} | |
continue; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that seems reasonable.
let ty_param = &ty_generics.params[index]; | ||
let mut hir_param = &hir_generics.params[index]; | ||
|
||
if ty_param.name != hir_param.name.ident().name { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if ty_param.name != hir_param.name.ident().name { | |
if ty_param.def_id != hir_param.def_id { |
Working with def_ids is always more robust.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch.
for hp in hir_generics.params { | ||
if hp.name.ident().name == ty_param.name { | ||
hir_param = hp; | ||
break; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for hp in hir_generics.params { | |
if hp.name.ident().name == ty_param.name { | |
hir_param = hp; | |
break; | |
} | |
} | |
if let Some(node) = tcx.find_node_by_def_id(ty_param.def_id) { | |
hir_param = node.expect_generic_param(); | |
} |
Thanks. |
☀️ Test successful - checks-actions |
Finished benchmarking commit (0237aa3): comparison URL. Overall result: no relevant changes - no action needed@rustbot label: -perf-regression Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesThis benchmark run did not return any relevant results for this metric. Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 633.587s -> 634.28s (0.11%) |
This happens because variances are constructed from ty generics, and ty generics are always constructed with lifetimes first.
rust/compiler/rustc_hir_analysis/src/collect/generics_of.rs
Lines 248 to 269 in b3aa8e7
Fixes #83556