Skip to content

Commit

Permalink
Suppress unnecessary outlives
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Aug 1, 2023
1 parent 9295817 commit 1c35634
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 22 deletions.
9 changes: 5 additions & 4 deletions compiler/rustc_hir_analysis/src/check/wfcheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -552,8 +552,8 @@ fn gather_gat_bounds<'tcx, T: TypeFoldable<TyCtxt<'tcx>>>(
for (region_a, region_a_idx) in &regions {
// Ignore `'static` lifetimes for the purpose of this lint: it's
// because we know it outlives everything and so doesn't give meaningful
// clues
if let ty::ReStatic = **region_a {
// clues. Also ignore `ReError`, to avoid knock-down errors.
if let ty::ReStatic | ty::ReError(_) = **region_a {
continue;
}
// For each region argument (e.g., `'a` in our example), check for a
Expand Down Expand Up @@ -596,8 +596,9 @@ fn gather_gat_bounds<'tcx, T: TypeFoldable<TyCtxt<'tcx>>>(
// on the GAT itself.
for (region_b, region_b_idx) in &regions {
// Again, skip `'static` because it outlives everything. Also, we trivially
// know that a region outlives itself.
if ty::ReStatic == **region_b || region_a == region_b {
// know that a region outlives itself. Also ignore `ReError`, to avoid
// knock-down errors.
if matches!(**region_b, ty::ReStatic | ty::ReError(_)) || region_a == region_b {
continue;
}
if region_known_to_outlive(
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -942,6 +942,10 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
generic_ty: Ty<'tcx>,
min: ty::Region<'tcx>,
) -> bool {
if let ty::ReError(_) = *min {
return true;
}

match bound {
VerifyBound::IfEq(verify_if_eq_b) => {
let verify_if_eq_b = var_values.normalize(self.region_rels.tcx, *verify_if_eq_b);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ trait Iterable {

fn iter(&self) -> impl Iterator<Item = Self::Item<'missing>>;
//~^ ERROR use of undeclared lifetime name `'missing`
//~| ERROR the parameter type `Self` may not live long enough
}

fn main() {}
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,6 @@ help: consider introducing lifetime `'missing` here
LL | trait Iterable<'missing> {
| ++++++++++

error[E0311]: the parameter type `Self` may not live long enough
--> $DIR/missing-lt-outlives-in-rpitit-114274.rs:8:37
|
LL | fn iter(&self) -> impl Iterator<Item = Self::Item<'missing>>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: consider adding an explicit lifetime bound `Self: 'a`...
= note: ...so that the type `Self` will meet its required lifetime bounds...
note: ...that is required by this bound
--> $DIR/missing-lt-outlives-in-rpitit-114274.rs:6:15
|
LL | Self: 'a;
| ^^

error: aborting due to 2 previous errors
error: aborting due to previous error

Some errors have detailed explanations: E0261, E0311.
For more information about an error, try `rustc --explain E0261`.
For more information about this error, try `rustc --explain E0261`.

0 comments on commit 1c35634

Please sign in to comment.