Skip to content
/ rust Public
forked from rust-lang/rust

Commit 1c35634

Browse files
Suppress unnecessary outlives
1 parent 9295817 commit 1c35634

File tree

4 files changed

+11
-22
lines changed

4 files changed

+11
-22
lines changed

compiler/rustc_hir_analysis/src/check/wfcheck.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -552,8 +552,8 @@ fn gather_gat_bounds<'tcx, T: TypeFoldable<TyCtxt<'tcx>>>(
552552
for (region_a, region_a_idx) in &regions {
553553
// Ignore `'static` lifetimes for the purpose of this lint: it's
554554
// because we know it outlives everything and so doesn't give meaningful
555-
// clues
556-
if let ty::ReStatic = **region_a {
555+
// clues. Also ignore `ReError`, to avoid knock-down errors.
556+
if let ty::ReStatic | ty::ReError(_) = **region_a {
557557
continue;
558558
}
559559
// For each region argument (e.g., `'a` in our example), check for a
@@ -596,8 +596,9 @@ fn gather_gat_bounds<'tcx, T: TypeFoldable<TyCtxt<'tcx>>>(
596596
// on the GAT itself.
597597
for (region_b, region_b_idx) in &regions {
598598
// Again, skip `'static` because it outlives everything. Also, we trivially
599-
// know that a region outlives itself.
600-
if ty::ReStatic == **region_b || region_a == region_b {
599+
// know that a region outlives itself. Also ignore `ReError`, to avoid
600+
// knock-down errors.
601+
if matches!(**region_b, ty::ReStatic | ty::ReError(_)) || region_a == region_b {
601602
continue;
602603
}
603604
if region_known_to_outlive(

compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -942,6 +942,10 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
942942
generic_ty: Ty<'tcx>,
943943
min: ty::Region<'tcx>,
944944
) -> bool {
945+
if let ty::ReError(_) = *min {
946+
return true;
947+
}
948+
945949
match bound {
946950
VerifyBound::IfEq(verify_if_eq_b) => {
947951
let verify_if_eq_b = var_values.normalize(self.region_rels.tcx, *verify_if_eq_b);

tests/ui/impl-trait/in-trait/missing-lt-outlives-in-rpitit-114274.rs

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ trait Iterable {
77

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

1312
fn main() {}

tests/ui/impl-trait/in-trait/missing-lt-outlives-in-rpitit-114274.stderr

+2-17
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,6 @@ help: consider introducing lifetime `'missing` here
1818
LL | trait Iterable<'missing> {
1919
| ++++++++++
2020

21-
error[E0311]: the parameter type `Self` may not live long enough
22-
--> $DIR/missing-lt-outlives-in-rpitit-114274.rs:8:37
23-
|
24-
LL | fn iter(&self) -> impl Iterator<Item = Self::Item<'missing>>;
25-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
26-
|
27-
= help: consider adding an explicit lifetime bound `Self: 'a`...
28-
= note: ...so that the type `Self` will meet its required lifetime bounds...
29-
note: ...that is required by this bound
30-
--> $DIR/missing-lt-outlives-in-rpitit-114274.rs:6:15
31-
|
32-
LL | Self: 'a;
33-
| ^^
34-
35-
error: aborting due to 2 previous errors
21+
error: aborting due to previous error
3622

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

0 commit comments

Comments
 (0)