about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorTyler Mandry <tmandry@gmail.com>2019-11-01 11:20:15 -0700
committerGitHub <noreply@github.com>2019-11-01 11:20:15 -0700
commitb7416348c8155e9cc36dfdce349328ad8bdc402d (patch)
tree6bbf7e7bfd8282175d81a72db939158d679a54b2 /src
parentd75338e6301ea842bc3dd92e3793626b20346aaf (diff)
parent58b67c88119970b7c96f678e3afaab00f086f612 (diff)
downloadrust-b7416348c8155e9cc36dfdce349328ad8bdc402d.tar.gz
rust-b7416348c8155e9cc36dfdce349328ad8bdc402d.zip
Rollup merge of #65914 - estebank:type-alias-bounds-sugg, r=davidtwco
Use structured suggestion for unnecessary bounds in type aliases
Diffstat (limited to 'src')
-rw-r--r--src/librustc_lint/builtin.rs17
-rw-r--r--src/test/ui/associated-type-bounds/type-alias.stderr60
-rw-r--r--src/test/ui/privacy/private-in-public-warn.stderr10
-rw-r--r--src/test/ui/trivial-bounds/trivial-bounds-inconsistent.stderr5
-rw-r--r--src/test/ui/type/type-alias-bounds.stderr45
5 files changed, 109 insertions, 28 deletions
diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs
index 7c19449f96b..e3c3966c2f5 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 a3fa97f54e3..7f58f7f73e3 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<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;
+   |                 --
 
diff --git a/src/test/ui/privacy/private-in-public-warn.stderr b/src/test/ui/privacy/private-in-public-warn.stderr
index 9741f3b6d0d..40aa47a7246 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: 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
 
diff --git a/src/test/ui/trivial-bounds/trivial-bounds-inconsistent.stderr b/src/test/ui/trivial-bounds/trivial-bounds-inconsistent.stderr
index 0eb0769c570..cb8bad6d9e7 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 dbb7b92563a..c381d30c64f 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<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>;
+   |         --