Expand suggestions for type ascription parse errors
This commit is contained in:
parent
9f91bee03f
commit
8ba1a97e37
20 changed files with 358 additions and 18 deletions
|
|
@ -3,6 +3,19 @@ error: expected type, found `1`
|
|||
|
|
||||
LL | if let S { x: _x, y: 2 } = S { x: 1, y: 2 } { println!("Ok"); }
|
||||
| ^ expecting a type here because of type ascription
|
||||
|
|
||||
= note: type ascription is a nightly only feature that lets you annotate expressions with a type: `<expr>: <type>`
|
||||
note: this expression is annotated with type ascription...
|
||||
--> $DIR/E0423.rs:12:36
|
||||
|
|
||||
LL | if let S { x: _x, y: 2 } = S { x: 1, y: 2 } { println!("Ok"); }
|
||||
| ^
|
||||
note: ...due to this, which is why a type is expected after
|
||||
--> $DIR/E0423.rs:12:37
|
||||
|
|
||||
LL | if let S { x: _x, y: 2 } = S { x: 1, y: 2 } { println!("Ok"); }
|
||||
| ^
|
||||
= help: this might be indicative of a syntax error elsewhere
|
||||
|
||||
error: expected expression, found `==`
|
||||
--> $DIR/E0423.rs:15:13
|
||||
|
|
@ -15,6 +28,19 @@ error: expected type, found `0`
|
|||
|
|
||||
LL | for _ in std::ops::Range { start: 0, end: 10 } {}
|
||||
| ^ expecting a type here because of type ascription
|
||||
|
|
||||
= note: type ascription is a nightly only feature that lets you annotate expressions with a type: `<expr>: <type>`
|
||||
note: this expression is annotated with type ascription...
|
||||
--> $DIR/E0423.rs:21:32
|
||||
|
|
||||
LL | for _ in std::ops::Range { start: 0, end: 10 } {}
|
||||
| ^^^^^
|
||||
note: ...due to this, which is why a type is expected after
|
||||
--> $DIR/E0423.rs:21:37
|
||||
|
|
||||
LL | for _ in std::ops::Range { start: 0, end: 10 } {}
|
||||
| ^
|
||||
= help: this might be indicative of a syntax error elsewhere
|
||||
|
||||
error[E0423]: expected function, found struct `Foo`
|
||||
--> $DIR/E0423.rs:4:13
|
||||
|
|
|
|||
|
|
@ -88,6 +88,19 @@ error: expected type, found `4`
|
|||
|
|
||||
LL | println!("{}", a: &mut 4);
|
||||
| ^ expecting a type here because of type ascription
|
||||
|
|
||||
= note: type ascription is a nightly only feature that lets you annotate expressions with a type: `<expr>: <type>`
|
||||
note: this expression is annotated with type ascription...
|
||||
--> $DIR/issue-22644.rs:34:20
|
||||
|
|
||||
LL | println!("{}", a: &mut 4);
|
||||
| ^
|
||||
note: ...due to this, which is why a type is expected after
|
||||
--> $DIR/issue-22644.rs:34:21
|
||||
|
|
||||
LL | println!("{}", a: &mut 4);
|
||||
| ^
|
||||
= help: this might be indicative of a syntax error elsewhere
|
||||
|
||||
error: aborting due to 9 previous errors
|
||||
|
||||
|
|
|
|||
10
src/test/ui/issues/issue-34255-1.rs
Normal file
10
src/test/ui/issues/issue-34255-1.rs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
enum Test {
|
||||
Drill {
|
||||
field: i32,
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
Test::Drill(field: 42);
|
||||
//~^ ERROR expected type, found
|
||||
}
|
||||
21
src/test/ui/issues/issue-34255-1.stderr
Normal file
21
src/test/ui/issues/issue-34255-1.stderr
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
error: expected type, found `42`
|
||||
--> $DIR/issue-34255-1.rs:8:24
|
||||
|
|
||||
LL | Test::Drill(field: 42);
|
||||
| ^^ expecting a type here because of type ascription
|
||||
|
|
||||
= note: type ascription is a nightly only feature that lets you annotate expressions with a type: `<expr>: <type>`
|
||||
note: this expression is annotated with type ascription...
|
||||
--> $DIR/issue-34255-1.rs:8:17
|
||||
|
|
||||
LL | Test::Drill(field: 42);
|
||||
| ^^^^^
|
||||
note: ...due to this, which is why a type is expected after
|
||||
--> $DIR/issue-34255-1.rs:8:22
|
||||
|
|
||||
LL | Test::Drill(field: 42);
|
||||
| ^
|
||||
= help: this might be indicative of a syntax error elsewhere
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
@ -13,6 +13,19 @@ error: expected type, found keyword `loop`
|
|||
|
|
||||
LL | loop { break 'label: loop { break 'label 42; }; }
|
||||
| ^^^^ expecting a type here because of type ascription
|
||||
|
|
||||
= note: type ascription is a nightly only feature that lets you annotate expressions with a type: `<expr>: <type>`
|
||||
note: this expression is annotated with type ascription...
|
||||
--> $DIR/lifetime_starts_expressions.rs:6:12
|
||||
|
|
||||
LL | loop { break 'label: loop { break 'label 42; }; }
|
||||
| ^^^^^^^^^^^^
|
||||
note: ...due to this, which is why a type is expected after
|
||||
--> $DIR/lifetime_starts_expressions.rs:6:24
|
||||
|
|
||||
LL | loop { break 'label: loop { break 'label 42; }; }
|
||||
| ^
|
||||
= help: this might be indicative of a syntax error elsewhere
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,19 @@ error: expected type, found `3`
|
|||
|
|
||||
LL | x: 3
|
||||
| ^ expecting a type here because of type ascription
|
||||
|
|
||||
= note: type ascription is a nightly only feature that lets you annotate expressions with a type: `<expr>: <type>`
|
||||
note: this expression is annotated with type ascription...
|
||||
--> $DIR/struct-literal-in-for.rs:13:9
|
||||
|
|
||||
LL | x: 3
|
||||
| ^
|
||||
note: ...due to this, which is why a type is expected after
|
||||
--> $DIR/struct-literal-in-for.rs:13:10
|
||||
|
|
||||
LL | x: 3
|
||||
| ^
|
||||
= help: this might be indicative of a syntax error elsewhere
|
||||
|
||||
error: expected one of `.`, `;`, `?`, `}`, or an operator, found `{`
|
||||
--> $DIR/struct-literal-in-for.rs:14:12
|
||||
|
|
|
|||
|
|
@ -3,6 +3,19 @@ error: expected type, found `3`
|
|||
|
|
||||
LL | x: 3
|
||||
| ^ expecting a type here because of type ascription
|
||||
|
|
||||
= note: type ascription is a nightly only feature that lets you annotate expressions with a type: `<expr>: <type>`
|
||||
note: this expression is annotated with type ascription...
|
||||
--> $DIR/struct-literal-in-if.rs:13:9
|
||||
|
|
||||
LL | x: 3
|
||||
| ^
|
||||
note: ...due to this, which is why a type is expected after
|
||||
--> $DIR/struct-literal-in-if.rs:13:10
|
||||
|
|
||||
LL | x: 3
|
||||
| ^
|
||||
= help: this might be indicative of a syntax error elsewhere
|
||||
|
||||
error: expected one of `.`, `;`, `?`, `}`, or an operator, found `{`
|
||||
--> $DIR/struct-literal-in-if.rs:14:12
|
||||
|
|
|
|||
|
|
@ -3,6 +3,19 @@ error: expected type, found `3`
|
|||
|
|
||||
LL | x: 3
|
||||
| ^ expecting a type here because of type ascription
|
||||
|
|
||||
= note: type ascription is a nightly only feature that lets you annotate expressions with a type: `<expr>: <type>`
|
||||
note: this expression is annotated with type ascription...
|
||||
--> $DIR/struct-literal-in-while.rs:13:9
|
||||
|
|
||||
LL | x: 3
|
||||
| ^
|
||||
note: ...due to this, which is why a type is expected after
|
||||
--> $DIR/struct-literal-in-while.rs:13:10
|
||||
|
|
||||
LL | x: 3
|
||||
| ^
|
||||
= help: this might be indicative of a syntax error elsewhere
|
||||
|
||||
error: expected one of `.`, `;`, `?`, `}`, or an operator, found `{`
|
||||
--> $DIR/struct-literal-in-while.rs:14:12
|
||||
|
|
|
|||
|
|
@ -3,6 +3,19 @@ error: expected type, found `3`
|
|||
|
|
||||
LL | x: 3
|
||||
| ^ expecting a type here because of type ascription
|
||||
|
|
||||
= note: type ascription is a nightly only feature that lets you annotate expressions with a type: `<expr>: <type>`
|
||||
note: this expression is annotated with type ascription...
|
||||
--> $DIR/struct-literal-restrictions-in-lamda.rs:13:9
|
||||
|
|
||||
LL | x: 3
|
||||
| ^
|
||||
note: ...due to this, which is why a type is expected after
|
||||
--> $DIR/struct-literal-restrictions-in-lamda.rs:13:10
|
||||
|
|
||||
LL | x: 3
|
||||
| ^
|
||||
= help: this might be indicative of a syntax error elsewhere
|
||||
|
||||
error: expected one of `.`, `;`, `?`, `}`, or an operator, found `{`
|
||||
--> $DIR/struct-literal-restrictions-in-lamda.rs:14:12
|
||||
|
|
|
|||
11
src/test/ui/suggestions/type-ascription-instead-of-let.rs
Normal file
11
src/test/ui/suggestions/type-ascription-instead-of-let.rs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fn fun(x: i32) -> i32 { x }
|
||||
|
||||
fn main() {
|
||||
let closure_annotated = |value: i32| -> i32 {
|
||||
temp: i32 = fun(5i32);
|
||||
//~^ ERROR cannot find value `temp` in this scope
|
||||
//~| ERROR type ascription is experimental
|
||||
temp + value + 1
|
||||
//~^ ERROR cannot find value `temp` in this scope
|
||||
};
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
error[E0425]: cannot find value `temp` in this scope
|
||||
--> $DIR/type-ascription-instead-of-let.rs:5:9
|
||||
|
|
||||
LL | temp: i32 = fun(5i32);
|
||||
| ^^^^
|
||||
| |
|
||||
| not found in this scope
|
||||
| expecting a type here because of type ascription
|
||||
| help: maybe you meant to write an assignment here: `let temp`
|
||||
|
||||
error[E0425]: cannot find value `temp` in this scope
|
||||
--> $DIR/type-ascription-instead-of-let.rs:8:9
|
||||
|
|
||||
LL | temp + value + 1
|
||||
| ^^^^ not found in this scope
|
||||
|
||||
error[E0658]: type ascription is experimental (see issue #23416)
|
||||
--> $DIR/type-ascription-instead-of-let.rs:5:9
|
||||
|
|
||||
LL | temp: i32 = fun(5i32);
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= help: add #![feature(type_ascription)] to the crate attributes to enable
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
Some errors occurred: E0425, E0658.
|
||||
For more information about an error, try `rustc --explain E0425`.
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
fn main() {
|
||||
Box:new("foo".to_string())
|
||||
//~^ ERROR expected type, found
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
error: expected type, found `"foo"`
|
||||
--> $DIR/type-ascription-instead-of-method.rs:2:13
|
||||
|
|
||||
LL | Box:new("foo".to_string())
|
||||
| - ^^^^^ expecting a type here because of type ascription
|
||||
| |
|
||||
| help: maybe you meant to write a path separator here: `::`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
fn main() {
|
||||
std:io::stdin();
|
||||
//~^ ERROR failed to resolve: use of undeclared type or module `io`
|
||||
//~| ERROR expected value, found module
|
||||
//~| ERROR type ascription is experimental
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
error[E0433]: failed to resolve: use of undeclared type or module `io`
|
||||
--> $DIR/type-ascription-instead-of-path.rs:2:9
|
||||
|
|
||||
LL | std:io::stdin();
|
||||
| ^^ use of undeclared type or module `io`
|
||||
|
||||
error[E0423]: expected value, found module `std`
|
||||
--> $DIR/type-ascription-instead-of-path.rs:2:5
|
||||
|
|
||||
LL | std:io::stdin();
|
||||
| ^^^
|
||||
| |
|
||||
| not a value
|
||||
| expecting a type here because of type ascription
|
||||
help: maybe you meant to write a path separator here
|
||||
|
|
||||
LL | std::io::stdin();
|
||||
| ^^
|
||||
help: maybe you meant to write an assignment here
|
||||
|
|
||||
LL | let std:io::stdin();
|
||||
| ^^^^^^^
|
||||
|
||||
error[E0658]: type ascription is experimental (see issue #23416)
|
||||
--> $DIR/type-ascription-instead-of-path.rs:2:5
|
||||
|
|
||||
LL | std:io::stdin();
|
||||
| ^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: add #![feature(type_ascription)] to the crate attributes to enable
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
Some errors occurred: E0423, E0433, E0658.
|
||||
For more information about an error, try `rustc --explain E0423`.
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
fn main() {
|
||||
let _ = Option:Some("");
|
||||
//~^ ERROR expected type, found
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
error: expected type, found `""`
|
||||
--> $DIR/type-ascription-instead-of-variant.rs:2:25
|
||||
|
|
||||
LL | let _ = Option:Some("");
|
||||
| - ^^ expecting a type here because of type ascription
|
||||
| |
|
||||
| help: maybe you meant to write a path separator here: `::`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
@ -11,6 +11,19 @@ error: expected type, found `0`
|
|||
|
|
||||
LL | println!("test"): 0;
|
||||
| ^ expecting a type here because of type ascription
|
||||
|
|
||||
= note: type ascription is a nightly only feature that lets you annotate expressions with a type: `<expr>: <type>`
|
||||
note: this expression is annotated with type ascription...
|
||||
--> $DIR/type-ascription-instead-of-statement-end.rs:9:5
|
||||
|
|
||||
LL | println!("test"): 0;
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
note: ...due to this, which is why a type is expected after
|
||||
--> $DIR/type-ascription-instead-of-statement-end.rs:9:21
|
||||
|
|
||||
LL | println!("test"): 0;
|
||||
| ^
|
||||
= help: this might be indicative of a syntax error elsewhere
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue