diff options
| author | Michael Goulet <michael@errs.io> | 2024-03-27 16:02:13 -0400 |
|---|---|---|
| committer | Michael Goulet <michael@errs.io> | 2024-04-09 12:17:34 -0400 |
| commit | da2b714ba122d7befe1f10c808e82a536c9efcf0 (patch) | |
| tree | 4dc85682bdaac5f816347510425e57c8754f1b40 /compiler | |
| parent | a9e262a32dbef558bbe40731ddfe272cb2f11948 (diff) | |
| download | rust-da2b714ba122d7befe1f10c808e82a536c9efcf0.tar.gz rust-da2b714ba122d7befe1f10c808e82a536c9efcf0.zip | |
Clarifying comment
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_hir_analysis/src/check/wfcheck.rs | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/compiler/rustc_hir_analysis/src/check/wfcheck.rs b/compiler/rustc_hir_analysis/src/check/wfcheck.rs index cc54db18750..c26f982fa47 100644 --- a/compiler/rustc_hir_analysis/src/check/wfcheck.rs +++ b/compiler/rustc_hir_analysis/src/check/wfcheck.rs @@ -2089,13 +2089,19 @@ fn lint_redundant_lifetimes<'tcx>( let mut shadowed = FxHashSet::default(); for (idx, &candidate) in lifetimes.iter().enumerate() { - // Don't suggest removing a lifetime twice. + // Don't suggest removing a lifetime twice. We only need to check this + // here and not up in the `victim` loop because equality is transitive, + // so if A = C and B = C, then A must = B, so it'll be shadowed too in + // A's victim loop. if shadowed.contains(&candidate) { continue; } for &victim in &lifetimes[(idx + 1)..] { - // We only care about lifetimes that are "real", i.e. that have a def-id. + // We should only have late-bound lifetimes of the `BrNamed` variety, + // since we get these signatures straight from `hir_lowering`. And any + // other regions (ReError/ReStatic/etc.) shouldn't matter, since we + // can't really suggest to remove them. let (ty::ReEarlyParam(ty::EarlyParamRegion { def_id, .. }) | ty::ReLateParam(ty::LateParamRegion { bound_region: ty::BoundRegionKind::BrNamed(def_id, _), @@ -2113,7 +2119,7 @@ fn lint_redundant_lifetimes<'tcx>( continue; } - // If there are no lifetime errors, then we have proven that `'candidate = 'victim`! + // If `candidate <: victim` and `victim <: candidate`, then they're equal. if outlives_env.free_region_map().sub_free_regions(tcx, candidate, victim) && outlives_env.free_region_map().sub_free_regions(tcx, victim, candidate) { |
