about summary refs log tree commit diff
path: root/src/test/ui
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2019-12-23 14:16:34 -0800
committerEsteban Küber <esteban@kuber.com.ar>2019-12-29 19:11:27 -0800
commit8cb193a5cb694ba62c83fb63a804f22720a118cf (patch)
tree69b9d30a3abea1300ff7a7ddde7d5e14d492e891 /src/test/ui
parent2ba0d2acbd6cb01fb07619628882120d5b66bd59 (diff)
downloadrust-8cb193a5cb694ba62c83fb63a804f22720a118cf.tar.gz
rust-8cb193a5cb694ba62c83fb63a804f22720a118cf.zip
Suggest type param when encountering `_` in fn defs
When encountering `_` type placeholder in fn arguments and return type,
suggest using generic type parameters.
Expand what counts as an inferable return type to slice, array and
tuples of `_`.
Diffstat (limited to 'src/test/ui')
-rw-r--r--src/test/ui/error-codes/E0121.stderr2
-rw-r--r--src/test/ui/self/self-infer.stderr14
-rw-r--r--src/test/ui/typeck/typeck_type_placeholder_item.rs26
-rw-r--r--src/test/ui/typeck/typeck_type_placeholder_item.stderr269
-rw-r--r--src/test/ui/typeck/typeck_type_placeholder_item_help.stderr2
5 files changed, 244 insertions, 69 deletions
diff --git a/src/test/ui/error-codes/E0121.stderr b/src/test/ui/error-codes/E0121.stderr
index beb8941320b..5da9a4c080f 100644
--- a/src/test/ui/error-codes/E0121.stderr
+++ b/src/test/ui/error-codes/E0121.stderr
@@ -5,7 +5,7 @@ LL | fn foo() -> _ { 5 }
    |             ^
    |             |
    |             not allowed in type signatures
-   |             help: replace `_` with the correct return type: `i32`
+   |             help: replace this with the correct return type: `i32`
 
 error[E0121]: the type placeholder `_` is not allowed within types on item signatures
   --> $DIR/E0121.rs:3:13
diff --git a/src/test/ui/self/self-infer.stderr b/src/test/ui/self/self-infer.stderr
index f91cfe5eb62..b064928d8a3 100644
--- a/src/test/ui/self/self-infer.stderr
+++ b/src/test/ui/self/self-infer.stderr
@@ -2,13 +2,23 @@ error[E0121]: the type placeholder `_` is not allowed within types on item signa
   --> $DIR/self-infer.rs:4:16
    |
 LL |     fn f(self: _) {}
-   |                ^ not allowed in type signatures
+   |                ^
+   |
+help: use type parameters instead
+   |
+LL |     fn f<T>(self: T) {}
+   |         ^^^       ^
 
 error[E0121]: the type placeholder `_` is not allowed within types on item signatures
   --> $DIR/self-infer.rs:5:17
    |
 LL |     fn g(self: &_) {}
-   |                 ^ not allowed in type signatures
+   |                 ^
+   |
+help: use type parameters instead
+   |
+LL |     fn g<T>(self: &T) {}
+   |         ^^^        ^
 
 error: aborting due to 2 previous errors
 
diff --git a/src/test/ui/typeck/typeck_type_placeholder_item.rs b/src/test/ui/typeck/typeck_type_placeholder_item.rs
index 46a5b8580dc..03ee61486c6 100644
--- a/src/test/ui/typeck/typeck_type_placeholder_item.rs
+++ b/src/test/ui/typeck/typeck_type_placeholder_item.rs
@@ -6,7 +6,6 @@ fn test() -> _ { 5 }
 
 fn test2() -> (_, _) { (5, 5) }
 //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
-//~^^ ERROR the type placeholder `_` is not allowed within types on item signatures
 
 static TEST3: _ = "test";
 //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
@@ -59,7 +58,6 @@ pub fn main() {
 
     fn fn_test2() -> (_, _) { (5, 5) }
     //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
-    //~^^ ERROR the type placeholder `_` is not allowed within types on item signatures
 
     static FN_TEST3: _ = "test";
     //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
@@ -106,4 +104,28 @@ pub fn main() {
         //~^^ ERROR the type placeholder `_` is not allowed within types on item signatures
     }
 
+    fn fn_test11(_: _) -> (_, _) { panic!() }
+    //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
+    //~| ERROR type annotations needed
+
+    fn fn_test12(x: i32) -> (_, _) { (x, x) }
+    //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
+
+    fn fn_test13(x: _) -> (i32, _) { (x, x) }
+    //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
 }
+
+trait T {
+    fn method_test1(&self, x: _);
+    //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
+    fn method_test2(&self, x: _) -> _;
+    //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
+    fn method_test3(&self) -> _;
+    //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
+    fn assoc_fn_test1(x: _);
+    //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
+    fn assoc_fn_test2(x: _) -> _;
+    //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
+    fn assoc_fn_test3() -> _;
+    //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
+}
\ No newline at end of file
diff --git a/src/test/ui/typeck/typeck_type_placeholder_item.stderr b/src/test/ui/typeck/typeck_type_placeholder_item.stderr
index 2b4d9966c3d..0edfa07a656 100644
--- a/src/test/ui/typeck/typeck_type_placeholder_item.stderr
+++ b/src/test/ui/typeck/typeck_type_placeholder_item.stderr
@@ -5,22 +5,19 @@ LL | fn test() -> _ { 5 }
    |              ^
    |              |
    |              not allowed in type signatures
-   |              help: replace `_` with the correct return type: `i32`
+   |              help: replace this with the correct return type: `i32`
 
 error[E0121]: the type placeholder `_` is not allowed within types on item signatures
-  --> $DIR/typeck_type_placeholder_item.rs:7:16
+  --> $DIR/typeck_type_placeholder_item.rs:7:15
    |
 LL | fn test2() -> (_, _) { (5, 5) }
-   |                ^ not allowed in type signatures
-
-error[E0121]: the type placeholder `_` is not allowed within types on item signatures
-  --> $DIR/typeck_type_placeholder_item.rs:7:19
-   |
-LL | fn test2() -> (_, _) { (5, 5) }
-   |                   ^ not allowed in type signatures
+   |               ^^^^^^
+   |               |
+   |               not allowed in type signatures
+   |               help: replace this with the correct return type: `(i32, i32)`
 
 error[E0121]: the type placeholder `_` is not allowed within types on item signatures
-  --> $DIR/typeck_type_placeholder_item.rs:11:15
+  --> $DIR/typeck_type_placeholder_item.rs:10:15
    |
 LL | static TEST3: _ = "test";
    |               ^
@@ -29,7 +26,7 @@ LL | static TEST3: _ = "test";
    |               help: replace `_` with the correct type: `&'static str`
 
 error[E0121]: the type placeholder `_` is not allowed within types on item signatures
-  --> $DIR/typeck_type_placeholder_item.rs:14:15
+  --> $DIR/typeck_type_placeholder_item.rs:13:15
    |
 LL | static TEST4: _ = 145;
    |               ^
@@ -38,94 +35,106 @@ LL | static TEST4: _ = 145;
    |               help: replace `_` with the correct type: `i32`
 
 error[E0121]: the type placeholder `_` is not allowed within types on item signatures
-  --> $DIR/typeck_type_placeholder_item.rs:17:16
+  --> $DIR/typeck_type_placeholder_item.rs:16:16
    |
 LL | static TEST5: (_, _) = (1, 2);
    |                ^ not allowed in type signatures
 
 error[E0121]: the type placeholder `_` is not allowed within types on item signatures
-  --> $DIR/typeck_type_placeholder_item.rs:17:19
+  --> $DIR/typeck_type_placeholder_item.rs:16:19
    |
 LL | static TEST5: (_, _) = (1, 2);
    |                   ^ not allowed in type signatures
 
 error[E0121]: the type placeholder `_` is not allowed within types on item signatures
-  --> $DIR/typeck_type_placeholder_item.rs:21:13
+  --> $DIR/typeck_type_placeholder_item.rs:20:13
    |
 LL | fn test6(_: _) { }
-   |             ^ not allowed in type signatures
+   |             ^
+   |
+help: use type parameters instead
+   |
+LL | fn test6<T>(_: T) { }
+   |         ^^^    ^
 
 error[E0121]: the type placeholder `_` is not allowed within types on item signatures
-  --> $DIR/typeck_type_placeholder_item.rs:24:13
+  --> $DIR/typeck_type_placeholder_item.rs:23:13
    |
 LL | fn test7(x: _) { let _x: usize = x; }
-   |             ^ not allowed in type signatures
+   |             ^
+   |
+help: use type parameters instead
+   |
+LL | fn test7<T>(x: T) { let _x: usize = x; }
+   |         ^^^    ^
 
 error[E0121]: the type placeholder `_` is not allowed within types on item signatures
-  --> $DIR/typeck_type_placeholder_item.rs:27:22
+  --> $DIR/typeck_type_placeholder_item.rs:26:22
    |
 LL | fn test8(_f: fn() -> _) { }
-   |                      ^ not allowed in type signatures
+   |                      ^
+   |
+help: use type parameters instead
+   |
+LL | fn test8<T>(_f: fn() -> T) { }
+   |         ^^^             ^
 
 error[E0121]: the type placeholder `_` is not allowed within types on item signatures
-  --> $DIR/typeck_type_placeholder_item.rs:49:8
+  --> $DIR/typeck_type_placeholder_item.rs:48:8
    |
 LL |     a: _,
    |        ^ not allowed in type signatures
 
 error[E0121]: the type placeholder `_` is not allowed within types on item signatures
-  --> $DIR/typeck_type_placeholder_item.rs:51:9
+  --> $DIR/typeck_type_placeholder_item.rs:50:9
    |
 LL |     b: (_, _),
    |         ^ not allowed in type signatures
 
 error[E0121]: the type placeholder `_` is not allowed within types on item signatures
-  --> $DIR/typeck_type_placeholder_item.rs:51:12
+  --> $DIR/typeck_type_placeholder_item.rs:50:12
    |
 LL |     b: (_, _),
    |            ^ not allowed in type signatures
 
 error[E0121]: the type placeholder `_` is not allowed within types on item signatures
-  --> $DIR/typeck_type_placeholder_item.rs:102:12
+  --> $DIR/typeck_type_placeholder_item.rs:100:12
    |
 LL |         a: _,
    |            ^ not allowed in type signatures
 
 error[E0121]: the type placeholder `_` is not allowed within types on item signatures
-  --> $DIR/typeck_type_placeholder_item.rs:104:13
+  --> $DIR/typeck_type_placeholder_item.rs:102:13
    |
 LL |         b: (_, _),
    |             ^ not allowed in type signatures
 
 error[E0121]: the type placeholder `_` is not allowed within types on item signatures
-  --> $DIR/typeck_type_placeholder_item.rs:104:16
+  --> $DIR/typeck_type_placeholder_item.rs:102:16
    |
 LL |         b: (_, _),
    |                ^ not allowed in type signatures
 
 error[E0121]: the type placeholder `_` is not allowed within types on item signatures
-  --> $DIR/typeck_type_placeholder_item.rs:57:21
+  --> $DIR/typeck_type_placeholder_item.rs:56:21
    |
 LL |     fn fn_test() -> _ { 5 }
    |                     ^
    |                     |
    |                     not allowed in type signatures
-   |                     help: replace `_` with the correct return type: `i32`
-
-error[E0121]: the type placeholder `_` is not allowed within types on item signatures
-  --> $DIR/typeck_type_placeholder_item.rs:60:23
-   |
-LL |     fn fn_test2() -> (_, _) { (5, 5) }
-   |                       ^ not allowed in type signatures
+   |                     help: replace this with the correct return type: `i32`
 
 error[E0121]: the type placeholder `_` is not allowed within types on item signatures
-  --> $DIR/typeck_type_placeholder_item.rs:60:26
+  --> $DIR/typeck_type_placeholder_item.rs:59:22
    |
 LL |     fn fn_test2() -> (_, _) { (5, 5) }
-   |                          ^ not allowed in type signatures
+   |                      ^^^^^^
+   |                      |
+   |                      not allowed in type signatures
+   |                      help: replace this with the correct return type: `(i32, i32)`
 
 error[E0121]: the type placeholder `_` is not allowed within types on item signatures
-  --> $DIR/typeck_type_placeholder_item.rs:64:22
+  --> $DIR/typeck_type_placeholder_item.rs:62:22
    |
 LL |     static FN_TEST3: _ = "test";
    |                      ^
@@ -134,7 +143,7 @@ LL |     static FN_TEST3: _ = "test";
    |                      help: replace `_` with the correct type: `&'static str`
 
 error[E0121]: the type placeholder `_` is not allowed within types on item signatures
-  --> $DIR/typeck_type_placeholder_item.rs:67:22
+  --> $DIR/typeck_type_placeholder_item.rs:65:22
    |
 LL |     static FN_TEST4: _ = 145;
    |                      ^
@@ -143,95 +152,229 @@ LL |     static FN_TEST4: _ = 145;
    |                      help: replace `_` with the correct type: `i32`
 
 error[E0121]: the type placeholder `_` is not allowed within types on item signatures
-  --> $DIR/typeck_type_placeholder_item.rs:70:23
+  --> $DIR/typeck_type_placeholder_item.rs:68:23
    |
 LL |     static FN_TEST5: (_, _) = (1, 2);
    |                       ^ not allowed in type signatures
 
 error[E0121]: the type placeholder `_` is not allowed within types on item signatures
-  --> $DIR/typeck_type_placeholder_item.rs:70:26
+  --> $DIR/typeck_type_placeholder_item.rs:68:26
    |
 LL |     static FN_TEST5: (_, _) = (1, 2);
    |                          ^ not allowed in type signatures
 
 error[E0121]: the type placeholder `_` is not allowed within types on item signatures
-  --> $DIR/typeck_type_placeholder_item.rs:74:20
+  --> $DIR/typeck_type_placeholder_item.rs:72:20
    |
 LL |     fn fn_test6(_: _) { }
-   |                    ^ not allowed in type signatures
+   |                    ^
+   |
+help: use type parameters instead
+   |
+LL |     fn fn_test6<T>(_: T) { }
+   |                ^^^    ^
 
 error[E0121]: the type placeholder `_` is not allowed within types on item signatures
-  --> $DIR/typeck_type_placeholder_item.rs:77:20
+  --> $DIR/typeck_type_placeholder_item.rs:75:20
    |
 LL |     fn fn_test7(x: _) { let _x: usize = x; }
-   |                    ^ not allowed in type signatures
+   |                    ^
+   |
+help: use type parameters instead
+   |
+LL |     fn fn_test7<T>(x: T) { let _x: usize = x; }
+   |                ^^^    ^
 
 error[E0121]: the type placeholder `_` is not allowed within types on item signatures
-  --> $DIR/typeck_type_placeholder_item.rs:80:29
+  --> $DIR/typeck_type_placeholder_item.rs:78:29
    |
 LL |     fn fn_test8(_f: fn() -> _) { }
-   |                             ^ not allowed in type signatures
+   |                             ^
+   |
+help: use type parameters instead
+   |
+LL |     fn fn_test8<T>(_f: fn() -> T) { }
+   |                ^^^             ^
+
+error[E0282]: type annotations needed
+  --> $DIR/typeck_type_placeholder_item.rs:107:27
+   |
+LL |     fn fn_test11(_: _) -> (_, _) { panic!() }
+   |                           ^^^^^^ cannot infer type
 
 error[E0121]: the type placeholder `_` is not allowed within types on item signatures
-  --> $DIR/typeck_type_placeholder_item.rs:33:24
+  --> $DIR/typeck_type_placeholder_item.rs:107:27
+   |
+LL |     fn fn_test11(_: _) -> (_, _) { panic!() }
+   |                           ^^^^^^ not allowed in type signatures
+
+error[E0121]: the type placeholder `_` is not allowed within types on item signatures
+  --> $DIR/typeck_type_placeholder_item.rs:111:29
+   |
+LL |     fn fn_test12(x: i32) -> (_, _) { (x, x) }
+   |                             ^^^^^^
+   |                             |
+   |                             not allowed in type signatures
+   |                             help: replace this with the correct return type: `(i32, i32)`
+
+error[E0121]: the type placeholder `_` is not allowed within types on item signatures
+  --> $DIR/typeck_type_placeholder_item.rs:114:21
+   |
+LL |     fn fn_test13(x: _) -> (i32, _) { (x, x) }
+   |                     ^           ^
+   |
+help: use type parameters instead
+   |
+LL |     fn fn_test13<T>(x: T) -> (i32, T) { (x, x) }
+   |                 ^^^    ^           ^
+
+error[E0121]: the type placeholder `_` is not allowed within types on item signatures
+  --> $DIR/typeck_type_placeholder_item.rs:119:31
+   |
+LL |     fn method_test1(&self, x: _);
+   |                               ^
+   |
+help: use type parameters instead
+   |
+LL |     fn method_test1<T>(&self, x: T);
+   |                    ^^^           ^
+
+error[E0121]: the type placeholder `_` is not allowed within types on item signatures
+  --> $DIR/typeck_type_placeholder_item.rs:121:31
+   |
+LL |     fn method_test2(&self, x: _) -> _;
+   |                               ^     ^
+   |
+help: use type parameters instead
+   |
+LL |     fn method_test2<T>(&self, x: T) -> T;
+   |                    ^^^           ^     ^
+
+error[E0121]: the type placeholder `_` is not allowed within types on item signatures
+  --> $DIR/typeck_type_placeholder_item.rs:123:31
+   |
+LL |     fn method_test3(&self) -> _;
+   |                               ^
+   |
+help: use type parameters instead
+   |
+LL |     fn method_test3<T>(&self) -> T;
+   |                    ^^^           ^
+
+error[E0121]: the type placeholder `_` is not allowed within types on item signatures
+  --> $DIR/typeck_type_placeholder_item.rs:125:26
+   |
+LL |     fn assoc_fn_test1(x: _);
+   |                          ^
+   |
+help: use type parameters instead
+   |
+LL |     fn assoc_fn_test1<T>(x: T);
+   |                      ^^^    ^
+
+error[E0121]: the type placeholder `_` is not allowed within types on item signatures
+  --> $DIR/typeck_type_placeholder_item.rs:127:26
+   |
+LL |     fn assoc_fn_test2(x: _) -> _;
+   |                          ^     ^
+   |
+help: use type parameters instead
+   |
+LL |     fn assoc_fn_test2<T>(x: T) -> T;
+   |                      ^^^    ^     ^
+
+error[E0121]: the type placeholder `_` is not allowed within types on item signatures
+  --> $DIR/typeck_type_placeholder_item.rs:129:28
+   |
+LL |     fn assoc_fn_test3() -> _;
+   |                            ^
+   |
+help: use type parameters instead
+   |
+LL |     fn assoc_fn_test3<T>() -> T;
+   |                      ^^^      ^
+
+error[E0121]: the type placeholder `_` is not allowed within types on item signatures
+  --> $DIR/typeck_type_placeholder_item.rs:32:24
    |
 LL |     fn test9(&self) -> _ { () }
    |                        ^
    |                        |
    |                        not allowed in type signatures
-   |                        help: replace `_` with the correct return type: `()`
+   |                        help: replace this with the correct return type: `()`
 
 error[E0121]: the type placeholder `_` is not allowed within types on item signatures
-  --> $DIR/typeck_type_placeholder_item.rs:36:27
+  --> $DIR/typeck_type_placeholder_item.rs:35:27
    |
 LL |     fn test10(&self, _x : _) { }
-   |                           ^ not allowed in type signatures
+   |                           ^
+   |
+help: use type parameters instead
+   |
+LL |     fn test10<T>(&self, _x : T) { }
+   |              ^^^             ^
 
 error[E0121]: the type placeholder `_` is not allowed within types on item signatures
-  --> $DIR/typeck_type_placeholder_item.rs:41:24
+  --> $DIR/typeck_type_placeholder_item.rs:40:24
    |
 LL |     fn clone(&self) -> _ { Test9 }
    |                        ^
    |                        |
    |                        not allowed in type signatures
-   |                        help: replace `_` with the correct return type: `Test9`
+   |                        help: replace this with the correct return type: `Test9`
 
 error[E0121]: the type placeholder `_` is not allowed within types on item signatures
-  --> $DIR/typeck_type_placeholder_item.rs:44:37
+  --> $DIR/typeck_type_placeholder_item.rs:43:37
    |
 LL |     fn clone_from(&mut self, other: _) { *self = Test9; }
-   |                                     ^ not allowed in type signatures
+   |                                     ^
+   |
+help: use type parameters instead
+   |
+LL |     fn clone_from<T>(&mut self, other: T) { *self = Test9; }
+   |                  ^^^                   ^
 
 error[E0121]: the type placeholder `_` is not allowed within types on item signatures
-  --> $DIR/typeck_type_placeholder_item.rs:86:31
+  --> $DIR/typeck_type_placeholder_item.rs:84:31
    |
 LL |         fn fn_test9(&self) -> _ { () }
    |                               ^
    |                               |
    |                               not allowed in type signatures
-   |                               help: replace `_` with the correct return type: `()`
+   |                               help: replace this with the correct return type: `()`
 
 error[E0121]: the type placeholder `_` is not allowed within types on item signatures
-  --> $DIR/typeck_type_placeholder_item.rs:89:34
+  --> $DIR/typeck_type_placeholder_item.rs:87:34
    |
 LL |         fn fn_test10(&self, _x : _) { }
-   |                                  ^ not allowed in type signatures
+   |                                  ^
+   |
+help: use type parameters instead
+   |
+LL |         fn fn_test10<T>(&self, _x : T) { }
+   |                     ^^^             ^
 
 error[E0121]: the type placeholder `_` is not allowed within types on item signatures
-  --> $DIR/typeck_type_placeholder_item.rs:94:28
+  --> $DIR/typeck_type_placeholder_item.rs:92:28
    |
 LL |         fn clone(&self) -> _ { FnTest9 }
    |                            ^
    |                            |
    |                            not allowed in type signatures
-   |                            help: replace `_` with the correct return type: `main::FnTest9`
+   |                            help: replace this with the correct return type: `main::FnTest9`
 
 error[E0121]: the type placeholder `_` is not allowed within types on item signatures
-  --> $DIR/typeck_type_placeholder_item.rs:97:41
+  --> $DIR/typeck_type_placeholder_item.rs:95:41
    |
 LL |         fn clone_from(&mut self, other: _) { *self = FnTest9; }
-   |                                         ^ not allowed in type signatures
+   |                                         ^
+   |
+help: use type parameters instead
+   |
+LL |         fn clone_from<T>(&mut self, other: T) { *self = FnTest9; }
+   |                      ^^^                   ^
 
-error: aborting due to 34 previous errors
+error: aborting due to 42 previous errors
 
-For more information about this error, try `rustc --explain E0121`.
+Some errors have detailed explanations: E0121, E0282.
+For more information about an error, try `rustc --explain E0121`.
diff --git a/src/test/ui/typeck/typeck_type_placeholder_item_help.stderr b/src/test/ui/typeck/typeck_type_placeholder_item_help.stderr
index c5b9566290c..ab002381b1f 100644
--- a/src/test/ui/typeck/typeck_type_placeholder_item_help.stderr
+++ b/src/test/ui/typeck/typeck_type_placeholder_item_help.stderr
@@ -5,7 +5,7 @@ LL | fn test1() -> _ { Some(42) }
    |               ^
    |               |
    |               not allowed in type signatures
-   |               help: replace `_` with the correct return type: `std::option::Option<i32>`
+   |               help: replace this with the correct return type: `std::option::Option<i32>`
 
 error[E0121]: the type placeholder `_` is not allowed within types on item signatures
   --> $DIR/typeck_type_placeholder_item_help.rs:7:14