fix overlapping spans for explicit_outlives_requirements
in macros
also delete trailing comma if necessary
This commit is contained in:
parent
31443c63b5
commit
e415e2f1a2
6 changed files with 135 additions and 12 deletions
|
@ -2173,13 +2173,31 @@ impl<'tcx> LateLintPass<'tcx> for ExplicitOutlivesRequirements {
|
||||||
dropped_predicate_count += 1;
|
dropped_predicate_count += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if drop_predicate && !in_where_clause {
|
if drop_predicate {
|
||||||
lint_spans.push(predicate_span);
|
if !in_where_clause {
|
||||||
} else if drop_predicate && i + 1 < num_predicates {
|
lint_spans.push(predicate_span);
|
||||||
// If all the bounds on a predicate were inferable and there are
|
} else if predicate_span.from_expansion() {
|
||||||
// further predicates, we want to eat the trailing comma.
|
// Don't try to extend the span if it comes from a macro expansion.
|
||||||
let next_predicate_span = hir_generics.predicates[i + 1].span();
|
where_lint_spans.push(predicate_span);
|
||||||
where_lint_spans.push(predicate_span.to(next_predicate_span.shrink_to_lo()));
|
} else if i + 1 < num_predicates {
|
||||||
|
// If all the bounds on a predicate were inferable and there are
|
||||||
|
// further predicates, we want to eat the trailing comma.
|
||||||
|
let next_predicate_span = hir_generics.predicates[i + 1].span();
|
||||||
|
if next_predicate_span.from_expansion() {
|
||||||
|
where_lint_spans.push(predicate_span);
|
||||||
|
} else {
|
||||||
|
where_lint_spans
|
||||||
|
.push(predicate_span.to(next_predicate_span.shrink_to_lo()));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Eat the optional trailing comma after the last predicate.
|
||||||
|
let where_span = hir_generics.where_clause_span;
|
||||||
|
if where_span.from_expansion() {
|
||||||
|
where_lint_spans.push(predicate_span);
|
||||||
|
} else {
|
||||||
|
where_lint_spans.push(predicate_span.to(where_span.shrink_to_hi()));
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
where_lint_spans.extend(self.consolidate_outlives_bound_spans(
|
where_lint_spans.extend(self.consolidate_outlives_bound_spans(
|
||||||
predicate_span.shrink_to_lo(),
|
predicate_span.shrink_to_lo(),
|
||||||
|
@ -2223,6 +2241,11 @@ impl<'tcx> LateLintPass<'tcx> for ExplicitOutlivesRequirements {
|
||||||
Applicability::MaybeIncorrect
|
Applicability::MaybeIncorrect
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Due to macros, there might be several predicates with the same span
|
||||||
|
// and we only want to suggest removing them once.
|
||||||
|
lint_spans.sort_unstable();
|
||||||
|
lint_spans.dedup();
|
||||||
|
|
||||||
cx.emit_spanned_lint(
|
cx.emit_spanned_lint(
|
||||||
EXPLICIT_OUTLIVES_REQUIREMENTS,
|
EXPLICIT_OUTLIVES_REQUIREMENTS,
|
||||||
lint_spans.clone(),
|
lint_spans.clone(),
|
||||||
|
|
|
@ -365,4 +365,24 @@ mod unions {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://github.com/rust-lang/rust/issues/106870
|
||||||
|
mod multiple_predicates_with_same_span {
|
||||||
|
macro_rules! m {
|
||||||
|
($($name:ident)+) => {
|
||||||
|
struct Inline<'a, $($name: 'a,)+>(&'a ($($name,)+));
|
||||||
|
//~^ ERROR: outlives requirements can be inferred
|
||||||
|
struct FullWhere<'a, $($name,)+>(&'a ($($name,)+)) where $($name: 'a,)+;
|
||||||
|
//~^ ERROR: outlives requirements can be inferred
|
||||||
|
struct PartialWhere<'a, $($name,)+>(&'a ($($name,)+)) where (): Sized, $($name: 'a,)+;
|
||||||
|
//~^ ERROR: outlives requirements can be inferred
|
||||||
|
struct Interleaved<'a, $($name,)+>(&'a ($($name,)+))
|
||||||
|
where
|
||||||
|
(): Sized,
|
||||||
|
$($name: 'a, $name: 'a, )+ //~ ERROR: outlives requirements can be inferred
|
||||||
|
$($name: 'a, $name: 'a, )+;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m!(T0 T1 T2 T3 T4 T5 T6 T7 T8 T9 T10 T11 T12 T13 T14 T15);
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
|
|
@ -819,5 +819,61 @@ LL - union BeeWhereAyTeeYooWhereOutlivesAyIsDebugBee<'a, 'b, T, U> where U:
|
||||||
LL + union BeeWhereAyTeeYooWhereOutlivesAyIsDebugBee<'a, 'b, T, U> where U: Debug, {
|
LL + union BeeWhereAyTeeYooWhereOutlivesAyIsDebugBee<'a, 'b, T, U> where U: Debug, {
|
||||||
|
|
|
|
||||||
|
|
||||||
error: aborting due to 68 previous errors
|
error: outlives requirements can be inferred
|
||||||
|
--> $DIR/edition-lint-infer-outlives-multispan.rs:372:38
|
||||||
|
|
|
||||||
|
LL | struct Inline<'a, $($name: 'a,)+>(&'a ($($name,)+));
|
||||||
|
| ^^^^ help: remove these bounds
|
||||||
|
...
|
||||||
|
LL | m!(T0 T1 T2 T3 T4 T5 T6 T7 T8 T9 T10 T11 T12 T13 T14 T15);
|
||||||
|
| --------------------------------------------------------- in this macro invocation
|
||||||
|
|
|
||||||
|
= note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||||
|
|
||||||
|
error: outlives requirements can be inferred
|
||||||
|
--> $DIR/edition-lint-infer-outlives-multispan.rs:374:64
|
||||||
|
|
|
||||||
|
LL | struct FullWhere<'a, $($name,)+>(&'a ($($name,)+)) where $($name: 'a,)+;
|
||||||
|
| ^^^^^^^^^^^^^^^^^^ help: remove these bounds
|
||||||
|
...
|
||||||
|
LL | m!(T0 T1 T2 T3 T4 T5 T6 T7 T8 T9 T10 T11 T12 T13 T14 T15);
|
||||||
|
| --------------------------------------------------------- in this macro invocation
|
||||||
|
|
|
||||||
|
= note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||||
|
|
||||||
|
error: outlives requirements can be inferred
|
||||||
|
--> $DIR/edition-lint-infer-outlives-multispan.rs:376:86
|
||||||
|
|
|
||||||
|
LL | struct PartialWhere<'a, $($name,)+>(&'a ($($name,)+)) where (): Sized, $($name: 'a,)+;
|
||||||
|
| ^^^^^^^^^ help: remove these bounds
|
||||||
|
...
|
||||||
|
LL | m!(T0 T1 T2 T3 T4 T5 T6 T7 T8 T9 T10 T11 T12 T13 T14 T15);
|
||||||
|
| --------------------------------------------------------- in this macro invocation
|
||||||
|
|
|
||||||
|
= note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||||
|
|
||||||
|
error: outlives requirements can be inferred
|
||||||
|
--> $DIR/edition-lint-infer-outlives-multispan.rs:381:19
|
||||||
|
|
|
||||||
|
LL | $($name: 'a, $name: 'a, )+
|
||||||
|
| ^^^^^^^^^ ^^^^^^^^^
|
||||||
|
LL | $($name: 'a, $name: 'a, )+;
|
||||||
|
| ^^^^^^^^^ ^^^^^^^^^
|
||||||
|
...
|
||||||
|
LL | m!(T0 T1 T2 T3 T4 T5 T6 T7 T8 T9 T10 T11 T12 T13 T14 T15);
|
||||||
|
| ---------------------------------------------------------
|
||||||
|
| |
|
||||||
|
| in this macro invocation
|
||||||
|
| in this macro invocation
|
||||||
|
| in this macro invocation
|
||||||
|
| in this macro invocation
|
||||||
|
|
|
||||||
|
= note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||||
|
help: remove these bounds
|
||||||
|
|
|
||||||
|
LL ~ $(, , )+
|
||||||
|
LL ~ $(, , )+;
|
||||||
|
|
|
||||||
|
|
||||||
|
error: aborting due to 72 previous errors
|
||||||
|
|
||||||
|
|
|
@ -791,5 +791,14 @@ struct StaticRef<T: 'static> {
|
||||||
field: &'static T
|
field: &'static T
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct TrailingCommaInWhereClause<'a, T, U>
|
||||||
|
where
|
||||||
|
T: 'a,
|
||||||
|
|
||||||
|
//~^ ERROR outlives requirements can be inferred
|
||||||
|
{
|
||||||
|
tee: T,
|
||||||
|
yoo: &'a U
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
|
|
@ -791,5 +791,14 @@ struct StaticRef<T: 'static> {
|
||||||
field: &'static T
|
field: &'static T
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct TrailingCommaInWhereClause<'a, T, U>
|
||||||
|
where
|
||||||
|
T: 'a,
|
||||||
|
U: 'a,
|
||||||
|
//~^ ERROR outlives requirements can be inferred
|
||||||
|
{
|
||||||
|
tee: T,
|
||||||
|
yoo: &'a U
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
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:797:5
|
||||||
|
|
|
|
||||||
LL | struct TeeOutlivesAy<'a, T: 'a> {
|
LL | U: 'a,
|
||||||
| ^^^^ help: remove this bound
|
| ^^^^^^ help: remove this bound
|
||||||
|
|
|
|
||||||
note: the lint level is defined here
|
note: the lint level is defined here
|
||||||
--> $DIR/edition-lint-infer-outlives.rs:4:9
|
--> $DIR/edition-lint-infer-outlives.rs:4:9
|
||||||
|
@ -10,6 +10,12 @@ 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:26:31
|
||||||
|
|
|
||||||
|
LL | struct TeeOutlivesAy<'a, T: 'a> {
|
||||||
|
| ^^^^ help: remove this bound
|
||||||
|
|
||||||
error: outlives requirements can be inferred
|
error: outlives requirements can be inferred
|
||||||
--> $DIR/edition-lint-infer-outlives.rs:31:40
|
--> $DIR/edition-lint-infer-outlives.rs:31:40
|
||||||
|
|
|
|
||||||
|
@ -916,5 +922,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 152 previous errors
|
error: aborting due to 153 previous errors
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue