Skip to content

Commit 9fae515

Browse files
authored
Unrolled build for rust-lang#128908
Rollup merge of rust-lang#128908 - notriddle:notriddle/self-inferred-lifetime-bounds, r=compiler-errors diagnostics: do not warn when a lifetime bound infers itself Fixes rust-lang#119228
2 parents 8291d68 + 4dc13c5 commit 9fae515

12 files changed

+97
-6
lines changed

compiler/rustc_lint/src/builtin.rs

+15-6
Original file line numberDiff line numberDiff line change
@@ -1924,14 +1924,13 @@ declare_lint_pass!(ExplicitOutlivesRequirements => [EXPLICIT_OUTLIVES_REQUIREMEN
19241924
impl ExplicitOutlivesRequirements {
19251925
fn lifetimes_outliving_lifetime<'tcx>(
19261926
tcx: TyCtxt<'tcx>,
1927-
inferred_outlives: &'tcx [(ty::Clause<'tcx>, Span)],
1927+
inferred_outlives: impl Iterator<Item = &'tcx (ty::Clause<'tcx>, Span)>,
19281928
item: DefId,
19291929
lifetime: DefId,
19301930
) -> Vec<ty::Region<'tcx>> {
19311931
let item_generics = tcx.generics_of(item);
19321932

19331933
inferred_outlives
1934-
.iter()
19351934
.filter_map(|(clause, _)| match clause.kind().skip_binder() {
19361935
ty::ClauseKind::RegionOutlives(ty::OutlivesPredicate(a, b)) => match *a {
19371936
ty::ReEarlyParam(ebr)
@@ -1947,11 +1946,10 @@ impl ExplicitOutlivesRequirements {
19471946
}
19481947

19491948
fn lifetimes_outliving_type<'tcx>(
1950-
inferred_outlives: &'tcx [(ty::Clause<'tcx>, Span)],
1949+
inferred_outlives: impl Iterator<Item = &'tcx (ty::Clause<'tcx>, Span)>,
19511950
index: u32,
19521951
) -> Vec<ty::Region<'tcx>> {
19531952
inferred_outlives
1954-
.iter()
19551953
.filter_map(|(clause, _)| match clause.kind().skip_binder() {
19561954
ty::ClauseKind::TypeOutlives(ty::OutlivesPredicate(a, b)) => {
19571955
a.is_param(index).then_some(b)
@@ -2094,7 +2092,11 @@ impl<'tcx> LateLintPass<'tcx> for ExplicitOutlivesRequirements {
20942092
(
20952093
Self::lifetimes_outliving_lifetime(
20962094
cx.tcx,
2097-
inferred_outlives,
2095+
// don't warn if the inferred span actually came from the predicate we're looking at
2096+
// this happens if the type is recursively defined
2097+
inferred_outlives
2098+
.iter()
2099+
.filter(|(_, span)| !predicate.span.contains(*span)),
20982100
item.owner_id.to_def_id(),
20992101
region_def_id,
21002102
),
@@ -2116,7 +2118,14 @@ impl<'tcx> LateLintPass<'tcx> for ExplicitOutlivesRequirements {
21162118
};
21172119
let index = ty_generics.param_def_id_to_index[&def_id];
21182120
(
2119-
Self::lifetimes_outliving_type(inferred_outlives, index),
2121+
Self::lifetimes_outliving_type(
2122+
// don't warn if the inferred span actually came from the predicate we're looking at
2123+
// this happens if the type is recursively defined
2124+
inferred_outlives.iter().filter(|(_, span)| {
2125+
!predicate.span.contains(*span)
2126+
}),
2127+
index,
2128+
),
21202129
&predicate.bounds,
21212130
predicate.span,
21222131
predicate.origin == PredicateOrigin::WhereClause,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
//@ run-rustfix
2+
//@ check-pass
3+
#![deny(explicit_outlives_requirements)]
4+
5+
pub trait TypeCx {
6+
type Ty;
7+
}
8+
9+
pub struct Pat<Cx: TypeCx> {
10+
pub ty: Cx::Ty,
11+
}
12+
13+
// Simple recursive case: no warning
14+
pub struct MyTypeContextSimpleRecursive<'thir, 'tcx: 'thir> {
15+
pub pat: Pat<MyTypeContextSimpleRecursive<'thir, 'tcx>>,
16+
}
17+
impl<'thir, 'tcx: 'thir> TypeCx for MyTypeContextSimpleRecursive<'thir, 'tcx> {
18+
type Ty = ();
19+
}
20+
21+
// Non-recursive case: we want a warning
22+
pub struct MyTypeContextNotRecursive<'thir, 'tcx: 'thir> {
23+
pub tcx: &'tcx (),
24+
pub thir: &'thir (),
25+
}
26+
impl<'thir, 'tcx: 'thir> TypeCx for MyTypeContextNotRecursive<'thir, 'tcx> {
27+
type Ty = ();
28+
}
29+
30+
31+
// Mixed-recursive case: we want a warning
32+
pub struct MyTypeContextMixedRecursive<'thir, 'tcx: 'thir> {
33+
pub pat: Pat<MyTypeContextMixedRecursive<'thir, 'tcx>>,
34+
pub tcx: &'tcx (),
35+
pub thir: &'thir (),
36+
}
37+
impl<'thir, 'tcx: 'thir> TypeCx for MyTypeContextMixedRecursive<'thir, 'tcx> {
38+
type Ty = ();
39+
}
40+
41+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
//@ run-rustfix
2+
//@ check-pass
3+
#![deny(explicit_outlives_requirements)]
4+
5+
pub trait TypeCx {
6+
type Ty;
7+
}
8+
9+
pub struct Pat<Cx: TypeCx> {
10+
pub ty: Cx::Ty,
11+
}
12+
13+
// Simple recursive case: no warning
14+
pub struct MyTypeContextSimpleRecursive<'thir, 'tcx: 'thir> {
15+
pub pat: Pat<MyTypeContextSimpleRecursive<'thir, 'tcx>>,
16+
}
17+
impl<'thir, 'tcx: 'thir> TypeCx for MyTypeContextSimpleRecursive<'thir, 'tcx> {
18+
type Ty = ();
19+
}
20+
21+
// Non-recursive case: we want a warning
22+
pub struct MyTypeContextNotRecursive<'thir, 'tcx: 'thir> {
23+
pub tcx: &'tcx (),
24+
pub thir: &'thir (),
25+
}
26+
impl<'thir, 'tcx: 'thir> TypeCx for MyTypeContextNotRecursive<'thir, 'tcx> {
27+
type Ty = ();
28+
}
29+
30+
31+
// Mixed-recursive case: we want a warning
32+
pub struct MyTypeContextMixedRecursive<'thir, 'tcx: 'thir> {
33+
pub pat: Pat<MyTypeContextMixedRecursive<'thir, 'tcx>>,
34+
pub tcx: &'tcx (),
35+
pub thir: &'thir (),
36+
}
37+
impl<'thir, 'tcx: 'thir> TypeCx for MyTypeContextMixedRecursive<'thir, 'tcx> {
38+
type Ty = ();
39+
}
40+
41+
fn main() {}

0 commit comments

Comments
 (0)