Rollup merge of #65914 - estebank:type-alias-bounds-sugg, r=davidtwco
Use structured suggestion for unnecessary bounds in type aliases
This commit is contained in:
commit
b7416348c8
@ -1125,8 +1125,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeAliasBounds {
|
||||
.map(|pred| pred.span()).collect();
|
||||
let mut err = cx.struct_span_lint(TYPE_ALIAS_BOUNDS, spans,
|
||||
"where clauses are not enforced in type aliases");
|
||||
err.help("the clause will not be checked when the type alias is used, \
|
||||
and should be removed");
|
||||
err.span_suggestion(
|
||||
type_alias_generics.where_clause.span_for_predicates_or_empty_place(),
|
||||
"the clause will not be checked when the type alias is used, and should be removed",
|
||||
String::new(),
|
||||
Applicability::MachineApplicable,
|
||||
);
|
||||
if !suggested_changing_assoc_types {
|
||||
TypeAliasBounds::suggest_changing_assoc_types(ty, &mut err);
|
||||
suggested_changing_assoc_types = true;
|
||||
@ -1136,14 +1140,19 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeAliasBounds {
|
||||
// The parameters must not have bounds
|
||||
for param in type_alias_generics.params.iter() {
|
||||
let spans: Vec<_> = param.bounds.iter().map(|b| b.span()).collect();
|
||||
let suggestion = spans.iter().map(|sp| {
|
||||
let start = param.span.between(*sp); // Include the `:` in `T: Bound`.
|
||||
(start.to(*sp), String::new())
|
||||
}).collect();
|
||||
if !spans.is_empty() {
|
||||
let mut err = cx.struct_span_lint(
|
||||
TYPE_ALIAS_BOUNDS,
|
||||
spans,
|
||||
"bounds on generic parameters are not enforced in type aliases",
|
||||
);
|
||||
err.help("the bound will not be checked when the type alias is used, \
|
||||
and should be removed");
|
||||
let msg = "the bound will not be checked when the type alias is used, \
|
||||
and should be removed";
|
||||
err.multipart_suggestion(&msg, suggestion, Applicability::MachineApplicable);
|
||||
if !suggested_changing_assoc_types {
|
||||
TypeAliasBounds::suggest_changing_assoc_types(ty, &mut err);
|
||||
suggested_changing_assoc_types = true;
|
||||
|
@ -5,7 +5,10 @@ LL | type _TaWhere1<T> where T: Iterator<Item: Copy> = T;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `#[warn(type_alias_bounds)]` on by default
|
||||
= help: the clause will not be checked when the type alias is used, and should be removed
|
||||
help: the clause will not be checked when the type alias is used, and should be removed
|
||||
|
|
||||
LL | type _TaWhere1<T> = T;
|
||||
| --
|
||||
|
||||
warning: where clauses are not enforced in type aliases
|
||||
--> $DIR/type-alias.rs:6:25
|
||||
@ -13,7 +16,10 @@ warning: where clauses are not enforced in type aliases
|
||||
LL | type _TaWhere2<T> where T: Iterator<Item: 'static> = T;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: the clause will not be checked when the type alias is used, and should be removed
|
||||
help: the clause will not be checked when the type alias is used, and should be removed
|
||||
|
|
||||
LL | type _TaWhere2<T> = T;
|
||||
| --
|
||||
|
||||
warning: where clauses are not enforced in type aliases
|
||||
--> $DIR/type-alias.rs:7:25
|
||||
@ -21,7 +27,10 @@ warning: where clauses are not enforced in type aliases
|
||||
LL | type _TaWhere3<T> where T: Iterator<Item: 'static> = T;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: the clause will not be checked when the type alias is used, and should be removed
|
||||
help: the clause will not be checked when the type alias is used, and should be removed
|
||||
|
|
||||
LL | type _TaWhere3<T> = T;
|
||||
| --
|
||||
|
||||
warning: where clauses are not enforced in type aliases
|
||||
--> $DIR/type-alias.rs:8:25
|
||||
@ -29,7 +38,10 @@ warning: where clauses are not enforced in type aliases
|
||||
LL | type _TaWhere4<T> where T: Iterator<Item: 'static + Copy + Send> = T;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: the clause will not be checked when the type alias is used, and should be removed
|
||||
help: the clause will not be checked when the type alias is used, and should be removed
|
||||
|
|
||||
LL | type _TaWhere4<T> = T;
|
||||
| --
|
||||
|
||||
warning: where clauses are not enforced in type aliases
|
||||
--> $DIR/type-alias.rs:9:25
|
||||
@ -37,7 +49,10 @@ warning: where clauses are not enforced in type aliases
|
||||
LL | type _TaWhere5<T> where T: Iterator<Item: for<'a> Into<&'a u8>> = T;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: the clause will not be checked when the type alias is used, and should be removed
|
||||
help: the clause will not be checked when the type alias is used, and should be removed
|
||||
|
|
||||
LL | type _TaWhere5<T> = T;
|
||||
| --
|
||||
|
||||
warning: where clauses are not enforced in type aliases
|
||||
--> $DIR/type-alias.rs:10:25
|
||||
@ -45,7 +60,10 @@ warning: where clauses are not enforced in type aliases
|
||||
LL | type _TaWhere6<T> where T: Iterator<Item: Iterator<Item: Copy>> = T;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: the clause will not be checked when the type alias is used, and should be removed
|
||||
help: the clause will not be checked when the type alias is used, and should be removed
|
||||
|
|
||||
LL | type _TaWhere6<T> = T;
|
||||
| --
|
||||
|
||||
warning: bounds on generic parameters are not enforced in type aliases
|
||||
--> $DIR/type-alias.rs:12:20
|
||||
@ -53,7 +71,10 @@ warning: bounds on generic parameters are not enforced in type aliases
|
||||
LL | type _TaInline1<T: Iterator<Item: Copy>> = T;
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: the bound will not be checked when the type alias is used, and should be removed
|
||||
help: the bound will not be checked when the type alias is used, and should be removed
|
||||
|
|
||||
LL | type _TaInline1<T> = T;
|
||||
| --
|
||||
|
||||
warning: bounds on generic parameters are not enforced in type aliases
|
||||
--> $DIR/type-alias.rs:13:20
|
||||
@ -61,7 +82,10 @@ warning: bounds on generic parameters are not enforced in type aliases
|
||||
LL | type _TaInline2<T: Iterator<Item: 'static>> = T;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: the bound will not be checked when the type alias is used, and should be removed
|
||||
help: the bound will not be checked when the type alias is used, and should be removed
|
||||
|
|
||||
LL | type _TaInline2<T> = T;
|
||||
| --
|
||||
|
||||
warning: bounds on generic parameters are not enforced in type aliases
|
||||
--> $DIR/type-alias.rs:14:20
|
||||
@ -69,7 +93,10 @@ warning: bounds on generic parameters are not enforced in type aliases
|
||||
LL | type _TaInline3<T: Iterator<Item: 'static>> = T;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: the bound will not be checked when the type alias is used, and should be removed
|
||||
help: the bound will not be checked when the type alias is used, and should be removed
|
||||
|
|
||||
LL | type _TaInline3<T> = T;
|
||||
| --
|
||||
|
||||
warning: bounds on generic parameters are not enforced in type aliases
|
||||
--> $DIR/type-alias.rs:15:20
|
||||
@ -77,7 +104,10 @@ warning: bounds on generic parameters are not enforced in type aliases
|
||||
LL | type _TaInline4<T: Iterator<Item: 'static + Copy + Send>> = T;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: the bound will not be checked when the type alias is used, and should be removed
|
||||
help: the bound will not be checked when the type alias is used, and should be removed
|
||||
|
|
||||
LL | type _TaInline4<T> = T;
|
||||
| --
|
||||
|
||||
warning: bounds on generic parameters are not enforced in type aliases
|
||||
--> $DIR/type-alias.rs:16:20
|
||||
@ -85,7 +115,10 @@ warning: bounds on generic parameters are not enforced in type aliases
|
||||
LL | type _TaInline5<T: Iterator<Item: for<'a> Into<&'a u8>>> = T;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: the bound will not be checked when the type alias is used, and should be removed
|
||||
help: the bound will not be checked when the type alias is used, and should be removed
|
||||
|
|
||||
LL | type _TaInline5<T> = T;
|
||||
| --
|
||||
|
||||
warning: bounds on generic parameters are not enforced in type aliases
|
||||
--> $DIR/type-alias.rs:17:20
|
||||
@ -93,5 +126,8 @@ warning: bounds on generic parameters are not enforced in type aliases
|
||||
LL | type _TaInline6<T: Iterator<Item: Iterator<Item: Copy>>> = T;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: the bound will not be checked when the type alias is used, and should be removed
|
||||
help: the bound will not be checked when the type alias is used, and should be removed
|
||||
|
|
||||
LL | type _TaInline6<T> = T;
|
||||
| --
|
||||
|
||||
|
@ -340,7 +340,10 @@ LL | pub type Alias<T: PrivTr> = T;
|
||||
| ^^^^^^
|
||||
|
|
||||
= note: `#[warn(type_alias_bounds)]` on by default
|
||||
= help: the bound will not be checked when the type alias is used, and should be removed
|
||||
help: the bound will not be checked when the type alias is used, and should be removed
|
||||
|
|
||||
LL | pub type Alias<T> = T;
|
||||
| --
|
||||
|
||||
warning: where clauses are not enforced in type aliases
|
||||
--> $DIR/private-in-public-warn.rs:75:29
|
||||
@ -348,7 +351,10 @@ warning: where clauses are not enforced in type aliases
|
||||
LL | pub type Alias<T> where T: PrivTr = T;
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= help: the clause will not be checked when the type alias is used, and should be removed
|
||||
help: the clause will not be checked when the type alias is used, and should be removed
|
||||
|
|
||||
LL | pub type Alias<T> = T;
|
||||
| --
|
||||
|
||||
error: aborting due to 36 previous errors
|
||||
|
||||
|
@ -31,7 +31,10 @@ LL | type Y where i32: Foo = ();
|
||||
| ^^^^^^^^
|
||||
|
|
||||
= note: `#[warn(type_alias_bounds)]` on by default
|
||||
= help: the clause will not be checked when the type alias is used, and should be removed
|
||||
help: the clause will not be checked when the type alias is used, and should be removed
|
||||
|
|
||||
LL | type Y = ();
|
||||
| --
|
||||
|
||||
warning: Trait bound i32: Foo does not depend on any type or lifetime parameters
|
||||
--> $DIR/trivial-bounds-inconsistent.rs:22:19
|
||||
|
@ -5,7 +5,10 @@ LL | type SVec<T: Send + Send> = Vec<T>;
|
||||
| ^^^^ ^^^^
|
||||
|
|
||||
= note: `#[warn(type_alias_bounds)]` on by default
|
||||
= help: the bound will not be checked when the type alias is used, and should be removed
|
||||
help: the bound will not be checked when the type alias is used, and should be removed
|
||||
|
|
||||
LL | type SVec<T> = Vec<T>;
|
||||
| -- --
|
||||
|
||||
warning: where clauses are not enforced in type aliases
|
||||
--> $DIR/type-alias-bounds.rs:10:21
|
||||
@ -13,7 +16,10 @@ warning: where clauses are not enforced in type aliases
|
||||
LL | type S2Vec<T> where T: Send = Vec<T>;
|
||||
| ^^^^^^^
|
||||
|
|
||||
= help: the clause will not be checked when the type alias is used, and should be removed
|
||||
help: the clause will not be checked when the type alias is used, and should be removed
|
||||
|
|
||||
LL | type S2Vec<T> = Vec<T>;
|
||||
| --
|
||||
|
||||
warning: bounds on generic parameters are not enforced in type aliases
|
||||
--> $DIR/type-alias-bounds.rs:12:19
|
||||
@ -21,7 +27,10 @@ warning: bounds on generic parameters are not enforced in type aliases
|
||||
LL | type VVec<'b, 'a: 'b + 'b> = (&'b u32, Vec<&'a i32>);
|
||||
| ^^ ^^
|
||||
|
|
||||
= help: the bound will not be checked when the type alias is used, and should be removed
|
||||
help: the bound will not be checked when the type alias is used, and should be removed
|
||||
|
|
||||
LL | type VVec<'b, 'a> = (&'b u32, Vec<&'a i32>);
|
||||
| -- --
|
||||
|
||||
warning: bounds on generic parameters are not enforced in type aliases
|
||||
--> $DIR/type-alias-bounds.rs:14:18
|
||||
@ -29,7 +38,10 @@ warning: bounds on generic parameters are not enforced in type aliases
|
||||
LL | type WVec<'b, T: 'b + 'b> = (&'b u32, Vec<T>);
|
||||
| ^^ ^^
|
||||
|
|
||||
= help: the bound will not be checked when the type alias is used, and should be removed
|
||||
help: the bound will not be checked when the type alias is used, and should be removed
|
||||
|
|
||||
LL | type WVec<'b, T> = (&'b u32, Vec<T>);
|
||||
| -- --
|
||||
|
||||
warning: where clauses are not enforced in type aliases
|
||||
--> $DIR/type-alias-bounds.rs:16:25
|
||||
@ -37,7 +49,10 @@ warning: where clauses are not enforced in type aliases
|
||||
LL | type W2Vec<'b, T> where T: 'b, T: 'b = (&'b u32, Vec<T>);
|
||||
| ^^^^^ ^^^^^
|
||||
|
|
||||
= help: the clause will not be checked when the type alias is used, and should be removed
|
||||
help: the clause will not be checked when the type alias is used, and should be removed
|
||||
|
|
||||
LL | type W2Vec<'b, T> = (&'b u32, Vec<T>);
|
||||
| --
|
||||
|
||||
warning: bounds on generic parameters are not enforced in type aliases
|
||||
--> $DIR/type-alias-bounds.rs:47:12
|
||||
@ -45,12 +60,15 @@ warning: bounds on generic parameters are not enforced in type aliases
|
||||
LL | type T1<U: Bound> = U::Assoc;
|
||||
| ^^^^^
|
||||
|
|
||||
= help: the bound will not be checked when the type alias is used, and should be removed
|
||||
help: use fully disambiguated paths (i.e., `<T as Trait>::Assoc`) to refer to associated types in type aliases
|
||||
--> $DIR/type-alias-bounds.rs:47:21
|
||||
|
|
||||
LL | type T1<U: Bound> = U::Assoc;
|
||||
| ^^^^^^^^
|
||||
help: the bound will not be checked when the type alias is used, and should be removed
|
||||
|
|
||||
LL | type T1<U> = U::Assoc;
|
||||
| --
|
||||
|
||||
warning: where clauses are not enforced in type aliases
|
||||
--> $DIR/type-alias-bounds.rs:48:18
|
||||
@ -58,12 +76,15 @@ warning: where clauses are not enforced in type aliases
|
||||
LL | type T2<U> where U: Bound = U::Assoc;
|
||||
| ^^^^^^^^
|
||||
|
|
||||
= help: the clause will not be checked when the type alias is used, and should be removed
|
||||
help: use fully disambiguated paths (i.e., `<T as Trait>::Assoc`) to refer to associated types in type aliases
|
||||
--> $DIR/type-alias-bounds.rs:48:29
|
||||
|
|
||||
LL | type T2<U> where U: Bound = U::Assoc;
|
||||
| ^^^^^^^^
|
||||
help: the clause will not be checked when the type alias is used, and should be removed
|
||||
|
|
||||
LL | type T2<U> = U::Assoc;
|
||||
| --
|
||||
|
||||
warning: bounds on generic parameters are not enforced in type aliases
|
||||
--> $DIR/type-alias-bounds.rs:56:12
|
||||
@ -71,7 +92,10 @@ warning: bounds on generic parameters are not enforced in type aliases
|
||||
LL | type T5<U: Bound> = <U as Bound>::Assoc;
|
||||
| ^^^^^
|
||||
|
|
||||
= help: the bound will not be checked when the type alias is used, and should be removed
|
||||
help: the bound will not be checked when the type alias is used, and should be removed
|
||||
|
|
||||
LL | type T5<U> = <U as Bound>::Assoc;
|
||||
| --
|
||||
|
||||
warning: bounds on generic parameters are not enforced in type aliases
|
||||
--> $DIR/type-alias-bounds.rs:57:12
|
||||
@ -79,5 +103,8 @@ warning: bounds on generic parameters are not enforced in type aliases
|
||||
LL | type T6<U: Bound> = ::std::vec::Vec<U>;
|
||||
| ^^^^^
|
||||
|
|
||||
= help: the bound will not be checked when the type alias is used, and should be removed
|
||||
help: the bound will not be checked when the type alias is used, and should be removed
|
||||
|
|
||||
LL | type T6<U> = ::std::vec::Vec<U>;
|
||||
| --
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user