diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index 7c19449f96b86..e3c3966c2f5e0 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -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; diff --git a/src/test/ui/associated-type-bounds/type-alias.stderr b/src/test/ui/associated-type-bounds/type-alias.stderr index a3fa97f54e385..7f58f7f73e38c 100644 --- a/src/test/ui/associated-type-bounds/type-alias.stderr +++ b/src/test/ui/associated-type-bounds/type-alias.stderr @@ -5,7 +5,10 @@ LL | type _TaWhere1 where T: Iterator = 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; + | -- 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 where T: Iterator = 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; + | -- 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 where T: Iterator = 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; + | -- 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 where T: Iterator = 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; + | -- 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 where T: Iterator 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; + | -- 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 where T: Iterator> = 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; + | -- 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; | ^^^^^^^^^^^^^^^^^^^^ | - = 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; + | -- 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; | ^^^^^^^^^^^^^^^^^^^^^^^ | - = 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; + | -- 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; | ^^^^^^^^^^^^^^^^^^^^^^^ | - = 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; + | -- 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; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = 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; + | -- 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 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; + | -- 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; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = 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; + | -- diff --git a/src/test/ui/privacy/private-in-public-warn.stderr b/src/test/ui/privacy/private-in-public-warn.stderr index 9741f3b6d0d41..40aa47a7246c4 100644 --- a/src/test/ui/privacy/private-in-public-warn.stderr +++ b/src/test/ui/privacy/private-in-public-warn.stderr @@ -340,7 +340,10 @@ LL | pub type Alias = 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; + | -- 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 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; + | -- error: aborting due to 36 previous errors diff --git a/src/test/ui/trivial-bounds/trivial-bounds-inconsistent.stderr b/src/test/ui/trivial-bounds/trivial-bounds-inconsistent.stderr index 0eb0769c57071..cb8bad6d9e74d 100644 --- a/src/test/ui/trivial-bounds/trivial-bounds-inconsistent.stderr +++ b/src/test/ui/trivial-bounds/trivial-bounds-inconsistent.stderr @@ -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 diff --git a/src/test/ui/type/type-alias-bounds.stderr b/src/test/ui/type/type-alias-bounds.stderr index dbb7b92563ab8..c381d30c64f14 100644 --- a/src/test/ui/type/type-alias-bounds.stderr +++ b/src/test/ui/type/type-alias-bounds.stderr @@ -5,7 +5,10 @@ LL | type SVec = Vec; | ^^^^ ^^^^ | = 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 = Vec; + | -- -- 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 where T: Send = Vec; | ^^^^^^^ | - = 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 = Vec; + | -- 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); | ^^ ^^ | - = 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); + | -- -- 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); | ^^^^^ ^^^^^ | - = 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); + | -- 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::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., `::Assoc`) to refer to associated types in type aliases --> $DIR/type-alias-bounds.rs:47:21 | LL | type T1 = U::Assoc; | ^^^^^^^^ +help: the bound will not be checked when the type alias is used, and should be removed + | +LL | type T1 = 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 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., `::Assoc`) to refer to associated types in type aliases --> $DIR/type-alias-bounds.rs:48:29 | LL | type T2 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::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 = ::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 = ::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 = ::std::vec::Vec; | ^^^^^ | - = 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 = ::std::vec::Vec; + | --