about summary refs log tree commit diff
diff options
context:
space:
mode:
authorYuki Okushi <yuki.okushi@huawei.com>2021-07-31 06:21:52 +0900
committerYuki Okushi <yuki.okushi@huawei.com>2021-07-31 06:21:52 +0900
commit924eddf30d0e72b61aa753daf8dc0c75790a8730 (patch)
tree1444823c5554b3407c37b96b1000e948a41a688c
parentf3c59a8df68fb0d1c40a6788e34b765c29e9cbd0 (diff)
downloadrust-924eddf30d0e72b61aa753daf8dc0c75790a8730.tar.gz
rust-924eddf30d0e72b61aa753daf8dc0c75790a8730.zip
Apply review suggestion
-rw-r--r--compiler/rustc_lint/src/unused.rs17
-rw-r--r--src/test/ui/lint/fn_must_use.stderr14
-rw-r--r--src/test/ui/lint/unused-borrows.stderr42
-rw-r--r--src/test/ui/lint/unused/issue-85913.stderr7
-rw-r--r--src/test/ui/lint/unused/must-use-ops.stderr147
5 files changed, 157 insertions, 70 deletions
diff --git a/compiler/rustc_lint/src/unused.rs b/compiler/rustc_lint/src/unused.rs
index 5437174a683..2b580452a60 100644
--- a/compiler/rustc_lint/src/unused.rs
+++ b/compiler/rustc_lint/src/unused.rs
@@ -162,16 +162,13 @@ 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| {
                 let mut lint = lint.build(&format!("unused {} that must be used", must_use_op));
-                lint.note(&format!("the {} produces a value", must_use_op));
-                if let Ok(snippet) = cx.sess().source_map().span_to_snippet(expr.span) {
-                    lint.span_suggestion(
-                        expr.span,
-                        "use `let _ = ...` to ignore it",
-                        format!("let _ = {}", snippet),
-                        Applicability::MachineApplicable,
-                    )
-                    .emit()
-                }
+                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;
diff --git a/src/test/ui/lint/fn_must_use.stderr b/src/test/ui/lint/fn_must_use.stderr
index 75a22823329..6a5fdac4d91 100644
--- a/src/test/ui/lint/fn_must_use.stderr
+++ b/src/test/ui/lint/fn_must_use.stderr
@@ -47,17 +47,23 @@ warning: unused comparison that must be used
   --> $DIR/fn_must_use.rs:74:5
    |
 LL |     2 == 3;
-   |     ^^^^^^ help: use `let _ = ...` to ignore it: `let _ = 2 == 3`
+   |     ^^^^^^ the comparison produces a value
    |
-   = note: 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;
-   |     ^^^^^^ help: use `let _ = ...` to ignore it: `let _ = m == n`
+   |     ^^^^^^ the comparison produces a value
+   |
+help: use `let _ = ...` to ignore the resulting value
    |
-   = note: the comparison produces a value
+LL |     let _ = m == n;
+   |     ^^^^^^^
 
 warning: 8 warnings emitted
 
diff --git a/src/test/ui/lint/unused-borrows.stderr b/src/test/ui/lint/unused-borrows.stderr
index 459381b642c..e91e02df476 100644
--- a/src/test/ui/lint/unused-borrows.stderr
+++ b/src/test/ui/lint/unused-borrows.stderr
@@ -2,54 +2,72 @@ error: unused borrow that must be used
   --> $DIR/unused-borrows.rs:6:5
    |
 LL |     &42;
-   |     ^^^ help: use `let _ = ...` to ignore it: `let _ = &42`
+   |     ^^^ the borrow produces a value
    |
 note: the lint level is defined here
   --> $DIR/unused-borrows.rs:1:9
    |
 LL | #![deny(unused_must_use)]
    |         ^^^^^^^^^^^^^^^
-   = note: 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:9:5
    |
 LL |     &mut foo(42);
-   |     ^^^^^^^^^^^^ help: use `let _ = ...` to ignore it: `let _ = &mut foo(42)`
+   |     ^^^^^^^^^^^^ the borrow produces a value
+   |
+help: use `let _ = ...` to ignore the resulting value
    |
-   = note: the borrow produces a value
+LL |     let _ = &mut foo(42);
+   |     ^^^^^^^
 
 error: unused borrow that must be used
   --> $DIR/unused-borrows.rs:12:5
    |
 LL |     &&42;
-   |     ^^^^ help: use `let _ = ...` to ignore it: `let _ = &&42`
+   |     ^^^^ the borrow produces a value
+   |
+help: use `let _ = ...` to ignore the resulting value
    |
-   = note: the borrow produces a value
+LL |     let _ = &&42;
+   |     ^^^^^^^
 
 error: unused borrow that must be used
   --> $DIR/unused-borrows.rs:15:5
    |
 LL |     &&mut 42;
-   |     ^^^^^^^^ help: use `let _ = ...` to ignore it: `let _ = &&mut 42`
+   |     ^^^^^^^^ the borrow produces a value
    |
-   = note: 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;
-   |     ^^^^^^^^ help: use `let _ = ...` to ignore it: `let _ = &mut &42`
+   |     ^^^^^^^^ the borrow produces a value
+   |
+help: use `let _ = ...` to ignore the resulting value
    |
-   = note: the borrow produces a value
+LL |     let _ = &mut &42;
+   |     ^^^^^^^
 
 error: unused borrow that must be used
   --> $DIR/unused-borrows.rs:23:5
    |
 LL |     && foo(42);
-   |     ^^^^^^^^^^ help: use `let _ = ...` to ignore it: `let _ = && foo(42)`
+   |     ^^^^^^^^^^ the borrow produces a value
+   |
+help: use `let _ = ...` to ignore the resulting value
    |
-   = note: the borrow produces a value
+LL |     let _ = && foo(42);
+   |     ^^^^^^^
 
 error: aborting due to 6 previous errors
 
diff --git a/src/test/ui/lint/unused/issue-85913.stderr b/src/test/ui/lint/unused/issue-85913.stderr
index d5d99f0f7d3..4835cfae46f 100644
--- a/src/test/ui/lint/unused/issue-85913.stderr
+++ b/src/test/ui/lint/unused/issue-85913.stderr
@@ -2,14 +2,17 @@ error: unused logical operation that must be used
   --> $DIR/issue-85913.rs:4:5
    |
 LL |     function() && return 1;
-   |     ^^^^^^^^^^^^^^^^^^^^^^ help: use `let _ = ...` to ignore it: `let _ = 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)]
    |         ^^^^^^^^^^^^^^^
-   = note: the logical operation produces a value
+help: use `let _ = ...` to ignore the resulting value
+   |
+LL |     let _ = function() && return 1;
+   |     ^^^^^^^
 
 error: aborting due to previous error
 
diff --git a/src/test/ui/lint/unused/must-use-ops.stderr b/src/test/ui/lint/unused/must-use-ops.stderr
index 73405d02a2e..4dd739088b9 100644
--- a/src/test/ui/lint/unused/must-use-ops.stderr
+++ b/src/test/ui/lint/unused/must-use-ops.stderr
@@ -2,174 +2,237 @@ warning: unused comparison that must be used
   --> $DIR/must-use-ops.rs:12:5
    |
 LL |     val == 1;
-   |     ^^^^^^^^ help: use `let _ = ...` to ignore it: `let _ = 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)]
    |         ^^^^^^^^^^^^^^^
-   = note: 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:13:5
    |
 LL |     val < 1;
-   |     ^^^^^^^ help: use `let _ = ...` to ignore it: `let _ = val < 1`
+   |     ^^^^^^^ the comparison produces a value
+   |
+help: use `let _ = ...` to ignore the resulting value
    |
-   = note: the comparison produces a value
+LL |     let _ = val < 1;
+   |     ^^^^^^^
 
 warning: unused comparison that must be used
   --> $DIR/must-use-ops.rs:14:5
    |
 LL |     val <= 1;
-   |     ^^^^^^^^ help: use `let _ = ...` to ignore it: `let _ = val <= 1`
+   |     ^^^^^^^^ the comparison produces a value
+   |
+help: use `let _ = ...` to ignore the resulting value
    |
-   = note: the comparison produces a value
+LL |     let _ = val <= 1;
+   |     ^^^^^^^
 
 warning: unused comparison that must be used
   --> $DIR/must-use-ops.rs:15:5
    |
 LL |     val != 1;
-   |     ^^^^^^^^ help: use `let _ = ...` to ignore it: `let _ = val != 1`
+   |     ^^^^^^^^ the comparison produces a value
    |
-   = note: 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;
-   |     ^^^^^^^^ help: use `let _ = ...` to ignore it: `let _ = val >= 1`
+   |     ^^^^^^^^ the comparison produces a value
+   |
+help: use `let _ = ...` to ignore the resulting value
    |
-   = note: the comparison produces a value
+LL |     let _ = val >= 1;
+   |     ^^^^^^^
 
 warning: unused comparison that must be used
   --> $DIR/must-use-ops.rs:17:5
    |
 LL |     val > 1;
-   |     ^^^^^^^ help: use `let _ = ...` to ignore it: `let _ = val > 1`
+   |     ^^^^^^^ the comparison produces a value
+   |
+help: use `let _ = ...` to ignore the resulting value
    |
-   = note: the comparison produces a value
+LL |     let _ = val > 1;
+   |     ^^^^^^^
 
 warning: unused arithmetic operation that must be used
   --> $DIR/must-use-ops.rs:20:5
    |
 LL |     val + 2;
-   |     ^^^^^^^ help: use `let _ = ...` to ignore it: `let _ = val + 2`
+   |     ^^^^^^^ the arithmetic operation produces a value
    |
-   = note: 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;
-   |     ^^^^^^^ help: use `let _ = ...` to ignore it: `let _ = val - 2`
+   |     ^^^^^^^ the arithmetic operation produces a value
+   |
+help: use `let _ = ...` to ignore the resulting value
    |
-   = note: the arithmetic operation produces a value
+LL |     let _ = val - 2;
+   |     ^^^^^^^
 
 warning: unused arithmetic operation that must be used
   --> $DIR/must-use-ops.rs:22:5
    |
 LL |     val / 2;
-   |     ^^^^^^^ help: use `let _ = ...` to ignore it: `let _ = val / 2`
+   |     ^^^^^^^ the arithmetic operation produces a value
+   |
+help: use `let _ = ...` to ignore the resulting value
    |
-   = note: the arithmetic operation produces a value
+LL |     let _ = val / 2;
+   |     ^^^^^^^
 
 warning: unused arithmetic operation that must be used
   --> $DIR/must-use-ops.rs:23:5
    |
 LL |     val * 2;
-   |     ^^^^^^^ help: use `let _ = ...` to ignore it: `let _ = val * 2`
+   |     ^^^^^^^ the arithmetic operation produces a value
    |
-   = note: 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;
-   |     ^^^^^^^ help: use `let _ = ...` to ignore it: `let _ = val % 2`
+   |     ^^^^^^^ the arithmetic operation produces a value
+   |
+help: use `let _ = ...` to ignore the resulting value
    |
-   = note: the arithmetic operation produces a value
+LL |     let _ = val % 2;
+   |     ^^^^^^^
 
 warning: unused logical operation that must be used
   --> $DIR/must-use-ops.rs:27:5
    |
 LL |     true && true;
-   |     ^^^^^^^^^^^^ help: use `let _ = ...` to ignore it: `let _ = true && true`
+   |     ^^^^^^^^^^^^ the logical operation produces a value
    |
-   = note: 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;
-   |     ^^^^^^^^^^^^^ help: use `let _ = ...` to ignore it: `let _ = false || true`
+   |     ^^^^^^^^^^^^^ the logical operation produces a value
+   |
+help: use `let _ = ...` to ignore the resulting value
    |
-   = note: the logical operation produces a value
+LL |     let _ = false || true;
+   |     ^^^^^^^
 
 warning: unused bitwise operation that must be used
   --> $DIR/must-use-ops.rs:31:5
    |
 LL |     5 ^ val;
-   |     ^^^^^^^ help: use `let _ = ...` to ignore it: `let _ = 5 ^ val`
+   |     ^^^^^^^ the bitwise operation produces a value
+   |
+help: use `let _ = ...` to ignore the resulting value
    |
-   = note: the bitwise operation produces a value
+LL |     let _ = 5 ^ val;
+   |     ^^^^^^^
 
 warning: unused bitwise operation that must be used
   --> $DIR/must-use-ops.rs:32:5
    |
 LL |     5 & val;
-   |     ^^^^^^^ help: use `let _ = ...` to ignore it: `let _ = 5 & val`
+   |     ^^^^^^^ the bitwise operation produces a value
    |
-   = note: 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;
-   |     ^^^^^^^ help: use `let _ = ...` to ignore it: `let _ = 5 | val`
+   |     ^^^^^^^ the bitwise operation produces a value
+   |
+help: use `let _ = ...` to ignore the resulting value
    |
-   = note: the bitwise operation produces a value
+LL |     let _ = 5 | val;
+   |     ^^^^^^^
 
 warning: unused bitwise operation that must be used
   --> $DIR/must-use-ops.rs:34:5
    |
 LL |     5 << val;
-   |     ^^^^^^^^ help: use `let _ = ...` to ignore it: `let _ = 5 << val`
+   |     ^^^^^^^^ the bitwise operation produces a value
    |
-   = note: 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;
-   |     ^^^^^^^^ help: use `let _ = ...` to ignore it: `let _ = 5 >> val`
+   |     ^^^^^^^^ the bitwise operation produces a value
+   |
+help: use `let _ = ...` to ignore the resulting value
    |
-   = note: the bitwise operation produces a value
+LL |     let _ = 5 >> val;
+   |     ^^^^^^^
 
 warning: unused unary operation that must be used
   --> $DIR/must-use-ops.rs:38:5
    |
 LL |     !val;
-   |     ^^^^ help: use `let _ = ...` to ignore it: `let _ = !val`
+   |     ^^^^ the unary operation produces a value
+   |
+help: use `let _ = ...` to ignore the resulting value
    |
-   = note: the unary operation produces a value
+LL |     let _ = !val;
+   |     ^^^^^^^
 
 warning: unused unary operation that must be used
   --> $DIR/must-use-ops.rs:39:5
    |
 LL |     -val;
-   |     ^^^^ help: use `let _ = ...` to ignore it: `let _ = -val`
+   |     ^^^^ the unary operation produces a value
    |
-   = note: 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;
-   |     ^^^^^^^^^^^^ help: use `let _ = ...` to ignore it: `let _ = *val_pointer`
+   |     ^^^^^^^^^^^^ the unary operation produces a value
+   |
+help: use `let _ = ...` to ignore the resulting value
    |
-   = note: the unary operation produces a value
+LL |     let _ = *val_pointer;
+   |     ^^^^^^^
 
 warning: 21 warnings emitted