Refactor must_use lint into two parts
Before, the lint did the checking for `must_use` and pretty printing the types in a special format in one pass, causing quite complex and untranslatable code. Now the collection and printing is split in two. That should also make it easier to translate or extract the type pretty printing in the future. Also fixes an integer overflow in the array length pluralization calculation.
This commit is contained in:
parent
62c627c7a3
commit
4e9ceef76d
5 changed files with 259 additions and 146 deletions
|
|
@ -3,12 +3,18 @@
|
|||
// check-pass
|
||||
|
||||
#![warn(unused_must_use)]
|
||||
#![feature(never_type)]
|
||||
|
||||
fn deref_never(x: &!) {
|
||||
// Don't lint for uninhabited typess
|
||||
*x;
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let val = 1;
|
||||
let val_pointer = &val;
|
||||
|
||||
// Comparison Operators
|
||||
// Comparison Operators
|
||||
val == 1; //~ WARNING unused comparison
|
||||
val < 1; //~ WARNING unused comparison
|
||||
val <= 1; //~ WARNING unused comparison
|
||||
|
|
@ -16,26 +22,30 @@ fn main() {
|
|||
val >= 1; //~ WARNING unused comparison
|
||||
val > 1; //~ WARNING unused comparison
|
||||
|
||||
// Arithmetic Operators
|
||||
// Arithmetic Operators
|
||||
val + 2; //~ WARNING unused arithmetic operation
|
||||
val - 2; //~ WARNING unused arithmetic operation
|
||||
val / 2; //~ WARNING unused arithmetic operation
|
||||
val * 2; //~ WARNING unused arithmetic operation
|
||||
val % 2; //~ WARNING unused arithmetic operation
|
||||
|
||||
// Logical Operators
|
||||
// Logical Operators
|
||||
true && true; //~ WARNING unused logical operation
|
||||
false || true; //~ WARNING unused logical operation
|
||||
|
||||
// Bitwise Operators
|
||||
// Bitwise Operators
|
||||
5 ^ val; //~ WARNING unused bitwise operation
|
||||
5 & val; //~ WARNING unused bitwise operation
|
||||
5 | val; //~ WARNING unused bitwise operation
|
||||
5 << val; //~ WARNING unused bitwise operation
|
||||
5 >> val; //~ WARNING unused bitwise operation
|
||||
|
||||
// Unary Operators
|
||||
// Unary Operators
|
||||
!val; //~ WARNING unused unary operation
|
||||
-val; //~ WARNING unused unary operation
|
||||
*val_pointer; //~ WARNING unused unary operation
|
||||
|
||||
if false {
|
||||
deref_never(&panic!());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
warning: unused comparison that must be used
|
||||
--> $DIR/must-use-ops.rs:12:5
|
||||
--> $DIR/must-use-ops.rs:18:5
|
||||
|
|
||||
LL | val == 1;
|
||||
| ^^^^^^^^ the comparison produces a value
|
||||
|
|
@ -15,7 +15,7 @@ LL | let _ = val == 1;
|
|||
| +++++++
|
||||
|
||||
warning: unused comparison that must be used
|
||||
--> $DIR/must-use-ops.rs:13:5
|
||||
--> $DIR/must-use-ops.rs:19:5
|
||||
|
|
||||
LL | val < 1;
|
||||
| ^^^^^^^ the comparison produces a value
|
||||
|
|
@ -26,7 +26,7 @@ LL | let _ = val < 1;
|
|||
| +++++++
|
||||
|
||||
warning: unused comparison that must be used
|
||||
--> $DIR/must-use-ops.rs:14:5
|
||||
--> $DIR/must-use-ops.rs:20:5
|
||||
|
|
||||
LL | val <= 1;
|
||||
| ^^^^^^^^ the comparison produces a value
|
||||
|
|
@ -37,7 +37,7 @@ LL | let _ = val <= 1;
|
|||
| +++++++
|
||||
|
||||
warning: unused comparison that must be used
|
||||
--> $DIR/must-use-ops.rs:15:5
|
||||
--> $DIR/must-use-ops.rs:21:5
|
||||
|
|
||||
LL | val != 1;
|
||||
| ^^^^^^^^ the comparison produces a value
|
||||
|
|
@ -48,7 +48,7 @@ LL | let _ = val != 1;
|
|||
| +++++++
|
||||
|
||||
warning: unused comparison that must be used
|
||||
--> $DIR/must-use-ops.rs:16:5
|
||||
--> $DIR/must-use-ops.rs:22:5
|
||||
|
|
||||
LL | val >= 1;
|
||||
| ^^^^^^^^ the comparison produces a value
|
||||
|
|
@ -59,7 +59,7 @@ LL | let _ = val >= 1;
|
|||
| +++++++
|
||||
|
||||
warning: unused comparison that must be used
|
||||
--> $DIR/must-use-ops.rs:17:5
|
||||
--> $DIR/must-use-ops.rs:23:5
|
||||
|
|
||||
LL | val > 1;
|
||||
| ^^^^^^^ the comparison produces a value
|
||||
|
|
@ -70,7 +70,7 @@ LL | let _ = val > 1;
|
|||
| +++++++
|
||||
|
||||
warning: unused arithmetic operation that must be used
|
||||
--> $DIR/must-use-ops.rs:20:5
|
||||
--> $DIR/must-use-ops.rs:26:5
|
||||
|
|
||||
LL | val + 2;
|
||||
| ^^^^^^^ the arithmetic operation produces a value
|
||||
|
|
@ -81,7 +81,7 @@ LL | let _ = val + 2;
|
|||
| +++++++
|
||||
|
||||
warning: unused arithmetic operation that must be used
|
||||
--> $DIR/must-use-ops.rs:21:5
|
||||
--> $DIR/must-use-ops.rs:27:5
|
||||
|
|
||||
LL | val - 2;
|
||||
| ^^^^^^^ the arithmetic operation produces a value
|
||||
|
|
@ -92,7 +92,7 @@ LL | let _ = val - 2;
|
|||
| +++++++
|
||||
|
||||
warning: unused arithmetic operation that must be used
|
||||
--> $DIR/must-use-ops.rs:22:5
|
||||
--> $DIR/must-use-ops.rs:28:5
|
||||
|
|
||||
LL | val / 2;
|
||||
| ^^^^^^^ the arithmetic operation produces a value
|
||||
|
|
@ -103,7 +103,7 @@ LL | let _ = val / 2;
|
|||
| +++++++
|
||||
|
||||
warning: unused arithmetic operation that must be used
|
||||
--> $DIR/must-use-ops.rs:23:5
|
||||
--> $DIR/must-use-ops.rs:29:5
|
||||
|
|
||||
LL | val * 2;
|
||||
| ^^^^^^^ the arithmetic operation produces a value
|
||||
|
|
@ -114,7 +114,7 @@ LL | let _ = val * 2;
|
|||
| +++++++
|
||||
|
||||
warning: unused arithmetic operation that must be used
|
||||
--> $DIR/must-use-ops.rs:24:5
|
||||
--> $DIR/must-use-ops.rs:30:5
|
||||
|
|
||||
LL | val % 2;
|
||||
| ^^^^^^^ the arithmetic operation produces a value
|
||||
|
|
@ -125,7 +125,7 @@ LL | let _ = val % 2;
|
|||
| +++++++
|
||||
|
||||
warning: unused logical operation that must be used
|
||||
--> $DIR/must-use-ops.rs:27:5
|
||||
--> $DIR/must-use-ops.rs:33:5
|
||||
|
|
||||
LL | true && true;
|
||||
| ^^^^^^^^^^^^ the logical operation produces a value
|
||||
|
|
@ -136,7 +136,7 @@ LL | let _ = true && true;
|
|||
| +++++++
|
||||
|
||||
warning: unused logical operation that must be used
|
||||
--> $DIR/must-use-ops.rs:28:5
|
||||
--> $DIR/must-use-ops.rs:34:5
|
||||
|
|
||||
LL | false || true;
|
||||
| ^^^^^^^^^^^^^ the logical operation produces a value
|
||||
|
|
@ -147,7 +147,7 @@ LL | let _ = false || true;
|
|||
| +++++++
|
||||
|
||||
warning: unused bitwise operation that must be used
|
||||
--> $DIR/must-use-ops.rs:31:5
|
||||
--> $DIR/must-use-ops.rs:37:5
|
||||
|
|
||||
LL | 5 ^ val;
|
||||
| ^^^^^^^ the bitwise operation produces a value
|
||||
|
|
@ -158,7 +158,7 @@ LL | let _ = 5 ^ val;
|
|||
| +++++++
|
||||
|
||||
warning: unused bitwise operation that must be used
|
||||
--> $DIR/must-use-ops.rs:32:5
|
||||
--> $DIR/must-use-ops.rs:38:5
|
||||
|
|
||||
LL | 5 & val;
|
||||
| ^^^^^^^ the bitwise operation produces a value
|
||||
|
|
@ -169,7 +169,7 @@ LL | let _ = 5 & val;
|
|||
| +++++++
|
||||
|
||||
warning: unused bitwise operation that must be used
|
||||
--> $DIR/must-use-ops.rs:33:5
|
||||
--> $DIR/must-use-ops.rs:39:5
|
||||
|
|
||||
LL | 5 | val;
|
||||
| ^^^^^^^ the bitwise operation produces a value
|
||||
|
|
@ -180,7 +180,7 @@ LL | let _ = 5 | val;
|
|||
| +++++++
|
||||
|
||||
warning: unused bitwise operation that must be used
|
||||
--> $DIR/must-use-ops.rs:34:5
|
||||
--> $DIR/must-use-ops.rs:40:5
|
||||
|
|
||||
LL | 5 << val;
|
||||
| ^^^^^^^^ the bitwise operation produces a value
|
||||
|
|
@ -191,7 +191,7 @@ LL | let _ = 5 << val;
|
|||
| +++++++
|
||||
|
||||
warning: unused bitwise operation that must be used
|
||||
--> $DIR/must-use-ops.rs:35:5
|
||||
--> $DIR/must-use-ops.rs:41:5
|
||||
|
|
||||
LL | 5 >> val;
|
||||
| ^^^^^^^^ the bitwise operation produces a value
|
||||
|
|
@ -202,7 +202,7 @@ LL | let _ = 5 >> val;
|
|||
| +++++++
|
||||
|
||||
warning: unused unary operation that must be used
|
||||
--> $DIR/must-use-ops.rs:38:5
|
||||
--> $DIR/must-use-ops.rs:44:5
|
||||
|
|
||||
LL | !val;
|
||||
| ^^^^ the unary operation produces a value
|
||||
|
|
@ -213,7 +213,7 @@ LL | let _ = !val;
|
|||
| +++++++
|
||||
|
||||
warning: unused unary operation that must be used
|
||||
--> $DIR/must-use-ops.rs:39:5
|
||||
--> $DIR/must-use-ops.rs:45:5
|
||||
|
|
||||
LL | -val;
|
||||
| ^^^^ the unary operation produces a value
|
||||
|
|
@ -224,7 +224,7 @@ LL | let _ = -val;
|
|||
| +++++++
|
||||
|
||||
warning: unused unary operation that must be used
|
||||
--> $DIR/must-use-ops.rs:40:5
|
||||
--> $DIR/must-use-ops.rs:46:5
|
||||
|
|
||||
LL | *val_pointer;
|
||||
| ^^^^^^^^^^^^ the unary operation produces a value
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#![deny(unused_must_use)]
|
||||
|
||||
#[must_use]
|
||||
#[derive(Clone, Copy)]
|
||||
struct S;
|
||||
|
||||
struct A;
|
||||
|
|
@ -34,6 +35,10 @@ fn array_of_arrays_of_arrays() -> [[[S; 1]; 2]; 1] {
|
|||
[[[S], [S]]]
|
||||
}
|
||||
|
||||
fn usize_max() -> [S; usize::MAX] {
|
||||
[S; usize::MAX]
|
||||
}
|
||||
|
||||
fn main() {
|
||||
empty(); // ok
|
||||
singleton(); //~ ERROR unused array of `S` that must be used
|
||||
|
|
@ -44,4 +49,6 @@ fn main() {
|
|||
//~^ ERROR unused array of boxed `T` trait objects in tuple element 1 that must be used
|
||||
array_of_arrays_of_arrays();
|
||||
//~^ ERROR unused array of arrays of arrays of `S` that must be used
|
||||
usize_max();
|
||||
//~^ ERROR unused array of `S` that must be used
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
error: unused array of `S` that must be used
|
||||
--> $DIR/must_use-array.rs:39:5
|
||||
--> $DIR/must_use-array.rs:44:5
|
||||
|
|
||||
LL | singleton();
|
||||
| ^^^^^^^^^^^
|
||||
|
|
@ -11,34 +11,40 @@ LL | #![deny(unused_must_use)]
|
|||
| ^^^^^^^^^^^^^^^
|
||||
|
||||
error: unused array of `S` that must be used
|
||||
--> $DIR/must_use-array.rs:40:5
|
||||
--> $DIR/must_use-array.rs:45:5
|
||||
|
|
||||
LL | many();
|
||||
| ^^^^^^
|
||||
|
||||
error: unused array of `S` in tuple element 0 that must be used
|
||||
--> $DIR/must_use-array.rs:41:6
|
||||
--> $DIR/must_use-array.rs:46:6
|
||||
|
|
||||
LL | ([S], 0, ());
|
||||
| ^^^
|
||||
|
||||
error: unused array of implementers of `T` that must be used
|
||||
--> $DIR/must_use-array.rs:42:5
|
||||
--> $DIR/must_use-array.rs:47:5
|
||||
|
|
||||
LL | array_of_impl_trait();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: unused array of boxed `T` trait objects in tuple element 1 that must be used
|
||||
--> $DIR/must_use-array.rs:43:5
|
||||
--> $DIR/must_use-array.rs:48:5
|
||||
|
|
||||
LL | impl_array();
|
||||
| ^^^^^^^^^^^^
|
||||
|
||||
error: unused array of arrays of arrays of `S` that must be used
|
||||
--> $DIR/must_use-array.rs:45:5
|
||||
--> $DIR/must_use-array.rs:50:5
|
||||
|
|
||||
LL | array_of_arrays_of_arrays();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 6 previous errors
|
||||
error: unused array of `S` that must be used
|
||||
--> $DIR/must_use-array.rs:52:5
|
||||
|
|
||||
LL | usize_max();
|
||||
| ^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 7 previous errors
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue