Auto merge of #87607 - JohnTitor:help-to-unused-must-use-op, r=estebank

Add a hint that the expressions produce a value

Fixes #85913
The second commit is semi-_unrelated_ but it allows us to run the related tests just on `src/test/ui/lint`.
This commit is contained in:
bors 2021-07-31 13:47:25 +00:00
commit 337181e07d
84 changed files with 325 additions and 143 deletions

View File

@ -161,7 +161,15 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults {
if let Some(must_use_op) = must_use_op {
cx.struct_span_lint(UNUSED_MUST_USE, expr.span, |lint| {
lint.build(&format!("unused {} that must be used", must_use_op)).emit()
let mut lint = lint.build(&format!("unused {} that must be used", must_use_op));
lint.span_label(expr.span, &format!("the {} produces a value", must_use_op));
lint.span_suggestion_verbose(
expr.span.shrink_to_lo(),
"use `let _ = ...` to ignore the resulting value",
"let _ = ".to_string(),
Applicability::MachineApplicable,
);
lint.emit();
});
op_warned = true;
}

View File

@ -47,13 +47,23 @@ warning: unused comparison that must be used
--> $DIR/fn_must_use.rs:74:5
|
LL | 2 == 3;
| ^^^^^^
| ^^^^^^ the comparison produces a value
|
help: use `let _ = ...` to ignore the resulting value
|
LL | let _ = 2 == 3;
| ^^^^^^^
warning: unused comparison that must be used
--> $DIR/fn_must_use.rs:75:5
|
LL | m == n;
| ^^^^^^
| ^^^^^^ the comparison produces a value
|
help: use `let _ = ...` to ignore the resulting value
|
LL | let _ = m == n;
| ^^^^^^^
warning: 8 warnings emitted

View File

@ -1,134 +0,0 @@
warning: unused comparison that must be used
--> $DIR/must-use-ops.rs:12:5
|
LL | val == 1;
| ^^^^^^^^
|
note: the lint level is defined here
--> $DIR/must-use-ops.rs:5:9
|
LL | #![warn(unused_must_use)]
| ^^^^^^^^^^^^^^^
warning: unused comparison that must be used
--> $DIR/must-use-ops.rs:13:5
|
LL | val < 1;
| ^^^^^^^
warning: unused comparison that must be used
--> $DIR/must-use-ops.rs:14:5
|
LL | val <= 1;
| ^^^^^^^^
warning: unused comparison that must be used
--> $DIR/must-use-ops.rs:15:5
|
LL | val != 1;
| ^^^^^^^^
warning: unused comparison that must be used
--> $DIR/must-use-ops.rs:16:5
|
LL | val >= 1;
| ^^^^^^^^
warning: unused comparison that must be used
--> $DIR/must-use-ops.rs:17:5
|
LL | val > 1;
| ^^^^^^^
warning: unused arithmetic operation that must be used
--> $DIR/must-use-ops.rs:20:5
|
LL | val + 2;
| ^^^^^^^
warning: unused arithmetic operation that must be used
--> $DIR/must-use-ops.rs:21:5
|
LL | val - 2;
| ^^^^^^^
warning: unused arithmetic operation that must be used
--> $DIR/must-use-ops.rs:22:5
|
LL | val / 2;
| ^^^^^^^
warning: unused arithmetic operation that must be used
--> $DIR/must-use-ops.rs:23:5
|
LL | val * 2;
| ^^^^^^^
warning: unused arithmetic operation that must be used
--> $DIR/must-use-ops.rs:24:5
|
LL | val % 2;
| ^^^^^^^
warning: unused logical operation that must be used
--> $DIR/must-use-ops.rs:27:5
|
LL | true && true;
| ^^^^^^^^^^^^
warning: unused logical operation that must be used
--> $DIR/must-use-ops.rs:28:5
|
LL | false || true;
| ^^^^^^^^^^^^^
warning: unused bitwise operation that must be used
--> $DIR/must-use-ops.rs:31:5
|
LL | 5 ^ val;
| ^^^^^^^
warning: unused bitwise operation that must be used
--> $DIR/must-use-ops.rs:32:5
|
LL | 5 & val;
| ^^^^^^^
warning: unused bitwise operation that must be used
--> $DIR/must-use-ops.rs:33:5
|
LL | 5 | val;
| ^^^^^^^
warning: unused bitwise operation that must be used
--> $DIR/must-use-ops.rs:34:5
|
LL | 5 << val;
| ^^^^^^^^
warning: unused bitwise operation that must be used
--> $DIR/must-use-ops.rs:35:5
|
LL | 5 >> val;
| ^^^^^^^^
warning: unused unary operation that must be used
--> $DIR/must-use-ops.rs:38:5
|
LL | !val;
| ^^^^
warning: unused unary operation that must be used
--> $DIR/must-use-ops.rs:39:5
|
LL | -val;
| ^^^^
warning: unused unary operation that must be used
--> $DIR/must-use-ops.rs:40:5
|
LL | *val_pointer;
| ^^^^^^^^^^^^
warning: 21 warnings emitted

View File

@ -2,43 +2,72 @@ error: unused borrow that must be used
--> $DIR/unused-borrows.rs:6:5
|
LL | &42;
| ^^^
| ^^^ the borrow produces a value
|
note: the lint level is defined here
--> $DIR/unused-borrows.rs:1:9
|
LL | #![deny(unused_must_use)]
| ^^^^^^^^^^^^^^^
help: use `let _ = ...` to ignore the resulting value
|
LL | let _ = &42;
| ^^^^^^^
error: unused borrow that must be used
--> $DIR/unused-borrows.rs:9:5
|
LL | &mut foo(42);
| ^^^^^^^^^^^^
| ^^^^^^^^^^^^ the borrow produces a value
|
help: use `let _ = ...` to ignore the resulting value
|
LL | let _ = &mut foo(42);
| ^^^^^^^
error: unused borrow that must be used
--> $DIR/unused-borrows.rs:12:5
|
LL | &&42;
| ^^^^
| ^^^^ the borrow produces a value
|
help: use `let _ = ...` to ignore the resulting value
|
LL | let _ = &&42;
| ^^^^^^^
error: unused borrow that must be used
--> $DIR/unused-borrows.rs:15:5
|
LL | &&mut 42;
| ^^^^^^^^
| ^^^^^^^^ the borrow produces a value
|
help: use `let _ = ...` to ignore the resulting value
|
LL | let _ = &&mut 42;
| ^^^^^^^
error: unused borrow that must be used
--> $DIR/unused-borrows.rs:18:5
|
LL | &mut &42;
| ^^^^^^^^
| ^^^^^^^^ the borrow produces a value
|
help: use `let _ = ...` to ignore the resulting value
|
LL | let _ = &mut &42;
| ^^^^^^^
error: unused borrow that must be used
--> $DIR/unused-borrows.rs:23:5
|
LL | && foo(42);
| ^^^^^^^^^^
| ^^^^^^^^^^ the borrow produces a value
|
help: use `let _ = ...` to ignore the resulting value
|
LL | let _ = && foo(42);
| ^^^^^^^
error: aborting due to 6 previous errors

View File

@ -0,0 +1,13 @@
#![deny(unused_must_use)]
pub fn fun() -> i32 {
function() && return 1;
//~^ ERROR: unused logical operation that must be used
return 0;
}
fn function() -> bool {
true
}
fn main() {}

View File

@ -0,0 +1,18 @@
error: unused logical operation that must be used
--> $DIR/issue-85913.rs:4:5
|
LL | function() && return 1;
| ^^^^^^^^^^^^^^^^^^^^^^ the logical operation produces a value
|
note: the lint level is defined here
--> $DIR/issue-85913.rs:1:9
|
LL | #![deny(unused_must_use)]
| ^^^^^^^^^^^^^^^
help: use `let _ = ...` to ignore the resulting value
|
LL | let _ = function() && return 1;
| ^^^^^^^
error: aborting due to previous error

View File

@ -0,0 +1,238 @@
warning: unused comparison that must be used
--> $DIR/must-use-ops.rs:12:5
|
LL | val == 1;
| ^^^^^^^^ the comparison produces a value
|
note: the lint level is defined here
--> $DIR/must-use-ops.rs:5:9
|
LL | #![warn(unused_must_use)]
| ^^^^^^^^^^^^^^^
help: use `let _ = ...` to ignore the resulting value
|
LL | let _ = val == 1;
| ^^^^^^^
warning: unused comparison that must be used
--> $DIR/must-use-ops.rs:13:5
|
LL | val < 1;
| ^^^^^^^ the comparison produces a value
|
help: use `let _ = ...` to ignore the resulting value
|
LL | let _ = val < 1;
| ^^^^^^^
warning: unused comparison that must be used
--> $DIR/must-use-ops.rs:14:5
|
LL | val <= 1;
| ^^^^^^^^ the comparison produces a value
|
help: use `let _ = ...` to ignore the resulting value
|
LL | let _ = val <= 1;
| ^^^^^^^
warning: unused comparison that must be used
--> $DIR/must-use-ops.rs:15:5
|
LL | val != 1;
| ^^^^^^^^ the comparison produces a value
|
help: use `let _ = ...` to ignore the resulting value
|
LL | let _ = val != 1;
| ^^^^^^^
warning: unused comparison that must be used
--> $DIR/must-use-ops.rs:16:5
|
LL | val >= 1;
| ^^^^^^^^ the comparison produces a value
|
help: use `let _ = ...` to ignore the resulting value
|
LL | let _ = val >= 1;
| ^^^^^^^
warning: unused comparison that must be used
--> $DIR/must-use-ops.rs:17:5
|
LL | val > 1;
| ^^^^^^^ the comparison produces a value
|
help: use `let _ = ...` to ignore the resulting value
|
LL | let _ = val > 1;
| ^^^^^^^
warning: unused arithmetic operation that must be used
--> $DIR/must-use-ops.rs:20:5
|
LL | val + 2;
| ^^^^^^^ the arithmetic operation produces a value
|
help: use `let _ = ...` to ignore the resulting value
|
LL | let _ = val + 2;
| ^^^^^^^
warning: unused arithmetic operation that must be used
--> $DIR/must-use-ops.rs:21:5
|
LL | val - 2;
| ^^^^^^^ the arithmetic operation produces a value
|
help: use `let _ = ...` to ignore the resulting value
|
LL | let _ = val - 2;
| ^^^^^^^
warning: unused arithmetic operation that must be used
--> $DIR/must-use-ops.rs:22:5
|
LL | val / 2;
| ^^^^^^^ the arithmetic operation produces a value
|
help: use `let _ = ...` to ignore the resulting value
|
LL | let _ = val / 2;
| ^^^^^^^
warning: unused arithmetic operation that must be used
--> $DIR/must-use-ops.rs:23:5
|
LL | val * 2;
| ^^^^^^^ the arithmetic operation produces a value
|
help: use `let _ = ...` to ignore the resulting value
|
LL | let _ = val * 2;
| ^^^^^^^
warning: unused arithmetic operation that must be used
--> $DIR/must-use-ops.rs:24:5
|
LL | val % 2;
| ^^^^^^^ the arithmetic operation produces a value
|
help: use `let _ = ...` to ignore the resulting value
|
LL | let _ = val % 2;
| ^^^^^^^
warning: unused logical operation that must be used
--> $DIR/must-use-ops.rs:27:5
|
LL | true && true;
| ^^^^^^^^^^^^ the logical operation produces a value
|
help: use `let _ = ...` to ignore the resulting value
|
LL | let _ = true && true;
| ^^^^^^^
warning: unused logical operation that must be used
--> $DIR/must-use-ops.rs:28:5
|
LL | false || true;
| ^^^^^^^^^^^^^ the logical operation produces a value
|
help: use `let _ = ...` to ignore the resulting value
|
LL | let _ = false || true;
| ^^^^^^^
warning: unused bitwise operation that must be used
--> $DIR/must-use-ops.rs:31:5
|
LL | 5 ^ val;
| ^^^^^^^ the bitwise operation produces a value
|
help: use `let _ = ...` to ignore the resulting value
|
LL | let _ = 5 ^ val;
| ^^^^^^^
warning: unused bitwise operation that must be used
--> $DIR/must-use-ops.rs:32:5
|
LL | 5 & val;
| ^^^^^^^ the bitwise operation produces a value
|
help: use `let _ = ...` to ignore the resulting value
|
LL | let _ = 5 & val;
| ^^^^^^^
warning: unused bitwise operation that must be used
--> $DIR/must-use-ops.rs:33:5
|
LL | 5 | val;
| ^^^^^^^ the bitwise operation produces a value
|
help: use `let _ = ...` to ignore the resulting value
|
LL | let _ = 5 | val;
| ^^^^^^^
warning: unused bitwise operation that must be used
--> $DIR/must-use-ops.rs:34:5
|
LL | 5 << val;
| ^^^^^^^^ the bitwise operation produces a value
|
help: use `let _ = ...` to ignore the resulting value
|
LL | let _ = 5 << val;
| ^^^^^^^
warning: unused bitwise operation that must be used
--> $DIR/must-use-ops.rs:35:5
|
LL | 5 >> val;
| ^^^^^^^^ the bitwise operation produces a value
|
help: use `let _ = ...` to ignore the resulting value
|
LL | let _ = 5 >> val;
| ^^^^^^^
warning: unused unary operation that must be used
--> $DIR/must-use-ops.rs:38:5
|
LL | !val;
| ^^^^ the unary operation produces a value
|
help: use `let _ = ...` to ignore the resulting value
|
LL | let _ = !val;
| ^^^^^^^
warning: unused unary operation that must be used
--> $DIR/must-use-ops.rs:39:5
|
LL | -val;
| ^^^^ the unary operation produces a value
|
help: use `let _ = ...` to ignore the resulting value
|
LL | let _ = -val;
| ^^^^^^^
warning: unused unary operation that must be used
--> $DIR/must-use-ops.rs:40:5
|
LL | *val_pointer;
| ^^^^^^^^^^^^ the unary operation produces a value
|
help: use `let _ = ...` to ignore the resulting value
|
LL | let _ = *val_pointer;
| ^^^^^^^
warning: 21 warnings emitted