Reduce verbosity of some type ascription errors
* Deduplicate type ascription LHS errors * Remove duplicated `:` -> `::` suggestion from parse error * Tweak wording to be more accurate * Modify `current_type_ascription` to reduce span wrangling * remove now unnecessary match arm * Add run-rustfix to appropriate tests
This commit is contained in:
parent
6b09c37ddc
commit
6ed06b2ba9
28 changed files with 212 additions and 181 deletions
6
src/test/ui/suggestions/issue-61226.fixed
Normal file
6
src/test/ui/suggestions/issue-61226.fixed
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
// run-rustfix
|
||||
struct X {}
|
||||
fn main() {
|
||||
let _ = vec![X {}]; //…
|
||||
//~^ ERROR expected value, found struct `X`
|
||||
}
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
// run-rustfix
|
||||
struct X {}
|
||||
fn main() {
|
||||
vec![X]; //…
|
||||
let _ = vec![X]; //…
|
||||
//~^ ERROR expected value, found struct `X`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
error[E0423]: expected value, found struct `X`
|
||||
--> $DIR/issue-61226.rs:3:10
|
||||
--> $DIR/issue-61226.rs:4:18
|
||||
|
|
||||
LL | struct X {}
|
||||
| ----------- `X` defined here
|
||||
LL | fn main() {
|
||||
LL | vec![X]; //…
|
||||
| ^ help: use struct literal syntax instead: `X {}`
|
||||
LL | let _ = vec![X]; //…
|
||||
| ^ help: use struct literal syntax instead: `X {}`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,5 @@
|
|||
// run-rustfix
|
||||
fn main() {
|
||||
let _ = Box::new("foo".to_string());
|
||||
//~^ ERROR expected type, found
|
||||
}
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
// run-rustfix
|
||||
fn main() {
|
||||
Box:new("foo".to_string())
|
||||
let _ = Box:new("foo".to_string());
|
||||
//~^ ERROR expected type, found
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
error: expected type, found `"foo"`
|
||||
--> $DIR/type-ascription-instead-of-method.rs:2:13
|
||||
--> $DIR/type-ascription-instead-of-method.rs:3:21
|
||||
|
|
||||
LL | Box:new("foo".to_string())
|
||||
| - ^^^^^ expected type
|
||||
| |
|
||||
| help: maybe write a path separator here: `::`
|
||||
LL | let _ = Box:new("foo".to_string());
|
||||
| - ^^^^^ expected type
|
||||
| |
|
||||
| help: maybe write a path separator here: `::`
|
||||
|
|
||||
= note: `#![feature(type_ascription)]` lets you annotate an expression with a type: `<expr>: <type>`
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,6 @@
|
|||
// run-rustfix
|
||||
fn main() -> Result<(), ()> {
|
||||
let _ = vec![Ok(2)].into_iter().collect::<Result<Vec<_>,_>>()?;
|
||||
//~^ ERROR expected `::`, found `(`
|
||||
Ok(())
|
||||
}
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
// run-rustfix
|
||||
fn main() -> Result<(), ()> {
|
||||
vec![Ok(2)].into_iter().collect:<Result<Vec<_>,_>>()?;
|
||||
let _ = vec![Ok(2)].into_iter().collect:<Result<Vec<_>,_>>()?;
|
||||
//~^ ERROR expected `::`, found `(`
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
error: expected `::`, found `(`
|
||||
--> $DIR/type-ascription-instead-of-path-2.rs:2:55
|
||||
--> $DIR/type-ascription-instead-of-path-2.rs:3:63
|
||||
|
|
||||
LL | vec![Ok(2)].into_iter().collect:<Result<Vec<_>,_>>()?;
|
||||
| - ^ expected `::`
|
||||
| |
|
||||
| help: maybe write a path separator here: `::`
|
||||
LL | let _ = vec![Ok(2)].into_iter().collect:<Result<Vec<_>,_>>()?;
|
||||
| - ^ expected `::`
|
||||
| |
|
||||
| help: maybe write a path separator here: `::`
|
||||
|
|
||||
= note: `#![feature(type_ascription)]` lets you annotate an expression with a type: `<expr>: <type>`
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,5 @@
|
|||
// run-rustfix
|
||||
fn main() {
|
||||
let _ = Option::Some("");
|
||||
//~^ ERROR expected type, found
|
||||
}
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
// run-rustfix
|
||||
fn main() {
|
||||
let _ = Option:Some("");
|
||||
//~^ ERROR expected type, found
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
error: expected type, found `""`
|
||||
--> $DIR/type-ascription-instead-of-variant.rs:2:25
|
||||
--> $DIR/type-ascription-instead-of-variant.rs:3:25
|
||||
|
|
||||
LL | let _ = Option:Some("");
|
||||
| - ^^ expected type
|
||||
|
|
|
|||
4
src/test/ui/type/ascription/issue-47666.fixed
Normal file
4
src/test/ui/type/ascription/issue-47666.fixed
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
// run-rustfix
|
||||
fn main() {
|
||||
let _ = Option::Some(vec![0, 1]); //~ ERROR expected type, found
|
||||
}
|
||||
|
|
@ -1,7 +1,4 @@
|
|||
// run-rustfix
|
||||
fn main() {
|
||||
let _ = Option:Some(vec![0, 1]); //~ ERROR expected type, found
|
||||
//~^ ERROR expected value, found enum `Option`
|
||||
//~| ERROR expected type, found variant `Some`
|
||||
}
|
||||
|
||||
// This case isn't currently being handled gracefully due to the macro invocation.
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
error: expected type, found reserved keyword `box`
|
||||
--> $DIR/issue-47666.rs:2:25
|
||||
--> $DIR/issue-47666.rs:3:25
|
||||
|
|
||||
LL | let _ = Option:Some(vec![0, 1]);
|
||||
| - ^^^^^^^^^^
|
||||
|
|
@ -12,35 +12,5 @@ LL | let _ = Option:Some(vec![0, 1]);
|
|||
= note: `#![feature(type_ascription)]` lets you annotate an expression with a type: `<expr>: <type>`
|
||||
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error[E0423]: expected value, found enum `Option`
|
||||
--> $DIR/issue-47666.rs:2:13
|
||||
|
|
||||
LL | let _ = Option:Some(vec![0, 1]);
|
||||
| ^^^^^^
|
||||
|
|
||||
help: try using one of the enum's variants
|
||||
|
|
||||
LL | let _ = std::option::Option::None:Some(vec![0, 1]);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
LL | let _ = std::option::Option::Some:Some(vec![0, 1]);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
error: aborting due to previous error
|
||||
|
||||
error[E0573]: expected type, found variant `Some`
|
||||
--> $DIR/issue-47666.rs:2:20
|
||||
|
|
||||
LL | let _ = Option:Some(vec![0, 1]);
|
||||
| ^^^^^^^^^^^^^^^^ not a type
|
||||
|
|
||||
help: try using the variant's enum
|
||||
|
|
||||
LL | let _ = Option:std::option::Option;
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
help: maybe you meant to write a path separator here
|
||||
|
|
||||
LL | let _ = Option::Some(vec![0, 1]);
|
||||
| ^^
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0423, E0573.
|
||||
For more information about an error, try `rustc --explain E0423`.
|
||||
|
|
|
|||
7
src/test/ui/type/ascription/issue-54516.fixed
Normal file
7
src/test/ui/type/ascription/issue-54516.fixed
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
// run-rustfix
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
fn main() {
|
||||
println!("{}", std::mem::size_of::<BTreeMap<u32, u32>>());
|
||||
//~^ ERROR casts cannot be followed by a function call
|
||||
}
|
||||
|
|
@ -1,8 +1,7 @@
|
|||
// run-rustfix
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
fn main() {
|
||||
println!("{}", std::mem:size_of::<BTreeMap<u32, u32>>());
|
||||
//~^ ERROR casts cannot be followed by a function call
|
||||
//~| ERROR expected value, found module `std::mem` [E0423]
|
||||
//~| ERROR cannot find type `size_of` in this scope [E0412]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
error: casts cannot be followed by a function call
|
||||
--> $DIR/issue-54516.rs:4:20
|
||||
--> $DIR/issue-54516.rs:5:20
|
||||
|
|
||||
LL | println!("{}", std::mem:size_of::<BTreeMap<u32, u32>>());
|
||||
| ^^^^^^^^-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
@ -8,23 +8,5 @@ LL | println!("{}", std::mem:size_of::<BTreeMap<u32, u32>>());
|
|||
|
|
||||
= note: `#![feature(type_ascription)]` lets you annotate an expression with a type: `<expr>: <type>`
|
||||
|
||||
error[E0423]: expected value, found module `std::mem`
|
||||
--> $DIR/issue-54516.rs:4:20
|
||||
|
|
||||
LL | println!("{}", std::mem:size_of::<BTreeMap<u32, u32>>());
|
||||
| ^^^^^^^^- help: maybe you meant to write a path separator here: `::`
|
||||
| |
|
||||
| not a value
|
||||
error: aborting due to previous error
|
||||
|
||||
error[E0412]: cannot find type `size_of` in this scope
|
||||
--> $DIR/issue-54516.rs:4:29
|
||||
|
|
||||
LL | println!("{}", std::mem:size_of::<BTreeMap<u32, u32>>());
|
||||
| -^^^^^^^ not found in this scope
|
||||
| |
|
||||
| help: maybe you meant to write a path separator here: `::`
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0412, E0423.
|
||||
For more information about an error, try `rustc --explain E0412`.
|
||||
|
|
|
|||
5
src/test/ui/type/ascription/issue-60933.fixed
Normal file
5
src/test/ui/type/ascription/issue-60933.fixed
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
// run-rustfix
|
||||
fn main() {
|
||||
let _: usize = std::mem::size_of::<u32>();
|
||||
//~^ ERROR casts cannot be followed by a function call
|
||||
}
|
||||
|
|
@ -1,6 +1,5 @@
|
|||
// run-rustfix
|
||||
fn main() {
|
||||
let u: usize = std::mem:size_of::<u32>();
|
||||
let _: usize = std::mem:size_of::<u32>();
|
||||
//~^ ERROR casts cannot be followed by a function call
|
||||
//~| ERROR expected value, found module `std::mem` [E0423]
|
||||
//~| ERROR cannot find type `size_of` in this scope [E0412]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,30 +1,12 @@
|
|||
error: casts cannot be followed by a function call
|
||||
--> $DIR/issue-60933.rs:2:20
|
||||
--> $DIR/issue-60933.rs:3:20
|
||||
|
|
||||
LL | let u: usize = std::mem:size_of::<u32>();
|
||||
LL | let _: usize = std::mem:size_of::<u32>();
|
||||
| ^^^^^^^^-^^^^^^^^^^^^^^
|
||||
| |
|
||||
| help: maybe write a path separator here: `::`
|
||||
|
|
||||
= note: `#![feature(type_ascription)]` lets you annotate an expression with a type: `<expr>: <type>`
|
||||
|
||||
error[E0423]: expected value, found module `std::mem`
|
||||
--> $DIR/issue-60933.rs:2:20
|
||||
|
|
||||
LL | let u: usize = std::mem:size_of::<u32>();
|
||||
| ^^^^^^^^- help: maybe you meant to write a path separator here: `::`
|
||||
| |
|
||||
| not a value
|
||||
error: aborting due to previous error
|
||||
|
||||
error[E0412]: cannot find type `size_of` in this scope
|
||||
--> $DIR/issue-60933.rs:2:29
|
||||
|
|
||||
LL | let u: usize = std::mem:size_of::<u32>();
|
||||
| -^^^^^^^ not found in this scope
|
||||
| |
|
||||
| help: maybe you meant to write a path separator here: `::`
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0412, E0423.
|
||||
For more information about an error, try `rustc --explain E0412`.
|
||||
|
|
|
|||
9
src/test/ui/type/type-ascription-with-fn-call.fixed
Normal file
9
src/test/ui/type/type-ascription-with-fn-call.fixed
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
// run-rustfix
|
||||
#![feature(type_ascription)]
|
||||
|
||||
fn main() {
|
||||
f() ;
|
||||
f(); //~ ERROR expected type, found function
|
||||
}
|
||||
|
||||
fn f() {}
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
// run-rustfix
|
||||
#![feature(type_ascription)]
|
||||
|
||||
fn main() {
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
error[E0573]: expected type, found function `f`
|
||||
--> $DIR/type-ascription-with-fn-call.rs:5:5
|
||||
--> $DIR/type-ascription-with-fn-call.rs:6:5
|
||||
|
|
||||
LL | f() :
|
||||
| - help: did you mean to use `;` here instead?
|
||||
| - help: maybe you meant to write `;` here
|
||||
LL | f();
|
||||
| ^^^
|
||||
| |
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue