Rollup merge of #112612 - sginnett:issue-105150, r=compiler-errors
Fix explicit-outlives-requirements lint span Fixes #105150 which caused the span reported by the explicit-outlives-requirements lint to be incorrect when 1) the lint should suggest the entire where clause to be removed and 2) there are inline bounds present that are not inferable outlives requirements In particular, this would cause rustfix to leave a dangling empty where clause.
This commit is contained in:
commit
41d5aeccec
4 changed files with 36 additions and 8 deletions
|
@ -2124,12 +2124,16 @@ impl<'tcx> LateLintPass<'tcx> for ExplicitOutlivesRequirements {
|
||||||
}
|
}
|
||||||
|
|
||||||
let ty_generics = cx.tcx.generics_of(def_id);
|
let ty_generics = cx.tcx.generics_of(def_id);
|
||||||
|
let num_where_predicates = hir_generics
|
||||||
|
.predicates
|
||||||
|
.iter()
|
||||||
|
.filter(|predicate| predicate.in_where_clause())
|
||||||
|
.count();
|
||||||
|
|
||||||
let mut bound_count = 0;
|
let mut bound_count = 0;
|
||||||
let mut lint_spans = Vec::new();
|
let mut lint_spans = Vec::new();
|
||||||
let mut where_lint_spans = Vec::new();
|
let mut where_lint_spans = Vec::new();
|
||||||
let mut dropped_predicate_count = 0;
|
let mut dropped_where_predicate_count = 0;
|
||||||
let num_predicates = hir_generics.predicates.len();
|
|
||||||
for (i, where_predicate) in hir_generics.predicates.iter().enumerate() {
|
for (i, where_predicate) in hir_generics.predicates.iter().enumerate() {
|
||||||
let (relevant_lifetimes, bounds, predicate_span, in_where_clause) =
|
let (relevant_lifetimes, bounds, predicate_span, in_where_clause) =
|
||||||
match where_predicate {
|
match where_predicate {
|
||||||
|
@ -2186,8 +2190,8 @@ impl<'tcx> LateLintPass<'tcx> for ExplicitOutlivesRequirements {
|
||||||
bound_count += bound_spans.len();
|
bound_count += bound_spans.len();
|
||||||
|
|
||||||
let drop_predicate = bound_spans.len() == bounds.len();
|
let drop_predicate = bound_spans.len() == bounds.len();
|
||||||
if drop_predicate {
|
if drop_predicate && in_where_clause {
|
||||||
dropped_predicate_count += 1;
|
dropped_where_predicate_count += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if drop_predicate {
|
if drop_predicate {
|
||||||
|
@ -2196,7 +2200,7 @@ impl<'tcx> LateLintPass<'tcx> for ExplicitOutlivesRequirements {
|
||||||
} else if predicate_span.from_expansion() {
|
} else if predicate_span.from_expansion() {
|
||||||
// Don't try to extend the span if it comes from a macro expansion.
|
// Don't try to extend the span if it comes from a macro expansion.
|
||||||
where_lint_spans.push(predicate_span);
|
where_lint_spans.push(predicate_span);
|
||||||
} else if i + 1 < num_predicates {
|
} else if i + 1 < num_where_predicates {
|
||||||
// If all the bounds on a predicate were inferable and there are
|
// If all the bounds on a predicate were inferable and there are
|
||||||
// further predicates, we want to eat the trailing comma.
|
// further predicates, we want to eat the trailing comma.
|
||||||
let next_predicate_span = hir_generics.predicates[i + 1].span();
|
let next_predicate_span = hir_generics.predicates[i + 1].span();
|
||||||
|
@ -2224,9 +2228,10 @@ impl<'tcx> LateLintPass<'tcx> for ExplicitOutlivesRequirements {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If all predicates are inferable, drop the entire clause
|
// If all predicates in where clause are inferable, drop the entire clause
|
||||||
// (including the `where`)
|
// (including the `where`)
|
||||||
if hir_generics.has_where_clause_predicates && dropped_predicate_count == num_predicates
|
if hir_generics.has_where_clause_predicates
|
||||||
|
&& dropped_where_predicate_count == num_where_predicates
|
||||||
{
|
{
|
||||||
let where_span = hir_generics.where_clause_span;
|
let where_span = hir_generics.where_clause_span;
|
||||||
// Extend the where clause back to the closing `>` of the
|
// Extend the where clause back to the closing `>` of the
|
||||||
|
|
|
@ -801,4 +801,10 @@ where
|
||||||
yoo: &'a U
|
yoo: &'a U
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://github.com/rust-lang/rust/issues/105150
|
||||||
|
struct InferredWhereBoundWithInlineBound<'a, T: ?Sized>
|
||||||
|
{
|
||||||
|
data: &'a T,
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
|
|
@ -801,4 +801,12 @@ where
|
||||||
yoo: &'a U
|
yoo: &'a U
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://github.com/rust-lang/rust/issues/105150
|
||||||
|
struct InferredWhereBoundWithInlineBound<'a, T: ?Sized>
|
||||||
|
//~^ ERROR outlives requirements can be inferred
|
||||||
|
where T: 'a,
|
||||||
|
{
|
||||||
|
data: &'a T,
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
|
|
@ -10,6 +10,15 @@ note: the lint level is defined here
|
||||||
LL | #![deny(explicit_outlives_requirements)]
|
LL | #![deny(explicit_outlives_requirements)]
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
error: outlives requirements can be inferred
|
||||||
|
--> $DIR/edition-lint-infer-outlives.rs:805:56
|
||||||
|
|
|
||||||
|
LL | struct InferredWhereBoundWithInlineBound<'a, T: ?Sized>
|
||||||
|
| ________________________________________________________^
|
||||||
|
LL | |
|
||||||
|
LL | | where T: 'a,
|
||||||
|
| |________________^ help: remove this bound
|
||||||
|
|
||||||
error: outlives requirements can be inferred
|
error: outlives requirements can be inferred
|
||||||
--> $DIR/edition-lint-infer-outlives.rs:26:31
|
--> $DIR/edition-lint-infer-outlives.rs:26:31
|
||||||
|
|
|
|
||||||
|
@ -922,5 +931,5 @@ error: outlives requirements can be inferred
|
||||||
LL | union BeeWhereOutlivesAyTeeWhereDebug<'a, 'b, T> where 'b: 'a, T: Debug {
|
LL | union BeeWhereOutlivesAyTeeWhereDebug<'a, 'b, T> where 'b: 'a, T: Debug {
|
||||||
| ^^^^^^^^ help: remove this bound
|
| ^^^^^^^^ help: remove this bound
|
||||||
|
|
||||||
error: aborting due to 153 previous errors
|
error: aborting due to 154 previous errors
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue