Rollup merge of #73953 - JohnTitor:audit-hidden-sugg, r=estebank
Audit hidden/short code suggestions Should fix #73641. Audit uses of `span_suggestion_short` and `tool_only_span_suggestion` (`span_suggestion_hidden` is already tested with `run-rustfix`). Leave some FIXMEs for futher improvements/fixes. r? @estebank
This commit is contained in:
commit
e74ab50d07
@ -280,6 +280,8 @@ impl<'a, 'b> Context<'a, 'b> {
|
||||
("x", "LowerHex"),
|
||||
("X", "UpperHex"),
|
||||
] {
|
||||
// FIXME: rustfix (`run-rustfix`) fails to apply suggestions.
|
||||
// > "Cannot replace slice of data that was already replaced"
|
||||
err.tool_only_span_suggestion(
|
||||
sp,
|
||||
&format!("use the `{}` trait", name),
|
||||
|
@ -1228,10 +1228,13 @@ impl<'a> Parser<'a> {
|
||||
if let Some(sp) = unmatched.unclosed_span {
|
||||
err.span_label(sp, "unclosed delimiter");
|
||||
}
|
||||
// Backticks should be removed to apply suggestions.
|
||||
let mut delim = delim.to_string();
|
||||
delim.retain(|c| c != '`');
|
||||
err.span_suggestion_short(
|
||||
self.prev_token.span.shrink_to_hi(),
|
||||
&format!("{} may belong here", delim.to_string()),
|
||||
delim.to_string(),
|
||||
&format!("`{}` may belong here", delim),
|
||||
delim,
|
||||
Applicability::MaybeIncorrect,
|
||||
);
|
||||
if unmatched.found_delim.is_none() {
|
||||
|
@ -699,7 +699,7 @@ impl<'a> Parser<'a> {
|
||||
// misses a separator.
|
||||
expect_err
|
||||
.span_suggestion_short(
|
||||
sp,
|
||||
self.sess.source_map().next_point(sp),
|
||||
&format!("missing `{}`", token_str),
|
||||
token_str,
|
||||
Applicability::MaybeIncorrect,
|
||||
|
12
src/test/ui/block-expression-remove-semicolon.fixed
Normal file
12
src/test/ui/block-expression-remove-semicolon.fixed
Normal file
@ -0,0 +1,12 @@
|
||||
// run-rustfix
|
||||
|
||||
fn foo() -> i32 {
|
||||
0
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let _x: i32 = {
|
||||
//~^ ERROR mismatched types
|
||||
foo() //~ HELP consider removing this semicolon
|
||||
};
|
||||
}
|
@ -1,9 +1,11 @@
|
||||
// run-rustfix
|
||||
|
||||
fn foo() -> i32 {
|
||||
0
|
||||
0
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let x: i32 = {
|
||||
let _x: i32 = {
|
||||
//~^ ERROR mismatched types
|
||||
foo(); //~ HELP consider removing this semicolon
|
||||
};
|
||||
|
@ -1,8 +1,8 @@
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/block-expression-remove-semicolon.rs:6:18
|
||||
--> $DIR/block-expression-remove-semicolon.rs:8:19
|
||||
|
|
||||
LL | let x: i32 = {
|
||||
| __________________^
|
||||
LL | let _x: i32 = {
|
||||
| ___________________^
|
||||
LL | |
|
||||
LL | | foo();
|
||||
| | - help: consider removing this semicolon
|
||||
|
13
src/test/ui/block-result/consider-removing-last-semi.fixed
Normal file
13
src/test/ui/block-result/consider-removing-last-semi.fixed
Normal file
@ -0,0 +1,13 @@
|
||||
// run-rustfix
|
||||
|
||||
pub fn f() -> String { //~ ERROR mismatched types
|
||||
0u8;
|
||||
"bla".to_string()
|
||||
}
|
||||
|
||||
pub fn g() -> String { //~ ERROR mismatched types
|
||||
"this won't work".to_string();
|
||||
"removeme".to_string()
|
||||
}
|
||||
|
||||
fn main() {}
|
@ -1,9 +1,11 @@
|
||||
fn f() -> String { //~ ERROR mismatched types
|
||||
// run-rustfix
|
||||
|
||||
pub fn f() -> String { //~ ERROR mismatched types
|
||||
0u8;
|
||||
"bla".to_string();
|
||||
}
|
||||
|
||||
fn g() -> String { //~ ERROR mismatched types
|
||||
pub fn g() -> String { //~ ERROR mismatched types
|
||||
"this won't work".to_string();
|
||||
"removeme".to_string();
|
||||
}
|
||||
|
@ -1,21 +1,21 @@
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/consider-removing-last-semi.rs:1:11
|
||||
--> $DIR/consider-removing-last-semi.rs:3:15
|
||||
|
|
||||
LL | fn f() -> String {
|
||||
| - ^^^^^^ expected struct `std::string::String`, found `()`
|
||||
| |
|
||||
| implicitly returns `()` as its body has no tail or `return` expression
|
||||
LL | pub fn f() -> String {
|
||||
| - ^^^^^^ expected struct `std::string::String`, found `()`
|
||||
| |
|
||||
| implicitly returns `()` as its body has no tail or `return` expression
|
||||
LL | 0u8;
|
||||
LL | "bla".to_string();
|
||||
| - help: consider removing this semicolon
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/consider-removing-last-semi.rs:6:11
|
||||
--> $DIR/consider-removing-last-semi.rs:8:15
|
||||
|
|
||||
LL | fn g() -> String {
|
||||
| - ^^^^^^ expected struct `std::string::String`, found `()`
|
||||
| |
|
||||
| implicitly returns `()` as its body has no tail or `return` expression
|
||||
LL | pub fn g() -> String {
|
||||
| - ^^^^^^ expected struct `std::string::String`, found `()`
|
||||
| |
|
||||
| implicitly returns `()` as its body has no tail or `return` expression
|
||||
LL | "this won't work".to_string();
|
||||
LL | "removeme".to_string();
|
||||
| - help: consider removing this semicolon
|
||||
|
@ -0,0 +1,16 @@
|
||||
// #41425 -- error message "mismatched types" has wrong types
|
||||
// run-rustfix
|
||||
|
||||
fn plus_one(x: i32) -> i32 { //~ ERROR mismatched types
|
||||
x + 1
|
||||
}
|
||||
|
||||
fn foo() -> Result<u8, u64> { //~ ERROR mismatched types
|
||||
Ok(1)
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let x = plus_one(5);
|
||||
let _ = foo();
|
||||
println!("X = {}", x);
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
// #41425 -- error message "mismatched types" has wrong types
|
||||
// run-rustfix
|
||||
|
||||
fn plus_one(x: i32) -> i32 { //~ ERROR mismatched types
|
||||
x + 1;
|
||||
@ -10,5 +11,6 @@ fn foo() -> Result<u8, u64> { //~ ERROR mismatched types
|
||||
|
||||
fn main() {
|
||||
let x = plus_one(5);
|
||||
let _ = foo();
|
||||
println!("X = {}", x);
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/coercion-missing-tail-expected-type.rs:3:24
|
||||
--> $DIR/coercion-missing-tail-expected-type.rs:4:24
|
||||
|
|
||||
LL | fn plus_one(x: i32) -> i32 {
|
||||
| -------- ^^^ expected `i32`, found `()`
|
||||
@ -9,7 +9,7 @@ LL | x + 1;
|
||||
| - help: consider removing this semicolon
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/coercion-missing-tail-expected-type.rs:7:13
|
||||
--> $DIR/coercion-missing-tail-expected-type.rs:8:13
|
||||
|
|
||||
LL | fn foo() -> Result<u8, u64> {
|
||||
| --- ^^^^^^^^^^^^^^^ expected enum `std::result::Result`, found `()`
|
||||
|
15
src/test/ui/const-generics/unused_braces.fixed
Normal file
15
src/test/ui/const-generics/unused_braces.fixed
Normal file
@ -0,0 +1,15 @@
|
||||
// check-pass
|
||||
// run-rustfix
|
||||
|
||||
#![allow(incomplete_features)]
|
||||
#![warn(unused_braces)]
|
||||
|
||||
#![feature(const_generics)]
|
||||
|
||||
struct A<const N: usize>;
|
||||
|
||||
fn main() {
|
||||
let _: A<7>; // ok
|
||||
let _: A< 7 >; //~ WARN unnecessary braces
|
||||
let _: A<{ 3 + 5 }>; // ok
|
||||
}
|
@ -1,8 +1,10 @@
|
||||
// check-pass
|
||||
// run-rustfix
|
||||
|
||||
#![allow(incomplete_features)]
|
||||
#![warn(unused_braces)]
|
||||
|
||||
#![feature(const_generics)]
|
||||
//~^ WARN the feature `const_generics` is incomplete
|
||||
|
||||
struct A<const N: usize>;
|
||||
|
||||
|
@ -1,23 +1,14 @@
|
||||
warning: the feature `const_generics` is incomplete and may not be safe to use and/or cause compiler crashes
|
||||
--> $DIR/unused_braces.rs:4:12
|
||||
|
|
||||
LL | #![feature(const_generics)]
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `#[warn(incomplete_features)]` on by default
|
||||
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information
|
||||
|
||||
warning: unnecessary braces around const expression
|
||||
--> $DIR/unused_braces.rs:11:14
|
||||
--> $DIR/unused_braces.rs:13:14
|
||||
|
|
||||
LL | let _: A<{ 7 }>;
|
||||
| ^^^^^ help: remove these braces
|
||||
|
|
||||
note: the lint level is defined here
|
||||
--> $DIR/unused_braces.rs:2:9
|
||||
--> $DIR/unused_braces.rs:5:9
|
||||
|
|
||||
LL | #![warn(unused_braces)]
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
warning: 2 warnings emitted
|
||||
warning: 1 warning emitted
|
||||
|
||||
|
@ -0,0 +1,5 @@
|
||||
// run-rustfix
|
||||
|
||||
fn main() {
|
||||
let _x = !1; //~ ERROR cannot be used as a unary operator
|
||||
}
|
@ -1,3 +1,5 @@
|
||||
// run-rustfix
|
||||
|
||||
fn main() {
|
||||
let x = ~1; //~ ERROR cannot be used as a unary operator
|
||||
let _x = ~1; //~ ERROR cannot be used as a unary operator
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
error: `~` cannot be used as a unary operator
|
||||
--> $DIR/issue-41679-tilde-bitwise-negation-attempt.rs:2:13
|
||||
--> $DIR/issue-41679-tilde-bitwise-negation-attempt.rs:4:14
|
||||
|
|
||||
LL | let x = ~1;
|
||||
| ^ help: use `!` to perform bitwise not
|
||||
LL | let _x = ~1;
|
||||
| ^ help: use `!` to perform bitwise not
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
69
src/test/ui/did_you_mean/issue-54109-without-witness.fixed
Normal file
69
src/test/ui/did_you_mean/issue-54109-without-witness.fixed
Normal file
@ -0,0 +1,69 @@
|
||||
// run-rustfix
|
||||
|
||||
// This test is to check if suggestions can be applied automatically.
|
||||
|
||||
#![allow(dead_code, unused_parens)]
|
||||
|
||||
fn main() {}
|
||||
|
||||
fn test_and() {
|
||||
let a = true;
|
||||
let b = false;
|
||||
|
||||
let _ = a && b; //~ ERROR `and` is not a logical operator
|
||||
//~| ERROR `and` is not a logical operator
|
||||
|
||||
if a && b { //~ ERROR `and` is not a logical operator
|
||||
//~| ERROR `and` is not a logical operator
|
||||
println!("both");
|
||||
}
|
||||
}
|
||||
|
||||
fn test_or() {
|
||||
let a = true;
|
||||
let b = false;
|
||||
|
||||
let _ = a || b; //~ ERROR `or` is not a logical operator
|
||||
//~| ERROR `or` is not a logical operator
|
||||
|
||||
if a || b { //~ ERROR `or` is not a logical operator
|
||||
//~| ERROR `or` is not a logical operator
|
||||
println!("both");
|
||||
}
|
||||
}
|
||||
|
||||
fn test_and_par() {
|
||||
let a = true;
|
||||
let b = false;
|
||||
if (a && b) { //~ ERROR `and` is not a logical operator
|
||||
//~| ERROR `and` is not a logical operator
|
||||
println!("both");
|
||||
}
|
||||
}
|
||||
|
||||
fn test_or_par() {
|
||||
let a = true;
|
||||
let b = false;
|
||||
if (a || b) { //~ ERROR `or` is not a logical operator
|
||||
//~| ERROR `or` is not a logical operator
|
||||
println!("both");
|
||||
}
|
||||
}
|
||||
|
||||
fn test_while_and() {
|
||||
let a = true;
|
||||
let b = false;
|
||||
while a && b { //~ ERROR `and` is not a logical operator
|
||||
//~| ERROR `and` is not a logical operator
|
||||
println!("both");
|
||||
}
|
||||
}
|
||||
|
||||
fn test_while_or() {
|
||||
let a = true;
|
||||
let b = false;
|
||||
while a || b { //~ ERROR `or` is not a logical operator
|
||||
//~| ERROR `or` is not a logical operator
|
||||
println!("both");
|
||||
}
|
||||
}
|
69
src/test/ui/did_you_mean/issue-54109-without-witness.rs
Normal file
69
src/test/ui/did_you_mean/issue-54109-without-witness.rs
Normal file
@ -0,0 +1,69 @@
|
||||
// run-rustfix
|
||||
|
||||
// This test is to check if suggestions can be applied automatically.
|
||||
|
||||
#![allow(dead_code, unused_parens)]
|
||||
|
||||
fn main() {}
|
||||
|
||||
fn test_and() {
|
||||
let a = true;
|
||||
let b = false;
|
||||
|
||||
let _ = a and b; //~ ERROR `and` is not a logical operator
|
||||
//~| ERROR `and` is not a logical operator
|
||||
|
||||
if a and b { //~ ERROR `and` is not a logical operator
|
||||
//~| ERROR `and` is not a logical operator
|
||||
println!("both");
|
||||
}
|
||||
}
|
||||
|
||||
fn test_or() {
|
||||
let a = true;
|
||||
let b = false;
|
||||
|
||||
let _ = a or b; //~ ERROR `or` is not a logical operator
|
||||
//~| ERROR `or` is not a logical operator
|
||||
|
||||
if a or b { //~ ERROR `or` is not a logical operator
|
||||
//~| ERROR `or` is not a logical operator
|
||||
println!("both");
|
||||
}
|
||||
}
|
||||
|
||||
fn test_and_par() {
|
||||
let a = true;
|
||||
let b = false;
|
||||
if (a and b) { //~ ERROR `and` is not a logical operator
|
||||
//~| ERROR `and` is not a logical operator
|
||||
println!("both");
|
||||
}
|
||||
}
|
||||
|
||||
fn test_or_par() {
|
||||
let a = true;
|
||||
let b = false;
|
||||
if (a or b) { //~ ERROR `or` is not a logical operator
|
||||
//~| ERROR `or` is not a logical operator
|
||||
println!("both");
|
||||
}
|
||||
}
|
||||
|
||||
fn test_while_and() {
|
||||
let a = true;
|
||||
let b = false;
|
||||
while a and b { //~ ERROR `and` is not a logical operator
|
||||
//~| ERROR `and` is not a logical operator
|
||||
println!("both");
|
||||
}
|
||||
}
|
||||
|
||||
fn test_while_or() {
|
||||
let a = true;
|
||||
let b = false;
|
||||
while a or b { //~ ERROR `or` is not a logical operator
|
||||
//~| ERROR `or` is not a logical operator
|
||||
println!("both");
|
||||
}
|
||||
}
|
130
src/test/ui/did_you_mean/issue-54109-without-witness.stderr
Normal file
130
src/test/ui/did_you_mean/issue-54109-without-witness.stderr
Normal file
@ -0,0 +1,130 @@
|
||||
error: `and` is not a logical operator
|
||||
--> $DIR/issue-54109-without-witness.rs:13:15
|
||||
|
|
||||
LL | let _ = a and b;
|
||||
| ^^^ help: use `&&` to perform logical conjunction
|
||||
|
|
||||
= note: unlike in e.g., python and PHP, `&&` and `||` are used for logical operators
|
||||
|
||||
error: `and` is not a logical operator
|
||||
--> $DIR/issue-54109-without-witness.rs:13:15
|
||||
|
|
||||
LL | let _ = a and b;
|
||||
| ^^^ help: use `&&` to perform logical conjunction
|
||||
|
|
||||
= note: unlike in e.g., python and PHP, `&&` and `||` are used for logical operators
|
||||
|
||||
error: `and` is not a logical operator
|
||||
--> $DIR/issue-54109-without-witness.rs:16:10
|
||||
|
|
||||
LL | if a and b {
|
||||
| ^^^ help: use `&&` to perform logical conjunction
|
||||
|
|
||||
= note: unlike in e.g., python and PHP, `&&` and `||` are used for logical operators
|
||||
|
||||
error: `and` is not a logical operator
|
||||
--> $DIR/issue-54109-without-witness.rs:16:10
|
||||
|
|
||||
LL | if a and b {
|
||||
| ^^^ help: use `&&` to perform logical conjunction
|
||||
|
|
||||
= note: unlike in e.g., python and PHP, `&&` and `||` are used for logical operators
|
||||
|
||||
error: `or` is not a logical operator
|
||||
--> $DIR/issue-54109-without-witness.rs:26:15
|
||||
|
|
||||
LL | let _ = a or b;
|
||||
| ^^ help: use `||` to perform logical disjunction
|
||||
|
|
||||
= note: unlike in e.g., python and PHP, `&&` and `||` are used for logical operators
|
||||
|
||||
error: `or` is not a logical operator
|
||||
--> $DIR/issue-54109-without-witness.rs:26:15
|
||||
|
|
||||
LL | let _ = a or b;
|
||||
| ^^ help: use `||` to perform logical disjunction
|
||||
|
|
||||
= note: unlike in e.g., python and PHP, `&&` and `||` are used for logical operators
|
||||
|
||||
error: `or` is not a logical operator
|
||||
--> $DIR/issue-54109-without-witness.rs:29:10
|
||||
|
|
||||
LL | if a or b {
|
||||
| ^^ help: use `||` to perform logical disjunction
|
||||
|
|
||||
= note: unlike in e.g., python and PHP, `&&` and `||` are used for logical operators
|
||||
|
||||
error: `or` is not a logical operator
|
||||
--> $DIR/issue-54109-without-witness.rs:29:10
|
||||
|
|
||||
LL | if a or b {
|
||||
| ^^ help: use `||` to perform logical disjunction
|
||||
|
|
||||
= note: unlike in e.g., python and PHP, `&&` and `||` are used for logical operators
|
||||
|
||||
error: `and` is not a logical operator
|
||||
--> $DIR/issue-54109-without-witness.rs:38:11
|
||||
|
|
||||
LL | if (a and b) {
|
||||
| ^^^ help: use `&&` to perform logical conjunction
|
||||
|
|
||||
= note: unlike in e.g., python and PHP, `&&` and `||` are used for logical operators
|
||||
|
||||
error: `and` is not a logical operator
|
||||
--> $DIR/issue-54109-without-witness.rs:38:11
|
||||
|
|
||||
LL | if (a and b) {
|
||||
| ^^^ help: use `&&` to perform logical conjunction
|
||||
|
|
||||
= note: unlike in e.g., python and PHP, `&&` and `||` are used for logical operators
|
||||
|
||||
error: `or` is not a logical operator
|
||||
--> $DIR/issue-54109-without-witness.rs:47:11
|
||||
|
|
||||
LL | if (a or b) {
|
||||
| ^^ help: use `||` to perform logical disjunction
|
||||
|
|
||||
= note: unlike in e.g., python and PHP, `&&` and `||` are used for logical operators
|
||||
|
||||
error: `or` is not a logical operator
|
||||
--> $DIR/issue-54109-without-witness.rs:47:11
|
||||
|
|
||||
LL | if (a or b) {
|
||||
| ^^ help: use `||` to perform logical disjunction
|
||||
|
|
||||
= note: unlike in e.g., python and PHP, `&&` and `||` are used for logical operators
|
||||
|
||||
error: `and` is not a logical operator
|
||||
--> $DIR/issue-54109-without-witness.rs:56:13
|
||||
|
|
||||
LL | while a and b {
|
||||
| ^^^ help: use `&&` to perform logical conjunction
|
||||
|
|
||||
= note: unlike in e.g., python and PHP, `&&` and `||` are used for logical operators
|
||||
|
||||
error: `and` is not a logical operator
|
||||
--> $DIR/issue-54109-without-witness.rs:56:13
|
||||
|
|
||||
LL | while a and b {
|
||||
| ^^^ help: use `&&` to perform logical conjunction
|
||||
|
|
||||
= note: unlike in e.g., python and PHP, `&&` and `||` are used for logical operators
|
||||
|
||||
error: `or` is not a logical operator
|
||||
--> $DIR/issue-54109-without-witness.rs:65:13
|
||||
|
|
||||
LL | while a or b {
|
||||
| ^^ help: use `||` to perform logical disjunction
|
||||
|
|
||||
= note: unlike in e.g., python and PHP, `&&` and `||` are used for logical operators
|
||||
|
||||
error: `or` is not a logical operator
|
||||
--> $DIR/issue-54109-without-witness.rs:65:13
|
||||
|
|
||||
LL | while a or b {
|
||||
| ^^ help: use `||` to perform logical disjunction
|
||||
|
|
||||
= note: unlike in e.g., python and PHP, `&&` and `||` are used for logical operators
|
||||
|
||||
error: aborting due to 16 previous errors
|
||||
|
20
src/test/ui/error-codes/E0642.fixed
Normal file
20
src/test/ui/error-codes/E0642.fixed
Normal file
@ -0,0 +1,20 @@
|
||||
// run-rustfix
|
||||
|
||||
#![allow(unused)] // for rustfix
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
struct S;
|
||||
|
||||
trait T {
|
||||
fn foo(_: (i32, i32)); //~ ERROR patterns aren't allowed in methods without bodies
|
||||
|
||||
fn bar(_: (i32, i32)) {} //~ ERROR patterns aren't allowed in methods without bodies
|
||||
|
||||
fn method(_: S) {} //~ ERROR patterns aren't allowed in methods without bodies
|
||||
|
||||
fn f(&ident: &S) {} // ok
|
||||
fn g(&&ident: &&S) {} // ok
|
||||
fn h(mut ident: S) {} // ok
|
||||
}
|
||||
|
||||
fn main() {}
|
@ -1,3 +1,7 @@
|
||||
// run-rustfix
|
||||
|
||||
#![allow(unused)] // for rustfix
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
struct S;
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
error[E0642]: patterns aren't allowed in methods without bodies
|
||||
--> $DIR/E0642.rs:5:12
|
||||
--> $DIR/E0642.rs:9:12
|
||||
|
|
||||
LL | fn foo((x, y): (i32, i32));
|
||||
| ^^^^^^
|
||||
@ -10,7 +10,7 @@ LL | fn foo(_: (i32, i32));
|
||||
| ^
|
||||
|
||||
error[E0642]: patterns aren't allowed in methods without bodies
|
||||
--> $DIR/E0642.rs:7:12
|
||||
--> $DIR/E0642.rs:11:12
|
||||
|
|
||||
LL | fn bar((x, y): (i32, i32)) {}
|
||||
| ^^^^^^
|
||||
@ -21,7 +21,7 @@ LL | fn bar(_: (i32, i32)) {}
|
||||
| ^
|
||||
|
||||
error[E0642]: patterns aren't allowed in methods without bodies
|
||||
--> $DIR/E0642.rs:9:15
|
||||
--> $DIR/E0642.rs:13:15
|
||||
|
|
||||
LL | fn method(S { .. }: S) {}
|
||||
| ^^^^^^^^
|
||||
|
17
src/test/ui/generic/generic-no-mangle.fixed
Normal file
17
src/test/ui/generic/generic-no-mangle.fixed
Normal file
@ -0,0 +1,17 @@
|
||||
// run-rustfix
|
||||
|
||||
#![deny(no_mangle_generic_items)]
|
||||
|
||||
|
||||
pub fn foo<T>() {} //~ ERROR functions generic over types or consts must be mangled
|
||||
|
||||
|
||||
pub extern fn bar<T>() {} //~ ERROR functions generic over types or consts must be mangled
|
||||
|
||||
#[no_mangle]
|
||||
pub fn baz(x: &i32) -> &i32 { x }
|
||||
|
||||
#[no_mangle]
|
||||
pub fn qux<'a>(x: &'a i32) -> &i32 { x }
|
||||
|
||||
fn main() {}
|
@ -1,3 +1,5 @@
|
||||
// run-rustfix
|
||||
|
||||
#![deny(no_mangle_generic_items)]
|
||||
|
||||
#[no_mangle]
|
||||
|
@ -1,5 +1,5 @@
|
||||
error: functions generic over types or consts must be mangled
|
||||
--> $DIR/generic-no-mangle.rs:4:1
|
||||
--> $DIR/generic-no-mangle.rs:6:1
|
||||
|
|
||||
LL | #[no_mangle]
|
||||
| ------------ help: remove this attribute
|
||||
@ -7,13 +7,13 @@ LL | pub fn foo<T>() {}
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: the lint level is defined here
|
||||
--> $DIR/generic-no-mangle.rs:1:9
|
||||
--> $DIR/generic-no-mangle.rs:3:9
|
||||
|
|
||||
LL | #![deny(no_mangle_generic_items)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: functions generic over types or consts must be mangled
|
||||
--> $DIR/generic-no-mangle.rs:7:1
|
||||
--> $DIR/generic-no-mangle.rs:9:1
|
||||
|
|
||||
LL | #[no_mangle]
|
||||
| ------------ help: remove this attribute
|
||||
|
20
src/test/ui/impossible_range.fixed
Normal file
20
src/test/ui/impossible_range.fixed
Normal file
@ -0,0 +1,20 @@
|
||||
// run-rustfix
|
||||
// Make sure that invalid ranges generate an error during parsing, not an ICE
|
||||
|
||||
#![allow(path_statements)]
|
||||
|
||||
pub fn main() {
|
||||
..;
|
||||
0..;
|
||||
..1;
|
||||
0..1;
|
||||
..; //~ERROR inclusive range with no end
|
||||
//~^HELP use `..` instead
|
||||
}
|
||||
|
||||
fn _foo1() {
|
||||
..=1;
|
||||
0..=1;
|
||||
0..; //~ERROR inclusive range with no end
|
||||
//~^HELP use `..` instead
|
||||
}
|
@ -1,5 +1,8 @@
|
||||
// run-rustfix
|
||||
// Make sure that invalid ranges generate an error during parsing, not an ICE
|
||||
|
||||
#![allow(path_statements)]
|
||||
|
||||
pub fn main() {
|
||||
..;
|
||||
0..;
|
||||
|
@ -1,5 +1,5 @@
|
||||
error[E0586]: inclusive range with no end
|
||||
--> $DIR/impossible_range.rs:8:5
|
||||
--> $DIR/impossible_range.rs:11:5
|
||||
|
|
||||
LL | ..=;
|
||||
| ^^^ help: use `..` instead
|
||||
@ -7,7 +7,7 @@ LL | ..=;
|
||||
= note: inclusive ranges must be bounded at the end (`..=b` or `a..=b`)
|
||||
|
||||
error[E0586]: inclusive range with no end
|
||||
--> $DIR/impossible_range.rs:15:6
|
||||
--> $DIR/impossible_range.rs:18:6
|
||||
|
|
||||
LL | 0..=;
|
||||
| ^^^ help: use `..` instead
|
||||
|
10
src/test/ui/issues/issue-1962.fixed
Normal file
10
src/test/ui/issues/issue-1962.fixed
Normal file
@ -0,0 +1,10 @@
|
||||
// compile-flags: -D while-true
|
||||
// run-rustfix
|
||||
|
||||
fn main() {
|
||||
let mut i = 0;
|
||||
loop { //~ ERROR denote infinite loops with `loop
|
||||
i += 1;
|
||||
if i == 5 { break; }
|
||||
}
|
||||
}
|
@ -1,8 +1,10 @@
|
||||
// compile-flags: -D while-true
|
||||
// run-rustfix
|
||||
|
||||
fn main() {
|
||||
let mut i = 0;
|
||||
while true { //~ ERROR denote infinite loops with `loop
|
||||
i += 1;
|
||||
if i == 5 { break; }
|
||||
}
|
||||
let mut i = 0;
|
||||
while true { //~ ERROR denote infinite loops with `loop
|
||||
i += 1;
|
||||
if i == 5 { break; }
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
error: denote infinite loops with `loop { ... }`
|
||||
--> $DIR/issue-1962.rs:4:3
|
||||
--> $DIR/issue-1962.rs:6:5
|
||||
|
|
||||
LL | while true {
|
||||
| ^^^^^^^^^^ help: use `loop`
|
||||
LL | while true {
|
||||
| ^^^^^^^^^^ help: use `loop`
|
||||
|
|
||||
= note: requested on the command line with `-D while-true`
|
||||
|
||||
|
6
src/test/ui/issues/issue-40782.fixed
Normal file
6
src/test/ui/issues/issue-40782.fixed
Normal file
@ -0,0 +1,6 @@
|
||||
// run-rustfix
|
||||
|
||||
fn main() {
|
||||
for _i in 0..2 { //~ ERROR missing `in`
|
||||
}
|
||||
}
|
@ -1,4 +1,6 @@
|
||||
// run-rustfix
|
||||
|
||||
fn main() {
|
||||
for i 0..2 { //~ ERROR missing `in`
|
||||
for _i 0..2 { //~ ERROR missing `in`
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
error: missing `in` in `for` loop
|
||||
--> $DIR/issue-40782.rs:2:10
|
||||
--> $DIR/issue-40782.rs:4:11
|
||||
|
|
||||
LL | for i 0..2 {
|
||||
| ^ help: try adding `in` here
|
||||
LL | for _i 0..2 {
|
||||
| ^ help: try adding `in` here
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
8
src/test/ui/issues/issue-46186.fixed
Normal file
8
src/test/ui/issues/issue-46186.fixed
Normal file
@ -0,0 +1,8 @@
|
||||
// run-rustfix
|
||||
|
||||
pub struct Struct {
|
||||
pub a: usize,
|
||||
}
|
||||
//~^ ERROR expected item, found `;`
|
||||
|
||||
fn main() {}
|
@ -1,5 +1,7 @@
|
||||
struct Struct {
|
||||
a: usize,
|
||||
// run-rustfix
|
||||
|
||||
pub struct Struct {
|
||||
pub a: usize,
|
||||
};
|
||||
//~^ ERROR expected item, found `;`
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
error: expected item, found `;`
|
||||
--> $DIR/issue-46186.rs:3:2
|
||||
--> $DIR/issue-46186.rs:5:2
|
||||
|
|
||||
LL | };
|
||||
| ^ help: remove this semicolon
|
||||
|
8
src/test/ui/issues/issue-50571.fixed
Normal file
8
src/test/ui/issues/issue-50571.fixed
Normal file
@ -0,0 +1,8 @@
|
||||
// run-rustfix
|
||||
|
||||
trait Foo {
|
||||
fn foo(_: [i32; 2]) {}
|
||||
//~^ ERROR: patterns aren't allowed in methods without bodies
|
||||
}
|
||||
|
||||
fn main() {}
|
@ -1,3 +1,5 @@
|
||||
// run-rustfix
|
||||
|
||||
trait Foo {
|
||||
fn foo([a, b]: [i32; 2]) {}
|
||||
//~^ ERROR: patterns aren't allowed in methods without bodies
|
||||
|
@ -1,5 +1,5 @@
|
||||
error[E0642]: patterns aren't allowed in methods without bodies
|
||||
--> $DIR/issue-50571.rs:2:12
|
||||
--> $DIR/issue-50571.rs:4:12
|
||||
|
|
||||
LL | fn foo([a, b]: [i32; 2]) {}
|
||||
| ^^^^^^
|
||||
|
107
src/test/ui/lint/issue-54538-unused-parens-lint.fixed
Normal file
107
src/test/ui/lint/issue-54538-unused-parens-lint.fixed
Normal file
@ -0,0 +1,107 @@
|
||||
// run-rustfix
|
||||
|
||||
#![feature(box_patterns, stmt_expr_attributes)]
|
||||
#![feature(or_patterns)]
|
||||
|
||||
#![allow(
|
||||
dead_code,
|
||||
ellipsis_inclusive_range_patterns,
|
||||
irrefutable_let_patterns,
|
||||
unreachable_patterns,
|
||||
unused_mut,
|
||||
unused_variables
|
||||
)]
|
||||
#![deny(unused_parens)]
|
||||
|
||||
fn lint_on_top_level() {
|
||||
let a = 0; //~ ERROR unnecessary parentheses around pattern
|
||||
for a in 0..1 {} //~ ERROR unnecessary parentheses around pattern
|
||||
if let a = 0 {} //~ ERROR unnecessary parentheses around pattern
|
||||
while let a = 0 {} //~ ERROR unnecessary parentheses around pattern
|
||||
fn foo(a: u8) {} //~ ERROR unnecessary parentheses around pattern
|
||||
let _ = |a: u8| 0; //~ ERROR unnecessary parentheses around pattern
|
||||
}
|
||||
|
||||
fn _no_lint_attr() {
|
||||
let _x = #[allow(dead_code)] (1 + 2);
|
||||
}
|
||||
|
||||
// Don't lint in these cases (#64106).
|
||||
fn or_patterns_no_lint() {
|
||||
match Box::new(0) {
|
||||
box (0 | 1) => {} // Should not lint as `box 0 | 1` binds as `(box 0) | 1`.
|
||||
_ => {}
|
||||
}
|
||||
|
||||
match 0 {
|
||||
x @ (0 | 1) => {} // Should not lint as `x @ 0 | 1` binds as `(x @ 0) | 1`.
|
||||
_ => {}
|
||||
}
|
||||
|
||||
if let &(0 | 1) = &0 {} // Should also not lint.
|
||||
if let &mut (0 | 1) = &mut 0 {} // Same.
|
||||
|
||||
fn foo((Ok(a) | Err(a)): Result<u8, u8>) {} // Doesn't parse if we remove parens for now.
|
||||
|
||||
let _ = |(Ok(a) | Err(a)): Result<u8, u8>| 1; // `|Ok(a) | Err(a)| 1` parses as bit-or.
|
||||
}
|
||||
|
||||
fn or_patterns_will_lint() {
|
||||
if let 0 | 1 = 0 {} //~ ERROR unnecessary parentheses around pattern
|
||||
if let (0 | 1,) = (0,) {} //~ ERROR unnecessary parentheses around pattern
|
||||
if let [0 | 1] = [0] {} //~ ERROR unnecessary parentheses around pattern
|
||||
if let 0 | 1 | 2 = 0 {} //~ ERROR unnecessary parentheses around pattern
|
||||
struct TS(u8);
|
||||
if let TS(0 | 1) = TS(0) {} //~ ERROR unnecessary parentheses around pattern
|
||||
struct NS { f: u8 }
|
||||
if let NS { f: 0 | 1 } = (NS { f: 0 }) {} //~ ERROR unnecessary parentheses around pattern
|
||||
}
|
||||
|
||||
// Don't lint on `&(mut x)` because `&mut x` means something else (#55342).
|
||||
fn deref_mut_binding_no_lint() {
|
||||
let &(mut x) = &0;
|
||||
}
|
||||
|
||||
fn main() {
|
||||
match 1 {
|
||||
_ => {} //~ ERROR unnecessary parentheses around pattern
|
||||
y => {} //~ ERROR unnecessary parentheses around pattern
|
||||
ref r => {} //~ ERROR unnecessary parentheses around pattern
|
||||
e @ 1...2 => {} //~ ERROR unnecessary parentheses around pattern
|
||||
(1...2) => {} // Non ambiguous range pattern should not warn
|
||||
e @ (3...4) => {} // Non ambiguous range pattern should not warn
|
||||
}
|
||||
|
||||
match &1 {
|
||||
e @ &(1...2) => {} //~ ERROR unnecessary parentheses around pattern
|
||||
&_ => {} //~ ERROR unnecessary parentheses around pattern
|
||||
e @ &(1...2) => {} // Ambiguous range pattern should not warn
|
||||
&(1...2) => {} // Ambiguous range pattern should not warn
|
||||
}
|
||||
|
||||
match &1 {
|
||||
e @ &(1...2) | e @ &(3...4) => {} // Complex ambiguous pattern should not warn
|
||||
&_ => {}
|
||||
}
|
||||
|
||||
match 1 {
|
||||
_ => {} //~ ERROR unnecessary parentheses around pattern
|
||||
y => {} //~ ERROR unnecessary parentheses around pattern
|
||||
ref r => {} //~ ERROR unnecessary parentheses around pattern
|
||||
e @ 1..=2 => {} //~ ERROR unnecessary parentheses around pattern
|
||||
(1..=2) => {} // Non ambiguous range pattern should not warn
|
||||
e @ (3..=4) => {} // Non ambiguous range pattern should not warn
|
||||
}
|
||||
|
||||
match &1 {
|
||||
e @ &(1..=2) => {} //~ ERROR unnecessary parentheses around pattern
|
||||
&_ => {} //~ ERROR unnecessary parentheses around pattern
|
||||
e @ &(1..=2) => {} // Ambiguous range pattern should not warn
|
||||
&(1..=2) => {} // Ambiguous range pattern should not warn
|
||||
}
|
||||
|
||||
match &1 {
|
||||
e @ &(1..=2) | e @ &(3..=4) => {} // Complex ambiguous pattern should not warn
|
||||
&_ => {}
|
||||
}
|
||||
}
|
@ -1,10 +1,16 @@
|
||||
#![feature(box_patterns, stmt_expr_attributes)]
|
||||
// run-rustfix
|
||||
|
||||
#![feature(box_patterns, stmt_expr_attributes)]
|
||||
#![feature(or_patterns)]
|
||||
|
||||
#![allow(ellipsis_inclusive_range_patterns)]
|
||||
#![allow(unreachable_patterns)]
|
||||
#![allow(unused_variables)]
|
||||
#![allow(
|
||||
dead_code,
|
||||
ellipsis_inclusive_range_patterns,
|
||||
irrefutable_let_patterns,
|
||||
unreachable_patterns,
|
||||
unused_mut,
|
||||
unused_variables
|
||||
)]
|
||||
#![deny(unused_parens)]
|
||||
|
||||
fn lint_on_top_level() {
|
||||
|
@ -1,149 +1,149 @@
|
||||
error: unnecessary parentheses around pattern
|
||||
--> $DIR/issue-54538-unused-parens-lint.rs:11:9
|
||||
--> $DIR/issue-54538-unused-parens-lint.rs:17:9
|
||||
|
|
||||
LL | let (a) = 0;
|
||||
| ^^^ help: remove these parentheses
|
||||
|
|
||||
note: the lint level is defined here
|
||||
--> $DIR/issue-54538-unused-parens-lint.rs:8:9
|
||||
--> $DIR/issue-54538-unused-parens-lint.rs:14:9
|
||||
|
|
||||
LL | #![deny(unused_parens)]
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: unnecessary parentheses around pattern
|
||||
--> $DIR/issue-54538-unused-parens-lint.rs:12:9
|
||||
--> $DIR/issue-54538-unused-parens-lint.rs:18:9
|
||||
|
|
||||
LL | for (a) in 0..1 {}
|
||||
| ^^^ help: remove these parentheses
|
||||
|
||||
error: unnecessary parentheses around pattern
|
||||
--> $DIR/issue-54538-unused-parens-lint.rs:13:12
|
||||
--> $DIR/issue-54538-unused-parens-lint.rs:19:12
|
||||
|
|
||||
LL | if let (a) = 0 {}
|
||||
| ^^^ help: remove these parentheses
|
||||
|
||||
error: unnecessary parentheses around pattern
|
||||
--> $DIR/issue-54538-unused-parens-lint.rs:14:15
|
||||
--> $DIR/issue-54538-unused-parens-lint.rs:20:15
|
||||
|
|
||||
LL | while let (a) = 0 {}
|
||||
| ^^^ help: remove these parentheses
|
||||
|
||||
error: unnecessary parentheses around pattern
|
||||
--> $DIR/issue-54538-unused-parens-lint.rs:15:12
|
||||
--> $DIR/issue-54538-unused-parens-lint.rs:21:12
|
||||
|
|
||||
LL | fn foo((a): u8) {}
|
||||
| ^^^ help: remove these parentheses
|
||||
|
||||
error: unnecessary parentheses around pattern
|
||||
--> $DIR/issue-54538-unused-parens-lint.rs:16:14
|
||||
--> $DIR/issue-54538-unused-parens-lint.rs:22:14
|
||||
|
|
||||
LL | let _ = |(a): u8| 0;
|
||||
| ^^^ help: remove these parentheses
|
||||
|
||||
error: unnecessary parentheses around pattern
|
||||
--> $DIR/issue-54538-unused-parens-lint.rs:44:12
|
||||
--> $DIR/issue-54538-unused-parens-lint.rs:50:12
|
||||
|
|
||||
LL | if let (0 | 1) = 0 {}
|
||||
| ^^^^^^^ help: remove these parentheses
|
||||
|
||||
error: unnecessary parentheses around pattern
|
||||
--> $DIR/issue-54538-unused-parens-lint.rs:45:13
|
||||
--> $DIR/issue-54538-unused-parens-lint.rs:51:13
|
||||
|
|
||||
LL | if let ((0 | 1),) = (0,) {}
|
||||
| ^^^^^^^ help: remove these parentheses
|
||||
|
||||
error: unnecessary parentheses around pattern
|
||||
--> $DIR/issue-54538-unused-parens-lint.rs:46:13
|
||||
--> $DIR/issue-54538-unused-parens-lint.rs:52:13
|
||||
|
|
||||
LL | if let [(0 | 1)] = [0] {}
|
||||
| ^^^^^^^ help: remove these parentheses
|
||||
|
||||
error: unnecessary parentheses around pattern
|
||||
--> $DIR/issue-54538-unused-parens-lint.rs:47:16
|
||||
--> $DIR/issue-54538-unused-parens-lint.rs:53:16
|
||||
|
|
||||
LL | if let 0 | (1 | 2) = 0 {}
|
||||
| ^^^^^^^ help: remove these parentheses
|
||||
|
||||
error: unnecessary parentheses around pattern
|
||||
--> $DIR/issue-54538-unused-parens-lint.rs:49:15
|
||||
--> $DIR/issue-54538-unused-parens-lint.rs:55:15
|
||||
|
|
||||
LL | if let TS((0 | 1)) = TS(0) {}
|
||||
| ^^^^^^^ help: remove these parentheses
|
||||
|
||||
error: unnecessary parentheses around pattern
|
||||
--> $DIR/issue-54538-unused-parens-lint.rs:51:20
|
||||
--> $DIR/issue-54538-unused-parens-lint.rs:57:20
|
||||
|
|
||||
LL | if let NS { f: (0 | 1) } = (NS { f: 0 }) {}
|
||||
| ^^^^^^^ help: remove these parentheses
|
||||
|
||||
error: unnecessary parentheses around pattern
|
||||
--> $DIR/issue-54538-unused-parens-lint.rs:61:9
|
||||
--> $DIR/issue-54538-unused-parens-lint.rs:67:9
|
||||
|
|
||||
LL | (_) => {}
|
||||
| ^^^ help: remove these parentheses
|
||||
|
||||
error: unnecessary parentheses around pattern
|
||||
--> $DIR/issue-54538-unused-parens-lint.rs:62:9
|
||||
--> $DIR/issue-54538-unused-parens-lint.rs:68:9
|
||||
|
|
||||
LL | (y) => {}
|
||||
| ^^^ help: remove these parentheses
|
||||
|
||||
error: unnecessary parentheses around pattern
|
||||
--> $DIR/issue-54538-unused-parens-lint.rs:63:9
|
||||
--> $DIR/issue-54538-unused-parens-lint.rs:69:9
|
||||
|
|
||||
LL | (ref r) => {}
|
||||
| ^^^^^^^ help: remove these parentheses
|
||||
|
||||
error: unnecessary parentheses around pattern
|
||||
--> $DIR/issue-54538-unused-parens-lint.rs:64:9
|
||||
--> $DIR/issue-54538-unused-parens-lint.rs:70:9
|
||||
|
|
||||
LL | (e @ 1...2) => {}
|
||||
| ^^^^^^^^^^^ help: remove these parentheses
|
||||
|
||||
error: unnecessary parentheses around pattern
|
||||
--> $DIR/issue-54538-unused-parens-lint.rs:70:9
|
||||
--> $DIR/issue-54538-unused-parens-lint.rs:76:9
|
||||
|
|
||||
LL | (e @ &(1...2)) => {}
|
||||
| ^^^^^^^^^^^^^^ help: remove these parentheses
|
||||
|
||||
error: unnecessary parentheses around pattern
|
||||
--> $DIR/issue-54538-unused-parens-lint.rs:71:10
|
||||
--> $DIR/issue-54538-unused-parens-lint.rs:77:10
|
||||
|
|
||||
LL | &(_) => {}
|
||||
| ^^^ help: remove these parentheses
|
||||
|
||||
error: unnecessary parentheses around pattern
|
||||
--> $DIR/issue-54538-unused-parens-lint.rs:82:9
|
||||
--> $DIR/issue-54538-unused-parens-lint.rs:88:9
|
||||
|
|
||||
LL | (_) => {}
|
||||
| ^^^ help: remove these parentheses
|
||||
|
||||
error: unnecessary parentheses around pattern
|
||||
--> $DIR/issue-54538-unused-parens-lint.rs:83:9
|
||||
--> $DIR/issue-54538-unused-parens-lint.rs:89:9
|
||||
|
|
||||
LL | (y) => {}
|
||||
| ^^^ help: remove these parentheses
|
||||
|
||||
error: unnecessary parentheses around pattern
|
||||
--> $DIR/issue-54538-unused-parens-lint.rs:84:9
|
||||
--> $DIR/issue-54538-unused-parens-lint.rs:90:9
|
||||
|
|
||||
LL | (ref r) => {}
|
||||
| ^^^^^^^ help: remove these parentheses
|
||||
|
||||
error: unnecessary parentheses around pattern
|
||||
--> $DIR/issue-54538-unused-parens-lint.rs:85:9
|
||||
--> $DIR/issue-54538-unused-parens-lint.rs:91:9
|
||||
|
|
||||
LL | (e @ 1..=2) => {}
|
||||
| ^^^^^^^^^^^ help: remove these parentheses
|
||||
|
||||
error: unnecessary parentheses around pattern
|
||||
--> $DIR/issue-54538-unused-parens-lint.rs:91:9
|
||||
--> $DIR/issue-54538-unused-parens-lint.rs:97:9
|
||||
|
|
||||
LL | (e @ &(1..=2)) => {}
|
||||
| ^^^^^^^^^^^^^^ help: remove these parentheses
|
||||
|
||||
error: unnecessary parentheses around pattern
|
||||
--> $DIR/issue-54538-unused-parens-lint.rs:92:10
|
||||
--> $DIR/issue-54538-unused-parens-lint.rs:98:10
|
||||
|
|
||||
LL | &(_) => {}
|
||||
| ^^^ help: remove these parentheses
|
||||
|
79
src/test/ui/lint/lint-unnecessary-parens.fixed
Normal file
79
src/test/ui/lint/lint-unnecessary-parens.fixed
Normal file
@ -0,0 +1,79 @@
|
||||
// run-rustfix
|
||||
|
||||
#![deny(unused_parens)]
|
||||
#![allow(while_true)] // for rustfix
|
||||
|
||||
#[derive(Eq, PartialEq)]
|
||||
struct X { y: bool }
|
||||
impl X {
|
||||
fn foo(&self, conjunct: bool) -> bool { self.y && conjunct }
|
||||
}
|
||||
|
||||
fn foo() -> isize {
|
||||
return 1; //~ ERROR unnecessary parentheses around `return` value
|
||||
}
|
||||
fn bar(y: bool) -> X {
|
||||
return X { y }; //~ ERROR unnecessary parentheses around `return` value
|
||||
}
|
||||
|
||||
pub fn unused_parens_around_return_type() -> u32 { //~ ERROR unnecessary parentheses around type
|
||||
panic!()
|
||||
}
|
||||
|
||||
pub fn unused_parens_around_block_return() -> u32 {
|
||||
let _foo = {
|
||||
5 //~ ERROR unnecessary parentheses around block return value
|
||||
};
|
||||
5 //~ ERROR unnecessary parentheses around block return value
|
||||
}
|
||||
|
||||
pub trait Trait {
|
||||
fn test(&self);
|
||||
}
|
||||
|
||||
pub fn passes_unused_parens_lint() -> &'static (dyn Trait) {
|
||||
panic!()
|
||||
}
|
||||
|
||||
macro_rules! baz {
|
||||
($($foo:expr),+) => {
|
||||
($($foo),*)
|
||||
}
|
||||
}
|
||||
|
||||
pub const CONST_ITEM: usize = 10; //~ ERROR unnecessary parentheses around assigned value
|
||||
pub static STATIC_ITEM: usize = 10; //~ ERROR unnecessary parentheses around assigned value
|
||||
|
||||
fn main() {
|
||||
foo();
|
||||
bar(true); //~ ERROR unnecessary parentheses around function argument
|
||||
|
||||
if true {} //~ ERROR unnecessary parentheses around `if` condition
|
||||
while true {} //~ ERROR unnecessary parentheses around `while` condition
|
||||
match true { //~ ERROR unnecessary parentheses around `match` scrutinee expression
|
||||
_ => {}
|
||||
}
|
||||
if let 1 = 1 {} //~ ERROR unnecessary parentheses around `let` scrutinee expression
|
||||
while let 1 = 2 {} //~ ERROR unnecessary parentheses around `let` scrutinee expression
|
||||
let v = X { y: false };
|
||||
// struct lits needs parens, so these shouldn't warn.
|
||||
if (v == X { y: true }) {}
|
||||
if (X { y: true } == v) {}
|
||||
if (X { y: false }.y) {}
|
||||
|
||||
while (X { y: false }.foo(true)) {}
|
||||
while (true | X { y: false }.y) {}
|
||||
|
||||
match (X { y: false }) {
|
||||
_ => {}
|
||||
}
|
||||
|
||||
X { y: false }.foo(true); //~ ERROR unnecessary parentheses around method argument
|
||||
|
||||
let mut _a = 0; //~ ERROR unnecessary parentheses around assigned value
|
||||
_a = 0; //~ ERROR unnecessary parentheses around assigned value
|
||||
_a += 1; //~ ERROR unnecessary parentheses around assigned value
|
||||
|
||||
let _a = baz!(3, 4);
|
||||
let _b = baz!(3);
|
||||
}
|
@ -1,4 +1,7 @@
|
||||
// run-rustfix
|
||||
|
||||
#![deny(unused_parens)]
|
||||
#![allow(while_true)] // for rustfix
|
||||
|
||||
#[derive(Eq, PartialEq)]
|
||||
struct X { y: bool }
|
||||
@ -13,22 +16,22 @@ fn bar(y: bool) -> X {
|
||||
return (X { y }); //~ ERROR unnecessary parentheses around `return` value
|
||||
}
|
||||
|
||||
fn unused_parens_around_return_type() -> (u32) { //~ ERROR unnecessary parentheses around type
|
||||
pub fn unused_parens_around_return_type() -> (u32) { //~ ERROR unnecessary parentheses around type
|
||||
panic!()
|
||||
}
|
||||
|
||||
fn unused_parens_around_block_return() -> u32 {
|
||||
let foo = {
|
||||
pub fn unused_parens_around_block_return() -> u32 {
|
||||
let _foo = {
|
||||
(5) //~ ERROR unnecessary parentheses around block return value
|
||||
};
|
||||
(5) //~ ERROR unnecessary parentheses around block return value
|
||||
}
|
||||
|
||||
trait Trait {
|
||||
pub trait Trait {
|
||||
fn test(&self);
|
||||
}
|
||||
|
||||
fn passes_unused_parens_lint() -> &'static (dyn Trait) {
|
||||
pub fn passes_unused_parens_lint() -> &'static (dyn Trait) {
|
||||
panic!()
|
||||
}
|
||||
|
||||
@ -38,8 +41,8 @@ macro_rules! baz {
|
||||
}
|
||||
}
|
||||
|
||||
const CONST_ITEM: usize = (10); //~ ERROR unnecessary parentheses around assigned value
|
||||
static STATIC_ITEM: usize = (10); //~ ERROR unnecessary parentheses around assigned value
|
||||
pub const CONST_ITEM: usize = (10); //~ ERROR unnecessary parentheses around assigned value
|
||||
pub static STATIC_ITEM: usize = (10); //~ ERROR unnecessary parentheses around assigned value
|
||||
|
||||
fn main() {
|
||||
foo();
|
||||
@ -47,7 +50,6 @@ fn main() {
|
||||
|
||||
if (true) {} //~ ERROR unnecessary parentheses around `if` condition
|
||||
while (true) {} //~ ERROR unnecessary parentheses around `while` condition
|
||||
//~^ WARN denote infinite loops with
|
||||
match (true) { //~ ERROR unnecessary parentheses around `match` scrutinee expression
|
||||
_ => {}
|
||||
}
|
||||
|
@ -1,118 +1,110 @@
|
||||
error: unnecessary parentheses around `return` value
|
||||
--> $DIR/lint-unnecessary-parens.rs:10:12
|
||||
--> $DIR/lint-unnecessary-parens.rs:13:12
|
||||
|
|
||||
LL | return (1);
|
||||
| ^^^ help: remove these parentheses
|
||||
|
|
||||
note: the lint level is defined here
|
||||
--> $DIR/lint-unnecessary-parens.rs:1:9
|
||||
--> $DIR/lint-unnecessary-parens.rs:3:9
|
||||
|
|
||||
LL | #![deny(unused_parens)]
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: unnecessary parentheses around `return` value
|
||||
--> $DIR/lint-unnecessary-parens.rs:13:12
|
||||
--> $DIR/lint-unnecessary-parens.rs:16:12
|
||||
|
|
||||
LL | return (X { y });
|
||||
| ^^^^^^^^^ help: remove these parentheses
|
||||
|
||||
error: unnecessary parentheses around type
|
||||
--> $DIR/lint-unnecessary-parens.rs:16:42
|
||||
--> $DIR/lint-unnecessary-parens.rs:19:46
|
||||
|
|
||||
LL | fn unused_parens_around_return_type() -> (u32) {
|
||||
| ^^^^^ help: remove these parentheses
|
||||
LL | pub fn unused_parens_around_return_type() -> (u32) {
|
||||
| ^^^^^ help: remove these parentheses
|
||||
|
||||
error: unnecessary parentheses around block return value
|
||||
--> $DIR/lint-unnecessary-parens.rs:22:9
|
||||
--> $DIR/lint-unnecessary-parens.rs:25:9
|
||||
|
|
||||
LL | (5)
|
||||
| ^^^ help: remove these parentheses
|
||||
|
||||
error: unnecessary parentheses around block return value
|
||||
--> $DIR/lint-unnecessary-parens.rs:24:5
|
||||
--> $DIR/lint-unnecessary-parens.rs:27:5
|
||||
|
|
||||
LL | (5)
|
||||
| ^^^ help: remove these parentheses
|
||||
|
||||
error: unnecessary parentheses around assigned value
|
||||
--> $DIR/lint-unnecessary-parens.rs:41:27
|
||||
--> $DIR/lint-unnecessary-parens.rs:44:31
|
||||
|
|
||||
LL | const CONST_ITEM: usize = (10);
|
||||
| ^^^^ help: remove these parentheses
|
||||
LL | pub const CONST_ITEM: usize = (10);
|
||||
| ^^^^ help: remove these parentheses
|
||||
|
||||
error: unnecessary parentheses around assigned value
|
||||
--> $DIR/lint-unnecessary-parens.rs:42:29
|
||||
--> $DIR/lint-unnecessary-parens.rs:45:33
|
||||
|
|
||||
LL | static STATIC_ITEM: usize = (10);
|
||||
| ^^^^ help: remove these parentheses
|
||||
LL | pub static STATIC_ITEM: usize = (10);
|
||||
| ^^^^ help: remove these parentheses
|
||||
|
||||
error: unnecessary parentheses around function argument
|
||||
--> $DIR/lint-unnecessary-parens.rs:46:9
|
||||
--> $DIR/lint-unnecessary-parens.rs:49:9
|
||||
|
|
||||
LL | bar((true));
|
||||
| ^^^^^^ help: remove these parentheses
|
||||
|
||||
error: unnecessary parentheses around `if` condition
|
||||
--> $DIR/lint-unnecessary-parens.rs:48:8
|
||||
--> $DIR/lint-unnecessary-parens.rs:51:8
|
||||
|
|
||||
LL | if (true) {}
|
||||
| ^^^^^^ help: remove these parentheses
|
||||
|
||||
error: unnecessary parentheses around `while` condition
|
||||
--> $DIR/lint-unnecessary-parens.rs:49:11
|
||||
--> $DIR/lint-unnecessary-parens.rs:52:11
|
||||
|
|
||||
LL | while (true) {}
|
||||
| ^^^^^^ help: remove these parentheses
|
||||
|
||||
warning: denote infinite loops with `loop { ... }`
|
||||
--> $DIR/lint-unnecessary-parens.rs:49:5
|
||||
|
|
||||
LL | while (true) {}
|
||||
| ^^^^^^^^^^^^ help: use `loop`
|
||||
|
|
||||
= note: `#[warn(while_true)]` on by default
|
||||
|
||||
error: unnecessary parentheses around `match` scrutinee expression
|
||||
--> $DIR/lint-unnecessary-parens.rs:51:11
|
||||
--> $DIR/lint-unnecessary-parens.rs:53:11
|
||||
|
|
||||
LL | match (true) {
|
||||
| ^^^^^^ help: remove these parentheses
|
||||
|
||||
error: unnecessary parentheses around `let` scrutinee expression
|
||||
--> $DIR/lint-unnecessary-parens.rs:54:16
|
||||
--> $DIR/lint-unnecessary-parens.rs:56:16
|
||||
|
|
||||
LL | if let 1 = (1) {}
|
||||
| ^^^ help: remove these parentheses
|
||||
|
||||
error: unnecessary parentheses around `let` scrutinee expression
|
||||
--> $DIR/lint-unnecessary-parens.rs:55:19
|
||||
--> $DIR/lint-unnecessary-parens.rs:57:19
|
||||
|
|
||||
LL | while let 1 = (2) {}
|
||||
| ^^^ help: remove these parentheses
|
||||
|
||||
error: unnecessary parentheses around method argument
|
||||
--> $DIR/lint-unnecessary-parens.rs:69:24
|
||||
--> $DIR/lint-unnecessary-parens.rs:71:24
|
||||
|
|
||||
LL | X { y: false }.foo((true));
|
||||
| ^^^^^^ help: remove these parentheses
|
||||
|
||||
error: unnecessary parentheses around assigned value
|
||||
--> $DIR/lint-unnecessary-parens.rs:71:18
|
||||
--> $DIR/lint-unnecessary-parens.rs:73:18
|
||||
|
|
||||
LL | let mut _a = (0);
|
||||
| ^^^ help: remove these parentheses
|
||||
|
||||
error: unnecessary parentheses around assigned value
|
||||
--> $DIR/lint-unnecessary-parens.rs:72:10
|
||||
--> $DIR/lint-unnecessary-parens.rs:74:10
|
||||
|
|
||||
LL | _a = (0);
|
||||
| ^^^ help: remove these parentheses
|
||||
|
||||
error: unnecessary parentheses around assigned value
|
||||
--> $DIR/lint-unnecessary-parens.rs:73:11
|
||||
--> $DIR/lint-unnecessary-parens.rs:75:11
|
||||
|
|
||||
LL | _a += (1);
|
||||
| ^^^ help: remove these parentheses
|
||||
|
||||
error: aborting due to 17 previous errors; 1 warning emitted
|
||||
error: aborting due to 17 previous errors
|
||||
|
||||
|
14
src/test/ui/lint/lint-unused-mut-self.fixed
Normal file
14
src/test/ui/lint/lint-unused-mut-self.fixed
Normal file
@ -0,0 +1,14 @@
|
||||
// run-rustfix
|
||||
|
||||
#![allow(unused_assignments)]
|
||||
#![allow(unused_variables)]
|
||||
#![allow(dead_code)]
|
||||
#![deny(unused_mut)]
|
||||
|
||||
struct Foo;
|
||||
impl Foo {
|
||||
fn foo(self) {} //~ ERROR: variable does not need to be mutable
|
||||
fn bar(self: Box<Foo>) {} //~ ERROR: variable does not need to be mutable
|
||||
}
|
||||
|
||||
fn main() {}
|
@ -1,3 +1,5 @@
|
||||
// run-rustfix
|
||||
|
||||
#![allow(unused_assignments)]
|
||||
#![allow(unused_variables)]
|
||||
#![allow(dead_code)]
|
||||
|
@ -1,5 +1,5 @@
|
||||
error: variable does not need to be mutable
|
||||
--> $DIR/lint-unused-mut-self.rs:8:12
|
||||
--> $DIR/lint-unused-mut-self.rs:10:12
|
||||
|
|
||||
LL | fn foo(mut self) {}
|
||||
| ----^^^^
|
||||
@ -7,13 +7,13 @@ LL | fn foo(mut self) {}
|
||||
| help: remove this `mut`
|
||||
|
|
||||
note: the lint level is defined here
|
||||
--> $DIR/lint-unused-mut-self.rs:4:9
|
||||
--> $DIR/lint-unused-mut-self.rs:6:9
|
||||
|
|
||||
LL | #![deny(unused_mut)]
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: variable does not need to be mutable
|
||||
--> $DIR/lint-unused-mut-self.rs:9:12
|
||||
--> $DIR/lint-unused-mut-self.rs:11:12
|
||||
|
|
||||
LL | fn bar(mut self: Box<Foo>) {}
|
||||
| ----^^^^
|
||||
|
@ -92,13 +92,16 @@ fn main() {
|
||||
mut x => {} //~ WARN: variable does not need to be mutable
|
||||
|
||||
}
|
||||
match (30, 2) {
|
||||
(mut x, 1) | //~ WARN: variable does not need to be mutable
|
||||
|
||||
(mut x, 2) |
|
||||
(mut x, 3) => {
|
||||
}
|
||||
_ => {}
|
||||
match (30, 2) {
|
||||
// FIXME: Here's a false positive,
|
||||
// shouldn't be removed `mut` not to be bound with a different way.
|
||||
(mut x, 1) | //~ WARN: variable does not need to be mutable
|
||||
|
||||
(mut x, 2) |
|
||||
(mut x, 3) => {
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
let x = |mut y: isize| 10; //~ WARN: variable does not need to be mutable
|
||||
|
@ -69,7 +69,7 @@ LL | mut a: i32,
|
||||
| help: remove this `mut`
|
||||
|
||||
warning: variable does not need to be mutable
|
||||
--> $DIR/lint-unused-mut-variables.rs:104:14
|
||||
--> $DIR/lint-unused-mut-variables.rs:107:14
|
||||
|
|
||||
LL | let x = |mut y: isize| 10;
|
||||
| ----^
|
||||
@ -141,15 +141,15 @@ LL | mut x => {}
|
||||
| help: remove this `mut`
|
||||
|
||||
warning: variable does not need to be mutable
|
||||
--> $DIR/lint-unused-mut-variables.rs:96:8
|
||||
--> $DIR/lint-unused-mut-variables.rs:99:10
|
||||
|
|
||||
LL | (mut x, 1) |
|
||||
| ----^
|
||||
| |
|
||||
| help: remove this `mut`
|
||||
LL | (mut x, 1) |
|
||||
| ----^
|
||||
| |
|
||||
| help: remove this `mut`
|
||||
|
||||
warning: variable does not need to be mutable
|
||||
--> $DIR/lint-unused-mut-variables.rs:109:9
|
||||
--> $DIR/lint-unused-mut-variables.rs:112:9
|
||||
|
|
||||
LL | let mut a = &mut 5;
|
||||
| ----^
|
||||
@ -157,7 +157,7 @@ LL | let mut a = &mut 5;
|
||||
| help: remove this `mut`
|
||||
|
||||
warning: variable does not need to be mutable
|
||||
--> $DIR/lint-unused-mut-variables.rs:114:9
|
||||
--> $DIR/lint-unused-mut-variables.rs:117:9
|
||||
|
|
||||
LL | let mut b = (&mut a,);
|
||||
| ----^
|
||||
@ -165,7 +165,7 @@ LL | let mut b = (&mut a,);
|
||||
| help: remove this `mut`
|
||||
|
||||
warning: variable does not need to be mutable
|
||||
--> $DIR/lint-unused-mut-variables.rs:117:9
|
||||
--> $DIR/lint-unused-mut-variables.rs:120:9
|
||||
|
|
||||
LL | let mut x = &mut 1;
|
||||
| ----^
|
||||
@ -173,7 +173,7 @@ LL | let mut x = &mut 1;
|
||||
| help: remove this `mut`
|
||||
|
||||
warning: variable does not need to be mutable
|
||||
--> $DIR/lint-unused-mut-variables.rs:129:9
|
||||
--> $DIR/lint-unused-mut-variables.rs:132:9
|
||||
|
|
||||
LL | let mut v : &mut Vec<()> = &mut vec![];
|
||||
| ----^
|
||||
@ -181,7 +181,7 @@ LL | let mut v : &mut Vec<()> = &mut vec![];
|
||||
| help: remove this `mut`
|
||||
|
||||
warning: variable does not need to be mutable
|
||||
--> $DIR/lint-unused-mut-variables.rs:184:9
|
||||
--> $DIR/lint-unused-mut-variables.rs:187:9
|
||||
|
|
||||
LL | let mut raw_address_of_const = 1;
|
||||
| ----^^^^^^^^^^^^^^^^^^^^
|
||||
@ -189,7 +189,7 @@ LL | let mut raw_address_of_const = 1;
|
||||
| help: remove this `mut`
|
||||
|
||||
warning: variable does not need to be mutable
|
||||
--> $DIR/lint-unused-mut-variables.rs:106:13
|
||||
--> $DIR/lint-unused-mut-variables.rs:109:13
|
||||
|
|
||||
LL | fn what(mut foo: isize) {}
|
||||
| ----^^^
|
||||
@ -197,7 +197,7 @@ LL | fn what(mut foo: isize) {}
|
||||
| help: remove this `mut`
|
||||
|
||||
warning: variable does not need to be mutable
|
||||
--> $DIR/lint-unused-mut-variables.rs:124:20
|
||||
--> $DIR/lint-unused-mut-variables.rs:127:20
|
||||
|
|
||||
LL | fn mut_ref_arg(mut arg : &mut [u8]) -> &mut [u8] {
|
||||
| ----^^^
|
||||
@ -205,7 +205,7 @@ LL | fn mut_ref_arg(mut arg : &mut [u8]) -> &mut [u8] {
|
||||
| help: remove this `mut`
|
||||
|
||||
error: variable does not need to be mutable
|
||||
--> $DIR/lint-unused-mut-variables.rs:202:9
|
||||
--> $DIR/lint-unused-mut-variables.rs:205:9
|
||||
|
|
||||
LL | let mut b = vec![2];
|
||||
| ----^
|
||||
@ -213,7 +213,7 @@ LL | let mut b = vec![2];
|
||||
| help: remove this `mut`
|
||||
|
|
||||
note: the lint level is defined here
|
||||
--> $DIR/lint-unused-mut-variables.rs:198:8
|
||||
--> $DIR/lint-unused-mut-variables.rs:201:8
|
||||
|
|
||||
LL | #[deny(unused_mut)]
|
||||
| ^^^^^^^^^^
|
||||
|
66
src/test/ui/lint/suggestions.fixed
Normal file
66
src/test/ui/lint/suggestions.fixed
Normal file
@ -0,0 +1,66 @@
|
||||
// ignore-tidy-tab
|
||||
// run-rustfix
|
||||
|
||||
#![warn(unused_mut, unused_parens)] // UI tests pass `-A unused`—see Issue #43896
|
||||
|
||||
#[no_mangle] pub static DISCOVERY: usize = 1;
|
||||
//~^ ERROR const items should never be `#[no_mangle]`
|
||||
//~| HELP try a static value
|
||||
|
||||
|
||||
//~^ HELP remove this attribute
|
||||
pub fn defiant<T>(_t: T) {}
|
||||
//~^ WARN functions generic over types or consts must be mangled
|
||||
|
||||
#[no_mangle]
|
||||
fn rio_grande() {}
|
||||
|
||||
mod badlands {
|
||||
// The private-no-mangle lints shouldn't suggest inserting `pub` when the
|
||||
// item is already `pub` (but triggered the lint because, e.g., it's in a
|
||||
// private module). (Issue #47383)
|
||||
#[no_mangle] pub static DAUNTLESS: bool = true;
|
||||
//~^ ERROR const items should never be `#[no_mangle]`
|
||||
//~| HELP try a static value
|
||||
#[allow(dead_code)] // for rustfix
|
||||
pub fn val_jean<T>() {}
|
||||
//~^ WARN functions generic over types or consts must be mangled
|
||||
//~| HELP remove this attribute
|
||||
|
||||
// ... but we can suggest just-`pub` instead of restricted
|
||||
#[no_mangle] pub static VETAR: bool = true;
|
||||
//~^ ERROR const items should never be `#[no_mangle]`
|
||||
//~| HELP try a static value
|
||||
#[allow(dead_code)] // for rustfix
|
||||
pub(crate) fn crossfield<T>() {}
|
||||
//~^ WARN functions generic over types or consts must be mangled
|
||||
//~| HELP remove this attribute
|
||||
}
|
||||
|
||||
struct Equinox {
|
||||
warp_factor: f32,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
loop {
|
||||
//~^ WARN denote infinite loops
|
||||
//~| HELP use `loop`
|
||||
let registry_no = format!("NX-{}", 74205);
|
||||
//~^ WARN does not need to be mutable
|
||||
//~| HELP remove this `mut`
|
||||
//~| WARN unnecessary parentheses
|
||||
//~| HELP remove these parentheses
|
||||
// the line after `mut` has a `\t` at the beginning, this is on purpose
|
||||
let b = 1;
|
||||
//~^^ WARN does not need to be mutable
|
||||
//~| HELP remove this `mut`
|
||||
let d = Equinox { warp_factor: 9.975 };
|
||||
match d {
|
||||
#[allow(unused_variables)] // for rustfix
|
||||
Equinox { warp_factor } => {}
|
||||
//~^ WARN this pattern is redundant
|
||||
//~| HELP use shorthand field pattern
|
||||
}
|
||||
println!("{} {}", registry_no, b);
|
||||
}
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
// ignore-tidy-tab
|
||||
// run-rustfix
|
||||
|
||||
#![warn(unused_mut, unused_parens)] // UI tests pass `-A unused`—see Issue #43896
|
||||
|
||||
@ -21,6 +22,7 @@ mod badlands {
|
||||
#[no_mangle] pub const DAUNTLESS: bool = true;
|
||||
//~^ ERROR const items should never be `#[no_mangle]`
|
||||
//~| HELP try a static value
|
||||
#[allow(dead_code)] // for rustfix
|
||||
#[no_mangle] pub fn val_jean<T>() {}
|
||||
//~^ WARN functions generic over types or consts must be mangled
|
||||
//~| HELP remove this attribute
|
||||
@ -29,6 +31,7 @@ mod badlands {
|
||||
#[no_mangle] pub(crate) const VETAR: bool = true;
|
||||
//~^ ERROR const items should never be `#[no_mangle]`
|
||||
//~| HELP try a static value
|
||||
#[allow(dead_code)] // for rustfix
|
||||
#[no_mangle] pub(crate) fn crossfield<T>() {}
|
||||
//~^ WARN functions generic over types or consts must be mangled
|
||||
//~| HELP remove this attribute
|
||||
@ -54,6 +57,7 @@ fn main() {
|
||||
//~| HELP remove this `mut`
|
||||
let d = Equinox { warp_factor: 9.975 };
|
||||
match d {
|
||||
#[allow(unused_variables)] // for rustfix
|
||||
Equinox { warp_factor: warp_factor } => {}
|
||||
//~^ WARN this pattern is redundant
|
||||
//~| HELP use shorthand field pattern
|
||||
|
@ -1,5 +1,5 @@
|
||||
warning: denote infinite loops with `loop { ... }`
|
||||
--> $DIR/suggestions.rs:42:5
|
||||
--> $DIR/suggestions.rs:45:5
|
||||
|
|
||||
LL | while true {
|
||||
| ^^^^^^^^^^ help: use `loop`
|
||||
@ -7,19 +7,19 @@ LL | while true {
|
||||
= note: `#[warn(while_true)]` on by default
|
||||
|
||||
warning: unnecessary parentheses around assigned value
|
||||
--> $DIR/suggestions.rs:45:31
|
||||
--> $DIR/suggestions.rs:48:31
|
||||
|
|
||||
LL | let mut registry_no = (format!("NX-{}", 74205));
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove these parentheses
|
||||
|
|
||||
note: the lint level is defined here
|
||||
--> $DIR/suggestions.rs:3:21
|
||||
--> $DIR/suggestions.rs:4:21
|
||||
|
|
||||
LL | #![warn(unused_mut, unused_parens)] // UI tests pass `-A unused`—see Issue #43896
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
warning: variable does not need to be mutable
|
||||
--> $DIR/suggestions.rs:45:13
|
||||
--> $DIR/suggestions.rs:48:13
|
||||
|
|
||||
LL | let mut registry_no = (format!("NX-{}", 74205));
|
||||
| ----^^^^^^^^^^^
|
||||
@ -27,13 +27,13 @@ LL | let mut registry_no = (format!("NX-{}", 74205));
|
||||
| help: remove this `mut`
|
||||
|
|
||||
note: the lint level is defined here
|
||||
--> $DIR/suggestions.rs:3:9
|
||||
--> $DIR/suggestions.rs:4:9
|
||||
|
|
||||
LL | #![warn(unused_mut, unused_parens)] // UI tests pass `-A unused`—see Issue #43896
|
||||
| ^^^^^^^^^^
|
||||
|
||||
warning: variable does not need to be mutable
|
||||
--> $DIR/suggestions.rs:51:13
|
||||
--> $DIR/suggestions.rs:54:13
|
||||
|
|
||||
LL | let mut
|
||||
| _____________^
|
||||
@ -45,7 +45,7 @@ LL | || b = 1;
|
||||
| help: remove this `mut`
|
||||
|
||||
error: const items should never be `#[no_mangle]`
|
||||
--> $DIR/suggestions.rs:5:14
|
||||
--> $DIR/suggestions.rs:6:14
|
||||
|
|
||||
LL | #[no_mangle] const DISCOVERY: usize = 1;
|
||||
| -----^^^^^^^^^^^^^^^^^^^^^^
|
||||
@ -55,7 +55,7 @@ LL | #[no_mangle] const DISCOVERY: usize = 1;
|
||||
= note: `#[deny(no_mangle_const_items)]` on by default
|
||||
|
||||
warning: functions generic over types or consts must be mangled
|
||||
--> $DIR/suggestions.rs:11:1
|
||||
--> $DIR/suggestions.rs:12:1
|
||||
|
|
||||
LL | #[no_mangle]
|
||||
| ------------ help: remove this attribute
|
||||
@ -66,7 +66,7 @@ LL | pub fn defiant<T>(_t: T) {}
|
||||
= note: `#[warn(no_mangle_generic_items)]` on by default
|
||||
|
||||
warning: the `warp_factor:` in this pattern is redundant
|
||||
--> $DIR/suggestions.rs:57:23
|
||||
--> $DIR/suggestions.rs:61:23
|
||||
|
|
||||
LL | Equinox { warp_factor: warp_factor } => {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: use shorthand field pattern: `warp_factor`
|
||||
@ -74,7 +74,7 @@ LL | Equinox { warp_factor: warp_factor } => {}
|
||||
= note: `#[warn(non_shorthand_field_patterns)]` on by default
|
||||
|
||||
error: const items should never be `#[no_mangle]`
|
||||
--> $DIR/suggestions.rs:21:18
|
||||
--> $DIR/suggestions.rs:22:18
|
||||
|
|
||||
LL | #[no_mangle] pub const DAUNTLESS: bool = true;
|
||||
| ---------^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
@ -82,7 +82,7 @@ LL | #[no_mangle] pub const DAUNTLESS: bool = true;
|
||||
| help: try a static value: `pub static`
|
||||
|
||||
warning: functions generic over types or consts must be mangled
|
||||
--> $DIR/suggestions.rs:24:18
|
||||
--> $DIR/suggestions.rs:26:18
|
||||
|
|
||||
LL | #[no_mangle] pub fn val_jean<T>() {}
|
||||
| ------------ ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
@ -90,7 +90,7 @@ LL | #[no_mangle] pub fn val_jean<T>() {}
|
||||
| help: remove this attribute
|
||||
|
||||
error: const items should never be `#[no_mangle]`
|
||||
--> $DIR/suggestions.rs:29:18
|
||||
--> $DIR/suggestions.rs:31:18
|
||||
|
|
||||
LL | #[no_mangle] pub(crate) const VETAR: bool = true;
|
||||
| ----------------^^^^^^^^^^^^^^^^^^^^
|
||||
@ -98,7 +98,7 @@ LL | #[no_mangle] pub(crate) const VETAR: bool = true;
|
||||
| help: try a static value: `pub static`
|
||||
|
||||
warning: functions generic over types or consts must be mangled
|
||||
--> $DIR/suggestions.rs:32:18
|
||||
--> $DIR/suggestions.rs:35:18
|
||||
|
|
||||
LL | #[no_mangle] pub(crate) fn crossfield<T>() {}
|
||||
| ------------ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
53
src/test/ui/lint/unused_braces.fixed
Normal file
53
src/test/ui/lint/unused_braces.fixed
Normal file
@ -0,0 +1,53 @@
|
||||
// check-pass
|
||||
// run-rustfix
|
||||
|
||||
#![warn(unused_braces, unused_parens)]
|
||||
#![allow(unreachable_code, unused_unsafe)] // for rustfix
|
||||
|
||||
fn consume<T>(_: T) {}
|
||||
|
||||
fn main() {
|
||||
let _ = 7;
|
||||
//~^WARN unnecessary parentheses
|
||||
|
||||
// Do not emit a lint in these cases,
|
||||
// as we have to be careful with
|
||||
// `ref` patterns.
|
||||
{
|
||||
let _ = { 7 };
|
||||
|
||||
if let 7 = { 7 } { }
|
||||
|
||||
match { 7 } {
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
if true {
|
||||
//~^ WARN unnecessary braces
|
||||
}
|
||||
|
||||
while false {
|
||||
//~^ WARN unnecessary braces
|
||||
}
|
||||
|
||||
let _: [u8; 3 ];
|
||||
//~^ WARN unnecessary braces
|
||||
|
||||
consume( 7 );
|
||||
//~^ WARN unnecessary braces
|
||||
|
||||
// Do not emit lint for multiline blocks.
|
||||
let _ = {
|
||||
7
|
||||
};
|
||||
|
||||
// Do not emit lint for unsafe blocks.
|
||||
let _ = unsafe { 7 };
|
||||
|
||||
// Do not emit lint, as the `{` would then
|
||||
// be parsed as part of the `return`.
|
||||
if { return } {
|
||||
|
||||
}
|
||||
}
|
@ -1,5 +1,8 @@
|
||||
// check-pass
|
||||
// run-rustfix
|
||||
|
||||
#![warn(unused_braces, unused_parens)]
|
||||
#![allow(unreachable_code, unused_unsafe)] // for rustfix
|
||||
|
||||
fn consume<T>(_: T) {}
|
||||
|
||||
|
@ -1,41 +1,41 @@
|
||||
warning: unnecessary parentheses around assigned value
|
||||
--> $DIR/unused_braces.rs:7:13
|
||||
--> $DIR/unused_braces.rs:10:13
|
||||
|
|
||||
LL | let _ = (7);
|
||||
| ^^^ help: remove these parentheses
|
||||
|
|
||||
note: the lint level is defined here
|
||||
--> $DIR/unused_braces.rs:2:24
|
||||
--> $DIR/unused_braces.rs:4:24
|
||||
|
|
||||
LL | #![warn(unused_braces, unused_parens)]
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
warning: unnecessary braces around `if` condition
|
||||
--> $DIR/unused_braces.rs:23:8
|
||||
--> $DIR/unused_braces.rs:26:8
|
||||
|
|
||||
LL | if { true } {
|
||||
| ^^^^^^^^ help: remove these braces
|
||||
|
|
||||
note: the lint level is defined here
|
||||
--> $DIR/unused_braces.rs:2:9
|
||||
--> $DIR/unused_braces.rs:4:9
|
||||
|
|
||||
LL | #![warn(unused_braces, unused_parens)]
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
warning: unnecessary braces around `while` condition
|
||||
--> $DIR/unused_braces.rs:27:11
|
||||
--> $DIR/unused_braces.rs:30:11
|
||||
|
|
||||
LL | while { false } {
|
||||
| ^^^^^^^^^ help: remove these braces
|
||||
|
||||
warning: unnecessary braces around const expression
|
||||
--> $DIR/unused_braces.rs:31:17
|
||||
--> $DIR/unused_braces.rs:34:17
|
||||
|
|
||||
LL | let _: [u8; { 3 }];
|
||||
| ^^^^^ help: remove these braces
|
||||
|
||||
warning: unnecessary braces around function argument
|
||||
--> $DIR/unused_braces.rs:34:13
|
||||
--> $DIR/unused_braces.rs:37:13
|
||||
|
|
||||
LL | consume({ 7 });
|
||||
| ^^^^^ help: remove these braces
|
||||
|
26
src/test/ui/lint/unused_braces_borrow.fixed
Normal file
26
src/test/ui/lint/unused_braces_borrow.fixed
Normal file
@ -0,0 +1,26 @@
|
||||
// check-pass
|
||||
// run-rustfix
|
||||
|
||||
#![warn(unused_braces)]
|
||||
|
||||
// changing `&{ expr }` to `&expr` changes the semantic of the program
|
||||
// so we should not warn this case
|
||||
|
||||
#[repr(packed)]
|
||||
pub struct A {
|
||||
pub a: u8,
|
||||
pub b: u32,
|
||||
}
|
||||
|
||||
fn consume<T>(_: T) {}
|
||||
|
||||
fn main() {
|
||||
let a = A {
|
||||
a: 42,
|
||||
b: 1729,
|
||||
};
|
||||
|
||||
consume(&{ a.b });
|
||||
consume( a.b );
|
||||
//~^ WARN unnecessary braces
|
||||
}
|
@ -1,13 +1,15 @@
|
||||
// check-pass
|
||||
// run-rustfix
|
||||
|
||||
#![warn(unused_braces)]
|
||||
|
||||
// changing `&{ expr }` to `&expr` changes the semantic of the program
|
||||
// so we should not warn this case
|
||||
|
||||
#[repr(packed)]
|
||||
struct A {
|
||||
a: u8,
|
||||
b: u32,
|
||||
pub struct A {
|
||||
pub a: u8,
|
||||
pub b: u32,
|
||||
}
|
||||
|
||||
fn consume<T>(_: T) {}
|
||||
|
@ -1,11 +1,11 @@
|
||||
warning: unnecessary braces around function argument
|
||||
--> $DIR/unused_braces_borrow.rs:22:13
|
||||
--> $DIR/unused_braces_borrow.rs:24:13
|
||||
|
|
||||
LL | consume({ a.b });
|
||||
| ^^^^^^^ help: remove these braces
|
||||
|
|
||||
note: the lint level is defined here
|
||||
--> $DIR/unused_braces_borrow.rs:2:9
|
||||
--> $DIR/unused_braces_borrow.rs:4:9
|
||||
|
|
||||
LL | #![warn(unused_braces)]
|
||||
| ^^^^^^^^^^^^^
|
||||
|
16
src/test/ui/nll/capture-mut-ref.fixed
Normal file
16
src/test/ui/nll/capture-mut-ref.fixed
Normal file
@ -0,0 +1,16 @@
|
||||
// run-rustfix
|
||||
|
||||
// Check that capturing a mutable reference by move and assigning to its
|
||||
// referent doesn't make the unused mut lint think that it is mutable.
|
||||
|
||||
#![deny(unused_mut)]
|
||||
|
||||
pub fn mutable_upvar() {
|
||||
let x = &mut 0;
|
||||
//~^ ERROR
|
||||
move || {
|
||||
*x = 1;
|
||||
};
|
||||
}
|
||||
|
||||
fn main() {}
|
@ -1,9 +1,11 @@
|
||||
// run-rustfix
|
||||
|
||||
// Check that capturing a mutable reference by move and assigning to its
|
||||
// referent doesn't make the unused mut lint think that it is mutable.
|
||||
|
||||
#![deny(unused_mut)]
|
||||
|
||||
fn mutable_upvar() {
|
||||
pub fn mutable_upvar() {
|
||||
let mut x = &mut 0;
|
||||
//~^ ERROR
|
||||
move || {
|
||||
|
@ -1,5 +1,5 @@
|
||||
error: variable does not need to be mutable
|
||||
--> $DIR/capture-mut-ref.rs:7:9
|
||||
--> $DIR/capture-mut-ref.rs:9:9
|
||||
|
|
||||
LL | let mut x = &mut 0;
|
||||
| ----^
|
||||
@ -7,7 +7,7 @@ LL | let mut x = &mut 0;
|
||||
| help: remove this `mut`
|
||||
|
|
||||
note: the lint level is defined here
|
||||
--> $DIR/capture-mut-ref.rs:4:9
|
||||
--> $DIR/capture-mut-ref.rs:6:9
|
||||
|
|
||||
LL | #![deny(unused_mut)]
|
||||
| ^^^^^^^^^^
|
||||
|
9
src/test/ui/nll/issue-61424.fixed
Normal file
9
src/test/ui/nll/issue-61424.fixed
Normal file
@ -0,0 +1,9 @@
|
||||
// run-rustfix
|
||||
|
||||
#![deny(unused_mut)]
|
||||
|
||||
fn main() {
|
||||
let x; //~ ERROR: variable does not need to be mutable
|
||||
x = String::new();
|
||||
dbg!(x);
|
||||
}
|
@ -1,3 +1,5 @@
|
||||
// run-rustfix
|
||||
|
||||
#![deny(unused_mut)]
|
||||
|
||||
fn main() {
|
||||
|
@ -1,5 +1,5 @@
|
||||
error: variable does not need to be mutable
|
||||
--> $DIR/issue-61424.rs:4:9
|
||||
--> $DIR/issue-61424.rs:6:9
|
||||
|
|
||||
LL | let mut x;
|
||||
| ----^
|
||||
@ -7,7 +7,7 @@ LL | let mut x;
|
||||
| help: remove this `mut`
|
||||
|
|
||||
note: the lint level is defined here
|
||||
--> $DIR/issue-61424.rs:1:9
|
||||
--> $DIR/issue-61424.rs:3:9
|
||||
|
|
||||
LL | #![deny(unused_mut)]
|
||||
| ^^^^^^^^^^
|
||||
|
9
src/test/ui/nll/unused-mut-issue-50343.fixed
Normal file
9
src/test/ui/nll/unused-mut-issue-50343.fixed
Normal file
@ -0,0 +1,9 @@
|
||||
// run-rustfix
|
||||
|
||||
#![deny(unused_mut)]
|
||||
#![allow(unused_variables)] // for rustfix
|
||||
|
||||
fn main() {
|
||||
vec![(42, 22)].iter().map(|(x, _y)| ()).count();
|
||||
//~^ ERROR: variable does not need to be mutable
|
||||
}
|
@ -1,4 +1,7 @@
|
||||
// run-rustfix
|
||||
|
||||
#![deny(unused_mut)]
|
||||
#![allow(unused_variables)] // for rustfix
|
||||
|
||||
fn main() {
|
||||
vec![(42, 22)].iter().map(|(mut x, _y)| ()).count();
|
||||
|
@ -1,5 +1,5 @@
|
||||
error: variable does not need to be mutable
|
||||
--> $DIR/unused-mut-issue-50343.rs:4:33
|
||||
--> $DIR/unused-mut-issue-50343.rs:7:33
|
||||
|
|
||||
LL | vec![(42, 22)].iter().map(|(mut x, _y)| ()).count();
|
||||
| ----^
|
||||
@ -7,7 +7,7 @@ LL | vec![(42, 22)].iter().map(|(mut x, _y)| ()).count();
|
||||
| help: remove this `mut`
|
||||
|
|
||||
note: the lint level is defined here
|
||||
--> $DIR/unused-mut-issue-50343.rs:1:9
|
||||
--> $DIR/unused-mut-issue-50343.rs:3:9
|
||||
|
|
||||
LL | #![deny(unused_mut)]
|
||||
| ^^^^^^^^^^
|
||||
|
26
src/test/ui/parser/bad-fn-ptr-qualifier.fixed
Normal file
26
src/test/ui/parser/bad-fn-ptr-qualifier.fixed
Normal file
@ -0,0 +1,26 @@
|
||||
// run-rustfix
|
||||
// edition:2018
|
||||
// Most of items are taken from ./recover-const-async-fn-ptr.rs but this is able to apply rustfix.
|
||||
|
||||
pub type T0 = fn(); //~ ERROR an `fn` pointer type cannot be `const`
|
||||
pub type T1 = extern "C" fn(); //~ ERROR an `fn` pointer type cannot be `const`
|
||||
pub type T2 = unsafe extern fn(); //~ ERROR an `fn` pointer type cannot be `const`
|
||||
pub type T3 = fn(); //~ ERROR an `fn` pointer type cannot be `async`
|
||||
pub type T4 = extern fn(); //~ ERROR an `fn` pointer type cannot be `async`
|
||||
pub type T5 = unsafe extern "C" fn(); //~ ERROR an `fn` pointer type cannot be `async`
|
||||
pub type T6 = unsafe extern "C" fn();
|
||||
//~^ ERROR an `fn` pointer type cannot be `const`
|
||||
//~| ERROR an `fn` pointer type cannot be `async`
|
||||
|
||||
pub type FTT0 = for<'a> fn(); //~ ERROR an `fn` pointer type cannot be `const`
|
||||
pub type FTT1 = for<'a> extern "C" fn(); //~ ERROR an `fn` pointer type cannot be `const`
|
||||
pub type FTT2 = for<'a> unsafe extern fn(); //~ ERROR an `fn` pointer type cannot be `const`
|
||||
pub type FTT3 = for<'a> fn(); //~ ERROR an `fn` pointer type cannot be `async`
|
||||
pub type FTT4 = for<'a> extern fn(); //~ ERROR an `fn` pointer type cannot be `async`
|
||||
pub type FTT5 = for<'a> unsafe extern "C" fn();
|
||||
//~^ ERROR an `fn` pointer type cannot be `async`
|
||||
pub type FTT6 = for<'a> unsafe extern "C" fn();
|
||||
//~^ ERROR an `fn` pointer type cannot be `const`
|
||||
//~| ERROR an `fn` pointer type cannot be `async`
|
||||
|
||||
fn main() {}
|
26
src/test/ui/parser/bad-fn-ptr-qualifier.rs
Normal file
26
src/test/ui/parser/bad-fn-ptr-qualifier.rs
Normal file
@ -0,0 +1,26 @@
|
||||
// run-rustfix
|
||||
// edition:2018
|
||||
// Most of items are taken from ./recover-const-async-fn-ptr.rs but this is able to apply rustfix.
|
||||
|
||||
pub type T0 = const fn(); //~ ERROR an `fn` pointer type cannot be `const`
|
||||
pub type T1 = const extern "C" fn(); //~ ERROR an `fn` pointer type cannot be `const`
|
||||
pub type T2 = const unsafe extern fn(); //~ ERROR an `fn` pointer type cannot be `const`
|
||||
pub type T3 = async fn(); //~ ERROR an `fn` pointer type cannot be `async`
|
||||
pub type T4 = async extern fn(); //~ ERROR an `fn` pointer type cannot be `async`
|
||||
pub type T5 = async unsafe extern "C" fn(); //~ ERROR an `fn` pointer type cannot be `async`
|
||||
pub type T6 = const async unsafe extern "C" fn();
|
||||
//~^ ERROR an `fn` pointer type cannot be `const`
|
||||
//~| ERROR an `fn` pointer type cannot be `async`
|
||||
|
||||
pub type FTT0 = for<'a> const fn(); //~ ERROR an `fn` pointer type cannot be `const`
|
||||
pub type FTT1 = for<'a> const extern "C" fn(); //~ ERROR an `fn` pointer type cannot be `const`
|
||||
pub type FTT2 = for<'a> const unsafe extern fn(); //~ ERROR an `fn` pointer type cannot be `const`
|
||||
pub type FTT3 = for<'a> async fn(); //~ ERROR an `fn` pointer type cannot be `async`
|
||||
pub type FTT4 = for<'a> async extern fn(); //~ ERROR an `fn` pointer type cannot be `async`
|
||||
pub type FTT5 = for<'a> async unsafe extern "C" fn();
|
||||
//~^ ERROR an `fn` pointer type cannot be `async`
|
||||
pub type FTT6 = for<'a> const async unsafe extern "C" fn();
|
||||
//~^ ERROR an `fn` pointer type cannot be `const`
|
||||
//~| ERROR an `fn` pointer type cannot be `async`
|
||||
|
||||
fn main() {}
|
146
src/test/ui/parser/bad-fn-ptr-qualifier.stderr
Normal file
146
src/test/ui/parser/bad-fn-ptr-qualifier.stderr
Normal file
@ -0,0 +1,146 @@
|
||||
error: an `fn` pointer type cannot be `const`
|
||||
--> $DIR/bad-fn-ptr-qualifier.rs:5:15
|
||||
|
|
||||
LL | pub type T0 = const fn();
|
||||
| -----^^^^^
|
||||
| |
|
||||
| `const` because of this
|
||||
| help: remove the `const` qualifier
|
||||
|
||||
error: an `fn` pointer type cannot be `const`
|
||||
--> $DIR/bad-fn-ptr-qualifier.rs:6:15
|
||||
|
|
||||
LL | pub type T1 = const extern "C" fn();
|
||||
| -----^^^^^^^^^^^^^^^^
|
||||
| |
|
||||
| `const` because of this
|
||||
| help: remove the `const` qualifier
|
||||
|
||||
error: an `fn` pointer type cannot be `const`
|
||||
--> $DIR/bad-fn-ptr-qualifier.rs:7:15
|
||||
|
|
||||
LL | pub type T2 = const unsafe extern fn();
|
||||
| -----^^^^^^^^^^^^^^^^^^^
|
||||
| |
|
||||
| `const` because of this
|
||||
| help: remove the `const` qualifier
|
||||
|
||||
error: an `fn` pointer type cannot be `async`
|
||||
--> $DIR/bad-fn-ptr-qualifier.rs:8:15
|
||||
|
|
||||
LL | pub type T3 = async fn();
|
||||
| -----^^^^^
|
||||
| |
|
||||
| `async` because of this
|
||||
| help: remove the `async` qualifier
|
||||
|
||||
error: an `fn` pointer type cannot be `async`
|
||||
--> $DIR/bad-fn-ptr-qualifier.rs:9:15
|
||||
|
|
||||
LL | pub type T4 = async extern fn();
|
||||
| -----^^^^^^^^^^^^
|
||||
| |
|
||||
| `async` because of this
|
||||
| help: remove the `async` qualifier
|
||||
|
||||
error: an `fn` pointer type cannot be `async`
|
||||
--> $DIR/bad-fn-ptr-qualifier.rs:10:15
|
||||
|
|
||||
LL | pub type T5 = async unsafe extern "C" fn();
|
||||
| -----^^^^^^^^^^^^^^^^^^^^^^^
|
||||
| |
|
||||
| `async` because of this
|
||||
| help: remove the `async` qualifier
|
||||
|
||||
error: an `fn` pointer type cannot be `const`
|
||||
--> $DIR/bad-fn-ptr-qualifier.rs:11:15
|
||||
|
|
||||
LL | pub type T6 = const async unsafe extern "C" fn();
|
||||
| -----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
| |
|
||||
| `const` because of this
|
||||
| help: remove the `const` qualifier
|
||||
|
||||
error: an `fn` pointer type cannot be `async`
|
||||
--> $DIR/bad-fn-ptr-qualifier.rs:11:15
|
||||
|
|
||||
LL | pub type T6 = const async unsafe extern "C" fn();
|
||||
| ^^^^^^-----^^^^^^^^^^^^^^^^^^^^^^^
|
||||
| |
|
||||
| `async` because of this
|
||||
| help: remove the `async` qualifier
|
||||
|
||||
error: an `fn` pointer type cannot be `const`
|
||||
--> $DIR/bad-fn-ptr-qualifier.rs:15:17
|
||||
|
|
||||
LL | pub type FTT0 = for<'a> const fn();
|
||||
| ^^^^^^^^-----^^^^^
|
||||
| |
|
||||
| `const` because of this
|
||||
| help: remove the `const` qualifier
|
||||
|
||||
error: an `fn` pointer type cannot be `const`
|
||||
--> $DIR/bad-fn-ptr-qualifier.rs:16:17
|
||||
|
|
||||
LL | pub type FTT1 = for<'a> const extern "C" fn();
|
||||
| ^^^^^^^^-----^^^^^^^^^^^^^^^^
|
||||
| |
|
||||
| `const` because of this
|
||||
| help: remove the `const` qualifier
|
||||
|
||||
error: an `fn` pointer type cannot be `const`
|
||||
--> $DIR/bad-fn-ptr-qualifier.rs:17:17
|
||||
|
|
||||
LL | pub type FTT2 = for<'a> const unsafe extern fn();
|
||||
| ^^^^^^^^-----^^^^^^^^^^^^^^^^^^^
|
||||
| |
|
||||
| `const` because of this
|
||||
| help: remove the `const` qualifier
|
||||
|
||||
error: an `fn` pointer type cannot be `async`
|
||||
--> $DIR/bad-fn-ptr-qualifier.rs:18:17
|
||||
|
|
||||
LL | pub type FTT3 = for<'a> async fn();
|
||||
| ^^^^^^^^-----^^^^^
|
||||
| |
|
||||
| `async` because of this
|
||||
| help: remove the `async` qualifier
|
||||
|
||||
error: an `fn` pointer type cannot be `async`
|
||||
--> $DIR/bad-fn-ptr-qualifier.rs:19:17
|
||||
|
|
||||
LL | pub type FTT4 = for<'a> async extern fn();
|
||||
| ^^^^^^^^-----^^^^^^^^^^^^
|
||||
| |
|
||||
| `async` because of this
|
||||
| help: remove the `async` qualifier
|
||||
|
||||
error: an `fn` pointer type cannot be `async`
|
||||
--> $DIR/bad-fn-ptr-qualifier.rs:20:17
|
||||
|
|
||||
LL | pub type FTT5 = for<'a> async unsafe extern "C" fn();
|
||||
| ^^^^^^^^-----^^^^^^^^^^^^^^^^^^^^^^^
|
||||
| |
|
||||
| `async` because of this
|
||||
| help: remove the `async` qualifier
|
||||
|
||||
error: an `fn` pointer type cannot be `const`
|
||||
--> $DIR/bad-fn-ptr-qualifier.rs:22:17
|
||||
|
|
||||
LL | pub type FTT6 = for<'a> const async unsafe extern "C" fn();
|
||||
| ^^^^^^^^-----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
| |
|
||||
| `const` because of this
|
||||
| help: remove the `const` qualifier
|
||||
|
||||
error: an `fn` pointer type cannot be `async`
|
||||
--> $DIR/bad-fn-ptr-qualifier.rs:22:17
|
||||
|
|
||||
LL | pub type FTT6 = for<'a> const async unsafe extern "C" fn();
|
||||
| ^^^^^^^^^^^^^^-----^^^^^^^^^^^^^^^^^^^^^^^
|
||||
| |
|
||||
| `async` because of this
|
||||
| help: remove the `async` qualifier
|
||||
|
||||
error: aborting due to 16 previous errors
|
||||
|
7
src/test/ui/parser/if-in-in.fixed
Normal file
7
src/test/ui/parser/if-in-in.fixed
Normal file
@ -0,0 +1,7 @@
|
||||
// run-rustfix
|
||||
|
||||
fn main() {
|
||||
for i in 1..2 { //~ ERROR expected iterable, found keyword `in`
|
||||
println!("{}", i);
|
||||
}
|
||||
}
|
@ -1,3 +1,5 @@
|
||||
// run-rustfix
|
||||
|
||||
fn main() {
|
||||
for i in in 1..2 { //~ ERROR expected iterable, found keyword `in`
|
||||
println!("{}", i);
|
||||
|
@ -1,5 +1,5 @@
|
||||
error: expected iterable, found keyword `in`
|
||||
--> $DIR/if-in-in.rs:2:14
|
||||
--> $DIR/if-in-in.rs:4:14
|
||||
|
|
||||
LL | for i in in 1..2 {
|
||||
| ---^^
|
||||
|
9
src/test/ui/parser/issue-10392-2.fixed
Normal file
9
src/test/ui/parser/issue-10392-2.fixed
Normal file
@ -0,0 +1,9 @@
|
||||
// run-rustfix
|
||||
|
||||
pub struct A { pub foo: isize }
|
||||
|
||||
fn a() -> A { panic!() }
|
||||
|
||||
fn main() {
|
||||
let A { .. } = a(); //~ ERROR: expected `}`
|
||||
}
|
@ -1,4 +1,6 @@
|
||||
struct A { foo: isize }
|
||||
// run-rustfix
|
||||
|
||||
pub struct A { pub foo: isize }
|
||||
|
||||
fn a() -> A { panic!() }
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
error: expected `}`, found `,`
|
||||
--> $DIR/issue-10392-2.rs:6:15
|
||||
--> $DIR/issue-10392-2.rs:8:15
|
||||
|
|
||||
LL | let A { .., } = a();
|
||||
| --^
|
||||
|
7
src/test/ui/parser/issue-3036.fixed
Normal file
7
src/test/ui/parser/issue-3036.fixed
Normal file
@ -0,0 +1,7 @@
|
||||
// run-rustfix
|
||||
|
||||
// Testing that semicolon tokens are printed correctly in errors
|
||||
|
||||
fn main() {
|
||||
let _x = 3; //~ ERROR: expected `;`
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
// run-rustfix
|
||||
|
||||
// Testing that semicolon tokens are printed correctly in errors
|
||||
|
||||
fn main()
|
||||
{
|
||||
let x = 3 //~ ERROR: expected `;`
|
||||
fn main() {
|
||||
let _x = 3 //~ ERROR: expected `;`
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
error: expected `;`, found `}`
|
||||
--> $DIR/issue-3036.rs:5:14
|
||||
--> $DIR/issue-3036.rs:6:15
|
||||
|
|
||||
LL | let x = 3
|
||||
| ^ help: add `;` here
|
||||
LL | let _x = 3
|
||||
| ^ help: add `;` here
|
||||
LL | }
|
||||
| - unexpected token
|
||||
|
||||
|
@ -0,0 +1,14 @@
|
||||
// run-rustfix
|
||||
|
||||
// In this regression test for #67146, we check that the
|
||||
// negative outlives bound `!'a` is rejected by the parser.
|
||||
// This regression was first introduced in PR #57364.
|
||||
|
||||
fn main() {}
|
||||
|
||||
pub fn f1<T>() {}
|
||||
//~^ ERROR negative bounds are not supported
|
||||
pub fn f2<'a, T: Ord>() {}
|
||||
//~^ ERROR negative bounds are not supported
|
||||
pub fn f3<'a, T: Ord>() {}
|
||||
//~^ ERROR negative bounds are not supported
|
@ -1,12 +1,14 @@
|
||||
// run-rustfix
|
||||
|
||||
// In this regression test for #67146, we check that the
|
||||
// negative outlives bound `!'a` is rejected by the parser.
|
||||
// This regression was first introduced in PR #57364.
|
||||
|
||||
fn main() {}
|
||||
|
||||
fn f1<T: !'static>() {}
|
||||
pub fn f1<T: !'static>() {}
|
||||
//~^ ERROR negative bounds are not supported
|
||||
fn f2<'a, T: Ord + !'a>() {}
|
||||
pub fn f2<'a, T: Ord + !'a>() {}
|
||||
//~^ ERROR negative bounds are not supported
|
||||
fn f3<'a, T: !'a + Ord>() {}
|
||||
pub fn f3<'a, T: !'a + Ord>() {}
|
||||
//~^ ERROR negative bounds are not supported
|
||||
|
@ -1,20 +1,20 @@
|
||||
error: negative bounds are not supported
|
||||
--> $DIR/issue-67146-negative-outlives-bound-syntactic-fail.rs:7:8
|
||||
--> $DIR/issue-67146-negative-outlives-bound-syntactic-fail.rs:9:12
|
||||
|
|
||||
LL | fn f1<T: !'static>() {}
|
||||
| ^^^^^^^^^^ negative bounds are not supported
|
||||
LL | pub fn f1<T: !'static>() {}
|
||||
| ^^^^^^^^^^ negative bounds are not supported
|
||||
|
||||
error: negative bounds are not supported
|
||||
--> $DIR/issue-67146-negative-outlives-bound-syntactic-fail.rs:9:18
|
||||
--> $DIR/issue-67146-negative-outlives-bound-syntactic-fail.rs:11:22
|
||||
|
|
||||
LL | fn f2<'a, T: Ord + !'a>() {}
|
||||
| ^^^^^ negative bounds are not supported
|
||||
LL | pub fn f2<'a, T: Ord + !'a>() {}
|
||||
| ^^^^^ negative bounds are not supported
|
||||
|
||||
error: negative bounds are not supported
|
||||
--> $DIR/issue-67146-negative-outlives-bound-syntactic-fail.rs:11:12
|
||||
--> $DIR/issue-67146-negative-outlives-bound-syntactic-fail.rs:13:16
|
||||
|
|
||||
LL | fn f3<'a, T: !'a + Ord>() {}
|
||||
| ^^^^^ negative bounds are not supported
|
||||
LL | pub fn f3<'a, T: !'a + Ord>() {}
|
||||
| ^^^^^ negative bounds are not supported
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
|
9
src/test/ui/parser/issue-70388-without-witness.fixed
Normal file
9
src/test/ui/parser/issue-70388-without-witness.fixed
Normal file
@ -0,0 +1,9 @@
|
||||
// run-rustfix
|
||||
// This is for checking if we can apply suggestions as-is.
|
||||
|
||||
pub struct Foo(i32);
|
||||
|
||||
fn main() {
|
||||
let Foo(..) = Foo(0); //~ ERROR unexpected `...`
|
||||
let [_, .., _] = [0, 1]; //~ ERROR unexpected `...`
|
||||
}
|
9
src/test/ui/parser/issue-70388-without-witness.rs
Normal file
9
src/test/ui/parser/issue-70388-without-witness.rs
Normal file
@ -0,0 +1,9 @@
|
||||
// run-rustfix
|
||||
// This is for checking if we can apply suggestions as-is.
|
||||
|
||||
pub struct Foo(i32);
|
||||
|
||||
fn main() {
|
||||
let Foo(...) = Foo(0); //~ ERROR unexpected `...`
|
||||
let [_, ..., _] = [0, 1]; //~ ERROR unexpected `...`
|
||||
}
|
20
src/test/ui/parser/issue-70388-without-witness.stderr
Normal file
20
src/test/ui/parser/issue-70388-without-witness.stderr
Normal file
@ -0,0 +1,20 @@
|
||||
error: unexpected `...`
|
||||
--> $DIR/issue-70388-without-witness.rs:7:13
|
||||
|
|
||||
LL | let Foo(...) = Foo(0);
|
||||
| ^^^
|
||||
| |
|
||||
| not a valid pattern
|
||||
| help: for a rest pattern, use `..` instead of `...`
|
||||
|
||||
error: unexpected `...`
|
||||
--> $DIR/issue-70388-without-witness.rs:8:13
|
||||
|
|
||||
LL | let [_, ..., _] = [0, 1];
|
||||
| ^^^
|
||||
| |
|
||||
| not a valid pattern
|
||||
| help: for a rest pattern, use `..` instead of `...`
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
10
src/test/ui/parser/let-binop.fixed
Normal file
10
src/test/ui/parser/let-binop.fixed
Normal file
@ -0,0 +1,10 @@
|
||||
// run-rustfix
|
||||
|
||||
fn main() {
|
||||
let a: i8 = 1; //~ ERROR can't reassign to an uninitialized variable
|
||||
let _ = a;
|
||||
let b = 1; //~ ERROR can't reassign to an uninitialized variable
|
||||
let _ = b;
|
||||
let c = 1; //~ ERROR can't reassign to an uninitialized variable
|
||||
let _ = c;
|
||||
}
|
@ -1,3 +1,5 @@
|
||||
// run-rustfix
|
||||
|
||||
fn main() {
|
||||
let a: i8 *= 1; //~ ERROR can't reassign to an uninitialized variable
|
||||
let _ = a;
|
||||
|
@ -1,17 +1,17 @@
|
||||
error: can't reassign to an uninitialized variable
|
||||
--> $DIR/let-binop.rs:2:15
|
||||
--> $DIR/let-binop.rs:4:15
|
||||
|
|
||||
LL | let a: i8 *= 1;
|
||||
| ^^ help: initialize the variable
|
||||
|
||||
error: can't reassign to an uninitialized variable
|
||||
--> $DIR/let-binop.rs:4:11
|
||||
--> $DIR/let-binop.rs:6:11
|
||||
|
|
||||
LL | let b += 1;
|
||||
| ^^ help: initialize the variable
|
||||
|
||||
error: can't reassign to an uninitialized variable
|
||||
--> $DIR/let-binop.rs:6:11
|
||||
--> $DIR/let-binop.rs:8:11
|
||||
|
|
||||
LL | let c *= 1;
|
||||
| ^^ help: initialize the variable
|
||||
|
12
src/test/ui/parser/match-refactor-to-expr.fixed
Normal file
12
src/test/ui/parser/match-refactor-to-expr.fixed
Normal file
@ -0,0 +1,12 @@
|
||||
// run-rustfix
|
||||
|
||||
fn main() {
|
||||
let foo =
|
||||
//~ NOTE while parsing this match expression
|
||||
Some(4).unwrap_or(5)
|
||||
//~^ NOTE expected one of `.`, `?`, `{`, or an operator
|
||||
; //~ NOTE unexpected token
|
||||
//~^ ERROR expected one of `.`, `?`, `{`, or an operator, found `;`
|
||||
|
||||
println!("{}", foo)
|
||||
}
|
@ -1,7 +1,9 @@
|
||||
// run-rustfix
|
||||
|
||||
fn main() {
|
||||
let foo =
|
||||
match //~ NOTE while parsing this match expression
|
||||
Some(4).unwrap_or_else(5)
|
||||
Some(4).unwrap_or(5)
|
||||
//~^ NOTE expected one of `.`, `?`, `{`, or an operator
|
||||
; //~ NOTE unexpected token
|
||||
//~^ ERROR expected one of `.`, `?`, `{`, or an operator, found `;`
|
||||
|
@ -1,13 +1,13 @@
|
||||
error: expected one of `.`, `?`, `{`, or an operator, found `;`
|
||||
--> $DIR/match-refactor-to-expr.rs:6:9
|
||||
--> $DIR/match-refactor-to-expr.rs:8:9
|
||||
|
|
||||
LL | match
|
||||
| -----
|
||||
| |
|
||||
| while parsing this match expression
|
||||
| help: try removing this `match`
|
||||
LL | Some(4).unwrap_or_else(5)
|
||||
| - expected one of `.`, `?`, `{`, or an operator
|
||||
LL | Some(4).unwrap_or(5)
|
||||
| - expected one of `.`, `?`, `{`, or an operator
|
||||
LL |
|
||||
LL | ;
|
||||
| ^ unexpected token
|
||||
|
7
src/test/ui/parser/range_inclusive.fixed
Normal file
7
src/test/ui/parser/range_inclusive.fixed
Normal file
@ -0,0 +1,7 @@
|
||||
// run-rustfix
|
||||
// Make sure that inclusive ranges with no end point don't parse.
|
||||
|
||||
pub fn main() {
|
||||
for _ in 1.. {} //~ERROR inclusive range with no end
|
||||
//~^HELP use `..` instead
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
// run-rustfix
|
||||
// Make sure that inclusive ranges with no end point don't parse.
|
||||
|
||||
pub fn main() {
|
||||
|
@ -1,5 +1,5 @@
|
||||
error[E0586]: inclusive range with no end
|
||||
--> $DIR/range_inclusive.rs:4:15
|
||||
--> $DIR/range_inclusive.rs:5:15
|
||||
|
|
||||
LL | for _ in 1..= {}
|
||||
| ^^^ help: use `..` instead
|
||||
|
@ -6,6 +6,7 @@ fn f<'a, T: Trait + ('a)>() {} //~ ERROR parenthesized lifetime bounds are not s
|
||||
|
||||
fn check<'a>() {
|
||||
let _: Box<Trait + ('a)>; //~ ERROR parenthesized lifetime bounds are not supported
|
||||
// FIXME: It'd be great if we could add suggestion to the following case.
|
||||
let _: Box<('a) + Trait>; //~ ERROR lifetime in trait object type must be followed by `+`
|
||||
}
|
||||
|
||||
|
@ -11,7 +11,7 @@ LL | let _: Box<Trait + ('a)>;
|
||||
| ^^^^ help: remove the parentheses
|
||||
|
||||
error: lifetime in trait object type must be followed by `+`
|
||||
--> $DIR/trait-object-lifetime-parens.rs:9:17
|
||||
--> $DIR/trait-object-lifetime-parens.rs:10:17
|
||||
|
|
||||
LL | let _: Box<('a) + Trait>;
|
||||
| ^^
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user