diff options
| author | bors <bors@rust-lang.org> | 2023-09-23 08:11:59 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-09-23 08:11:59 +0000 |
| commit | 0237aa3d771f4c6152c7d46a888ea89c538b121e (patch) | |
| tree | 78f582992954a507120260c950b0c26ed8f25837 /compiler/rustc_hir_analysis/src/check | |
| parent | 136d74fab8503366fa8b2eb9099f9d7f1b4cb5ec (diff) | |
| parent | 58ef3a0ec9a3e2151a103964683b5d00932304d8 (diff) | |
| download | rust-0237aa3d771f4c6152c7d46a888ea89c538b121e.tar.gz rust-0237aa3d771f4c6152c7d46a888ea89c538b121e.zip | |
Auto merge of #116045 - notriddle:notriddle/issue-83556, r=cjgillot
diagnostics: avoid mismatch between variance index and hir generic This happens because variances are constructed from ty generics, and ty generics are always constructed with lifetimes first. https://github.com/rust-lang/rust/blob/b3aa8e7168a3d940122db3561289ffbf3f587262/compiler/rustc_hir_analysis/src/collect/generics_of.rs#L248-L269 Fixes #83556
Diffstat (limited to 'compiler/rustc_hir_analysis/src/check')
| -rw-r--r-- | compiler/rustc_hir_analysis/src/check/wfcheck.rs | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/compiler/rustc_hir_analysis/src/check/wfcheck.rs b/compiler/rustc_hir_analysis/src/check/wfcheck.rs index b97e0a80fe6..00a684f2963 100644 --- a/compiler/rustc_hir_analysis/src/check/wfcheck.rs +++ b/compiler/rustc_hir_analysis/src/check/wfcheck.rs @@ -1755,6 +1755,8 @@ fn check_variances_for_type_defn<'tcx>( .collect::<FxHashSet<_>>() }); + let ty_generics = tcx.generics_of(item.owner_id); + for (index, _) in variances.iter().enumerate() { let parameter = Parameter(index as u32); @@ -1762,13 +1764,27 @@ fn check_variances_for_type_defn<'tcx>( continue; } - let param = &hir_generics.params[index]; + let ty_param = &ty_generics.params[index]; + let hir_param = &hir_generics.params[index]; + + if ty_param.def_id != hir_param.def_id.into() { + // valid programs always have lifetimes before types in the generic parameter list + // ty_generics are normalized to be in this required order, and variances are built + // from ty generics, not from hir generics. but we need hir generics to get + // a span out + // + // if they aren't in the same order, then the user has written invalid code, and already + // got an error about it (or I'm wrong about this) + tcx.sess + .delay_span_bug(hir_param.span, "hir generics and ty generics in different order"); + continue; + } - match param.name { + match hir_param.name { hir::ParamName::Error => {} _ => { let has_explicit_bounds = explicitly_bounded_params.contains(¶meter); - report_bivariance(tcx, param, has_explicit_bounds); + report_bivariance(tcx, hir_param, has_explicit_bounds); } } } |
