From eaff0fc25bfe6f831038953ff5bd8fa2372dba22 Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Fri, 30 Jul 2021 05:35:03 +0900 Subject: Add a hint that the expressions produce a value --- src/test/ui/lint/fn_must_use.stderr | 8 +++- src/test/ui/lint/must-use-ops.stderr | 83 +++++++++++++++++++++++++--------- src/test/ui/lint/unused-borrows.stderr | 23 +++++++--- src/test/ui/unused/issue-85913.rs | 13 ++++++ src/test/ui/unused/issue-85913.stderr | 15 ++++++ 5 files changed, 113 insertions(+), 29 deletions(-) create mode 100644 src/test/ui/unused/issue-85913.rs create mode 100644 src/test/ui/unused/issue-85913.stderr (limited to 'src/test') diff --git a/src/test/ui/lint/fn_must_use.stderr b/src/test/ui/lint/fn_must_use.stderr index d6b1cf3ae1f..75a22823329 100644 --- a/src/test/ui/lint/fn_must_use.stderr +++ b/src/test/ui/lint/fn_must_use.stderr @@ -47,13 +47,17 @@ 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` + | + = note: the comparison produces a value 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` + | + = note: the comparison produces a value warning: 8 warnings emitted diff --git a/src/test/ui/lint/must-use-ops.stderr b/src/test/ui/lint/must-use-ops.stderr index 3fb80f7e798..73405d02a2e 100644 --- a/src/test/ui/lint/must-use-ops.stderr +++ b/src/test/ui/lint/must-use-ops.stderr @@ -2,133 +2,174 @@ 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` | 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 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` + | + = note: the comparison produces a value 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` + | + = note: the comparison produces a value 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` + | + = note: the comparison produces a value 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` + | + = note: the comparison produces a value 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` + | + = note: the comparison produces a value 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` + | + = note: the arithmetic operation produces a value 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` + | + = note: the arithmetic operation produces a value 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` + | + = note: the arithmetic operation produces a value 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` + | + = note: the arithmetic operation produces a value 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` + | + = note: the arithmetic operation produces a value 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` + | + = note: the logical operation produces a value 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` + | + = note: the logical operation produces a value 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` + | + = note: the bitwise operation produces a value 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` + | + = note: the bitwise operation produces a value 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` + | + = note: the bitwise operation produces a value 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` + | + = note: the bitwise operation produces a value 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` + | + = note: the bitwise operation produces a value 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` + | + = note: the unary operation produces a value 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` + | + = note: the unary operation produces a value 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` + | + = note: the unary operation produces a value warning: 21 warnings emitted diff --git a/src/test/ui/lint/unused-borrows.stderr b/src/test/ui/lint/unused-borrows.stderr index 24899fe992b..459381b642c 100644 --- a/src/test/ui/lint/unused-borrows.stderr +++ b/src/test/ui/lint/unused-borrows.stderr @@ -2,43 +2,54 @@ error: unused borrow that must be used --> $DIR/unused-borrows.rs:6:5 | LL | &42; - | ^^^ + | ^^^ help: use `let _ = ...` to ignore it: `let _ = &42` | note: the lint level is defined here --> $DIR/unused-borrows.rs:1:9 | LL | #![deny(unused_must_use)] | ^^^^^^^^^^^^^^^ + = note: the borrow produces a value 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)` + | + = note: the borrow produces a value error: unused borrow that must be used --> $DIR/unused-borrows.rs:12:5 | LL | &&42; - | ^^^^ + | ^^^^ help: use `let _ = ...` to ignore it: `let _ = &&42` + | + = note: the borrow produces a value 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` + | + = note: the borrow produces a value 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` + | + = note: the borrow produces a value 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)` + | + = note: the borrow produces a value error: aborting due to 6 previous errors diff --git a/src/test/ui/unused/issue-85913.rs b/src/test/ui/unused/issue-85913.rs new file mode 100644 index 00000000000..7f3817b6ef1 --- /dev/null +++ b/src/test/ui/unused/issue-85913.rs @@ -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() {} diff --git a/src/test/ui/unused/issue-85913.stderr b/src/test/ui/unused/issue-85913.stderr new file mode 100644 index 00000000000..d5d99f0f7d3 --- /dev/null +++ b/src/test/ui/unused/issue-85913.stderr @@ -0,0 +1,15 @@ +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` + | +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 + +error: aborting due to previous error + -- cgit 1.4.1-3-g733a5 From f3c59a8df68fb0d1c40a6788e34b765c29e9cbd0 Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Fri, 30 Jul 2021 05:41:10 +0900 Subject: Move the `unused` dir to `lint`s subdir --- .../ui/lint/auxiliary/lint_unused_extern_crate.rs | 1 - .../ui/lint/auxiliary/lint_unused_extern_crate2.rs | 1 - .../ui/lint/auxiliary/lint_unused_extern_crate3.rs | 1 - .../ui/lint/auxiliary/lint_unused_extern_crate4.rs | 1 - .../ui/lint/auxiliary/lint_unused_extern_crate5.rs | 1 - ...ssue-47390-unused-variable-in-struct-pattern.rs | 88 -------- ...-47390-unused-variable-in-struct-pattern.stderr | 126 ------------ .../ui/lint/issue-54180-unused-ref-field.fixed | 34 ---- src/test/ui/lint/issue-54180-unused-ref-field.rs | 34 ---- .../ui/lint/issue-54180-unused-ref-field.stderr | 33 --- .../ui/lint/issue-54538-unused-parens-lint.fixed | 106 ---------- src/test/ui/lint/issue-54538-unused-parens-lint.rs | 106 ---------- .../ui/lint/issue-54538-unused-parens-lint.stderr | 152 -------------- .../lint/issue-67691-unused-field-in-or-pattern.rs | 85 -------- .../issue-67691-unused-field-in-or-pattern.stderr | 74 ------- src/test/ui/lint/issue-71290-unused-paren-binop.rs | 23 --- .../lint/issue-74883-unused-paren-baren-yield.rs | 26 --- .../issue-74883-unused-paren-baren-yield.stderr | 50 ----- .../ui/lint/issue-81314-unused-span-ident.fixed | 12 -- src/test/ui/lint/issue-81314-unused-span-ident.rs | 12 -- .../ui/lint/issue-81314-unused-span-ident.stderr | 21 -- src/test/ui/lint/lint-unused-extern-crate.rs | 35 ---- src/test/ui/lint/lint-unused-extern-crate.stderr | 20 -- src/test/ui/lint/lint-unused-imports.rs | 90 --------- src/test/ui/lint/lint-unused-imports.stderr | 78 -------- src/test/ui/lint/lint-unused-mut-self.fixed | 14 -- src/test/ui/lint/lint-unused-mut-self.rs | 14 -- src/test/ui/lint/lint-unused-mut-self.stderr | 24 --- src/test/ui/lint/lint-unused-mut-variables.rs | 207 ------------------- src/test/ui/lint/lint-unused-mut-variables.stderr | 222 --------------------- src/test/ui/lint/lint-unused-variables.rs | 79 -------- src/test/ui/lint/lint-unused-variables.stderr | 74 ------- src/test/ui/lint/must-use-ops.rs | 41 ---- src/test/ui/lint/must-use-ops.stderr | 175 ---------------- src/test/ui/lint/must_use-array.rs | 47 ----- src/test/ui/lint/must_use-array.stderr | 44 ---- src/test/ui/lint/must_use-in-stdlib-traits.rs | 47 ----- src/test/ui/lint/must_use-in-stdlib-traits.stderr | 47 ----- src/test/ui/lint/must_use-trait.rs | 39 ---- src/test/ui/lint/must_use-trait.stderr | 38 ---- src/test/ui/lint/must_use-tuple.rs | 17 -- src/test/ui/lint/must_use-tuple.stderr | 47 ----- src/test/ui/lint/must_use-unit.rs | 16 -- src/test/ui/lint/must_use-unit.stderr | 20 -- src/test/ui/lint/no-unused-parens-return-block.rs | 9 - .../unused/auxiliary/lint_unused_extern_crate.rs | 1 + .../unused/auxiliary/lint_unused_extern_crate2.rs | 1 + .../unused/auxiliary/lint_unused_extern_crate3.rs | 1 + .../unused/auxiliary/lint_unused_extern_crate4.rs | 1 + .../unused/auxiliary/lint_unused_extern_crate5.rs | 1 + src/test/ui/lint/unused/issue-30730.rs | 5 + src/test/ui/lint/unused/issue-30730.stderr | 15 ++ src/test/ui/lint/unused/issue-46576.rs | 21 ++ src/test/ui/lint/unused/issue-46576.stderr | 14 ++ ...ssue-47390-unused-variable-in-struct-pattern.rs | 88 ++++++++ ...-47390-unused-variable-in-struct-pattern.stderr | 126 ++++++++++++ .../lint/unused/issue-54180-unused-ref-field.fixed | 34 ++++ .../ui/lint/unused/issue-54180-unused-ref-field.rs | 34 ++++ .../unused/issue-54180-unused-ref-field.stderr | 33 +++ .../unused/issue-54538-unused-parens-lint.fixed | 106 ++++++++++ .../lint/unused/issue-54538-unused-parens-lint.rs | 106 ++++++++++ .../unused/issue-54538-unused-parens-lint.stderr | 152 ++++++++++++++ src/test/ui/lint/unused/issue-59896.rs | 9 + src/test/ui/lint/unused/issue-59896.stderr | 17 ++ .../issue-67691-unused-field-in-or-pattern.rs | 85 ++++++++ .../issue-67691-unused-field-in-or-pattern.stderr | 74 +++++++ src/test/ui/lint/unused/issue-70041.rs | 13 ++ src/test/ui/lint/unused/issue-70041.stderr | 21 ++ .../lint/unused/issue-71290-unused-paren-binop.rs | 23 +++ .../unused/issue-74883-unused-paren-baren-yield.rs | 26 +++ .../issue-74883-unused-paren-baren-yield.stderr | 50 +++++ .../unused/issue-81314-unused-span-ident.fixed | 12 ++ .../lint/unused/issue-81314-unused-span-ident.rs | 12 ++ .../unused/issue-81314-unused-span-ident.stderr | 21 ++ src/test/ui/lint/unused/issue-85913.rs | 13 ++ src/test/ui/lint/unused/issue-85913.stderr | 15 ++ .../ui/lint/unused/lint-unused-extern-crate.rs | 35 ++++ .../ui/lint/unused/lint-unused-extern-crate.stderr | 20 ++ src/test/ui/lint/unused/lint-unused-imports.rs | 90 +++++++++ src/test/ui/lint/unused/lint-unused-imports.stderr | 78 ++++++++ src/test/ui/lint/unused/lint-unused-mut-self.fixed | 14 ++ src/test/ui/lint/unused/lint-unused-mut-self.rs | 14 ++ .../ui/lint/unused/lint-unused-mut-self.stderr | 24 +++ .../ui/lint/unused/lint-unused-mut-variables.rs | 207 +++++++++++++++++++ .../lint/unused/lint-unused-mut-variables.stderr | 222 +++++++++++++++++++++ src/test/ui/lint/unused/lint-unused-variables.rs | 79 ++++++++ .../ui/lint/unused/lint-unused-variables.stderr | 74 +++++++ src/test/ui/lint/unused/must-use-ops.rs | 41 ++++ src/test/ui/lint/unused/must-use-ops.stderr | 175 ++++++++++++++++ src/test/ui/lint/unused/must_use-array.rs | 47 +++++ src/test/ui/lint/unused/must_use-array.stderr | 44 ++++ .../ui/lint/unused/must_use-in-stdlib-traits.rs | 47 +++++ .../lint/unused/must_use-in-stdlib-traits.stderr | 47 +++++ src/test/ui/lint/unused/must_use-trait.rs | 39 ++++ src/test/ui/lint/unused/must_use-trait.stderr | 38 ++++ src/test/ui/lint/unused/must_use-tuple.rs | 17 ++ src/test/ui/lint/unused/must_use-tuple.stderr | 47 +++++ src/test/ui/lint/unused/must_use-unit.rs | 16 ++ src/test/ui/lint/unused/must_use-unit.stderr | 20 ++ .../lint/unused/no-unused-parens-return-block.rs | 9 + src/test/ui/lint/unused/unused-attr-macro-rules.rs | 34 ++++ .../ui/lint/unused/unused-attr-macro-rules.stderr | 32 +++ src/test/ui/lint/unused/unused-attr.rs | 49 +++++ src/test/ui/lint/unused/unused-attr.stderr | 98 +++++++++ src/test/ui/lint/unused/unused-closure.rs | 35 ++++ src/test/ui/lint/unused/unused-closure.stderr | 65 ++++++ .../lint/unused/unused-doc-comments-edge-cases.rs | 29 +++ .../unused/unused-doc-comments-edge-cases.stderr | 61 ++++++ .../lint/unused/unused-doc-comments-for-macros.rs | 17 ++ .../unused/unused-doc-comments-for-macros.stderr | 31 +++ src/test/ui/lint/unused/unused-macro-rules.rs | 29 +++ src/test/ui/lint/unused/unused-macro-rules.stderr | 43 ++++ .../lint/unused/unused-macro-with-bad-frag-spec.rs | 9 + .../unused/unused-macro-with-bad-frag-spec.stderr | 10 + .../unused/unused-macro-with-follow-violation.rs | 7 + .../unused-macro-with-follow-violation.stderr | 10 + src/test/ui/lint/unused/unused-macro.rs | 26 +++ src/test/ui/lint/unused/unused-macro.stderr | 38 ++++ .../unused/unused-mut-warning-captured-var.fixed | 9 + .../lint/unused/unused-mut-warning-captured-var.rs | 9 + .../unused/unused-mut-warning-captured-var.stderr | 16 ++ src/test/ui/lint/unused/unused-result.rs | 42 ++++ src/test/ui/lint/unused/unused-result.stderr | 48 +++++ src/test/ui/lint/unused/useless-comment.rs | 45 +++++ src/test/ui/lint/unused/useless-comment.stderr | 110 ++++++++++ src/test/ui/unused/issue-30730.rs | 5 - src/test/ui/unused/issue-30730.stderr | 15 -- src/test/ui/unused/issue-46576.rs | 21 -- src/test/ui/unused/issue-46576.stderr | 14 -- src/test/ui/unused/issue-59896.rs | 9 - src/test/ui/unused/issue-59896.stderr | 17 -- src/test/ui/unused/issue-70041.rs | 13 -- src/test/ui/unused/issue-70041.stderr | 21 -- src/test/ui/unused/issue-85913.rs | 13 -- src/test/ui/unused/issue-85913.stderr | 15 -- src/test/ui/unused/unused-attr-macro-rules.rs | 34 ---- src/test/ui/unused/unused-attr-macro-rules.stderr | 32 --- src/test/ui/unused/unused-attr.rs | 49 ----- src/test/ui/unused/unused-attr.stderr | 98 --------- src/test/ui/unused/unused-closure.rs | 35 ---- src/test/ui/unused/unused-closure.stderr | 65 ------ .../ui/unused/unused-doc-comments-edge-cases.rs | 29 --- .../unused/unused-doc-comments-edge-cases.stderr | 61 ------ .../ui/unused/unused-doc-comments-for-macros.rs | 17 -- .../unused/unused-doc-comments-for-macros.stderr | 31 --- src/test/ui/unused/unused-macro-rules.rs | 29 --- src/test/ui/unused/unused-macro-rules.stderr | 43 ---- .../ui/unused/unused-macro-with-bad-frag-spec.rs | 9 - .../unused/unused-macro-with-bad-frag-spec.stderr | 10 - .../unused/unused-macro-with-follow-violation.rs | 7 - .../unused-macro-with-follow-violation.stderr | 10 - src/test/ui/unused/unused-macro.rs | 26 --- src/test/ui/unused/unused-macro.stderr | 38 ---- .../unused/unused-mut-warning-captured-var.fixed | 9 - .../ui/unused/unused-mut-warning-captured-var.rs | 9 - .../unused/unused-mut-warning-captured-var.stderr | 16 -- src/test/ui/unused/unused-result.rs | 42 ---- src/test/ui/unused/unused-result.stderr | 48 ----- src/test/ui/unused/useless-comment.rs | 45 ----- src/test/ui/unused/useless-comment.stderr | 110 ---------- 160 files changed, 3476 insertions(+), 3476 deletions(-) delete mode 100644 src/test/ui/lint/auxiliary/lint_unused_extern_crate.rs delete mode 100644 src/test/ui/lint/auxiliary/lint_unused_extern_crate2.rs delete mode 100644 src/test/ui/lint/auxiliary/lint_unused_extern_crate3.rs delete mode 100644 src/test/ui/lint/auxiliary/lint_unused_extern_crate4.rs delete mode 100644 src/test/ui/lint/auxiliary/lint_unused_extern_crate5.rs delete mode 100644 src/test/ui/lint/issue-47390-unused-variable-in-struct-pattern.rs delete mode 100644 src/test/ui/lint/issue-47390-unused-variable-in-struct-pattern.stderr delete mode 100644 src/test/ui/lint/issue-54180-unused-ref-field.fixed delete mode 100644 src/test/ui/lint/issue-54180-unused-ref-field.rs delete mode 100644 src/test/ui/lint/issue-54180-unused-ref-field.stderr delete mode 100644 src/test/ui/lint/issue-54538-unused-parens-lint.fixed delete mode 100644 src/test/ui/lint/issue-54538-unused-parens-lint.rs delete mode 100644 src/test/ui/lint/issue-54538-unused-parens-lint.stderr delete mode 100644 src/test/ui/lint/issue-67691-unused-field-in-or-pattern.rs delete mode 100644 src/test/ui/lint/issue-67691-unused-field-in-or-pattern.stderr delete mode 100644 src/test/ui/lint/issue-71290-unused-paren-binop.rs delete mode 100644 src/test/ui/lint/issue-74883-unused-paren-baren-yield.rs delete mode 100644 src/test/ui/lint/issue-74883-unused-paren-baren-yield.stderr delete mode 100644 src/test/ui/lint/issue-81314-unused-span-ident.fixed delete mode 100644 src/test/ui/lint/issue-81314-unused-span-ident.rs delete mode 100644 src/test/ui/lint/issue-81314-unused-span-ident.stderr delete mode 100644 src/test/ui/lint/lint-unused-extern-crate.rs delete mode 100644 src/test/ui/lint/lint-unused-extern-crate.stderr delete mode 100644 src/test/ui/lint/lint-unused-imports.rs delete mode 100644 src/test/ui/lint/lint-unused-imports.stderr delete mode 100644 src/test/ui/lint/lint-unused-mut-self.fixed delete mode 100644 src/test/ui/lint/lint-unused-mut-self.rs delete mode 100644 src/test/ui/lint/lint-unused-mut-self.stderr delete mode 100644 src/test/ui/lint/lint-unused-mut-variables.rs delete mode 100644 src/test/ui/lint/lint-unused-mut-variables.stderr delete mode 100644 src/test/ui/lint/lint-unused-variables.rs delete mode 100644 src/test/ui/lint/lint-unused-variables.stderr delete mode 100644 src/test/ui/lint/must-use-ops.rs delete mode 100644 src/test/ui/lint/must-use-ops.stderr delete mode 100644 src/test/ui/lint/must_use-array.rs delete mode 100644 src/test/ui/lint/must_use-array.stderr delete mode 100644 src/test/ui/lint/must_use-in-stdlib-traits.rs delete mode 100644 src/test/ui/lint/must_use-in-stdlib-traits.stderr delete mode 100644 src/test/ui/lint/must_use-trait.rs delete mode 100644 src/test/ui/lint/must_use-trait.stderr delete mode 100644 src/test/ui/lint/must_use-tuple.rs delete mode 100644 src/test/ui/lint/must_use-tuple.stderr delete mode 100644 src/test/ui/lint/must_use-unit.rs delete mode 100644 src/test/ui/lint/must_use-unit.stderr delete mode 100644 src/test/ui/lint/no-unused-parens-return-block.rs create mode 100644 src/test/ui/lint/unused/auxiliary/lint_unused_extern_crate.rs create mode 100644 src/test/ui/lint/unused/auxiliary/lint_unused_extern_crate2.rs create mode 100644 src/test/ui/lint/unused/auxiliary/lint_unused_extern_crate3.rs create mode 100644 src/test/ui/lint/unused/auxiliary/lint_unused_extern_crate4.rs create mode 100644 src/test/ui/lint/unused/auxiliary/lint_unused_extern_crate5.rs create mode 100644 src/test/ui/lint/unused/issue-30730.rs create mode 100644 src/test/ui/lint/unused/issue-30730.stderr create mode 100644 src/test/ui/lint/unused/issue-46576.rs create mode 100644 src/test/ui/lint/unused/issue-46576.stderr create mode 100644 src/test/ui/lint/unused/issue-47390-unused-variable-in-struct-pattern.rs create mode 100644 src/test/ui/lint/unused/issue-47390-unused-variable-in-struct-pattern.stderr create mode 100644 src/test/ui/lint/unused/issue-54180-unused-ref-field.fixed create mode 100644 src/test/ui/lint/unused/issue-54180-unused-ref-field.rs create mode 100644 src/test/ui/lint/unused/issue-54180-unused-ref-field.stderr create mode 100644 src/test/ui/lint/unused/issue-54538-unused-parens-lint.fixed create mode 100644 src/test/ui/lint/unused/issue-54538-unused-parens-lint.rs create mode 100644 src/test/ui/lint/unused/issue-54538-unused-parens-lint.stderr create mode 100644 src/test/ui/lint/unused/issue-59896.rs create mode 100644 src/test/ui/lint/unused/issue-59896.stderr create mode 100644 src/test/ui/lint/unused/issue-67691-unused-field-in-or-pattern.rs create mode 100644 src/test/ui/lint/unused/issue-67691-unused-field-in-or-pattern.stderr create mode 100644 src/test/ui/lint/unused/issue-70041.rs create mode 100644 src/test/ui/lint/unused/issue-70041.stderr create mode 100644 src/test/ui/lint/unused/issue-71290-unused-paren-binop.rs create mode 100644 src/test/ui/lint/unused/issue-74883-unused-paren-baren-yield.rs create mode 100644 src/test/ui/lint/unused/issue-74883-unused-paren-baren-yield.stderr create mode 100644 src/test/ui/lint/unused/issue-81314-unused-span-ident.fixed create mode 100644 src/test/ui/lint/unused/issue-81314-unused-span-ident.rs create mode 100644 src/test/ui/lint/unused/issue-81314-unused-span-ident.stderr create mode 100644 src/test/ui/lint/unused/issue-85913.rs create mode 100644 src/test/ui/lint/unused/issue-85913.stderr create mode 100644 src/test/ui/lint/unused/lint-unused-extern-crate.rs create mode 100644 src/test/ui/lint/unused/lint-unused-extern-crate.stderr create mode 100644 src/test/ui/lint/unused/lint-unused-imports.rs create mode 100644 src/test/ui/lint/unused/lint-unused-imports.stderr create mode 100644 src/test/ui/lint/unused/lint-unused-mut-self.fixed create mode 100644 src/test/ui/lint/unused/lint-unused-mut-self.rs create mode 100644 src/test/ui/lint/unused/lint-unused-mut-self.stderr create mode 100644 src/test/ui/lint/unused/lint-unused-mut-variables.rs create mode 100644 src/test/ui/lint/unused/lint-unused-mut-variables.stderr create mode 100644 src/test/ui/lint/unused/lint-unused-variables.rs create mode 100644 src/test/ui/lint/unused/lint-unused-variables.stderr create mode 100644 src/test/ui/lint/unused/must-use-ops.rs create mode 100644 src/test/ui/lint/unused/must-use-ops.stderr create mode 100644 src/test/ui/lint/unused/must_use-array.rs create mode 100644 src/test/ui/lint/unused/must_use-array.stderr create mode 100644 src/test/ui/lint/unused/must_use-in-stdlib-traits.rs create mode 100644 src/test/ui/lint/unused/must_use-in-stdlib-traits.stderr create mode 100644 src/test/ui/lint/unused/must_use-trait.rs create mode 100644 src/test/ui/lint/unused/must_use-trait.stderr create mode 100644 src/test/ui/lint/unused/must_use-tuple.rs create mode 100644 src/test/ui/lint/unused/must_use-tuple.stderr create mode 100644 src/test/ui/lint/unused/must_use-unit.rs create mode 100644 src/test/ui/lint/unused/must_use-unit.stderr create mode 100644 src/test/ui/lint/unused/no-unused-parens-return-block.rs create mode 100644 src/test/ui/lint/unused/unused-attr-macro-rules.rs create mode 100644 src/test/ui/lint/unused/unused-attr-macro-rules.stderr create mode 100644 src/test/ui/lint/unused/unused-attr.rs create mode 100644 src/test/ui/lint/unused/unused-attr.stderr create mode 100644 src/test/ui/lint/unused/unused-closure.rs create mode 100644 src/test/ui/lint/unused/unused-closure.stderr create mode 100644 src/test/ui/lint/unused/unused-doc-comments-edge-cases.rs create mode 100644 src/test/ui/lint/unused/unused-doc-comments-edge-cases.stderr create mode 100644 src/test/ui/lint/unused/unused-doc-comments-for-macros.rs create mode 100644 src/test/ui/lint/unused/unused-doc-comments-for-macros.stderr create mode 100644 src/test/ui/lint/unused/unused-macro-rules.rs create mode 100644 src/test/ui/lint/unused/unused-macro-rules.stderr create mode 100644 src/test/ui/lint/unused/unused-macro-with-bad-frag-spec.rs create mode 100644 src/test/ui/lint/unused/unused-macro-with-bad-frag-spec.stderr create mode 100644 src/test/ui/lint/unused/unused-macro-with-follow-violation.rs create mode 100644 src/test/ui/lint/unused/unused-macro-with-follow-violation.stderr create mode 100644 src/test/ui/lint/unused/unused-macro.rs create mode 100644 src/test/ui/lint/unused/unused-macro.stderr create mode 100644 src/test/ui/lint/unused/unused-mut-warning-captured-var.fixed create mode 100644 src/test/ui/lint/unused/unused-mut-warning-captured-var.rs create mode 100644 src/test/ui/lint/unused/unused-mut-warning-captured-var.stderr create mode 100644 src/test/ui/lint/unused/unused-result.rs create mode 100644 src/test/ui/lint/unused/unused-result.stderr create mode 100644 src/test/ui/lint/unused/useless-comment.rs create mode 100644 src/test/ui/lint/unused/useless-comment.stderr delete mode 100644 src/test/ui/unused/issue-30730.rs delete mode 100644 src/test/ui/unused/issue-30730.stderr delete mode 100644 src/test/ui/unused/issue-46576.rs delete mode 100644 src/test/ui/unused/issue-46576.stderr delete mode 100644 src/test/ui/unused/issue-59896.rs delete mode 100644 src/test/ui/unused/issue-59896.stderr delete mode 100644 src/test/ui/unused/issue-70041.rs delete mode 100644 src/test/ui/unused/issue-70041.stderr delete mode 100644 src/test/ui/unused/issue-85913.rs delete mode 100644 src/test/ui/unused/issue-85913.stderr delete mode 100644 src/test/ui/unused/unused-attr-macro-rules.rs delete mode 100644 src/test/ui/unused/unused-attr-macro-rules.stderr delete mode 100644 src/test/ui/unused/unused-attr.rs delete mode 100644 src/test/ui/unused/unused-attr.stderr delete mode 100644 src/test/ui/unused/unused-closure.rs delete mode 100644 src/test/ui/unused/unused-closure.stderr delete mode 100644 src/test/ui/unused/unused-doc-comments-edge-cases.rs delete mode 100644 src/test/ui/unused/unused-doc-comments-edge-cases.stderr delete mode 100644 src/test/ui/unused/unused-doc-comments-for-macros.rs delete mode 100644 src/test/ui/unused/unused-doc-comments-for-macros.stderr delete mode 100644 src/test/ui/unused/unused-macro-rules.rs delete mode 100644 src/test/ui/unused/unused-macro-rules.stderr delete mode 100644 src/test/ui/unused/unused-macro-with-bad-frag-spec.rs delete mode 100644 src/test/ui/unused/unused-macro-with-bad-frag-spec.stderr delete mode 100644 src/test/ui/unused/unused-macro-with-follow-violation.rs delete mode 100644 src/test/ui/unused/unused-macro-with-follow-violation.stderr delete mode 100644 src/test/ui/unused/unused-macro.rs delete mode 100644 src/test/ui/unused/unused-macro.stderr delete mode 100644 src/test/ui/unused/unused-mut-warning-captured-var.fixed delete mode 100644 src/test/ui/unused/unused-mut-warning-captured-var.rs delete mode 100644 src/test/ui/unused/unused-mut-warning-captured-var.stderr delete mode 100644 src/test/ui/unused/unused-result.rs delete mode 100644 src/test/ui/unused/unused-result.stderr delete mode 100644 src/test/ui/unused/useless-comment.rs delete mode 100644 src/test/ui/unused/useless-comment.stderr (limited to 'src/test') diff --git a/src/test/ui/lint/auxiliary/lint_unused_extern_crate.rs b/src/test/ui/lint/auxiliary/lint_unused_extern_crate.rs deleted file mode 100644 index b76b4321d62..00000000000 --- a/src/test/ui/lint/auxiliary/lint_unused_extern_crate.rs +++ /dev/null @@ -1 +0,0 @@ -pub fn foo() {} diff --git a/src/test/ui/lint/auxiliary/lint_unused_extern_crate2.rs b/src/test/ui/lint/auxiliary/lint_unused_extern_crate2.rs deleted file mode 100644 index b76b4321d62..00000000000 --- a/src/test/ui/lint/auxiliary/lint_unused_extern_crate2.rs +++ /dev/null @@ -1 +0,0 @@ -pub fn foo() {} diff --git a/src/test/ui/lint/auxiliary/lint_unused_extern_crate3.rs b/src/test/ui/lint/auxiliary/lint_unused_extern_crate3.rs deleted file mode 100644 index b76b4321d62..00000000000 --- a/src/test/ui/lint/auxiliary/lint_unused_extern_crate3.rs +++ /dev/null @@ -1 +0,0 @@ -pub fn foo() {} diff --git a/src/test/ui/lint/auxiliary/lint_unused_extern_crate4.rs b/src/test/ui/lint/auxiliary/lint_unused_extern_crate4.rs deleted file mode 100644 index d11c69f812a..00000000000 --- a/src/test/ui/lint/auxiliary/lint_unused_extern_crate4.rs +++ /dev/null @@ -1 +0,0 @@ -// intentionally empty diff --git a/src/test/ui/lint/auxiliary/lint_unused_extern_crate5.rs b/src/test/ui/lint/auxiliary/lint_unused_extern_crate5.rs deleted file mode 100644 index d11c69f812a..00000000000 --- a/src/test/ui/lint/auxiliary/lint_unused_extern_crate5.rs +++ /dev/null @@ -1 +0,0 @@ -// intentionally empty diff --git a/src/test/ui/lint/issue-47390-unused-variable-in-struct-pattern.rs b/src/test/ui/lint/issue-47390-unused-variable-in-struct-pattern.rs deleted file mode 100644 index 0ad014e3361..00000000000 --- a/src/test/ui/lint/issue-47390-unused-variable-in-struct-pattern.rs +++ /dev/null @@ -1,88 +0,0 @@ -// check-pass - -#![feature(box_syntax)] -#![feature(box_patterns)] -#![warn(unused)] // UI tests pass `-A unused` (#43896) - -struct SoulHistory { - corridors_of_light: usize, - hours_are_suns: bool, - endless_and_singing: bool -} - -struct LovelyAmbition { - lips: usize, - fire: usize -} - -#[derive(Clone, Copy)] -enum Large { - Suit { case: () } -} - -struct Tuple(Large, ()); - -fn main() { - let i_think_continually = 2; //~ WARNING unused variable: `i_think_continually` - let who_from_the_womb_remembered = SoulHistory { - corridors_of_light: 5, - hours_are_suns: true, - endless_and_singing: true - }; - - let mut mut_unused_var = 1; - //~^ WARNING unused variable: `mut_unused_var` - //~| WARNING variable does not need to be mutable - - let (mut var, unused_var) = (1, 2); - //~^ WARNING unused variable: `var` - //~| WARNING unused variable: `unused_var` - //~| WARNING variable does not need to be mutable - // NOTE: `var` comes after `unused_var` lexicographically yet the warning - // for `var` will be emitted before the one for `unused_var`. We use an - // `IndexMap` to ensure this is the case instead of a `BTreeMap`. - - if let SoulHistory { corridors_of_light, //~ WARNING unused variable: `corridors_of_light` - mut hours_are_suns, //~ WARNING `hours_are_suns` is assigned to, but - endless_and_singing: true } = who_from_the_womb_remembered { - hours_are_suns = false; //~ WARNING unused_assignments - } - - let the_spirit = LovelyAmbition { lips: 1, fire: 2 }; - let LovelyAmbition { lips, fire } = the_spirit; //~ WARNING unused variable: `fire` - println!("{}", lips); - - let bag = Large::Suit { - case: () - }; - - // Plain struct - match bag { - Large::Suit { case } => {} //~ WARNING unused variable: `case` - }; - - // Referenced struct - match &bag { - &Large::Suit { case } => {} //~ WARNING unused variable: `case` - }; - - // Boxed struct - match box bag { - box Large::Suit { case } => {} //~ WARNING unused variable: `case` - }; - - // Tuple with struct - match (bag,) { - (Large::Suit { case },) => {} //~ WARNING unused variable: `case` - }; - - // Slice with struct - match [bag] { - [Large::Suit { case }] => {} //~ WARNING unused variable: `case` - }; - - // Tuple struct with struct - match Tuple(bag, ()) { - Tuple(Large::Suit { case }, ()) => {} //~ WARNING unused variable: `case` - }; -} diff --git a/src/test/ui/lint/issue-47390-unused-variable-in-struct-pattern.stderr b/src/test/ui/lint/issue-47390-unused-variable-in-struct-pattern.stderr deleted file mode 100644 index 2ef655efdbd..00000000000 --- a/src/test/ui/lint/issue-47390-unused-variable-in-struct-pattern.stderr +++ /dev/null @@ -1,126 +0,0 @@ -warning: unused variable: `i_think_continually` - --> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:26:9 - | -LL | let i_think_continually = 2; - | ^^^^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_i_think_continually` - | -note: the lint level is defined here - --> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:5:9 - | -LL | #![warn(unused)] // UI tests pass `-A unused` (#43896) - | ^^^^^^ - = note: `#[warn(unused_variables)]` implied by `#[warn(unused)]` - -warning: unused variable: `mut_unused_var` - --> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:33:13 - | -LL | let mut mut_unused_var = 1; - | ^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_mut_unused_var` - -warning: unused variable: `var` - --> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:37:14 - | -LL | let (mut var, unused_var) = (1, 2); - | ^^^ help: if this is intentional, prefix it with an underscore: `_var` - -warning: unused variable: `unused_var` - --> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:37:19 - | -LL | let (mut var, unused_var) = (1, 2); - | ^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_unused_var` - -warning: unused variable: `corridors_of_light` - --> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:45:26 - | -LL | if let SoulHistory { corridors_of_light, - | ^^^^^^^^^^^^^^^^^^ help: try ignoring the field: `corridors_of_light: _` - -warning: variable `hours_are_suns` is assigned to, but never used - --> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:46:30 - | -LL | mut hours_are_suns, - | ^^^^^^^^^^^^^^ - | - = note: consider using `_hours_are_suns` instead - -warning: value assigned to `hours_are_suns` is never read - --> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:48:9 - | -LL | hours_are_suns = false; - | ^^^^^^^^^^^^^^ - | -note: the lint level is defined here - --> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:5:9 - | -LL | #![warn(unused)] // UI tests pass `-A unused` (#43896) - | ^^^^^^ - = note: `#[warn(unused_assignments)]` implied by `#[warn(unused)]` - = help: maybe it is overwritten before being read? - -warning: unused variable: `fire` - --> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:52:32 - | -LL | let LovelyAmbition { lips, fire } = the_spirit; - | ^^^^ help: try ignoring the field: `fire: _` - -warning: unused variable: `case` - --> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:61:23 - | -LL | Large::Suit { case } => {} - | ^^^^ help: try ignoring the field: `case: _` - -warning: unused variable: `case` - --> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:66:24 - | -LL | &Large::Suit { case } => {} - | ^^^^ help: try ignoring the field: `case: _` - -warning: unused variable: `case` - --> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:71:27 - | -LL | box Large::Suit { case } => {} - | ^^^^ help: try ignoring the field: `case: _` - -warning: unused variable: `case` - --> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:76:24 - | -LL | (Large::Suit { case },) => {} - | ^^^^ help: try ignoring the field: `case: _` - -warning: unused variable: `case` - --> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:81:24 - | -LL | [Large::Suit { case }] => {} - | ^^^^ help: try ignoring the field: `case: _` - -warning: unused variable: `case` - --> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:86:29 - | -LL | Tuple(Large::Suit { case }, ()) => {} - | ^^^^ help: try ignoring the field: `case: _` - -warning: variable does not need to be mutable - --> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:33:9 - | -LL | let mut mut_unused_var = 1; - | ----^^^^^^^^^^^^^^ - | | - | help: remove this `mut` - | -note: the lint level is defined here - --> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:5:9 - | -LL | #![warn(unused)] // UI tests pass `-A unused` (#43896) - | ^^^^^^ - = note: `#[warn(unused_mut)]` implied by `#[warn(unused)]` - -warning: variable does not need to be mutable - --> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:37:10 - | -LL | let (mut var, unused_var) = (1, 2); - | ----^^^ - | | - | help: remove this `mut` - -warning: 16 warnings emitted - diff --git a/src/test/ui/lint/issue-54180-unused-ref-field.fixed b/src/test/ui/lint/issue-54180-unused-ref-field.fixed deleted file mode 100644 index 1350b7ca699..00000000000 --- a/src/test/ui/lint/issue-54180-unused-ref-field.fixed +++ /dev/null @@ -1,34 +0,0 @@ -// run-rustfix - -#![deny(unused)] - -pub struct S { - pub f1: i32, -} - -pub struct Point { - pub x: i32, - pub y: i32, -} - -pub enum E { - Variant { field: String } -} - -pub fn foo(arg: &E) { - match arg { - E::Variant { field: _ } => (), //~ ERROR unused variable - } -} - -fn main() { - let s = S { f1: 123 }; - let S { f1: _ } = s; //~ ERROR unused variable - - let points = vec![Point { x: 1, y: 2 }]; - let _: i32 = points.iter().map(|Point { x: _, y }| y).sum(); //~ ERROR unused variable - - match (Point { x: 1, y: 2 }) { - Point { y, x: _ } => y, //~ ERROR unused variable - }; -} diff --git a/src/test/ui/lint/issue-54180-unused-ref-field.rs b/src/test/ui/lint/issue-54180-unused-ref-field.rs deleted file mode 100644 index 7b3392b609a..00000000000 --- a/src/test/ui/lint/issue-54180-unused-ref-field.rs +++ /dev/null @@ -1,34 +0,0 @@ -// run-rustfix - -#![deny(unused)] - -pub struct S { - pub f1: i32, -} - -pub struct Point { - pub x: i32, - pub y: i32, -} - -pub enum E { - Variant { field: String } -} - -pub fn foo(arg: &E) { - match arg { - E::Variant { ref field } => (), //~ ERROR unused variable - } -} - -fn main() { - let s = S { f1: 123 }; - let S { ref f1 } = s; //~ ERROR unused variable - - let points = vec![Point { x: 1, y: 2 }]; - let _: i32 = points.iter().map(|Point { x, y }| y).sum(); //~ ERROR unused variable - - match (Point { x: 1, y: 2 }) { - Point { y, ref mut x } => y, //~ ERROR unused variable - }; -} diff --git a/src/test/ui/lint/issue-54180-unused-ref-field.stderr b/src/test/ui/lint/issue-54180-unused-ref-field.stderr deleted file mode 100644 index c501aa25f13..00000000000 --- a/src/test/ui/lint/issue-54180-unused-ref-field.stderr +++ /dev/null @@ -1,33 +0,0 @@ -error: unused variable: `field` - --> $DIR/issue-54180-unused-ref-field.rs:20:22 - | -LL | E::Variant { ref field } => (), - | ^^^^^^^^^ help: try ignoring the field: `field: _` - | -note: the lint level is defined here - --> $DIR/issue-54180-unused-ref-field.rs:3:9 - | -LL | #![deny(unused)] - | ^^^^^^ - = note: `#[deny(unused_variables)]` implied by `#[deny(unused)]` - -error: unused variable: `x` - --> $DIR/issue-54180-unused-ref-field.rs:29:45 - | -LL | let _: i32 = points.iter().map(|Point { x, y }| y).sum(); - | ^ help: try ignoring the field: `x: _` - -error: unused variable: `f1` - --> $DIR/issue-54180-unused-ref-field.rs:26:13 - | -LL | let S { ref f1 } = s; - | ^^^^^^ help: try ignoring the field: `f1: _` - -error: unused variable: `x` - --> $DIR/issue-54180-unused-ref-field.rs:32:20 - | -LL | Point { y, ref mut x } => y, - | ^^^^^^^^^ help: try ignoring the field: `x: _` - -error: aborting due to 4 previous errors - diff --git a/src/test/ui/lint/issue-54538-unused-parens-lint.fixed b/src/test/ui/lint/issue-54538-unused-parens-lint.fixed deleted file mode 100644 index 0b3fe9371f7..00000000000 --- a/src/test/ui/lint/issue-54538-unused-parens-lint.fixed +++ /dev/null @@ -1,106 +0,0 @@ -// run-rustfix - -#![feature(box_patterns, stmt_expr_attributes)] - -#![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) {} // Doesn't parse if we remove parens for now. - - let _ = |(Ok(a) | Err(a)): Result| 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 - &_ => {} - } -} diff --git a/src/test/ui/lint/issue-54538-unused-parens-lint.rs b/src/test/ui/lint/issue-54538-unused-parens-lint.rs deleted file mode 100644 index 1e78ec5f7d9..00000000000 --- a/src/test/ui/lint/issue-54538-unused-parens-lint.rs +++ /dev/null @@ -1,106 +0,0 @@ -// run-rustfix - -#![feature(box_patterns, stmt_expr_attributes)] - -#![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) {} // Doesn't parse if we remove parens for now. - - let _ = |(Ok(a) | Err(a)): Result| 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 - &_ => {} - } -} diff --git a/src/test/ui/lint/issue-54538-unused-parens-lint.stderr b/src/test/ui/lint/issue-54538-unused-parens-lint.stderr deleted file mode 100644 index e6d0a359c5c..00000000000 --- a/src/test/ui/lint/issue-54538-unused-parens-lint.stderr +++ /dev/null @@ -1,152 +0,0 @@ -error: unnecessary parentheses around pattern - --> $DIR/issue-54538-unused-parens-lint.rs:16:9 - | -LL | let (a) = 0; - | ^^^ help: remove these parentheses - | -note: the lint level is defined here - --> $DIR/issue-54538-unused-parens-lint.rs:13:9 - | -LL | #![deny(unused_parens)] - | ^^^^^^^^^^^^^ - -error: unnecessary parentheses around pattern - --> $DIR/issue-54538-unused-parens-lint.rs:17:9 - | -LL | for (a) in 0..1 {} - | ^^^ help: remove these parentheses - -error: unnecessary parentheses around pattern - --> $DIR/issue-54538-unused-parens-lint.rs:18:12 - | -LL | if let (a) = 0 {} - | ^^^ help: remove these parentheses - -error: unnecessary parentheses around pattern - --> $DIR/issue-54538-unused-parens-lint.rs:19:15 - | -LL | while let (a) = 0 {} - | ^^^ help: remove these parentheses - -error: unnecessary parentheses around pattern - --> $DIR/issue-54538-unused-parens-lint.rs:20:12 - | -LL | fn foo((a): u8) {} - | ^^^ help: remove these parentheses - -error: unnecessary parentheses around pattern - --> $DIR/issue-54538-unused-parens-lint.rs:21:14 - | -LL | let _ = |(a): u8| 0; - | ^^^ help: remove these parentheses - -error: unnecessary parentheses around pattern - --> $DIR/issue-54538-unused-parens-lint.rs:49:12 - | -LL | if let (0 | 1) = 0 {} - | ^^^^^^^ help: remove these parentheses - -error: unnecessary parentheses around pattern - --> $DIR/issue-54538-unused-parens-lint.rs:50:13 - | -LL | if let ((0 | 1),) = (0,) {} - | ^^^^^^^ help: remove these parentheses - -error: unnecessary parentheses around pattern - --> $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:52:16 - | -LL | if let 0 | (1 | 2) = 0 {} - | ^^^^^^^ help: remove these parentheses - -error: unnecessary parentheses around pattern - --> $DIR/issue-54538-unused-parens-lint.rs:54: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:56: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:66:9 - | -LL | (_) => {} - | ^^^ help: remove these parentheses - -error: unnecessary parentheses around pattern - --> $DIR/issue-54538-unused-parens-lint.rs:67:9 - | -LL | (y) => {} - | ^^^ help: remove these parentheses - -error: unnecessary parentheses around pattern - --> $DIR/issue-54538-unused-parens-lint.rs:68:9 - | -LL | (ref r) => {} - | ^^^^^^^ help: remove these parentheses - -error: unnecessary parentheses around pattern - --> $DIR/issue-54538-unused-parens-lint.rs:69:9 - | -LL | (e @ 1...2) => {} - | ^^^^^^^^^^^ help: remove these parentheses - -error: unnecessary parentheses around pattern - --> $DIR/issue-54538-unused-parens-lint.rs:75:9 - | -LL | (e @ &(1...2)) => {} - | ^^^^^^^^^^^^^^ help: remove these parentheses - -error: unnecessary parentheses around pattern - --> $DIR/issue-54538-unused-parens-lint.rs:76:10 - | -LL | &(_) => {} - | ^^^ help: remove these parentheses - -error: unnecessary parentheses around pattern - --> $DIR/issue-54538-unused-parens-lint.rs:87:9 - | -LL | (_) => {} - | ^^^ help: remove these parentheses - -error: unnecessary parentheses around pattern - --> $DIR/issue-54538-unused-parens-lint.rs:88:9 - | -LL | (y) => {} - | ^^^ help: remove these parentheses - -error: unnecessary parentheses around pattern - --> $DIR/issue-54538-unused-parens-lint.rs:89:9 - | -LL | (ref r) => {} - | ^^^^^^^ help: remove these parentheses - -error: unnecessary parentheses around pattern - --> $DIR/issue-54538-unused-parens-lint.rs:90:9 - | -LL | (e @ 1..=2) => {} - | ^^^^^^^^^^^ help: remove these parentheses - -error: unnecessary parentheses around pattern - --> $DIR/issue-54538-unused-parens-lint.rs:96:9 - | -LL | (e @ &(1..=2)) => {} - | ^^^^^^^^^^^^^^ help: remove these parentheses - -error: unnecessary parentheses around pattern - --> $DIR/issue-54538-unused-parens-lint.rs:97:10 - | -LL | &(_) => {} - | ^^^ help: remove these parentheses - -error: aborting due to 24 previous errors - diff --git a/src/test/ui/lint/issue-67691-unused-field-in-or-pattern.rs b/src/test/ui/lint/issue-67691-unused-field-in-or-pattern.rs deleted file mode 100644 index e3631d014d6..00000000000 --- a/src/test/ui/lint/issue-67691-unused-field-in-or-pattern.rs +++ /dev/null @@ -1,85 +0,0 @@ -// FIXME: should be run-rustfix, but rustfix doesn't currently support multipart suggestions, see -// #53934 - -#![deny(unused)] - -pub enum MyEnum { - A { i: i32, j: i32 }, - B { i: i32, j: i32 }, -} - -pub enum MixedEnum { - A { i: i32 }, - B(i32), -} - -pub fn no_ref(x: MyEnum) { - use MyEnum::*; - - match x { - A { i, j } | B { i, j } => { //~ ERROR unused variable - println!("{}", i); - } - } -} - -pub fn with_ref(x: MyEnum) { - use MyEnum::*; - - match x { - A { i, ref j } | B { i, ref j } => { //~ ERROR unused variable - println!("{}", i); - } - } -} - -pub fn inner_no_ref(x: Option) { - use MyEnum::*; - - match x { - Some(A { i, j } | B { i, j }) => { //~ ERROR unused variable - println!("{}", i); - } - - _ => {} - } -} - -pub fn inner_with_ref(x: Option) { - use MyEnum::*; - - match x { - Some(A { i, ref j } | B { i, ref j }) => { //~ ERROR unused variable - println!("{}", i); - } - - _ => {} - } -} - -pub fn mixed_no_ref(x: MixedEnum) { - match x { - MixedEnum::A { i } | MixedEnum::B(i) => { //~ ERROR unused variable - println!("match"); - } - } -} - -pub fn mixed_with_ref(x: MixedEnum) { - match x { - MixedEnum::A { ref i } | MixedEnum::B(ref i) => { //~ ERROR unused variable - println!("match"); - } - } -} - -pub fn main() { - no_ref(MyEnum::A { i: 1, j: 2 }); - with_ref(MyEnum::A { i: 1, j: 2 }); - - inner_no_ref(Some(MyEnum::A { i: 1, j: 2 })); - inner_with_ref(Some(MyEnum::A { i: 1, j: 2 })); - - mixed_no_ref(MixedEnum::B(5)); - mixed_with_ref(MixedEnum::B(5)); -} diff --git a/src/test/ui/lint/issue-67691-unused-field-in-or-pattern.stderr b/src/test/ui/lint/issue-67691-unused-field-in-or-pattern.stderr deleted file mode 100644 index 8aefe243a94..00000000000 --- a/src/test/ui/lint/issue-67691-unused-field-in-or-pattern.stderr +++ /dev/null @@ -1,74 +0,0 @@ -error: unused variable: `j` - --> $DIR/issue-67691-unused-field-in-or-pattern.rs:20:16 - | -LL | A { i, j } | B { i, j } => { - | ^ ^ - | -note: the lint level is defined here - --> $DIR/issue-67691-unused-field-in-or-pattern.rs:4:9 - | -LL | #![deny(unused)] - | ^^^^^^ - = note: `#[deny(unused_variables)]` implied by `#[deny(unused)]` -help: try ignoring the field - | -LL | A { i, j: _ } | B { i, j: _ } => { - | ^^^^ ^^^^ - -error: unused variable: `j` - --> $DIR/issue-67691-unused-field-in-or-pattern.rs:30:16 - | -LL | A { i, ref j } | B { i, ref j } => { - | ^^^^^ ^^^^^ - | -help: try ignoring the field - | -LL | A { i, j: _ } | B { i, j: _ } => { - | ^^^^ ^^^^ - -error: unused variable: `j` - --> $DIR/issue-67691-unused-field-in-or-pattern.rs:40:21 - | -LL | Some(A { i, j } | B { i, j }) => { - | ^ ^ - | -help: try ignoring the field - | -LL | Some(A { i, j: _ } | B { i, j: _ }) => { - | ^^^^ ^^^^ - -error: unused variable: `j` - --> $DIR/issue-67691-unused-field-in-or-pattern.rs:52:21 - | -LL | Some(A { i, ref j } | B { i, ref j }) => { - | ^^^^^ ^^^^^ - | -help: try ignoring the field - | -LL | Some(A { i, j: _ } | B { i, j: _ }) => { - | ^^^^ ^^^^ - -error: unused variable: `i` - --> $DIR/issue-67691-unused-field-in-or-pattern.rs:62:24 - | -LL | MixedEnum::A { i } | MixedEnum::B(i) => { - | ^ ^ - | -help: try ignoring the field - | -LL | MixedEnum::A { i: _ } | MixedEnum::B(_) => { - | ^^^^ ^ - -error: unused variable: `i` - --> $DIR/issue-67691-unused-field-in-or-pattern.rs:70:24 - | -LL | MixedEnum::A { ref i } | MixedEnum::B(ref i) => { - | ^^^^^ ^^^^^ - | -help: try ignoring the field - | -LL | MixedEnum::A { i: _ } | MixedEnum::B(_) => { - | ^^^^ ^ - -error: aborting due to 6 previous errors - diff --git a/src/test/ui/lint/issue-71290-unused-paren-binop.rs b/src/test/ui/lint/issue-71290-unused-paren-binop.rs deleted file mode 100644 index 24d77e36d94..00000000000 --- a/src/test/ui/lint/issue-71290-unused-paren-binop.rs +++ /dev/null @@ -1,23 +0,0 @@ -// check-pass -// Make sure unused parens lint doesn't emit a false positive. -// See https://github.com/rust-lang/rust/issues/71290 for details. -#![deny(unused_parens)] - -fn x() -> u8 { - ({ 0 }) + 1 -} - -fn y() -> u8 { - ({ 0 } + 1) -} - -pub fn foo(a: bool, b: bool) -> u8 { - (if a { 1 } else { 0 } + if b { 1 } else { 0 }) -} - -pub fn bar() -> u8 { - // Make sure nested expressions are handled correctly as well - ({ 0 } + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9) -} - -fn main() {} diff --git a/src/test/ui/lint/issue-74883-unused-paren-baren-yield.rs b/src/test/ui/lint/issue-74883-unused-paren-baren-yield.rs deleted file mode 100644 index 8064c3a88d1..00000000000 --- a/src/test/ui/lint/issue-74883-unused-paren-baren-yield.rs +++ /dev/null @@ -1,26 +0,0 @@ -#![feature(generator_trait)] -#![feature(generators)] -#![deny(unused_braces, unused_parens)] - -use std::ops::Generator; -use std::pin::Pin; - -fn main() { - let mut x = |_| { - while let Some(_) = (yield) {} - while let Some(_) = {yield} {} - - // Only warn these cases - while let Some(_) = ({yield}) {} //~ ERROR: unnecessary parentheses - while let Some(_) = ((yield)) {} //~ ERROR: unnecessary parentheses - {{yield}}; //~ ERROR: unnecessary braces - {( yield )}; //~ ERROR: unnecessary parentheses - while let Some(_) = {(yield)} {} //~ ERROR: unnecessary parentheses - while let Some(_) = {{yield}} {} //~ ERROR: unnecessary braces - - // FIXME: It'd be great if we could also warn them. - ((yield)); - ({ yield }); - }; - let _ = Pin::new(&mut x).resume(Some(5)); -} diff --git a/src/test/ui/lint/issue-74883-unused-paren-baren-yield.stderr b/src/test/ui/lint/issue-74883-unused-paren-baren-yield.stderr deleted file mode 100644 index 3f6260dc6e1..00000000000 --- a/src/test/ui/lint/issue-74883-unused-paren-baren-yield.stderr +++ /dev/null @@ -1,50 +0,0 @@ -error: unnecessary parentheses around `let` scrutinee expression - --> $DIR/issue-74883-unused-paren-baren-yield.rs:14:29 - | -LL | while let Some(_) = ({yield}) {} - | ^^^^^^^^^ help: remove these parentheses - | -note: the lint level is defined here - --> $DIR/issue-74883-unused-paren-baren-yield.rs:3:24 - | -LL | #![deny(unused_braces, unused_parens)] - | ^^^^^^^^^^^^^ - -error: unnecessary parentheses around `let` scrutinee expression - --> $DIR/issue-74883-unused-paren-baren-yield.rs:15:29 - | -LL | while let Some(_) = ((yield)) {} - | ^^^^^^^^^ help: remove these parentheses - -error: unnecessary braces around block return value - --> $DIR/issue-74883-unused-paren-baren-yield.rs:16:10 - | -LL | {{yield}}; - | ^^^^^^^ help: remove these braces - | -note: the lint level is defined here - --> $DIR/issue-74883-unused-paren-baren-yield.rs:3:9 - | -LL | #![deny(unused_braces, unused_parens)] - | ^^^^^^^^^^^^^ - -error: unnecessary parentheses around block return value - --> $DIR/issue-74883-unused-paren-baren-yield.rs:17:10 - | -LL | {( yield )}; - | ^^^^^^^^^ help: remove these parentheses - -error: unnecessary parentheses around block return value - --> $DIR/issue-74883-unused-paren-baren-yield.rs:18:30 - | -LL | while let Some(_) = {(yield)} {} - | ^^^^^^^ help: remove these parentheses - -error: unnecessary braces around block return value - --> $DIR/issue-74883-unused-paren-baren-yield.rs:19:30 - | -LL | while let Some(_) = {{yield}} {} - | ^^^^^^^ help: remove these braces - -error: aborting due to 6 previous errors - diff --git a/src/test/ui/lint/issue-81314-unused-span-ident.fixed b/src/test/ui/lint/issue-81314-unused-span-ident.fixed deleted file mode 100644 index aac918f2bc8..00000000000 --- a/src/test/ui/lint/issue-81314-unused-span-ident.fixed +++ /dev/null @@ -1,12 +0,0 @@ -// run-rustfix -// Regression test for #81314: Unused variable lint should -// span only the identifier and not the rest of the pattern - -#![deny(unused)] - -fn main() { - let [_rest @ ..] = [1, 2, 3]; //~ ERROR unused variable -} - -pub fn foo([_rest @ ..]: &[i32]) { //~ ERROR unused variable -} diff --git a/src/test/ui/lint/issue-81314-unused-span-ident.rs b/src/test/ui/lint/issue-81314-unused-span-ident.rs deleted file mode 100644 index 78296f4258d..00000000000 --- a/src/test/ui/lint/issue-81314-unused-span-ident.rs +++ /dev/null @@ -1,12 +0,0 @@ -// run-rustfix -// Regression test for #81314: Unused variable lint should -// span only the identifier and not the rest of the pattern - -#![deny(unused)] - -fn main() { - let [rest @ ..] = [1, 2, 3]; //~ ERROR unused variable -} - -pub fn foo([rest @ ..]: &[i32]) { //~ ERROR unused variable -} diff --git a/src/test/ui/lint/issue-81314-unused-span-ident.stderr b/src/test/ui/lint/issue-81314-unused-span-ident.stderr deleted file mode 100644 index 519c71e9413..00000000000 --- a/src/test/ui/lint/issue-81314-unused-span-ident.stderr +++ /dev/null @@ -1,21 +0,0 @@ -error: unused variable: `rest` - --> $DIR/issue-81314-unused-span-ident.rs:8:10 - | -LL | let [rest @ ..] = [1, 2, 3]; - | ^^^^ help: if this is intentional, prefix it with an underscore: `_rest` - | -note: the lint level is defined here - --> $DIR/issue-81314-unused-span-ident.rs:5:9 - | -LL | #![deny(unused)] - | ^^^^^^ - = note: `#[deny(unused_variables)]` implied by `#[deny(unused)]` - -error: unused variable: `rest` - --> $DIR/issue-81314-unused-span-ident.rs:11:13 - | -LL | pub fn foo([rest @ ..]: &[i32]) { - | ^^^^ help: if this is intentional, prefix it with an underscore: `_rest` - -error: aborting due to 2 previous errors - diff --git a/src/test/ui/lint/lint-unused-extern-crate.rs b/src/test/ui/lint/lint-unused-extern-crate.rs deleted file mode 100644 index d5e4da526a1..00000000000 --- a/src/test/ui/lint/lint-unused-extern-crate.rs +++ /dev/null @@ -1,35 +0,0 @@ -// aux-build:lint_unused_extern_crate.rs -// aux-build:lint_unused_extern_crate2.rs -// aux-build:lint_unused_extern_crate3.rs -// aux-build:lint_unused_extern_crate4.rs -// aux-build:lint_unused_extern_crate5.rs - -#![deny(unused_extern_crates)] -#![allow(unused_variables)] -#![allow(deprecated)] - -extern crate lint_unused_extern_crate5; //~ ERROR: unused extern crate - -pub extern crate lint_unused_extern_crate4; // no error, it is re-exported - -extern crate lint_unused_extern_crate3; // no error, it is used - -extern crate lint_unused_extern_crate2; // no error, the use marks it as used - // even if imported objects aren't used - -extern crate lint_unused_extern_crate as other; // no error, the use * marks it as used - -#[allow(unused_imports)] -use lint_unused_extern_crate2::foo as bar; - -use other::*; - -mod foo { - // Test that this is unused even though an earlier `extern crate` is used. - extern crate lint_unused_extern_crate2; //~ ERROR unused extern crate -} - -fn main() { - lint_unused_extern_crate3::foo(); - let y = foo(); -} diff --git a/src/test/ui/lint/lint-unused-extern-crate.stderr b/src/test/ui/lint/lint-unused-extern-crate.stderr deleted file mode 100644 index 46d8f3beeab..00000000000 --- a/src/test/ui/lint/lint-unused-extern-crate.stderr +++ /dev/null @@ -1,20 +0,0 @@ -error: unused extern crate - --> $DIR/lint-unused-extern-crate.rs:11:1 - | -LL | extern crate lint_unused_extern_crate5; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove it - | -note: the lint level is defined here - --> $DIR/lint-unused-extern-crate.rs:7:9 - | -LL | #![deny(unused_extern_crates)] - | ^^^^^^^^^^^^^^^^^^^^ - -error: unused extern crate - --> $DIR/lint-unused-extern-crate.rs:29:5 - | -LL | extern crate lint_unused_extern_crate2; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove it - -error: aborting due to 2 previous errors - diff --git a/src/test/ui/lint/lint-unused-imports.rs b/src/test/ui/lint/lint-unused-imports.rs deleted file mode 100644 index 4754d888076..00000000000 --- a/src/test/ui/lint/lint-unused-imports.rs +++ /dev/null @@ -1,90 +0,0 @@ -#![deny(unused_imports)] -#![allow(dead_code)] - -use bar::c::cc as cal; - -use std::mem::*; // shouldn't get errors for not using - // everything imported -use std::fmt::{}; -//~^ ERROR unused import: `std::fmt::{}` - -// Should get errors for both 'Some' and 'None' -use std::option::Option::{Some, None}; -//~^ ERROR unused imports: `None`, `Some` - -use test::A; //~ ERROR unused import: `test::A` -// Be sure that if we just bring some methods into scope that they're also -// counted as being used. -use test::B; -// But only when actually used: do not get confused by the method with the same name. -use test::B2; //~ ERROR unused import: `test::B2` - -// Make sure this import is warned about when at least one of its imported names -// is unused -use test2::{foo, bar}; //~ ERROR unused import: `bar` - -mod test2 { - pub fn foo() {} - pub fn bar() {} -} - -mod test { - pub trait A { fn a(&self) {} } - pub trait B { fn b(&self) {} } - pub trait B2 { fn b(&self) {} } - pub struct C; - impl A for C {} - impl B for C {} -} - -mod foo { - pub struct Point{pub x: isize, pub y: isize} - pub struct Square{pub p: Point, pub h: usize, pub w: usize} -} - -mod bar { - // Don't ignore on 'pub use' because we're not sure if it's used or not - pub use std::cmp::PartialEq; - pub struct Square; - - pub mod c { - use foo::Point; - use foo::Square; //~ ERROR unused import: `foo::Square` - pub fn cc(_p: Point) -> super::Square { - fn f() -> super::Square { - super::Square - } - f() - } - } - - #[allow(unused_imports)] - mod foo { - use std::cmp::PartialEq; - } -} - -fn g() { - use self::g; //~ ERROR unused import: `self::g` - //~^ ERROR the item `g` is imported redundantly - fn f() { - self::g(); - } -} - -// cf. issue #35135. -#[allow(unused_variables)] -fn h() { - use test2::foo; //~ ERROR unused import: `test2::foo` - //~^ ERROR the item `foo` is imported redundantly - let foo = 0; -} - -fn main() { - cal(foo::Point{x:3, y:9}); - let mut a = 3; - let mut b = 4; - swap(&mut a, &mut b); - test::C.b(); - let _a = foo(); -} diff --git a/src/test/ui/lint/lint-unused-imports.stderr b/src/test/ui/lint/lint-unused-imports.stderr deleted file mode 100644 index 0574ca4569f..00000000000 --- a/src/test/ui/lint/lint-unused-imports.stderr +++ /dev/null @@ -1,78 +0,0 @@ -error: unused import: `std::fmt::{}` - --> $DIR/lint-unused-imports.rs:8:5 - | -LL | use std::fmt::{}; - | ^^^^^^^^^^^^ - | -note: the lint level is defined here - --> $DIR/lint-unused-imports.rs:1:9 - | -LL | #![deny(unused_imports)] - | ^^^^^^^^^^^^^^ - -error: unused imports: `None`, `Some` - --> $DIR/lint-unused-imports.rs:12:27 - | -LL | use std::option::Option::{Some, None}; - | ^^^^ ^^^^ - -error: unused import: `test::A` - --> $DIR/lint-unused-imports.rs:15:5 - | -LL | use test::A; - | ^^^^^^^ - -error: unused import: `bar` - --> $DIR/lint-unused-imports.rs:24:18 - | -LL | use test2::{foo, bar}; - | ^^^ - -error: unused import: `foo::Square` - --> $DIR/lint-unused-imports.rs:52:13 - | -LL | use foo::Square; - | ^^^^^^^^^^^ - -error: the item `g` is imported redundantly - --> $DIR/lint-unused-imports.rs:68:9 - | -LL | / fn g() { -LL | | use self::g; - | | ^^^^^^^ -LL | | -LL | | fn f() { -LL | | self::g(); -LL | | } -LL | | } - | |_- the item `g` is already defined here - -error: unused import: `self::g` - --> $DIR/lint-unused-imports.rs:68:9 - | -LL | use self::g; - | ^^^^^^^ - -error: the item `foo` is imported redundantly - --> $DIR/lint-unused-imports.rs:78:9 - | -LL | use test2::{foo, bar}; - | --- the item `foo` is already imported here -... -LL | use test2::foo; - | ^^^^^^^^^^ - -error: unused import: `test2::foo` - --> $DIR/lint-unused-imports.rs:78:9 - | -LL | use test2::foo; - | ^^^^^^^^^^ - -error: unused import: `test::B2` - --> $DIR/lint-unused-imports.rs:20:5 - | -LL | use test::B2; - | ^^^^^^^^ - -error: aborting due to 10 previous errors - diff --git a/src/test/ui/lint/lint-unused-mut-self.fixed b/src/test/ui/lint/lint-unused-mut-self.fixed deleted file mode 100644 index 92ce103586c..00000000000 --- a/src/test/ui/lint/lint-unused-mut-self.fixed +++ /dev/null @@ -1,14 +0,0 @@ -// 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) {} //~ ERROR: variable does not need to be mutable -} - -fn main() {} diff --git a/src/test/ui/lint/lint-unused-mut-self.rs b/src/test/ui/lint/lint-unused-mut-self.rs deleted file mode 100644 index 70736ce216e..00000000000 --- a/src/test/ui/lint/lint-unused-mut-self.rs +++ /dev/null @@ -1,14 +0,0 @@ -// run-rustfix - -#![allow(unused_assignments)] -#![allow(unused_variables)] -#![allow(dead_code)] -#![deny(unused_mut)] - -struct Foo; -impl Foo { - fn foo(mut self) {} //~ ERROR: variable does not need to be mutable - fn bar(mut self: Box) {} //~ ERROR: variable does not need to be mutable -} - -fn main() {} diff --git a/src/test/ui/lint/lint-unused-mut-self.stderr b/src/test/ui/lint/lint-unused-mut-self.stderr deleted file mode 100644 index 01a524bd323..00000000000 --- a/src/test/ui/lint/lint-unused-mut-self.stderr +++ /dev/null @@ -1,24 +0,0 @@ -error: variable does not need to be mutable - --> $DIR/lint-unused-mut-self.rs:10:12 - | -LL | fn foo(mut self) {} - | ----^^^^ - | | - | help: remove this `mut` - | -note: the lint level is defined here - --> $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:11:12 - | -LL | fn bar(mut self: Box) {} - | ----^^^^ - | | - | help: remove this `mut` - -error: aborting due to 2 previous errors - diff --git a/src/test/ui/lint/lint-unused-mut-variables.rs b/src/test/ui/lint/lint-unused-mut-variables.rs deleted file mode 100644 index 67ec7facf17..00000000000 --- a/src/test/ui/lint/lint-unused-mut-variables.rs +++ /dev/null @@ -1,207 +0,0 @@ -// edition:2018 - -// Exercise the unused_mut attribute in some positive and negative cases - -#![warn(unused_mut)] -#![feature(async_closure, raw_ref_op)] - -async fn baz_async( - mut a: i32, - //~^ WARN: variable does not need to be mutable - #[allow(unused_mut)] mut b: i32, -) {} -fn baz( - mut a: i32, - //~^ WARN: variable does not need to be mutable - #[allow(unused_mut)] mut b: i32, - #[allow(unused_mut)] (mut c, d): (i32, i32) -) {} - -struct RefStruct {} -impl RefStruct { - async fn baz_async( - mut a: i32, - //~^ WARN: variable does not need to be mutable - #[allow(unused_mut)] mut b: i32, - ) {} - fn baz( - &self, - mut a: i32, - //~^ WARN: variable does not need to be mutable - #[allow(unused_mut)] mut b: i32, - #[allow(unused_mut)] (mut c, d): (i32, i32) - ) {} -} - -trait RefTrait { - fn baz( - &self, - mut a: i32, - //~^ WARN: variable does not need to be mutable - #[allow(unused_mut)] mut b: i32, - #[allow(unused_mut)] (mut c, d): (i32, i32) - ) {} -} -impl RefTrait for () { - fn baz( - &self, - mut a: i32, - //~^ WARN: variable does not need to be mutable - #[allow(unused_mut)] mut b: i32, - #[allow(unused_mut)] (mut c, d): (i32, i32) - ) {} -} - -fn main() { - let _ = async move | - mut a: i32, - //~^ WARN: variable does not need to be mutable - #[allow(unused_mut)] mut b: i32, - | {}; - let _ = | - mut a: i32, - //~^ WARN: variable does not need to be mutable - #[allow(unused_mut)] mut b: i32, - #[allow(unused_mut)] (mut c, d): (i32, i32) - | {}; - - // negative cases - let mut a = 3; //~ WARN: variable does not need to be mutable - - let mut a = 2; //~ WARN: variable does not need to be mutable - - let mut b = 3; //~ WARN: variable does not need to be mutable - - let mut a = vec![3]; //~ WARN: variable does not need to be mutable - - let (mut a, b) = (1, 2); //~ WARN: variable does not need to be mutable - - let mut a; //~ WARN: variable does not need to be mutable - - a = 3; - - let mut b; //~ WARN: variable does not need to be mutable - - if true { - b = 3; - } else { - b = 4; - } - - match 30 { - mut x => {} //~ WARN: variable does not need to be mutable - - } - - 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 - - fn what(mut foo: isize) {} //~ WARN: variable does not need to be mutable - - - let mut a = &mut 5; //~ WARN: variable does not need to be mutable - - *a = 4; - - let mut a = 5; - let mut b = (&mut a,); //~ WARN: variable does not need to be mutable - *b.0 = 4; - - let mut x = &mut 1; //~ WARN: variable does not need to be mutable - - let mut f = || { - *x += 1; - }; - f(); - - fn mut_ref_arg(mut arg : &mut [u8]) -> &mut [u8] { - &mut arg[..] //~^ WARN: variable does not need to be mutable - - } - - let mut v : &mut Vec<()> = &mut vec![]; //~ WARN: variable does not need to be mutable - - v.push(()); - - // positive cases - let mut a = 2; - a = 3; - let mut a = Vec::new(); - a.push(3); - let mut a = Vec::new(); - callback(|| { - a.push(3); - }); - let mut a = Vec::new(); - callback(|| { - callback(|| { - a.push(3); - }); - }); - let (mut a, b) = (1, 2); - a = 34; - - match 30 { - mut x => { - x = 21; - } - } - - match (30, 2) { - (mut x, 1) | - (mut x, 2) | - (mut x, 3) => { - x = 21 - } - _ => {} - } - - // Attribute should be respected on match arms - match 0 { - #[allow(unused_mut)] - mut x => { - let mut y = 1; - }, - } - - let x = |mut y: isize| y = 32; - fn nothing(mut foo: isize) { foo = 37; } - - // leading underscore should avoid the warning, just like the - // unused variable lint. - let mut _allowed = 1; - - let mut raw_address_of_mut = 1; // OK - let mut_ptr = &raw mut raw_address_of_mut; - - let mut raw_address_of_const = 1; //~ WARN: variable does not need to be mutable - let const_ptr = &raw const raw_address_of_const; -} - -fn callback(f: F) where F: FnOnce() {} - -// make sure the lint attribute can be turned off -#[allow(unused_mut)] -fn foo(mut a: isize) { - let mut a = 3; - let mut b = vec![2]; -} - -// make sure the lint attribute can be turned off on let statements -#[deny(unused_mut)] -fn bar() { - #[allow(unused_mut)] - let mut a = 3; - let mut b = vec![2]; //~ ERROR: variable does not need to be mutable - -} diff --git a/src/test/ui/lint/lint-unused-mut-variables.stderr b/src/test/ui/lint/lint-unused-mut-variables.stderr deleted file mode 100644 index 805ed2b40bb..00000000000 --- a/src/test/ui/lint/lint-unused-mut-variables.stderr +++ /dev/null @@ -1,222 +0,0 @@ -warning: variable does not need to be mutable - --> $DIR/lint-unused-mut-variables.rs:9:5 - | -LL | mut a: i32, - | ----^ - | | - | help: remove this `mut` - | -note: the lint level is defined here - --> $DIR/lint-unused-mut-variables.rs:5:9 - | -LL | #![warn(unused_mut)] - | ^^^^^^^^^^ - -warning: variable does not need to be mutable - --> $DIR/lint-unused-mut-variables.rs:23:9 - | -LL | mut a: i32, - | ----^ - | | - | help: remove this `mut` - -warning: variable does not need to be mutable - --> $DIR/lint-unused-mut-variables.rs:14:5 - | -LL | mut a: i32, - | ----^ - | | - | help: remove this `mut` - -warning: variable does not need to be mutable - --> $DIR/lint-unused-mut-variables.rs:29:9 - | -LL | mut a: i32, - | ----^ - | | - | help: remove this `mut` - -warning: variable does not need to be mutable - --> $DIR/lint-unused-mut-variables.rs:39:9 - | -LL | mut a: i32, - | ----^ - | | - | help: remove this `mut` - -warning: variable does not need to be mutable - --> $DIR/lint-unused-mut-variables.rs:48:9 - | -LL | mut a: i32, - | ----^ - | | - | help: remove this `mut` - -warning: variable does not need to be mutable - --> $DIR/lint-unused-mut-variables.rs:57:9 - | -LL | mut a: i32, - | ----^ - | | - | help: remove this `mut` - -warning: variable does not need to be mutable - --> $DIR/lint-unused-mut-variables.rs:62:9 - | -LL | mut a: i32, - | ----^ - | | - | help: remove this `mut` - -warning: variable does not need to be mutable - --> $DIR/lint-unused-mut-variables.rs:107:14 - | -LL | let x = |mut y: isize| 10; - | ----^ - | | - | help: remove this `mut` - -warning: variable does not need to be mutable - --> $DIR/lint-unused-mut-variables.rs:69:9 - | -LL | let mut a = 3; - | ----^ - | | - | help: remove this `mut` - -warning: variable does not need to be mutable - --> $DIR/lint-unused-mut-variables.rs:71:9 - | -LL | let mut a = 2; - | ----^ - | | - | help: remove this `mut` - -warning: variable does not need to be mutable - --> $DIR/lint-unused-mut-variables.rs:73:9 - | -LL | let mut b = 3; - | ----^ - | | - | help: remove this `mut` - -warning: variable does not need to be mutable - --> $DIR/lint-unused-mut-variables.rs:75:9 - | -LL | let mut a = vec![3]; - | ----^ - | | - | help: remove this `mut` - -warning: variable does not need to be mutable - --> $DIR/lint-unused-mut-variables.rs:77:10 - | -LL | let (mut a, b) = (1, 2); - | ----^ - | | - | help: remove this `mut` - -warning: variable does not need to be mutable - --> $DIR/lint-unused-mut-variables.rs:79:9 - | -LL | let mut a; - | ----^ - | | - | help: remove this `mut` - -warning: variable does not need to be mutable - --> $DIR/lint-unused-mut-variables.rs:83:9 - | -LL | let mut b; - | ----^ - | | - | help: remove this `mut` - -warning: variable does not need to be mutable - --> $DIR/lint-unused-mut-variables.rs:92:9 - | -LL | mut x => {} - | ----^ - | | - | help: remove this `mut` - -warning: variable does not need to be mutable - --> $DIR/lint-unused-mut-variables.rs:99:10 - | -LL | (mut x, 1) | - | ----^ - | | - | help: remove this `mut` - -warning: variable does not need to be mutable - --> $DIR/lint-unused-mut-variables.rs:112:9 - | -LL | let mut a = &mut 5; - | ----^ - | | - | help: remove this `mut` - -warning: variable does not need to be mutable - --> $DIR/lint-unused-mut-variables.rs:117:9 - | -LL | let mut b = (&mut a,); - | ----^ - | | - | help: remove this `mut` - -warning: variable does not need to be mutable - --> $DIR/lint-unused-mut-variables.rs:120:9 - | -LL | let mut x = &mut 1; - | ----^ - | | - | help: remove this `mut` - -warning: variable does not need to be mutable - --> $DIR/lint-unused-mut-variables.rs:132:9 - | -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:187:9 - | -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:109:13 - | -LL | fn what(mut foo: isize) {} - | ----^^^ - | | - | help: remove this `mut` - -warning: variable does not need to be mutable - --> $DIR/lint-unused-mut-variables.rs:127:20 - | -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:205:9 - | -LL | let mut b = vec![2]; - | ----^ - | | - | help: remove this `mut` - | -note: the lint level is defined here - --> $DIR/lint-unused-mut-variables.rs:201:8 - | -LL | #[deny(unused_mut)] - | ^^^^^^^^^^ - -error: aborting due to previous error; 25 warnings emitted - diff --git a/src/test/ui/lint/lint-unused-variables.rs b/src/test/ui/lint/lint-unused-variables.rs deleted file mode 100644 index 6850e999242..00000000000 --- a/src/test/ui/lint/lint-unused-variables.rs +++ /dev/null @@ -1,79 +0,0 @@ -// compile-flags: --cfg something -// edition:2018 - -#![feature(async_closure)] -#![deny(unused_variables)] - -async fn foo_async( - a: i32, - //~^ ERROR unused variable: `a` - #[allow(unused_variables)] b: i32, -) {} -fn foo( - #[allow(unused_variables)] a: i32, - b: i32, - //~^ ERROR unused variable: `b` -) {} - -struct RefStruct {} -impl RefStruct { - async fn bar_async( - &self, - a: i32, - //~^ ERROR unused variable: `a` - #[allow(unused_variables)] b: i32, - ) {} - fn bar( - &self, - #[allow(unused_variables)] a: i32, - b: i32, - //~^ ERROR unused variable: `b` - ) {} - fn issue_64682_associated_fn( - #[allow(unused_variables)] a: i32, - b: i32, - //~^ ERROR unused variable: `b` - ) {} -} -trait RefTrait { - fn bar( - &self, - #[allow(unused_variables)] a: i32, - b: i32, - //~^ ERROR unused variable: `b` - ) {} - fn issue_64682_associated_fn( - #[allow(unused_variables)] a: i32, - b: i32, - //~^ ERROR unused variable: `b` - ) {} -} -impl RefTrait for RefStruct { - fn bar( - &self, - #[allow(unused_variables)] a: i32, - b: i32, - //~^ ERROR unused variable: `b` - ) {} - fn issue_64682_associated_fn( - #[allow(unused_variables)] a: i32, - b: i32, - //~^ ERROR unused variable: `b` - ) {} -} - -fn main() { - let _: fn(_, _) = foo; - let a = async move | - a: i32, - //~^ ERROR unused variable: `a` - #[allow(unused_variables)] b: i32, - | {}; - let b = | - #[allow(unused_variables)] a: i32, - b: i32, - //~^ ERROR unused variable: `b` - | {}; - let _ = a(1, 2); - let _ = b(1, 2); -} diff --git a/src/test/ui/lint/lint-unused-variables.stderr b/src/test/ui/lint/lint-unused-variables.stderr deleted file mode 100644 index d6e684e8306..00000000000 --- a/src/test/ui/lint/lint-unused-variables.stderr +++ /dev/null @@ -1,74 +0,0 @@ -error: unused variable: `a` - --> $DIR/lint-unused-variables.rs:8:5 - | -LL | a: i32, - | ^ help: if this is intentional, prefix it with an underscore: `_a` - | -note: the lint level is defined here - --> $DIR/lint-unused-variables.rs:5:9 - | -LL | #![deny(unused_variables)] - | ^^^^^^^^^^^^^^^^ - -error: unused variable: `b` - --> $DIR/lint-unused-variables.rs:14:5 - | -LL | b: i32, - | ^ help: if this is intentional, prefix it with an underscore: `_b` - -error: unused variable: `a` - --> $DIR/lint-unused-variables.rs:68:9 - | -LL | a: i32, - | ^ help: if this is intentional, prefix it with an underscore: `_a` - -error: unused variable: `b` - --> $DIR/lint-unused-variables.rs:74:9 - | -LL | b: i32, - | ^ help: if this is intentional, prefix it with an underscore: `_b` - -error: unused variable: `b` - --> $DIR/lint-unused-variables.rs:42:9 - | -LL | b: i32, - | ^ help: if this is intentional, prefix it with an underscore: `_b` - -error: unused variable: `b` - --> $DIR/lint-unused-variables.rs:47:9 - | -LL | b: i32, - | ^ help: if this is intentional, prefix it with an underscore: `_b` - -error: unused variable: `a` - --> $DIR/lint-unused-variables.rs:22:9 - | -LL | a: i32, - | ^ help: if this is intentional, prefix it with an underscore: `_a` - -error: unused variable: `b` - --> $DIR/lint-unused-variables.rs:29:9 - | -LL | b: i32, - | ^ help: if this is intentional, prefix it with an underscore: `_b` - -error: unused variable: `b` - --> $DIR/lint-unused-variables.rs:34:9 - | -LL | b: i32, - | ^ help: if this is intentional, prefix it with an underscore: `_b` - -error: unused variable: `b` - --> $DIR/lint-unused-variables.rs:55:9 - | -LL | b: i32, - | ^ help: if this is intentional, prefix it with an underscore: `_b` - -error: unused variable: `b` - --> $DIR/lint-unused-variables.rs:60:9 - | -LL | b: i32, - | ^ help: if this is intentional, prefix it with an underscore: `_b` - -error: aborting due to 11 previous errors - diff --git a/src/test/ui/lint/must-use-ops.rs b/src/test/ui/lint/must-use-ops.rs deleted file mode 100644 index 3e425727e78..00000000000 --- a/src/test/ui/lint/must-use-ops.rs +++ /dev/null @@ -1,41 +0,0 @@ -// Issue #50124 - Test warning for unused operator expressions - -// check-pass - -#![warn(unused_must_use)] - -fn main() { - let val = 1; - let val_pointer = &val; - -// Comparison Operators - val == 1; //~ WARNING unused comparison - val < 1; //~ WARNING unused comparison - val <= 1; //~ WARNING unused comparison - val != 1; //~ WARNING unused comparison - val >= 1; //~ WARNING unused comparison - val > 1; //~ WARNING unused comparison - -// 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 - true && true; //~ WARNING unused logical operation - false || true; //~ WARNING unused logical operation - -// 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 - !val; //~ WARNING unused unary operation - -val; //~ WARNING unused unary operation - *val_pointer; //~ WARNING unused unary operation -} diff --git a/src/test/ui/lint/must-use-ops.stderr b/src/test/ui/lint/must-use-ops.stderr deleted file mode 100644 index 73405d02a2e..00000000000 --- a/src/test/ui/lint/must-use-ops.stderr +++ /dev/null @@ -1,175 +0,0 @@ -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` - | -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 - -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` - | - = note: the comparison produces a value - -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` - | - = note: the comparison produces a value - -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` - | - = note: the comparison produces a value - -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` - | - = note: the comparison produces a value - -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` - | - = note: the comparison produces a value - -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` - | - = note: the arithmetic operation produces a value - -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` - | - = note: the arithmetic operation produces a value - -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` - | - = note: the arithmetic operation produces a value - -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` - | - = note: the arithmetic operation produces a value - -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` - | - = note: the arithmetic operation produces a value - -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` - | - = note: the logical operation produces a value - -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` - | - = note: the logical operation produces a value - -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` - | - = note: the bitwise operation produces a value - -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` - | - = note: the bitwise operation produces a value - -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` - | - = note: the bitwise operation produces a value - -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` - | - = note: the bitwise operation produces a value - -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` - | - = note: the bitwise operation produces a value - -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` - | - = note: the unary operation produces a value - -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` - | - = note: the unary operation produces a value - -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` - | - = note: the unary operation produces a value - -warning: 21 warnings emitted - diff --git a/src/test/ui/lint/must_use-array.rs b/src/test/ui/lint/must_use-array.rs deleted file mode 100644 index 97825dd2f6c..00000000000 --- a/src/test/ui/lint/must_use-array.rs +++ /dev/null @@ -1,47 +0,0 @@ -#![deny(unused_must_use)] - -#[must_use] -struct S; - -struct A; - -#[must_use] -trait T {} - -impl T for A {} - -fn empty() -> [S; 0] { - [] -} - -fn singleton() -> [S; 1] { - [S] -} - -fn many() -> [S; 4] { - [S, S, S, S] -} - -fn array_of_impl_trait() -> [impl T; 2] { - [A, A] -} - -fn impl_array() -> [(u8, Box); 2] { - [(0, Box::new(A)), (0, Box::new(A))] -} - -fn array_of_arrays_of_arrays() -> [[[S; 1]; 2]; 1] { - [[[S], [S]]] -} - -fn main() { - empty(); // ok - singleton(); //~ ERROR unused array of `S` that must be used - many(); //~ ERROR unused array of `S` that must be used - ([S], 0, ()); //~ ERROR unused array of `S` in tuple element 0 that must be used - array_of_impl_trait(); //~ ERROR unused array of implementers of `T` that must be used - impl_array(); - //~^ 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 -} diff --git a/src/test/ui/lint/must_use-array.stderr b/src/test/ui/lint/must_use-array.stderr deleted file mode 100644 index c42223b5198..00000000000 --- a/src/test/ui/lint/must_use-array.stderr +++ /dev/null @@ -1,44 +0,0 @@ -error: unused array of `S` that must be used - --> $DIR/must_use-array.rs:39:5 - | -LL | singleton(); - | ^^^^^^^^^^^^ - | -note: the lint level is defined here - --> $DIR/must_use-array.rs:1:9 - | -LL | #![deny(unused_must_use)] - | ^^^^^^^^^^^^^^^ - -error: unused array of `S` that must be used - --> $DIR/must_use-array.rs:40:5 - | -LL | many(); - | ^^^^^^^ - -error: unused array of `S` in tuple element 0 that must be used - --> $DIR/must_use-array.rs:41:6 - | -LL | ([S], 0, ()); - | ^^^ - -error: unused array of implementers of `T` that must be used - --> $DIR/must_use-array.rs:42: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 - | -LL | impl_array(); - | ^^^^^^^^^^^^^ - -error: unused array of arrays of arrays of `S` that must be used - --> $DIR/must_use-array.rs:45:5 - | -LL | array_of_arrays_of_arrays(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to 6 previous errors - diff --git a/src/test/ui/lint/must_use-in-stdlib-traits.rs b/src/test/ui/lint/must_use-in-stdlib-traits.rs deleted file mode 100644 index 70dddf61fb7..00000000000 --- a/src/test/ui/lint/must_use-in-stdlib-traits.rs +++ /dev/null @@ -1,47 +0,0 @@ -#![deny(unused_must_use)] -#![feature(arbitrary_self_types)] - -use std::iter::Iterator; -use std::future::Future; - -use std::task::{Context, Poll}; -use std::pin::Pin; -use std::unimplemented; - -struct MyFuture; - -impl Future for MyFuture { - type Output = u32; - - fn poll(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll { - Poll::Pending - } -} - -fn iterator() -> impl Iterator { - std::iter::empty::() -} - -fn future() -> impl Future { - MyFuture -} - -fn square_fn_once() -> impl FnOnce(u32) -> u32 { - |x| x * x -} - -fn square_fn_mut() -> impl FnMut(u32) -> u32 { - |x| x * x -} - -fn square_fn() -> impl Fn(u32) -> u32 { - |x| x * x -} - -fn main() { - iterator(); //~ ERROR unused implementer of `Iterator` that must be used - future(); //~ ERROR unused implementer of `Future` that must be used - square_fn_once(); //~ ERROR unused implementer of `FnOnce` that must be used - square_fn_mut(); //~ ERROR unused implementer of `FnMut` that must be used - square_fn(); //~ ERROR unused implementer of `Fn` that must be used -} diff --git a/src/test/ui/lint/must_use-in-stdlib-traits.stderr b/src/test/ui/lint/must_use-in-stdlib-traits.stderr deleted file mode 100644 index 76978d29dc8..00000000000 --- a/src/test/ui/lint/must_use-in-stdlib-traits.stderr +++ /dev/null @@ -1,47 +0,0 @@ -error: unused implementer of `Iterator` that must be used - --> $DIR/must_use-in-stdlib-traits.rs:42:4 - | -LL | iterator(); - | ^^^^^^^^^^^ - | -note: the lint level is defined here - --> $DIR/must_use-in-stdlib-traits.rs:1:9 - | -LL | #![deny(unused_must_use)] - | ^^^^^^^^^^^^^^^ - = note: iterators are lazy and do nothing unless consumed - -error: unused implementer of `Future` that must be used - --> $DIR/must_use-in-stdlib-traits.rs:43:4 - | -LL | future(); - | ^^^^^^^^^ - | - = note: futures do nothing unless you `.await` or poll them - -error: unused implementer of `FnOnce` that must be used - --> $DIR/must_use-in-stdlib-traits.rs:44:4 - | -LL | square_fn_once(); - | ^^^^^^^^^^^^^^^^^ - | - = note: closures are lazy and do nothing unless called - -error: unused implementer of `FnMut` that must be used - --> $DIR/must_use-in-stdlib-traits.rs:45:4 - | -LL | square_fn_mut(); - | ^^^^^^^^^^^^^^^^ - | - = note: closures are lazy and do nothing unless called - -error: unused implementer of `Fn` that must be used - --> $DIR/must_use-in-stdlib-traits.rs:46:4 - | -LL | square_fn(); - | ^^^^^^^^^^^^ - | - = note: closures are lazy and do nothing unless called - -error: aborting due to 5 previous errors - diff --git a/src/test/ui/lint/must_use-trait.rs b/src/test/ui/lint/must_use-trait.rs deleted file mode 100644 index 0aa751443a0..00000000000 --- a/src/test/ui/lint/must_use-trait.rs +++ /dev/null @@ -1,39 +0,0 @@ -#![deny(unused_must_use)] - -#[must_use] -trait Critical {} - -trait NotSoCritical {} - -trait DecidedlyUnimportant {} - -struct Anon; - -impl Critical for Anon {} -impl NotSoCritical for Anon {} -impl DecidedlyUnimportant for Anon {} - -fn get_critical() -> impl NotSoCritical + Critical + DecidedlyUnimportant { - Anon {} -} - -fn get_boxed_critical() -> Box { - Box::new(Anon {}) -} - -fn get_nested_boxed_critical() -> Box> { - Box::new(Box::new(Anon {})) -} - -fn get_critical_tuple() -> (u32, Box, impl Critical, ()) { - (0, get_boxed_critical(), get_critical(), ()) -} - -fn main() { - get_critical(); //~ ERROR unused implementer of `Critical` that must be used - get_boxed_critical(); //~ ERROR unused boxed `Critical` trait object that must be used - get_nested_boxed_critical(); - //~^ ERROR unused boxed boxed `Critical` trait object that must be used - get_critical_tuple(); //~ ERROR unused boxed `Critical` trait object in tuple element 1 - //~^ ERROR unused implementer of `Critical` in tuple element 2 -} diff --git a/src/test/ui/lint/must_use-trait.stderr b/src/test/ui/lint/must_use-trait.stderr deleted file mode 100644 index 11555d80825..00000000000 --- a/src/test/ui/lint/must_use-trait.stderr +++ /dev/null @@ -1,38 +0,0 @@ -error: unused implementer of `Critical` that must be used - --> $DIR/must_use-trait.rs:33:5 - | -LL | get_critical(); - | ^^^^^^^^^^^^^^^ - | -note: the lint level is defined here - --> $DIR/must_use-trait.rs:1:9 - | -LL | #![deny(unused_must_use)] - | ^^^^^^^^^^^^^^^ - -error: unused boxed `Critical` trait object that must be used - --> $DIR/must_use-trait.rs:34:5 - | -LL | get_boxed_critical(); - | ^^^^^^^^^^^^^^^^^^^^^ - -error: unused boxed boxed `Critical` trait object that must be used - --> $DIR/must_use-trait.rs:35:5 - | -LL | get_nested_boxed_critical(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: unused boxed `Critical` trait object in tuple element 1 that must be used - --> $DIR/must_use-trait.rs:37:5 - | -LL | get_critical_tuple(); - | ^^^^^^^^^^^^^^^^^^^^^ - -error: unused implementer of `Critical` in tuple element 2 that must be used - --> $DIR/must_use-trait.rs:37:5 - | -LL | get_critical_tuple(); - | ^^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to 5 previous errors - diff --git a/src/test/ui/lint/must_use-tuple.rs b/src/test/ui/lint/must_use-tuple.rs deleted file mode 100644 index 0f0aa20253c..00000000000 --- a/src/test/ui/lint/must_use-tuple.rs +++ /dev/null @@ -1,17 +0,0 @@ -#![deny(unused_must_use)] - -fn foo() -> (Result<(), ()>, ()) { - (Ok::<(), ()>(()), ()) -} - -fn main() { - (Ok::<(), ()>(()),); //~ ERROR unused `Result` - - (Ok::<(), ()>(()), 0, Ok::<(), ()>(()), 5); - //~^ ERROR unused `Result` - //~^^ ERROR unused `Result` - - foo(); //~ ERROR unused `Result` - - ((Err::<(), ()>(()), ()), ()); //~ ERROR unused `Result` -} diff --git a/src/test/ui/lint/must_use-tuple.stderr b/src/test/ui/lint/must_use-tuple.stderr deleted file mode 100644 index 0532d89e039..00000000000 --- a/src/test/ui/lint/must_use-tuple.stderr +++ /dev/null @@ -1,47 +0,0 @@ -error: unused `Result` in tuple element 0 that must be used - --> $DIR/must_use-tuple.rs:8:6 - | -LL | (Ok::<(), ()>(()),); - | ^^^^^^^^^^^^^^^^ - | -note: the lint level is defined here - --> $DIR/must_use-tuple.rs:1:9 - | -LL | #![deny(unused_must_use)] - | ^^^^^^^^^^^^^^^ - = note: this `Result` may be an `Err` variant, which should be handled - -error: unused `Result` in tuple element 0 that must be used - --> $DIR/must_use-tuple.rs:10:6 - | -LL | (Ok::<(), ()>(()), 0, Ok::<(), ()>(()), 5); - | ^^^^^^^^^^^^^^^^ - | - = note: this `Result` may be an `Err` variant, which should be handled - -error: unused `Result` in tuple element 2 that must be used - --> $DIR/must_use-tuple.rs:10:27 - | -LL | (Ok::<(), ()>(()), 0, Ok::<(), ()>(()), 5); - | ^^^^^^^^^^^^^^^^ - | - = note: this `Result` may be an `Err` variant, which should be handled - -error: unused `Result` in tuple element 0 that must be used - --> $DIR/must_use-tuple.rs:14:5 - | -LL | foo(); - | ^^^^^^ - | - = note: this `Result` may be an `Err` variant, which should be handled - -error: unused `Result` in tuple element 0 that must be used - --> $DIR/must_use-tuple.rs:16:6 - | -LL | ((Err::<(), ()>(()), ()), ()); - | ^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: this `Result` may be an `Err` variant, which should be handled - -error: aborting due to 5 previous errors - diff --git a/src/test/ui/lint/must_use-unit.rs b/src/test/ui/lint/must_use-unit.rs deleted file mode 100644 index 4dd4798abb7..00000000000 --- a/src/test/ui/lint/must_use-unit.rs +++ /dev/null @@ -1,16 +0,0 @@ -#![feature(never_type)] -#![deny(unused_must_use)] - -#[must_use] -fn foo() {} - -#[must_use] -fn bar() -> ! { - unimplemented!() -} - -fn main() { - foo(); //~ unused return value of `foo` - - bar(); //~ unused return value of `bar` -} diff --git a/src/test/ui/lint/must_use-unit.stderr b/src/test/ui/lint/must_use-unit.stderr deleted file mode 100644 index 7f25a193508..00000000000 --- a/src/test/ui/lint/must_use-unit.stderr +++ /dev/null @@ -1,20 +0,0 @@ -error: unused return value of `foo` that must be used - --> $DIR/must_use-unit.rs:13:5 - | -LL | foo(); - | ^^^^^^ - | -note: the lint level is defined here - --> $DIR/must_use-unit.rs:2:9 - | -LL | #![deny(unused_must_use)] - | ^^^^^^^^^^^^^^^ - -error: unused return value of `bar` that must be used - --> $DIR/must_use-unit.rs:15:5 - | -LL | bar(); - | ^^^^^^ - -error: aborting due to 2 previous errors - diff --git a/src/test/ui/lint/no-unused-parens-return-block.rs b/src/test/ui/lint/no-unused-parens-return-block.rs deleted file mode 100644 index 37dc519a204..00000000000 --- a/src/test/ui/lint/no-unused-parens-return-block.rs +++ /dev/null @@ -1,9 +0,0 @@ -// run-pass - -#![deny(unused_parens)] -#![allow(unreachable_code)] - -fn main() { - match (return) {} // ok - if (return) {} // ok -} diff --git a/src/test/ui/lint/unused/auxiliary/lint_unused_extern_crate.rs b/src/test/ui/lint/unused/auxiliary/lint_unused_extern_crate.rs new file mode 100644 index 00000000000..b76b4321d62 --- /dev/null +++ b/src/test/ui/lint/unused/auxiliary/lint_unused_extern_crate.rs @@ -0,0 +1 @@ +pub fn foo() {} diff --git a/src/test/ui/lint/unused/auxiliary/lint_unused_extern_crate2.rs b/src/test/ui/lint/unused/auxiliary/lint_unused_extern_crate2.rs new file mode 100644 index 00000000000..b76b4321d62 --- /dev/null +++ b/src/test/ui/lint/unused/auxiliary/lint_unused_extern_crate2.rs @@ -0,0 +1 @@ +pub fn foo() {} diff --git a/src/test/ui/lint/unused/auxiliary/lint_unused_extern_crate3.rs b/src/test/ui/lint/unused/auxiliary/lint_unused_extern_crate3.rs new file mode 100644 index 00000000000..b76b4321d62 --- /dev/null +++ b/src/test/ui/lint/unused/auxiliary/lint_unused_extern_crate3.rs @@ -0,0 +1 @@ +pub fn foo() {} diff --git a/src/test/ui/lint/unused/auxiliary/lint_unused_extern_crate4.rs b/src/test/ui/lint/unused/auxiliary/lint_unused_extern_crate4.rs new file mode 100644 index 00000000000..d11c69f812a --- /dev/null +++ b/src/test/ui/lint/unused/auxiliary/lint_unused_extern_crate4.rs @@ -0,0 +1 @@ +// intentionally empty diff --git a/src/test/ui/lint/unused/auxiliary/lint_unused_extern_crate5.rs b/src/test/ui/lint/unused/auxiliary/lint_unused_extern_crate5.rs new file mode 100644 index 00000000000..d11c69f812a --- /dev/null +++ b/src/test/ui/lint/unused/auxiliary/lint_unused_extern_crate5.rs @@ -0,0 +1 @@ +// intentionally empty diff --git a/src/test/ui/lint/unused/issue-30730.rs b/src/test/ui/lint/unused/issue-30730.rs new file mode 100644 index 00000000000..d6be90c8148 --- /dev/null +++ b/src/test/ui/lint/unused/issue-30730.rs @@ -0,0 +1,5 @@ +#![warn(unused)] +#![deny(warnings)] +use std::thread; +//~^ ERROR: unused import +fn main() {} diff --git a/src/test/ui/lint/unused/issue-30730.stderr b/src/test/ui/lint/unused/issue-30730.stderr new file mode 100644 index 00000000000..b299e99a3a9 --- /dev/null +++ b/src/test/ui/lint/unused/issue-30730.stderr @@ -0,0 +1,15 @@ +error: unused import: `std::thread` + --> $DIR/issue-30730.rs:3:5 + | +LL | use std::thread; + | ^^^^^^^^^^^ + | +note: the lint level is defined here + --> $DIR/issue-30730.rs:2:9 + | +LL | #![deny(warnings)] + | ^^^^^^^^ + = note: `#[deny(unused_imports)]` implied by `#[deny(warnings)]` + +error: aborting due to previous error + diff --git a/src/test/ui/lint/unused/issue-46576.rs b/src/test/ui/lint/unused/issue-46576.rs new file mode 100644 index 00000000000..15f458f3844 --- /dev/null +++ b/src/test/ui/lint/unused/issue-46576.rs @@ -0,0 +1,21 @@ +#![allow(dead_code)] +#![deny(unused_imports)] + +use std::fs::File; +use std::io::{BufRead, BufReader, Read}; +//~^ ERROR unused import: `BufRead` + +pub fn read_from_file(path: &str) { + let file = File::open(&path).unwrap(); + let mut reader = BufReader::new(file); + let mut s = String::new(); + reader.read_to_string(&mut s).unwrap(); +} + +pub fn read_lines(s: &str) { + for _line in s.lines() { + + } +} + +fn main() {} diff --git a/src/test/ui/lint/unused/issue-46576.stderr b/src/test/ui/lint/unused/issue-46576.stderr new file mode 100644 index 00000000000..6f4d97068b3 --- /dev/null +++ b/src/test/ui/lint/unused/issue-46576.stderr @@ -0,0 +1,14 @@ +error: unused import: `BufRead` + --> $DIR/issue-46576.rs:5:15 + | +LL | use std::io::{BufRead, BufReader, Read}; + | ^^^^^^^ + | +note: the lint level is defined here + --> $DIR/issue-46576.rs:2:9 + | +LL | #![deny(unused_imports)] + | ^^^^^^^^^^^^^^ + +error: aborting due to previous error + diff --git a/src/test/ui/lint/unused/issue-47390-unused-variable-in-struct-pattern.rs b/src/test/ui/lint/unused/issue-47390-unused-variable-in-struct-pattern.rs new file mode 100644 index 00000000000..0ad014e3361 --- /dev/null +++ b/src/test/ui/lint/unused/issue-47390-unused-variable-in-struct-pattern.rs @@ -0,0 +1,88 @@ +// check-pass + +#![feature(box_syntax)] +#![feature(box_patterns)] +#![warn(unused)] // UI tests pass `-A unused` (#43896) + +struct SoulHistory { + corridors_of_light: usize, + hours_are_suns: bool, + endless_and_singing: bool +} + +struct LovelyAmbition { + lips: usize, + fire: usize +} + +#[derive(Clone, Copy)] +enum Large { + Suit { case: () } +} + +struct Tuple(Large, ()); + +fn main() { + let i_think_continually = 2; //~ WARNING unused variable: `i_think_continually` + let who_from_the_womb_remembered = SoulHistory { + corridors_of_light: 5, + hours_are_suns: true, + endless_and_singing: true + }; + + let mut mut_unused_var = 1; + //~^ WARNING unused variable: `mut_unused_var` + //~| WARNING variable does not need to be mutable + + let (mut var, unused_var) = (1, 2); + //~^ WARNING unused variable: `var` + //~| WARNING unused variable: `unused_var` + //~| WARNING variable does not need to be mutable + // NOTE: `var` comes after `unused_var` lexicographically yet the warning + // for `var` will be emitted before the one for `unused_var`. We use an + // `IndexMap` to ensure this is the case instead of a `BTreeMap`. + + if let SoulHistory { corridors_of_light, //~ WARNING unused variable: `corridors_of_light` + mut hours_are_suns, //~ WARNING `hours_are_suns` is assigned to, but + endless_and_singing: true } = who_from_the_womb_remembered { + hours_are_suns = false; //~ WARNING unused_assignments + } + + let the_spirit = LovelyAmbition { lips: 1, fire: 2 }; + let LovelyAmbition { lips, fire } = the_spirit; //~ WARNING unused variable: `fire` + println!("{}", lips); + + let bag = Large::Suit { + case: () + }; + + // Plain struct + match bag { + Large::Suit { case } => {} //~ WARNING unused variable: `case` + }; + + // Referenced struct + match &bag { + &Large::Suit { case } => {} //~ WARNING unused variable: `case` + }; + + // Boxed struct + match box bag { + box Large::Suit { case } => {} //~ WARNING unused variable: `case` + }; + + // Tuple with struct + match (bag,) { + (Large::Suit { case },) => {} //~ WARNING unused variable: `case` + }; + + // Slice with struct + match [bag] { + [Large::Suit { case }] => {} //~ WARNING unused variable: `case` + }; + + // Tuple struct with struct + match Tuple(bag, ()) { + Tuple(Large::Suit { case }, ()) => {} //~ WARNING unused variable: `case` + }; +} diff --git a/src/test/ui/lint/unused/issue-47390-unused-variable-in-struct-pattern.stderr b/src/test/ui/lint/unused/issue-47390-unused-variable-in-struct-pattern.stderr new file mode 100644 index 00000000000..2ef655efdbd --- /dev/null +++ b/src/test/ui/lint/unused/issue-47390-unused-variable-in-struct-pattern.stderr @@ -0,0 +1,126 @@ +warning: unused variable: `i_think_continually` + --> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:26:9 + | +LL | let i_think_continually = 2; + | ^^^^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_i_think_continually` + | +note: the lint level is defined here + --> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:5:9 + | +LL | #![warn(unused)] // UI tests pass `-A unused` (#43896) + | ^^^^^^ + = note: `#[warn(unused_variables)]` implied by `#[warn(unused)]` + +warning: unused variable: `mut_unused_var` + --> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:33:13 + | +LL | let mut mut_unused_var = 1; + | ^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_mut_unused_var` + +warning: unused variable: `var` + --> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:37:14 + | +LL | let (mut var, unused_var) = (1, 2); + | ^^^ help: if this is intentional, prefix it with an underscore: `_var` + +warning: unused variable: `unused_var` + --> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:37:19 + | +LL | let (mut var, unused_var) = (1, 2); + | ^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_unused_var` + +warning: unused variable: `corridors_of_light` + --> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:45:26 + | +LL | if let SoulHistory { corridors_of_light, + | ^^^^^^^^^^^^^^^^^^ help: try ignoring the field: `corridors_of_light: _` + +warning: variable `hours_are_suns` is assigned to, but never used + --> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:46:30 + | +LL | mut hours_are_suns, + | ^^^^^^^^^^^^^^ + | + = note: consider using `_hours_are_suns` instead + +warning: value assigned to `hours_are_suns` is never read + --> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:48:9 + | +LL | hours_are_suns = false; + | ^^^^^^^^^^^^^^ + | +note: the lint level is defined here + --> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:5:9 + | +LL | #![warn(unused)] // UI tests pass `-A unused` (#43896) + | ^^^^^^ + = note: `#[warn(unused_assignments)]` implied by `#[warn(unused)]` + = help: maybe it is overwritten before being read? + +warning: unused variable: `fire` + --> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:52:32 + | +LL | let LovelyAmbition { lips, fire } = the_spirit; + | ^^^^ help: try ignoring the field: `fire: _` + +warning: unused variable: `case` + --> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:61:23 + | +LL | Large::Suit { case } => {} + | ^^^^ help: try ignoring the field: `case: _` + +warning: unused variable: `case` + --> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:66:24 + | +LL | &Large::Suit { case } => {} + | ^^^^ help: try ignoring the field: `case: _` + +warning: unused variable: `case` + --> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:71:27 + | +LL | box Large::Suit { case } => {} + | ^^^^ help: try ignoring the field: `case: _` + +warning: unused variable: `case` + --> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:76:24 + | +LL | (Large::Suit { case },) => {} + | ^^^^ help: try ignoring the field: `case: _` + +warning: unused variable: `case` + --> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:81:24 + | +LL | [Large::Suit { case }] => {} + | ^^^^ help: try ignoring the field: `case: _` + +warning: unused variable: `case` + --> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:86:29 + | +LL | Tuple(Large::Suit { case }, ()) => {} + | ^^^^ help: try ignoring the field: `case: _` + +warning: variable does not need to be mutable + --> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:33:9 + | +LL | let mut mut_unused_var = 1; + | ----^^^^^^^^^^^^^^ + | | + | help: remove this `mut` + | +note: the lint level is defined here + --> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:5:9 + | +LL | #![warn(unused)] // UI tests pass `-A unused` (#43896) + | ^^^^^^ + = note: `#[warn(unused_mut)]` implied by `#[warn(unused)]` + +warning: variable does not need to be mutable + --> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:37:10 + | +LL | let (mut var, unused_var) = (1, 2); + | ----^^^ + | | + | help: remove this `mut` + +warning: 16 warnings emitted + diff --git a/src/test/ui/lint/unused/issue-54180-unused-ref-field.fixed b/src/test/ui/lint/unused/issue-54180-unused-ref-field.fixed new file mode 100644 index 00000000000..1350b7ca699 --- /dev/null +++ b/src/test/ui/lint/unused/issue-54180-unused-ref-field.fixed @@ -0,0 +1,34 @@ +// run-rustfix + +#![deny(unused)] + +pub struct S { + pub f1: i32, +} + +pub struct Point { + pub x: i32, + pub y: i32, +} + +pub enum E { + Variant { field: String } +} + +pub fn foo(arg: &E) { + match arg { + E::Variant { field: _ } => (), //~ ERROR unused variable + } +} + +fn main() { + let s = S { f1: 123 }; + let S { f1: _ } = s; //~ ERROR unused variable + + let points = vec![Point { x: 1, y: 2 }]; + let _: i32 = points.iter().map(|Point { x: _, y }| y).sum(); //~ ERROR unused variable + + match (Point { x: 1, y: 2 }) { + Point { y, x: _ } => y, //~ ERROR unused variable + }; +} diff --git a/src/test/ui/lint/unused/issue-54180-unused-ref-field.rs b/src/test/ui/lint/unused/issue-54180-unused-ref-field.rs new file mode 100644 index 00000000000..7b3392b609a --- /dev/null +++ b/src/test/ui/lint/unused/issue-54180-unused-ref-field.rs @@ -0,0 +1,34 @@ +// run-rustfix + +#![deny(unused)] + +pub struct S { + pub f1: i32, +} + +pub struct Point { + pub x: i32, + pub y: i32, +} + +pub enum E { + Variant { field: String } +} + +pub fn foo(arg: &E) { + match arg { + E::Variant { ref field } => (), //~ ERROR unused variable + } +} + +fn main() { + let s = S { f1: 123 }; + let S { ref f1 } = s; //~ ERROR unused variable + + let points = vec![Point { x: 1, y: 2 }]; + let _: i32 = points.iter().map(|Point { x, y }| y).sum(); //~ ERROR unused variable + + match (Point { x: 1, y: 2 }) { + Point { y, ref mut x } => y, //~ ERROR unused variable + }; +} diff --git a/src/test/ui/lint/unused/issue-54180-unused-ref-field.stderr b/src/test/ui/lint/unused/issue-54180-unused-ref-field.stderr new file mode 100644 index 00000000000..c501aa25f13 --- /dev/null +++ b/src/test/ui/lint/unused/issue-54180-unused-ref-field.stderr @@ -0,0 +1,33 @@ +error: unused variable: `field` + --> $DIR/issue-54180-unused-ref-field.rs:20:22 + | +LL | E::Variant { ref field } => (), + | ^^^^^^^^^ help: try ignoring the field: `field: _` + | +note: the lint level is defined here + --> $DIR/issue-54180-unused-ref-field.rs:3:9 + | +LL | #![deny(unused)] + | ^^^^^^ + = note: `#[deny(unused_variables)]` implied by `#[deny(unused)]` + +error: unused variable: `x` + --> $DIR/issue-54180-unused-ref-field.rs:29:45 + | +LL | let _: i32 = points.iter().map(|Point { x, y }| y).sum(); + | ^ help: try ignoring the field: `x: _` + +error: unused variable: `f1` + --> $DIR/issue-54180-unused-ref-field.rs:26:13 + | +LL | let S { ref f1 } = s; + | ^^^^^^ help: try ignoring the field: `f1: _` + +error: unused variable: `x` + --> $DIR/issue-54180-unused-ref-field.rs:32:20 + | +LL | Point { y, ref mut x } => y, + | ^^^^^^^^^ help: try ignoring the field: `x: _` + +error: aborting due to 4 previous errors + diff --git a/src/test/ui/lint/unused/issue-54538-unused-parens-lint.fixed b/src/test/ui/lint/unused/issue-54538-unused-parens-lint.fixed new file mode 100644 index 00000000000..0b3fe9371f7 --- /dev/null +++ b/src/test/ui/lint/unused/issue-54538-unused-parens-lint.fixed @@ -0,0 +1,106 @@ +// run-rustfix + +#![feature(box_patterns, stmt_expr_attributes)] + +#![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) {} // Doesn't parse if we remove parens for now. + + let _ = |(Ok(a) | Err(a)): Result| 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 + &_ => {} + } +} diff --git a/src/test/ui/lint/unused/issue-54538-unused-parens-lint.rs b/src/test/ui/lint/unused/issue-54538-unused-parens-lint.rs new file mode 100644 index 00000000000..1e78ec5f7d9 --- /dev/null +++ b/src/test/ui/lint/unused/issue-54538-unused-parens-lint.rs @@ -0,0 +1,106 @@ +// run-rustfix + +#![feature(box_patterns, stmt_expr_attributes)] + +#![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) {} // Doesn't parse if we remove parens for now. + + let _ = |(Ok(a) | Err(a)): Result| 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 + &_ => {} + } +} diff --git a/src/test/ui/lint/unused/issue-54538-unused-parens-lint.stderr b/src/test/ui/lint/unused/issue-54538-unused-parens-lint.stderr new file mode 100644 index 00000000000..e6d0a359c5c --- /dev/null +++ b/src/test/ui/lint/unused/issue-54538-unused-parens-lint.stderr @@ -0,0 +1,152 @@ +error: unnecessary parentheses around pattern + --> $DIR/issue-54538-unused-parens-lint.rs:16:9 + | +LL | let (a) = 0; + | ^^^ help: remove these parentheses + | +note: the lint level is defined here + --> $DIR/issue-54538-unused-parens-lint.rs:13:9 + | +LL | #![deny(unused_parens)] + | ^^^^^^^^^^^^^ + +error: unnecessary parentheses around pattern + --> $DIR/issue-54538-unused-parens-lint.rs:17:9 + | +LL | for (a) in 0..1 {} + | ^^^ help: remove these parentheses + +error: unnecessary parentheses around pattern + --> $DIR/issue-54538-unused-parens-lint.rs:18:12 + | +LL | if let (a) = 0 {} + | ^^^ help: remove these parentheses + +error: unnecessary parentheses around pattern + --> $DIR/issue-54538-unused-parens-lint.rs:19:15 + | +LL | while let (a) = 0 {} + | ^^^ help: remove these parentheses + +error: unnecessary parentheses around pattern + --> $DIR/issue-54538-unused-parens-lint.rs:20:12 + | +LL | fn foo((a): u8) {} + | ^^^ help: remove these parentheses + +error: unnecessary parentheses around pattern + --> $DIR/issue-54538-unused-parens-lint.rs:21:14 + | +LL | let _ = |(a): u8| 0; + | ^^^ help: remove these parentheses + +error: unnecessary parentheses around pattern + --> $DIR/issue-54538-unused-parens-lint.rs:49:12 + | +LL | if let (0 | 1) = 0 {} + | ^^^^^^^ help: remove these parentheses + +error: unnecessary parentheses around pattern + --> $DIR/issue-54538-unused-parens-lint.rs:50:13 + | +LL | if let ((0 | 1),) = (0,) {} + | ^^^^^^^ help: remove these parentheses + +error: unnecessary parentheses around pattern + --> $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:52:16 + | +LL | if let 0 | (1 | 2) = 0 {} + | ^^^^^^^ help: remove these parentheses + +error: unnecessary parentheses around pattern + --> $DIR/issue-54538-unused-parens-lint.rs:54: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:56: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:66:9 + | +LL | (_) => {} + | ^^^ help: remove these parentheses + +error: unnecessary parentheses around pattern + --> $DIR/issue-54538-unused-parens-lint.rs:67:9 + | +LL | (y) => {} + | ^^^ help: remove these parentheses + +error: unnecessary parentheses around pattern + --> $DIR/issue-54538-unused-parens-lint.rs:68:9 + | +LL | (ref r) => {} + | ^^^^^^^ help: remove these parentheses + +error: unnecessary parentheses around pattern + --> $DIR/issue-54538-unused-parens-lint.rs:69:9 + | +LL | (e @ 1...2) => {} + | ^^^^^^^^^^^ help: remove these parentheses + +error: unnecessary parentheses around pattern + --> $DIR/issue-54538-unused-parens-lint.rs:75:9 + | +LL | (e @ &(1...2)) => {} + | ^^^^^^^^^^^^^^ help: remove these parentheses + +error: unnecessary parentheses around pattern + --> $DIR/issue-54538-unused-parens-lint.rs:76:10 + | +LL | &(_) => {} + | ^^^ help: remove these parentheses + +error: unnecessary parentheses around pattern + --> $DIR/issue-54538-unused-parens-lint.rs:87:9 + | +LL | (_) => {} + | ^^^ help: remove these parentheses + +error: unnecessary parentheses around pattern + --> $DIR/issue-54538-unused-parens-lint.rs:88:9 + | +LL | (y) => {} + | ^^^ help: remove these parentheses + +error: unnecessary parentheses around pattern + --> $DIR/issue-54538-unused-parens-lint.rs:89:9 + | +LL | (ref r) => {} + | ^^^^^^^ help: remove these parentheses + +error: unnecessary parentheses around pattern + --> $DIR/issue-54538-unused-parens-lint.rs:90:9 + | +LL | (e @ 1..=2) => {} + | ^^^^^^^^^^^ help: remove these parentheses + +error: unnecessary parentheses around pattern + --> $DIR/issue-54538-unused-parens-lint.rs:96:9 + | +LL | (e @ &(1..=2)) => {} + | ^^^^^^^^^^^^^^ help: remove these parentheses + +error: unnecessary parentheses around pattern + --> $DIR/issue-54538-unused-parens-lint.rs:97:10 + | +LL | &(_) => {} + | ^^^ help: remove these parentheses + +error: aborting due to 24 previous errors + diff --git a/src/test/ui/lint/unused/issue-59896.rs b/src/test/ui/lint/unused/issue-59896.rs new file mode 100644 index 00000000000..ff9f19acf84 --- /dev/null +++ b/src/test/ui/lint/unused/issue-59896.rs @@ -0,0 +1,9 @@ +#![deny(unused_imports)] + +struct S; + +fn main() { + use S; //~ ERROR the item `S` is imported redundantly + + let _s = S; +} diff --git a/src/test/ui/lint/unused/issue-59896.stderr b/src/test/ui/lint/unused/issue-59896.stderr new file mode 100644 index 00000000000..95b7938ae03 --- /dev/null +++ b/src/test/ui/lint/unused/issue-59896.stderr @@ -0,0 +1,17 @@ +error: the item `S` is imported redundantly + --> $DIR/issue-59896.rs:6:9 + | +LL | struct S; + | --------- the item `S` is already defined here +... +LL | use S; + | ^ + | +note: the lint level is defined here + --> $DIR/issue-59896.rs:1:9 + | +LL | #![deny(unused_imports)] + | ^^^^^^^^^^^^^^ + +error: aborting due to previous error + diff --git a/src/test/ui/lint/unused/issue-67691-unused-field-in-or-pattern.rs b/src/test/ui/lint/unused/issue-67691-unused-field-in-or-pattern.rs new file mode 100644 index 00000000000..e3631d014d6 --- /dev/null +++ b/src/test/ui/lint/unused/issue-67691-unused-field-in-or-pattern.rs @@ -0,0 +1,85 @@ +// FIXME: should be run-rustfix, but rustfix doesn't currently support multipart suggestions, see +// #53934 + +#![deny(unused)] + +pub enum MyEnum { + A { i: i32, j: i32 }, + B { i: i32, j: i32 }, +} + +pub enum MixedEnum { + A { i: i32 }, + B(i32), +} + +pub fn no_ref(x: MyEnum) { + use MyEnum::*; + + match x { + A { i, j } | B { i, j } => { //~ ERROR unused variable + println!("{}", i); + } + } +} + +pub fn with_ref(x: MyEnum) { + use MyEnum::*; + + match x { + A { i, ref j } | B { i, ref j } => { //~ ERROR unused variable + println!("{}", i); + } + } +} + +pub fn inner_no_ref(x: Option) { + use MyEnum::*; + + match x { + Some(A { i, j } | B { i, j }) => { //~ ERROR unused variable + println!("{}", i); + } + + _ => {} + } +} + +pub fn inner_with_ref(x: Option) { + use MyEnum::*; + + match x { + Some(A { i, ref j } | B { i, ref j }) => { //~ ERROR unused variable + println!("{}", i); + } + + _ => {} + } +} + +pub fn mixed_no_ref(x: MixedEnum) { + match x { + MixedEnum::A { i } | MixedEnum::B(i) => { //~ ERROR unused variable + println!("match"); + } + } +} + +pub fn mixed_with_ref(x: MixedEnum) { + match x { + MixedEnum::A { ref i } | MixedEnum::B(ref i) => { //~ ERROR unused variable + println!("match"); + } + } +} + +pub fn main() { + no_ref(MyEnum::A { i: 1, j: 2 }); + with_ref(MyEnum::A { i: 1, j: 2 }); + + inner_no_ref(Some(MyEnum::A { i: 1, j: 2 })); + inner_with_ref(Some(MyEnum::A { i: 1, j: 2 })); + + mixed_no_ref(MixedEnum::B(5)); + mixed_with_ref(MixedEnum::B(5)); +} diff --git a/src/test/ui/lint/unused/issue-67691-unused-field-in-or-pattern.stderr b/src/test/ui/lint/unused/issue-67691-unused-field-in-or-pattern.stderr new file mode 100644 index 00000000000..8aefe243a94 --- /dev/null +++ b/src/test/ui/lint/unused/issue-67691-unused-field-in-or-pattern.stderr @@ -0,0 +1,74 @@ +error: unused variable: `j` + --> $DIR/issue-67691-unused-field-in-or-pattern.rs:20:16 + | +LL | A { i, j } | B { i, j } => { + | ^ ^ + | +note: the lint level is defined here + --> $DIR/issue-67691-unused-field-in-or-pattern.rs:4:9 + | +LL | #![deny(unused)] + | ^^^^^^ + = note: `#[deny(unused_variables)]` implied by `#[deny(unused)]` +help: try ignoring the field + | +LL | A { i, j: _ } | B { i, j: _ } => { + | ^^^^ ^^^^ + +error: unused variable: `j` + --> $DIR/issue-67691-unused-field-in-or-pattern.rs:30:16 + | +LL | A { i, ref j } | B { i, ref j } => { + | ^^^^^ ^^^^^ + | +help: try ignoring the field + | +LL | A { i, j: _ } | B { i, j: _ } => { + | ^^^^ ^^^^ + +error: unused variable: `j` + --> $DIR/issue-67691-unused-field-in-or-pattern.rs:40:21 + | +LL | Some(A { i, j } | B { i, j }) => { + | ^ ^ + | +help: try ignoring the field + | +LL | Some(A { i, j: _ } | B { i, j: _ }) => { + | ^^^^ ^^^^ + +error: unused variable: `j` + --> $DIR/issue-67691-unused-field-in-or-pattern.rs:52:21 + | +LL | Some(A { i, ref j } | B { i, ref j }) => { + | ^^^^^ ^^^^^ + | +help: try ignoring the field + | +LL | Some(A { i, j: _ } | B { i, j: _ }) => { + | ^^^^ ^^^^ + +error: unused variable: `i` + --> $DIR/issue-67691-unused-field-in-or-pattern.rs:62:24 + | +LL | MixedEnum::A { i } | MixedEnum::B(i) => { + | ^ ^ + | +help: try ignoring the field + | +LL | MixedEnum::A { i: _ } | MixedEnum::B(_) => { + | ^^^^ ^ + +error: unused variable: `i` + --> $DIR/issue-67691-unused-field-in-or-pattern.rs:70:24 + | +LL | MixedEnum::A { ref i } | MixedEnum::B(ref i) => { + | ^^^^^ ^^^^^ + | +help: try ignoring the field + | +LL | MixedEnum::A { i: _ } | MixedEnum::B(_) => { + | ^^^^ ^ + +error: aborting due to 6 previous errors + diff --git a/src/test/ui/lint/unused/issue-70041.rs b/src/test/ui/lint/unused/issue-70041.rs new file mode 100644 index 00000000000..22e42295eed --- /dev/null +++ b/src/test/ui/lint/unused/issue-70041.rs @@ -0,0 +1,13 @@ +// compile-flags: --edition=2018 +// run-pass + +macro_rules! regex { + //~^ WARN unused macro definition + () => {}; +} + +#[allow(dead_code)] +use regex; +//~^ WARN unused import + +fn main() {} diff --git a/src/test/ui/lint/unused/issue-70041.stderr b/src/test/ui/lint/unused/issue-70041.stderr new file mode 100644 index 00000000000..ecd618eae8b --- /dev/null +++ b/src/test/ui/lint/unused/issue-70041.stderr @@ -0,0 +1,21 @@ +warning: unused macro definition + --> $DIR/issue-70041.rs:4:1 + | +LL | / macro_rules! regex { +LL | | +LL | | () => {}; +LL | | } + | |_^ + | + = note: `#[warn(unused_macros)]` on by default + +warning: unused import: `regex` + --> $DIR/issue-70041.rs:10:5 + | +LL | use regex; + | ^^^^^ + | + = note: `#[warn(unused_imports)]` on by default + +warning: 2 warnings emitted + diff --git a/src/test/ui/lint/unused/issue-71290-unused-paren-binop.rs b/src/test/ui/lint/unused/issue-71290-unused-paren-binop.rs new file mode 100644 index 00000000000..24d77e36d94 --- /dev/null +++ b/src/test/ui/lint/unused/issue-71290-unused-paren-binop.rs @@ -0,0 +1,23 @@ +// check-pass +// Make sure unused parens lint doesn't emit a false positive. +// See https://github.com/rust-lang/rust/issues/71290 for details. +#![deny(unused_parens)] + +fn x() -> u8 { + ({ 0 }) + 1 +} + +fn y() -> u8 { + ({ 0 } + 1) +} + +pub fn foo(a: bool, b: bool) -> u8 { + (if a { 1 } else { 0 } + if b { 1 } else { 0 }) +} + +pub fn bar() -> u8 { + // Make sure nested expressions are handled correctly as well + ({ 0 } + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9) +} + +fn main() {} diff --git a/src/test/ui/lint/unused/issue-74883-unused-paren-baren-yield.rs b/src/test/ui/lint/unused/issue-74883-unused-paren-baren-yield.rs new file mode 100644 index 00000000000..8064c3a88d1 --- /dev/null +++ b/src/test/ui/lint/unused/issue-74883-unused-paren-baren-yield.rs @@ -0,0 +1,26 @@ +#![feature(generator_trait)] +#![feature(generators)] +#![deny(unused_braces, unused_parens)] + +use std::ops::Generator; +use std::pin::Pin; + +fn main() { + let mut x = |_| { + while let Some(_) = (yield) {} + while let Some(_) = {yield} {} + + // Only warn these cases + while let Some(_) = ({yield}) {} //~ ERROR: unnecessary parentheses + while let Some(_) = ((yield)) {} //~ ERROR: unnecessary parentheses + {{yield}}; //~ ERROR: unnecessary braces + {( yield )}; //~ ERROR: unnecessary parentheses + while let Some(_) = {(yield)} {} //~ ERROR: unnecessary parentheses + while let Some(_) = {{yield}} {} //~ ERROR: unnecessary braces + + // FIXME: It'd be great if we could also warn them. + ((yield)); + ({ yield }); + }; + let _ = Pin::new(&mut x).resume(Some(5)); +} diff --git a/src/test/ui/lint/unused/issue-74883-unused-paren-baren-yield.stderr b/src/test/ui/lint/unused/issue-74883-unused-paren-baren-yield.stderr new file mode 100644 index 00000000000..3f6260dc6e1 --- /dev/null +++ b/src/test/ui/lint/unused/issue-74883-unused-paren-baren-yield.stderr @@ -0,0 +1,50 @@ +error: unnecessary parentheses around `let` scrutinee expression + --> $DIR/issue-74883-unused-paren-baren-yield.rs:14:29 + | +LL | while let Some(_) = ({yield}) {} + | ^^^^^^^^^ help: remove these parentheses + | +note: the lint level is defined here + --> $DIR/issue-74883-unused-paren-baren-yield.rs:3:24 + | +LL | #![deny(unused_braces, unused_parens)] + | ^^^^^^^^^^^^^ + +error: unnecessary parentheses around `let` scrutinee expression + --> $DIR/issue-74883-unused-paren-baren-yield.rs:15:29 + | +LL | while let Some(_) = ((yield)) {} + | ^^^^^^^^^ help: remove these parentheses + +error: unnecessary braces around block return value + --> $DIR/issue-74883-unused-paren-baren-yield.rs:16:10 + | +LL | {{yield}}; + | ^^^^^^^ help: remove these braces + | +note: the lint level is defined here + --> $DIR/issue-74883-unused-paren-baren-yield.rs:3:9 + | +LL | #![deny(unused_braces, unused_parens)] + | ^^^^^^^^^^^^^ + +error: unnecessary parentheses around block return value + --> $DIR/issue-74883-unused-paren-baren-yield.rs:17:10 + | +LL | {( yield )}; + | ^^^^^^^^^ help: remove these parentheses + +error: unnecessary parentheses around block return value + --> $DIR/issue-74883-unused-paren-baren-yield.rs:18:30 + | +LL | while let Some(_) = {(yield)} {} + | ^^^^^^^ help: remove these parentheses + +error: unnecessary braces around block return value + --> $DIR/issue-74883-unused-paren-baren-yield.rs:19:30 + | +LL | while let Some(_) = {{yield}} {} + | ^^^^^^^ help: remove these braces + +error: aborting due to 6 previous errors + diff --git a/src/test/ui/lint/unused/issue-81314-unused-span-ident.fixed b/src/test/ui/lint/unused/issue-81314-unused-span-ident.fixed new file mode 100644 index 00000000000..aac918f2bc8 --- /dev/null +++ b/src/test/ui/lint/unused/issue-81314-unused-span-ident.fixed @@ -0,0 +1,12 @@ +// run-rustfix +// Regression test for #81314: Unused variable lint should +// span only the identifier and not the rest of the pattern + +#![deny(unused)] + +fn main() { + let [_rest @ ..] = [1, 2, 3]; //~ ERROR unused variable +} + +pub fn foo([_rest @ ..]: &[i32]) { //~ ERROR unused variable +} diff --git a/src/test/ui/lint/unused/issue-81314-unused-span-ident.rs b/src/test/ui/lint/unused/issue-81314-unused-span-ident.rs new file mode 100644 index 00000000000..78296f4258d --- /dev/null +++ b/src/test/ui/lint/unused/issue-81314-unused-span-ident.rs @@ -0,0 +1,12 @@ +// run-rustfix +// Regression test for #81314: Unused variable lint should +// span only the identifier and not the rest of the pattern + +#![deny(unused)] + +fn main() { + let [rest @ ..] = [1, 2, 3]; //~ ERROR unused variable +} + +pub fn foo([rest @ ..]: &[i32]) { //~ ERROR unused variable +} diff --git a/src/test/ui/lint/unused/issue-81314-unused-span-ident.stderr b/src/test/ui/lint/unused/issue-81314-unused-span-ident.stderr new file mode 100644 index 00000000000..519c71e9413 --- /dev/null +++ b/src/test/ui/lint/unused/issue-81314-unused-span-ident.stderr @@ -0,0 +1,21 @@ +error: unused variable: `rest` + --> $DIR/issue-81314-unused-span-ident.rs:8:10 + | +LL | let [rest @ ..] = [1, 2, 3]; + | ^^^^ help: if this is intentional, prefix it with an underscore: `_rest` + | +note: the lint level is defined here + --> $DIR/issue-81314-unused-span-ident.rs:5:9 + | +LL | #![deny(unused)] + | ^^^^^^ + = note: `#[deny(unused_variables)]` implied by `#[deny(unused)]` + +error: unused variable: `rest` + --> $DIR/issue-81314-unused-span-ident.rs:11:13 + | +LL | pub fn foo([rest @ ..]: &[i32]) { + | ^^^^ help: if this is intentional, prefix it with an underscore: `_rest` + +error: aborting due to 2 previous errors + diff --git a/src/test/ui/lint/unused/issue-85913.rs b/src/test/ui/lint/unused/issue-85913.rs new file mode 100644 index 00000000000..7f3817b6ef1 --- /dev/null +++ b/src/test/ui/lint/unused/issue-85913.rs @@ -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() {} diff --git a/src/test/ui/lint/unused/issue-85913.stderr b/src/test/ui/lint/unused/issue-85913.stderr new file mode 100644 index 00000000000..d5d99f0f7d3 --- /dev/null +++ b/src/test/ui/lint/unused/issue-85913.stderr @@ -0,0 +1,15 @@ +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` + | +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 + +error: aborting due to previous error + diff --git a/src/test/ui/lint/unused/lint-unused-extern-crate.rs b/src/test/ui/lint/unused/lint-unused-extern-crate.rs new file mode 100644 index 00000000000..d5e4da526a1 --- /dev/null +++ b/src/test/ui/lint/unused/lint-unused-extern-crate.rs @@ -0,0 +1,35 @@ +// aux-build:lint_unused_extern_crate.rs +// aux-build:lint_unused_extern_crate2.rs +// aux-build:lint_unused_extern_crate3.rs +// aux-build:lint_unused_extern_crate4.rs +// aux-build:lint_unused_extern_crate5.rs + +#![deny(unused_extern_crates)] +#![allow(unused_variables)] +#![allow(deprecated)] + +extern crate lint_unused_extern_crate5; //~ ERROR: unused extern crate + +pub extern crate lint_unused_extern_crate4; // no error, it is re-exported + +extern crate lint_unused_extern_crate3; // no error, it is used + +extern crate lint_unused_extern_crate2; // no error, the use marks it as used + // even if imported objects aren't used + +extern crate lint_unused_extern_crate as other; // no error, the use * marks it as used + +#[allow(unused_imports)] +use lint_unused_extern_crate2::foo as bar; + +use other::*; + +mod foo { + // Test that this is unused even though an earlier `extern crate` is used. + extern crate lint_unused_extern_crate2; //~ ERROR unused extern crate +} + +fn main() { + lint_unused_extern_crate3::foo(); + let y = foo(); +} diff --git a/src/test/ui/lint/unused/lint-unused-extern-crate.stderr b/src/test/ui/lint/unused/lint-unused-extern-crate.stderr new file mode 100644 index 00000000000..46d8f3beeab --- /dev/null +++ b/src/test/ui/lint/unused/lint-unused-extern-crate.stderr @@ -0,0 +1,20 @@ +error: unused extern crate + --> $DIR/lint-unused-extern-crate.rs:11:1 + | +LL | extern crate lint_unused_extern_crate5; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove it + | +note: the lint level is defined here + --> $DIR/lint-unused-extern-crate.rs:7:9 + | +LL | #![deny(unused_extern_crates)] + | ^^^^^^^^^^^^^^^^^^^^ + +error: unused extern crate + --> $DIR/lint-unused-extern-crate.rs:29:5 + | +LL | extern crate lint_unused_extern_crate2; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove it + +error: aborting due to 2 previous errors + diff --git a/src/test/ui/lint/unused/lint-unused-imports.rs b/src/test/ui/lint/unused/lint-unused-imports.rs new file mode 100644 index 00000000000..4754d888076 --- /dev/null +++ b/src/test/ui/lint/unused/lint-unused-imports.rs @@ -0,0 +1,90 @@ +#![deny(unused_imports)] +#![allow(dead_code)] + +use bar::c::cc as cal; + +use std::mem::*; // shouldn't get errors for not using + // everything imported +use std::fmt::{}; +//~^ ERROR unused import: `std::fmt::{}` + +// Should get errors for both 'Some' and 'None' +use std::option::Option::{Some, None}; +//~^ ERROR unused imports: `None`, `Some` + +use test::A; //~ ERROR unused import: `test::A` +// Be sure that if we just bring some methods into scope that they're also +// counted as being used. +use test::B; +// But only when actually used: do not get confused by the method with the same name. +use test::B2; //~ ERROR unused import: `test::B2` + +// Make sure this import is warned about when at least one of its imported names +// is unused +use test2::{foo, bar}; //~ ERROR unused import: `bar` + +mod test2 { + pub fn foo() {} + pub fn bar() {} +} + +mod test { + pub trait A { fn a(&self) {} } + pub trait B { fn b(&self) {} } + pub trait B2 { fn b(&self) {} } + pub struct C; + impl A for C {} + impl B for C {} +} + +mod foo { + pub struct Point{pub x: isize, pub y: isize} + pub struct Square{pub p: Point, pub h: usize, pub w: usize} +} + +mod bar { + // Don't ignore on 'pub use' because we're not sure if it's used or not + pub use std::cmp::PartialEq; + pub struct Square; + + pub mod c { + use foo::Point; + use foo::Square; //~ ERROR unused import: `foo::Square` + pub fn cc(_p: Point) -> super::Square { + fn f() -> super::Square { + super::Square + } + f() + } + } + + #[allow(unused_imports)] + mod foo { + use std::cmp::PartialEq; + } +} + +fn g() { + use self::g; //~ ERROR unused import: `self::g` + //~^ ERROR the item `g` is imported redundantly + fn f() { + self::g(); + } +} + +// cf. issue #35135. +#[allow(unused_variables)] +fn h() { + use test2::foo; //~ ERROR unused import: `test2::foo` + //~^ ERROR the item `foo` is imported redundantly + let foo = 0; +} + +fn main() { + cal(foo::Point{x:3, y:9}); + let mut a = 3; + let mut b = 4; + swap(&mut a, &mut b); + test::C.b(); + let _a = foo(); +} diff --git a/src/test/ui/lint/unused/lint-unused-imports.stderr b/src/test/ui/lint/unused/lint-unused-imports.stderr new file mode 100644 index 00000000000..0574ca4569f --- /dev/null +++ b/src/test/ui/lint/unused/lint-unused-imports.stderr @@ -0,0 +1,78 @@ +error: unused import: `std::fmt::{}` + --> $DIR/lint-unused-imports.rs:8:5 + | +LL | use std::fmt::{}; + | ^^^^^^^^^^^^ + | +note: the lint level is defined here + --> $DIR/lint-unused-imports.rs:1:9 + | +LL | #![deny(unused_imports)] + | ^^^^^^^^^^^^^^ + +error: unused imports: `None`, `Some` + --> $DIR/lint-unused-imports.rs:12:27 + | +LL | use std::option::Option::{Some, None}; + | ^^^^ ^^^^ + +error: unused import: `test::A` + --> $DIR/lint-unused-imports.rs:15:5 + | +LL | use test::A; + | ^^^^^^^ + +error: unused import: `bar` + --> $DIR/lint-unused-imports.rs:24:18 + | +LL | use test2::{foo, bar}; + | ^^^ + +error: unused import: `foo::Square` + --> $DIR/lint-unused-imports.rs:52:13 + | +LL | use foo::Square; + | ^^^^^^^^^^^ + +error: the item `g` is imported redundantly + --> $DIR/lint-unused-imports.rs:68:9 + | +LL | / fn g() { +LL | | use self::g; + | | ^^^^^^^ +LL | | +LL | | fn f() { +LL | | self::g(); +LL | | } +LL | | } + | |_- the item `g` is already defined here + +error: unused import: `self::g` + --> $DIR/lint-unused-imports.rs:68:9 + | +LL | use self::g; + | ^^^^^^^ + +error: the item `foo` is imported redundantly + --> $DIR/lint-unused-imports.rs:78:9 + | +LL | use test2::{foo, bar}; + | --- the item `foo` is already imported here +... +LL | use test2::foo; + | ^^^^^^^^^^ + +error: unused import: `test2::foo` + --> $DIR/lint-unused-imports.rs:78:9 + | +LL | use test2::foo; + | ^^^^^^^^^^ + +error: unused import: `test::B2` + --> $DIR/lint-unused-imports.rs:20:5 + | +LL | use test::B2; + | ^^^^^^^^ + +error: aborting due to 10 previous errors + diff --git a/src/test/ui/lint/unused/lint-unused-mut-self.fixed b/src/test/ui/lint/unused/lint-unused-mut-self.fixed new file mode 100644 index 00000000000..92ce103586c --- /dev/null +++ b/src/test/ui/lint/unused/lint-unused-mut-self.fixed @@ -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) {} //~ ERROR: variable does not need to be mutable +} + +fn main() {} diff --git a/src/test/ui/lint/unused/lint-unused-mut-self.rs b/src/test/ui/lint/unused/lint-unused-mut-self.rs new file mode 100644 index 00000000000..70736ce216e --- /dev/null +++ b/src/test/ui/lint/unused/lint-unused-mut-self.rs @@ -0,0 +1,14 @@ +// run-rustfix + +#![allow(unused_assignments)] +#![allow(unused_variables)] +#![allow(dead_code)] +#![deny(unused_mut)] + +struct Foo; +impl Foo { + fn foo(mut self) {} //~ ERROR: variable does not need to be mutable + fn bar(mut self: Box) {} //~ ERROR: variable does not need to be mutable +} + +fn main() {} diff --git a/src/test/ui/lint/unused/lint-unused-mut-self.stderr b/src/test/ui/lint/unused/lint-unused-mut-self.stderr new file mode 100644 index 00000000000..01a524bd323 --- /dev/null +++ b/src/test/ui/lint/unused/lint-unused-mut-self.stderr @@ -0,0 +1,24 @@ +error: variable does not need to be mutable + --> $DIR/lint-unused-mut-self.rs:10:12 + | +LL | fn foo(mut self) {} + | ----^^^^ + | | + | help: remove this `mut` + | +note: the lint level is defined here + --> $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:11:12 + | +LL | fn bar(mut self: Box) {} + | ----^^^^ + | | + | help: remove this `mut` + +error: aborting due to 2 previous errors + diff --git a/src/test/ui/lint/unused/lint-unused-mut-variables.rs b/src/test/ui/lint/unused/lint-unused-mut-variables.rs new file mode 100644 index 00000000000..67ec7facf17 --- /dev/null +++ b/src/test/ui/lint/unused/lint-unused-mut-variables.rs @@ -0,0 +1,207 @@ +// edition:2018 + +// Exercise the unused_mut attribute in some positive and negative cases + +#![warn(unused_mut)] +#![feature(async_closure, raw_ref_op)] + +async fn baz_async( + mut a: i32, + //~^ WARN: variable does not need to be mutable + #[allow(unused_mut)] mut b: i32, +) {} +fn baz( + mut a: i32, + //~^ WARN: variable does not need to be mutable + #[allow(unused_mut)] mut b: i32, + #[allow(unused_mut)] (mut c, d): (i32, i32) +) {} + +struct RefStruct {} +impl RefStruct { + async fn baz_async( + mut a: i32, + //~^ WARN: variable does not need to be mutable + #[allow(unused_mut)] mut b: i32, + ) {} + fn baz( + &self, + mut a: i32, + //~^ WARN: variable does not need to be mutable + #[allow(unused_mut)] mut b: i32, + #[allow(unused_mut)] (mut c, d): (i32, i32) + ) {} +} + +trait RefTrait { + fn baz( + &self, + mut a: i32, + //~^ WARN: variable does not need to be mutable + #[allow(unused_mut)] mut b: i32, + #[allow(unused_mut)] (mut c, d): (i32, i32) + ) {} +} +impl RefTrait for () { + fn baz( + &self, + mut a: i32, + //~^ WARN: variable does not need to be mutable + #[allow(unused_mut)] mut b: i32, + #[allow(unused_mut)] (mut c, d): (i32, i32) + ) {} +} + +fn main() { + let _ = async move | + mut a: i32, + //~^ WARN: variable does not need to be mutable + #[allow(unused_mut)] mut b: i32, + | {}; + let _ = | + mut a: i32, + //~^ WARN: variable does not need to be mutable + #[allow(unused_mut)] mut b: i32, + #[allow(unused_mut)] (mut c, d): (i32, i32) + | {}; + + // negative cases + let mut a = 3; //~ WARN: variable does not need to be mutable + + let mut a = 2; //~ WARN: variable does not need to be mutable + + let mut b = 3; //~ WARN: variable does not need to be mutable + + let mut a = vec![3]; //~ WARN: variable does not need to be mutable + + let (mut a, b) = (1, 2); //~ WARN: variable does not need to be mutable + + let mut a; //~ WARN: variable does not need to be mutable + + a = 3; + + let mut b; //~ WARN: variable does not need to be mutable + + if true { + b = 3; + } else { + b = 4; + } + + match 30 { + mut x => {} //~ WARN: variable does not need to be mutable + + } + + 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 + + fn what(mut foo: isize) {} //~ WARN: variable does not need to be mutable + + + let mut a = &mut 5; //~ WARN: variable does not need to be mutable + + *a = 4; + + let mut a = 5; + let mut b = (&mut a,); //~ WARN: variable does not need to be mutable + *b.0 = 4; + + let mut x = &mut 1; //~ WARN: variable does not need to be mutable + + let mut f = || { + *x += 1; + }; + f(); + + fn mut_ref_arg(mut arg : &mut [u8]) -> &mut [u8] { + &mut arg[..] //~^ WARN: variable does not need to be mutable + + } + + let mut v : &mut Vec<()> = &mut vec![]; //~ WARN: variable does not need to be mutable + + v.push(()); + + // positive cases + let mut a = 2; + a = 3; + let mut a = Vec::new(); + a.push(3); + let mut a = Vec::new(); + callback(|| { + a.push(3); + }); + let mut a = Vec::new(); + callback(|| { + callback(|| { + a.push(3); + }); + }); + let (mut a, b) = (1, 2); + a = 34; + + match 30 { + mut x => { + x = 21; + } + } + + match (30, 2) { + (mut x, 1) | + (mut x, 2) | + (mut x, 3) => { + x = 21 + } + _ => {} + } + + // Attribute should be respected on match arms + match 0 { + #[allow(unused_mut)] + mut x => { + let mut y = 1; + }, + } + + let x = |mut y: isize| y = 32; + fn nothing(mut foo: isize) { foo = 37; } + + // leading underscore should avoid the warning, just like the + // unused variable lint. + let mut _allowed = 1; + + let mut raw_address_of_mut = 1; // OK + let mut_ptr = &raw mut raw_address_of_mut; + + let mut raw_address_of_const = 1; //~ WARN: variable does not need to be mutable + let const_ptr = &raw const raw_address_of_const; +} + +fn callback(f: F) where F: FnOnce() {} + +// make sure the lint attribute can be turned off +#[allow(unused_mut)] +fn foo(mut a: isize) { + let mut a = 3; + let mut b = vec![2]; +} + +// make sure the lint attribute can be turned off on let statements +#[deny(unused_mut)] +fn bar() { + #[allow(unused_mut)] + let mut a = 3; + let mut b = vec![2]; //~ ERROR: variable does not need to be mutable + +} diff --git a/src/test/ui/lint/unused/lint-unused-mut-variables.stderr b/src/test/ui/lint/unused/lint-unused-mut-variables.stderr new file mode 100644 index 00000000000..805ed2b40bb --- /dev/null +++ b/src/test/ui/lint/unused/lint-unused-mut-variables.stderr @@ -0,0 +1,222 @@ +warning: variable does not need to be mutable + --> $DIR/lint-unused-mut-variables.rs:9:5 + | +LL | mut a: i32, + | ----^ + | | + | help: remove this `mut` + | +note: the lint level is defined here + --> $DIR/lint-unused-mut-variables.rs:5:9 + | +LL | #![warn(unused_mut)] + | ^^^^^^^^^^ + +warning: variable does not need to be mutable + --> $DIR/lint-unused-mut-variables.rs:23:9 + | +LL | mut a: i32, + | ----^ + | | + | help: remove this `mut` + +warning: variable does not need to be mutable + --> $DIR/lint-unused-mut-variables.rs:14:5 + | +LL | mut a: i32, + | ----^ + | | + | help: remove this `mut` + +warning: variable does not need to be mutable + --> $DIR/lint-unused-mut-variables.rs:29:9 + | +LL | mut a: i32, + | ----^ + | | + | help: remove this `mut` + +warning: variable does not need to be mutable + --> $DIR/lint-unused-mut-variables.rs:39:9 + | +LL | mut a: i32, + | ----^ + | | + | help: remove this `mut` + +warning: variable does not need to be mutable + --> $DIR/lint-unused-mut-variables.rs:48:9 + | +LL | mut a: i32, + | ----^ + | | + | help: remove this `mut` + +warning: variable does not need to be mutable + --> $DIR/lint-unused-mut-variables.rs:57:9 + | +LL | mut a: i32, + | ----^ + | | + | help: remove this `mut` + +warning: variable does not need to be mutable + --> $DIR/lint-unused-mut-variables.rs:62:9 + | +LL | mut a: i32, + | ----^ + | | + | help: remove this `mut` + +warning: variable does not need to be mutable + --> $DIR/lint-unused-mut-variables.rs:107:14 + | +LL | let x = |mut y: isize| 10; + | ----^ + | | + | help: remove this `mut` + +warning: variable does not need to be mutable + --> $DIR/lint-unused-mut-variables.rs:69:9 + | +LL | let mut a = 3; + | ----^ + | | + | help: remove this `mut` + +warning: variable does not need to be mutable + --> $DIR/lint-unused-mut-variables.rs:71:9 + | +LL | let mut a = 2; + | ----^ + | | + | help: remove this `mut` + +warning: variable does not need to be mutable + --> $DIR/lint-unused-mut-variables.rs:73:9 + | +LL | let mut b = 3; + | ----^ + | | + | help: remove this `mut` + +warning: variable does not need to be mutable + --> $DIR/lint-unused-mut-variables.rs:75:9 + | +LL | let mut a = vec![3]; + | ----^ + | | + | help: remove this `mut` + +warning: variable does not need to be mutable + --> $DIR/lint-unused-mut-variables.rs:77:10 + | +LL | let (mut a, b) = (1, 2); + | ----^ + | | + | help: remove this `mut` + +warning: variable does not need to be mutable + --> $DIR/lint-unused-mut-variables.rs:79:9 + | +LL | let mut a; + | ----^ + | | + | help: remove this `mut` + +warning: variable does not need to be mutable + --> $DIR/lint-unused-mut-variables.rs:83:9 + | +LL | let mut b; + | ----^ + | | + | help: remove this `mut` + +warning: variable does not need to be mutable + --> $DIR/lint-unused-mut-variables.rs:92:9 + | +LL | mut x => {} + | ----^ + | | + | help: remove this `mut` + +warning: variable does not need to be mutable + --> $DIR/lint-unused-mut-variables.rs:99:10 + | +LL | (mut x, 1) | + | ----^ + | | + | help: remove this `mut` + +warning: variable does not need to be mutable + --> $DIR/lint-unused-mut-variables.rs:112:9 + | +LL | let mut a = &mut 5; + | ----^ + | | + | help: remove this `mut` + +warning: variable does not need to be mutable + --> $DIR/lint-unused-mut-variables.rs:117:9 + | +LL | let mut b = (&mut a,); + | ----^ + | | + | help: remove this `mut` + +warning: variable does not need to be mutable + --> $DIR/lint-unused-mut-variables.rs:120:9 + | +LL | let mut x = &mut 1; + | ----^ + | | + | help: remove this `mut` + +warning: variable does not need to be mutable + --> $DIR/lint-unused-mut-variables.rs:132:9 + | +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:187:9 + | +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:109:13 + | +LL | fn what(mut foo: isize) {} + | ----^^^ + | | + | help: remove this `mut` + +warning: variable does not need to be mutable + --> $DIR/lint-unused-mut-variables.rs:127:20 + | +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:205:9 + | +LL | let mut b = vec![2]; + | ----^ + | | + | help: remove this `mut` + | +note: the lint level is defined here + --> $DIR/lint-unused-mut-variables.rs:201:8 + | +LL | #[deny(unused_mut)] + | ^^^^^^^^^^ + +error: aborting due to previous error; 25 warnings emitted + diff --git a/src/test/ui/lint/unused/lint-unused-variables.rs b/src/test/ui/lint/unused/lint-unused-variables.rs new file mode 100644 index 00000000000..6850e999242 --- /dev/null +++ b/src/test/ui/lint/unused/lint-unused-variables.rs @@ -0,0 +1,79 @@ +// compile-flags: --cfg something +// edition:2018 + +#![feature(async_closure)] +#![deny(unused_variables)] + +async fn foo_async( + a: i32, + //~^ ERROR unused variable: `a` + #[allow(unused_variables)] b: i32, +) {} +fn foo( + #[allow(unused_variables)] a: i32, + b: i32, + //~^ ERROR unused variable: `b` +) {} + +struct RefStruct {} +impl RefStruct { + async fn bar_async( + &self, + a: i32, + //~^ ERROR unused variable: `a` + #[allow(unused_variables)] b: i32, + ) {} + fn bar( + &self, + #[allow(unused_variables)] a: i32, + b: i32, + //~^ ERROR unused variable: `b` + ) {} + fn issue_64682_associated_fn( + #[allow(unused_variables)] a: i32, + b: i32, + //~^ ERROR unused variable: `b` + ) {} +} +trait RefTrait { + fn bar( + &self, + #[allow(unused_variables)] a: i32, + b: i32, + //~^ ERROR unused variable: `b` + ) {} + fn issue_64682_associated_fn( + #[allow(unused_variables)] a: i32, + b: i32, + //~^ ERROR unused variable: `b` + ) {} +} +impl RefTrait for RefStruct { + fn bar( + &self, + #[allow(unused_variables)] a: i32, + b: i32, + //~^ ERROR unused variable: `b` + ) {} + fn issue_64682_associated_fn( + #[allow(unused_variables)] a: i32, + b: i32, + //~^ ERROR unused variable: `b` + ) {} +} + +fn main() { + let _: fn(_, _) = foo; + let a = async move | + a: i32, + //~^ ERROR unused variable: `a` + #[allow(unused_variables)] b: i32, + | {}; + let b = | + #[allow(unused_variables)] a: i32, + b: i32, + //~^ ERROR unused variable: `b` + | {}; + let _ = a(1, 2); + let _ = b(1, 2); +} diff --git a/src/test/ui/lint/unused/lint-unused-variables.stderr b/src/test/ui/lint/unused/lint-unused-variables.stderr new file mode 100644 index 00000000000..d6e684e8306 --- /dev/null +++ b/src/test/ui/lint/unused/lint-unused-variables.stderr @@ -0,0 +1,74 @@ +error: unused variable: `a` + --> $DIR/lint-unused-variables.rs:8:5 + | +LL | a: i32, + | ^ help: if this is intentional, prefix it with an underscore: `_a` + | +note: the lint level is defined here + --> $DIR/lint-unused-variables.rs:5:9 + | +LL | #![deny(unused_variables)] + | ^^^^^^^^^^^^^^^^ + +error: unused variable: `b` + --> $DIR/lint-unused-variables.rs:14:5 + | +LL | b: i32, + | ^ help: if this is intentional, prefix it with an underscore: `_b` + +error: unused variable: `a` + --> $DIR/lint-unused-variables.rs:68:9 + | +LL | a: i32, + | ^ help: if this is intentional, prefix it with an underscore: `_a` + +error: unused variable: `b` + --> $DIR/lint-unused-variables.rs:74:9 + | +LL | b: i32, + | ^ help: if this is intentional, prefix it with an underscore: `_b` + +error: unused variable: `b` + --> $DIR/lint-unused-variables.rs:42:9 + | +LL | b: i32, + | ^ help: if this is intentional, prefix it with an underscore: `_b` + +error: unused variable: `b` + --> $DIR/lint-unused-variables.rs:47:9 + | +LL | b: i32, + | ^ help: if this is intentional, prefix it with an underscore: `_b` + +error: unused variable: `a` + --> $DIR/lint-unused-variables.rs:22:9 + | +LL | a: i32, + | ^ help: if this is intentional, prefix it with an underscore: `_a` + +error: unused variable: `b` + --> $DIR/lint-unused-variables.rs:29:9 + | +LL | b: i32, + | ^ help: if this is intentional, prefix it with an underscore: `_b` + +error: unused variable: `b` + --> $DIR/lint-unused-variables.rs:34:9 + | +LL | b: i32, + | ^ help: if this is intentional, prefix it with an underscore: `_b` + +error: unused variable: `b` + --> $DIR/lint-unused-variables.rs:55:9 + | +LL | b: i32, + | ^ help: if this is intentional, prefix it with an underscore: `_b` + +error: unused variable: `b` + --> $DIR/lint-unused-variables.rs:60:9 + | +LL | b: i32, + | ^ help: if this is intentional, prefix it with an underscore: `_b` + +error: aborting due to 11 previous errors + diff --git a/src/test/ui/lint/unused/must-use-ops.rs b/src/test/ui/lint/unused/must-use-ops.rs new file mode 100644 index 00000000000..3e425727e78 --- /dev/null +++ b/src/test/ui/lint/unused/must-use-ops.rs @@ -0,0 +1,41 @@ +// Issue #50124 - Test warning for unused operator expressions + +// check-pass + +#![warn(unused_must_use)] + +fn main() { + let val = 1; + let val_pointer = &val; + +// Comparison Operators + val == 1; //~ WARNING unused comparison + val < 1; //~ WARNING unused comparison + val <= 1; //~ WARNING unused comparison + val != 1; //~ WARNING unused comparison + val >= 1; //~ WARNING unused comparison + val > 1; //~ WARNING unused comparison + +// 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 + true && true; //~ WARNING unused logical operation + false || true; //~ WARNING unused logical operation + +// 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 + !val; //~ WARNING unused unary operation + -val; //~ WARNING unused unary operation + *val_pointer; //~ WARNING unused unary operation +} diff --git a/src/test/ui/lint/unused/must-use-ops.stderr b/src/test/ui/lint/unused/must-use-ops.stderr new file mode 100644 index 00000000000..73405d02a2e --- /dev/null +++ b/src/test/ui/lint/unused/must-use-ops.stderr @@ -0,0 +1,175 @@ +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` + | +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 + +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` + | + = note: the comparison produces a value + +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` + | + = note: the comparison produces a value + +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` + | + = note: the comparison produces a value + +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` + | + = note: the comparison produces a value + +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` + | + = note: the comparison produces a value + +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` + | + = note: the arithmetic operation produces a value + +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` + | + = note: the arithmetic operation produces a value + +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` + | + = note: the arithmetic operation produces a value + +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` + | + = note: the arithmetic operation produces a value + +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` + | + = note: the arithmetic operation produces a value + +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` + | + = note: the logical operation produces a value + +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` + | + = note: the logical operation produces a value + +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` + | + = note: the bitwise operation produces a value + +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` + | + = note: the bitwise operation produces a value + +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` + | + = note: the bitwise operation produces a value + +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` + | + = note: the bitwise operation produces a value + +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` + | + = note: the bitwise operation produces a value + +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` + | + = note: the unary operation produces a value + +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` + | + = note: the unary operation produces a value + +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` + | + = note: the unary operation produces a value + +warning: 21 warnings emitted + diff --git a/src/test/ui/lint/unused/must_use-array.rs b/src/test/ui/lint/unused/must_use-array.rs new file mode 100644 index 00000000000..97825dd2f6c --- /dev/null +++ b/src/test/ui/lint/unused/must_use-array.rs @@ -0,0 +1,47 @@ +#![deny(unused_must_use)] + +#[must_use] +struct S; + +struct A; + +#[must_use] +trait T {} + +impl T for A {} + +fn empty() -> [S; 0] { + [] +} + +fn singleton() -> [S; 1] { + [S] +} + +fn many() -> [S; 4] { + [S, S, S, S] +} + +fn array_of_impl_trait() -> [impl T; 2] { + [A, A] +} + +fn impl_array() -> [(u8, Box); 2] { + [(0, Box::new(A)), (0, Box::new(A))] +} + +fn array_of_arrays_of_arrays() -> [[[S; 1]; 2]; 1] { + [[[S], [S]]] +} + +fn main() { + empty(); // ok + singleton(); //~ ERROR unused array of `S` that must be used + many(); //~ ERROR unused array of `S` that must be used + ([S], 0, ()); //~ ERROR unused array of `S` in tuple element 0 that must be used + array_of_impl_trait(); //~ ERROR unused array of implementers of `T` that must be used + impl_array(); + //~^ 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 +} diff --git a/src/test/ui/lint/unused/must_use-array.stderr b/src/test/ui/lint/unused/must_use-array.stderr new file mode 100644 index 00000000000..c42223b5198 --- /dev/null +++ b/src/test/ui/lint/unused/must_use-array.stderr @@ -0,0 +1,44 @@ +error: unused array of `S` that must be used + --> $DIR/must_use-array.rs:39:5 + | +LL | singleton(); + | ^^^^^^^^^^^^ + | +note: the lint level is defined here + --> $DIR/must_use-array.rs:1:9 + | +LL | #![deny(unused_must_use)] + | ^^^^^^^^^^^^^^^ + +error: unused array of `S` that must be used + --> $DIR/must_use-array.rs:40:5 + | +LL | many(); + | ^^^^^^^ + +error: unused array of `S` in tuple element 0 that must be used + --> $DIR/must_use-array.rs:41:6 + | +LL | ([S], 0, ()); + | ^^^ + +error: unused array of implementers of `T` that must be used + --> $DIR/must_use-array.rs:42: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 + | +LL | impl_array(); + | ^^^^^^^^^^^^^ + +error: unused array of arrays of arrays of `S` that must be used + --> $DIR/must_use-array.rs:45:5 + | +LL | array_of_arrays_of_arrays(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 6 previous errors + diff --git a/src/test/ui/lint/unused/must_use-in-stdlib-traits.rs b/src/test/ui/lint/unused/must_use-in-stdlib-traits.rs new file mode 100644 index 00000000000..70dddf61fb7 --- /dev/null +++ b/src/test/ui/lint/unused/must_use-in-stdlib-traits.rs @@ -0,0 +1,47 @@ +#![deny(unused_must_use)] +#![feature(arbitrary_self_types)] + +use std::iter::Iterator; +use std::future::Future; + +use std::task::{Context, Poll}; +use std::pin::Pin; +use std::unimplemented; + +struct MyFuture; + +impl Future for MyFuture { + type Output = u32; + + fn poll(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll { + Poll::Pending + } +} + +fn iterator() -> impl Iterator { + std::iter::empty::() +} + +fn future() -> impl Future { + MyFuture +} + +fn square_fn_once() -> impl FnOnce(u32) -> u32 { + |x| x * x +} + +fn square_fn_mut() -> impl FnMut(u32) -> u32 { + |x| x * x +} + +fn square_fn() -> impl Fn(u32) -> u32 { + |x| x * x +} + +fn main() { + iterator(); //~ ERROR unused implementer of `Iterator` that must be used + future(); //~ ERROR unused implementer of `Future` that must be used + square_fn_once(); //~ ERROR unused implementer of `FnOnce` that must be used + square_fn_mut(); //~ ERROR unused implementer of `FnMut` that must be used + square_fn(); //~ ERROR unused implementer of `Fn` that must be used +} diff --git a/src/test/ui/lint/unused/must_use-in-stdlib-traits.stderr b/src/test/ui/lint/unused/must_use-in-stdlib-traits.stderr new file mode 100644 index 00000000000..76978d29dc8 --- /dev/null +++ b/src/test/ui/lint/unused/must_use-in-stdlib-traits.stderr @@ -0,0 +1,47 @@ +error: unused implementer of `Iterator` that must be used + --> $DIR/must_use-in-stdlib-traits.rs:42:4 + | +LL | iterator(); + | ^^^^^^^^^^^ + | +note: the lint level is defined here + --> $DIR/must_use-in-stdlib-traits.rs:1:9 + | +LL | #![deny(unused_must_use)] + | ^^^^^^^^^^^^^^^ + = note: iterators are lazy and do nothing unless consumed + +error: unused implementer of `Future` that must be used + --> $DIR/must_use-in-stdlib-traits.rs:43:4 + | +LL | future(); + | ^^^^^^^^^ + | + = note: futures do nothing unless you `.await` or poll them + +error: unused implementer of `FnOnce` that must be used + --> $DIR/must_use-in-stdlib-traits.rs:44:4 + | +LL | square_fn_once(); + | ^^^^^^^^^^^^^^^^^ + | + = note: closures are lazy and do nothing unless called + +error: unused implementer of `FnMut` that must be used + --> $DIR/must_use-in-stdlib-traits.rs:45:4 + | +LL | square_fn_mut(); + | ^^^^^^^^^^^^^^^^ + | + = note: closures are lazy and do nothing unless called + +error: unused implementer of `Fn` that must be used + --> $DIR/must_use-in-stdlib-traits.rs:46:4 + | +LL | square_fn(); + | ^^^^^^^^^^^^ + | + = note: closures are lazy and do nothing unless called + +error: aborting due to 5 previous errors + diff --git a/src/test/ui/lint/unused/must_use-trait.rs b/src/test/ui/lint/unused/must_use-trait.rs new file mode 100644 index 00000000000..0aa751443a0 --- /dev/null +++ b/src/test/ui/lint/unused/must_use-trait.rs @@ -0,0 +1,39 @@ +#![deny(unused_must_use)] + +#[must_use] +trait Critical {} + +trait NotSoCritical {} + +trait DecidedlyUnimportant {} + +struct Anon; + +impl Critical for Anon {} +impl NotSoCritical for Anon {} +impl DecidedlyUnimportant for Anon {} + +fn get_critical() -> impl NotSoCritical + Critical + DecidedlyUnimportant { + Anon {} +} + +fn get_boxed_critical() -> Box { + Box::new(Anon {}) +} + +fn get_nested_boxed_critical() -> Box> { + Box::new(Box::new(Anon {})) +} + +fn get_critical_tuple() -> (u32, Box, impl Critical, ()) { + (0, get_boxed_critical(), get_critical(), ()) +} + +fn main() { + get_critical(); //~ ERROR unused implementer of `Critical` that must be used + get_boxed_critical(); //~ ERROR unused boxed `Critical` trait object that must be used + get_nested_boxed_critical(); + //~^ ERROR unused boxed boxed `Critical` trait object that must be used + get_critical_tuple(); //~ ERROR unused boxed `Critical` trait object in tuple element 1 + //~^ ERROR unused implementer of `Critical` in tuple element 2 +} diff --git a/src/test/ui/lint/unused/must_use-trait.stderr b/src/test/ui/lint/unused/must_use-trait.stderr new file mode 100644 index 00000000000..11555d80825 --- /dev/null +++ b/src/test/ui/lint/unused/must_use-trait.stderr @@ -0,0 +1,38 @@ +error: unused implementer of `Critical` that must be used + --> $DIR/must_use-trait.rs:33:5 + | +LL | get_critical(); + | ^^^^^^^^^^^^^^^ + | +note: the lint level is defined here + --> $DIR/must_use-trait.rs:1:9 + | +LL | #![deny(unused_must_use)] + | ^^^^^^^^^^^^^^^ + +error: unused boxed `Critical` trait object that must be used + --> $DIR/must_use-trait.rs:34:5 + | +LL | get_boxed_critical(); + | ^^^^^^^^^^^^^^^^^^^^^ + +error: unused boxed boxed `Critical` trait object that must be used + --> $DIR/must_use-trait.rs:35:5 + | +LL | get_nested_boxed_critical(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: unused boxed `Critical` trait object in tuple element 1 that must be used + --> $DIR/must_use-trait.rs:37:5 + | +LL | get_critical_tuple(); + | ^^^^^^^^^^^^^^^^^^^^^ + +error: unused implementer of `Critical` in tuple element 2 that must be used + --> $DIR/must_use-trait.rs:37:5 + | +LL | get_critical_tuple(); + | ^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 5 previous errors + diff --git a/src/test/ui/lint/unused/must_use-tuple.rs b/src/test/ui/lint/unused/must_use-tuple.rs new file mode 100644 index 00000000000..0f0aa20253c --- /dev/null +++ b/src/test/ui/lint/unused/must_use-tuple.rs @@ -0,0 +1,17 @@ +#![deny(unused_must_use)] + +fn foo() -> (Result<(), ()>, ()) { + (Ok::<(), ()>(()), ()) +} + +fn main() { + (Ok::<(), ()>(()),); //~ ERROR unused `Result` + + (Ok::<(), ()>(()), 0, Ok::<(), ()>(()), 5); + //~^ ERROR unused `Result` + //~^^ ERROR unused `Result` + + foo(); //~ ERROR unused `Result` + + ((Err::<(), ()>(()), ()), ()); //~ ERROR unused `Result` +} diff --git a/src/test/ui/lint/unused/must_use-tuple.stderr b/src/test/ui/lint/unused/must_use-tuple.stderr new file mode 100644 index 00000000000..0532d89e039 --- /dev/null +++ b/src/test/ui/lint/unused/must_use-tuple.stderr @@ -0,0 +1,47 @@ +error: unused `Result` in tuple element 0 that must be used + --> $DIR/must_use-tuple.rs:8:6 + | +LL | (Ok::<(), ()>(()),); + | ^^^^^^^^^^^^^^^^ + | +note: the lint level is defined here + --> $DIR/must_use-tuple.rs:1:9 + | +LL | #![deny(unused_must_use)] + | ^^^^^^^^^^^^^^^ + = note: this `Result` may be an `Err` variant, which should be handled + +error: unused `Result` in tuple element 0 that must be used + --> $DIR/must_use-tuple.rs:10:6 + | +LL | (Ok::<(), ()>(()), 0, Ok::<(), ()>(()), 5); + | ^^^^^^^^^^^^^^^^ + | + = note: this `Result` may be an `Err` variant, which should be handled + +error: unused `Result` in tuple element 2 that must be used + --> $DIR/must_use-tuple.rs:10:27 + | +LL | (Ok::<(), ()>(()), 0, Ok::<(), ()>(()), 5); + | ^^^^^^^^^^^^^^^^ + | + = note: this `Result` may be an `Err` variant, which should be handled + +error: unused `Result` in tuple element 0 that must be used + --> $DIR/must_use-tuple.rs:14:5 + | +LL | foo(); + | ^^^^^^ + | + = note: this `Result` may be an `Err` variant, which should be handled + +error: unused `Result` in tuple element 0 that must be used + --> $DIR/must_use-tuple.rs:16:6 + | +LL | ((Err::<(), ()>(()), ()), ()); + | ^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: this `Result` may be an `Err` variant, which should be handled + +error: aborting due to 5 previous errors + diff --git a/src/test/ui/lint/unused/must_use-unit.rs b/src/test/ui/lint/unused/must_use-unit.rs new file mode 100644 index 00000000000..4dd4798abb7 --- /dev/null +++ b/src/test/ui/lint/unused/must_use-unit.rs @@ -0,0 +1,16 @@ +#![feature(never_type)] +#![deny(unused_must_use)] + +#[must_use] +fn foo() {} + +#[must_use] +fn bar() -> ! { + unimplemented!() +} + +fn main() { + foo(); //~ unused return value of `foo` + + bar(); //~ unused return value of `bar` +} diff --git a/src/test/ui/lint/unused/must_use-unit.stderr b/src/test/ui/lint/unused/must_use-unit.stderr new file mode 100644 index 00000000000..7f25a193508 --- /dev/null +++ b/src/test/ui/lint/unused/must_use-unit.stderr @@ -0,0 +1,20 @@ +error: unused return value of `foo` that must be used + --> $DIR/must_use-unit.rs:13:5 + | +LL | foo(); + | ^^^^^^ + | +note: the lint level is defined here + --> $DIR/must_use-unit.rs:2:9 + | +LL | #![deny(unused_must_use)] + | ^^^^^^^^^^^^^^^ + +error: unused return value of `bar` that must be used + --> $DIR/must_use-unit.rs:15:5 + | +LL | bar(); + | ^^^^^^ + +error: aborting due to 2 previous errors + diff --git a/src/test/ui/lint/unused/no-unused-parens-return-block.rs b/src/test/ui/lint/unused/no-unused-parens-return-block.rs new file mode 100644 index 00000000000..37dc519a204 --- /dev/null +++ b/src/test/ui/lint/unused/no-unused-parens-return-block.rs @@ -0,0 +1,9 @@ +// run-pass + +#![deny(unused_parens)] +#![allow(unreachable_code)] + +fn main() { + match (return) {} // ok + if (return) {} // ok +} diff --git a/src/test/ui/lint/unused/unused-attr-macro-rules.rs b/src/test/ui/lint/unused/unused-attr-macro-rules.rs new file mode 100644 index 00000000000..396137a11d0 --- /dev/null +++ b/src/test/ui/lint/unused/unused-attr-macro-rules.rs @@ -0,0 +1,34 @@ +#![deny(unused_attributes)] +// Unused attributes on macro_rules requires special handling since the +// macro_rules definition does not survive towards HIR. + +// A sample of various built-in attributes. +#[macro_export] +#[macro_use] //~ ERROR unused attribute +#[path="foo"] //~ ERROR unused attribute +#[recursion_limit="1"] //~ ERROR unused attribute + //~| ERROR crate-level attribute should be an inner attribute +macro_rules! foo { + () => {}; +} + +// The following should not warn about unused attributes. +#[allow(unused)] +macro_rules! foo2 { + () => {}; +} + +#[cfg(FALSE)] +macro_rules! foo { + () => {}; +} + +/// Some docs +#[deprecated] +#[doc = "more docs"] +#[macro_export] +macro_rules! bar { + () => {}; +} + +fn main() {} diff --git a/src/test/ui/lint/unused/unused-attr-macro-rules.stderr b/src/test/ui/lint/unused/unused-attr-macro-rules.stderr new file mode 100644 index 00000000000..4606be01ac0 --- /dev/null +++ b/src/test/ui/lint/unused/unused-attr-macro-rules.stderr @@ -0,0 +1,32 @@ +error: unused attribute + --> $DIR/unused-attr-macro-rules.rs:7:1 + | +LL | #[macro_use] + | ^^^^^^^^^^^^ + | +note: the lint level is defined here + --> $DIR/unused-attr-macro-rules.rs:1:9 + | +LL | #![deny(unused_attributes)] + | ^^^^^^^^^^^^^^^^^ + +error: unused attribute + --> $DIR/unused-attr-macro-rules.rs:8:1 + | +LL | #[path="foo"] + | ^^^^^^^^^^^^^ + +error: unused attribute + --> $DIR/unused-attr-macro-rules.rs:9:1 + | +LL | #[recursion_limit="1"] + | ^^^^^^^^^^^^^^^^^^^^^^ + +error: crate-level attribute should be an inner attribute: add an exclamation mark: `#![foo]` + --> $DIR/unused-attr-macro-rules.rs:9:1 + | +LL | #[recursion_limit="1"] + | ^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 4 previous errors + diff --git a/src/test/ui/lint/unused/unused-attr.rs b/src/test/ui/lint/unused/unused-attr.rs new file mode 100644 index 00000000000..cb8ac0e6a05 --- /dev/null +++ b/src/test/ui/lint/unused/unused-attr.rs @@ -0,0 +1,49 @@ +#![deny(unused_attributes)] +#![feature(rustc_attrs)] + +#![rustc_dummy] //~ ERROR unused attribute + +#[rustc_dummy] //~ ERROR unused attribute +extern crate core; + +#[rustc_dummy] //~ ERROR unused attribute +use std::collections; + +#[rustc_dummy] //~ ERROR unused attribute +extern "C" { + #[rustc_dummy] //~ ERROR unused attribute + fn foo(); +} + +#[rustc_dummy] //~ ERROR unused attribute +mod foo { + #[rustc_dummy] //~ ERROR unused attribute + pub enum Foo { + #[rustc_dummy] //~ ERROR unused attribute + Bar, + } +} + +#[rustc_dummy] //~ ERROR unused attribute +fn bar(f: foo::Foo) { + match f { + #[rustc_dummy] //~ ERROR unused attribute + foo::Foo::Bar => {} + } +} + +#[rustc_dummy] //~ ERROR unused attribute +struct Foo { + #[rustc_dummy] //~ ERROR unused attribute + a: isize +} + +#[rustc_dummy] //~ ERROR unused attribute +trait Baz { + #[rustc_dummy] //~ ERROR unused attribute + fn blah(&self); + #[rustc_dummy] //~ ERROR unused attribute + fn blah2(&self) {} +} + +fn main() {} diff --git a/src/test/ui/lint/unused/unused-attr.stderr b/src/test/ui/lint/unused/unused-attr.stderr new file mode 100644 index 00000000000..707521b7802 --- /dev/null +++ b/src/test/ui/lint/unused/unused-attr.stderr @@ -0,0 +1,98 @@ +error: unused attribute + --> $DIR/unused-attr.rs:4:1 + | +LL | #![rustc_dummy] + | ^^^^^^^^^^^^^^^ + | +note: the lint level is defined here + --> $DIR/unused-attr.rs:1:9 + | +LL | #![deny(unused_attributes)] + | ^^^^^^^^^^^^^^^^^ + +error: unused attribute + --> $DIR/unused-attr.rs:6:1 + | +LL | #[rustc_dummy] + | ^^^^^^^^^^^^^^ + +error: unused attribute + --> $DIR/unused-attr.rs:9:1 + | +LL | #[rustc_dummy] + | ^^^^^^^^^^^^^^ + +error: unused attribute + --> $DIR/unused-attr.rs:12:1 + | +LL | #[rustc_dummy] + | ^^^^^^^^^^^^^^ + +error: unused attribute + --> $DIR/unused-attr.rs:14:5 + | +LL | #[rustc_dummy] + | ^^^^^^^^^^^^^^ + +error: unused attribute + --> $DIR/unused-attr.rs:18:1 + | +LL | #[rustc_dummy] + | ^^^^^^^^^^^^^^ + +error: unused attribute + --> $DIR/unused-attr.rs:20:5 + | +LL | #[rustc_dummy] + | ^^^^^^^^^^^^^^ + +error: unused attribute + --> $DIR/unused-attr.rs:22:9 + | +LL | #[rustc_dummy] + | ^^^^^^^^^^^^^^ + +error: unused attribute + --> $DIR/unused-attr.rs:27:1 + | +LL | #[rustc_dummy] + | ^^^^^^^^^^^^^^ + +error: unused attribute + --> $DIR/unused-attr.rs:30:9 + | +LL | #[rustc_dummy] + | ^^^^^^^^^^^^^^ + +error: unused attribute + --> $DIR/unused-attr.rs:35:1 + | +LL | #[rustc_dummy] + | ^^^^^^^^^^^^^^ + +error: unused attribute + --> $DIR/unused-attr.rs:37:5 + | +LL | #[rustc_dummy] + | ^^^^^^^^^^^^^^ + +error: unused attribute + --> $DIR/unused-attr.rs:41:1 + | +LL | #[rustc_dummy] + | ^^^^^^^^^^^^^^ + +error: unused attribute + --> $DIR/unused-attr.rs:43:5 + | +LL | #[rustc_dummy] + | ^^^^^^^^^^^^^^ + +error: unused attribute + --> $DIR/unused-attr.rs:45:5 + | +LL | #[rustc_dummy] + | ^^^^^^^^^^^^^^ + +error: aborting due to 15 previous errors + diff --git a/src/test/ui/lint/unused/unused-closure.rs b/src/test/ui/lint/unused/unused-closure.rs new file mode 100644 index 00000000000..c96c907318c --- /dev/null +++ b/src/test/ui/lint/unused/unused-closure.rs @@ -0,0 +1,35 @@ +// Test that closures and generators are "must use" types. +// edition:2018 + +#![feature(async_closure)] +#![feature(generators)] +#![deny(unused_must_use)] + +fn unused() { + || { //~ ERROR unused closure that must be used + println!("Hello!"); + }; + + async {}; //~ ERROR unused implementer of `Future` that must be used + || async {}; //~ ERROR unused closure that must be used + async || {}; //~ ERROR unused closure that must be used + + + [Box::new([|| {}; 10]); 1]; //~ ERROR unused array of boxed arrays of closures that must be used + + vec![|| "a"].pop().unwrap(); //~ ERROR unused closure that must be used + + let b = false; + || true; //~ ERROR unused closure that must be used + println!("{}", b); +} + +fn ignored() { + let _ = || {}; + let _ = || yield 42; +} + +fn main() { + unused(); + ignored(); +} diff --git a/src/test/ui/lint/unused/unused-closure.stderr b/src/test/ui/lint/unused/unused-closure.stderr new file mode 100644 index 00000000000..265d3e8e075 --- /dev/null +++ b/src/test/ui/lint/unused/unused-closure.stderr @@ -0,0 +1,65 @@ +error: unused closure that must be used + --> $DIR/unused-closure.rs:9:5 + | +LL | / || { +LL | | println!("Hello!"); +LL | | }; + | |______^ + | +note: the lint level is defined here + --> $DIR/unused-closure.rs:6:9 + | +LL | #![deny(unused_must_use)] + | ^^^^^^^^^^^^^^^ + = note: closures are lazy and do nothing unless called + +error: unused implementer of `Future` that must be used + --> $DIR/unused-closure.rs:13:5 + | +LL | async {}; + | ^^^^^^^^^ + | + = note: futures do nothing unless you `.await` or poll them + +error: unused closure that must be used + --> $DIR/unused-closure.rs:14:5 + | +LL | || async {}; + | ^^^^^^^^^^^^ + | + = note: closures are lazy and do nothing unless called + +error: unused closure that must be used + --> $DIR/unused-closure.rs:15:5 + | +LL | async || {}; + | ^^^^^^^^^^^^ + | + = note: closures are lazy and do nothing unless called + +error: unused array of boxed arrays of closures that must be used + --> $DIR/unused-closure.rs:18:5 + | +LL | [Box::new([|| {}; 10]); 1]; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: closures are lazy and do nothing unless called + +error: unused closure that must be used + --> $DIR/unused-closure.rs:20:5 + | +LL | vec![|| "a"].pop().unwrap(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: closures are lazy and do nothing unless called + +error: unused closure that must be used + --> $DIR/unused-closure.rs:23:9 + | +LL | || true; + | ^^^^^^^^ + | + = note: closures are lazy and do nothing unless called + +error: aborting due to 7 previous errors + diff --git a/src/test/ui/lint/unused/unused-doc-comments-edge-cases.rs b/src/test/ui/lint/unused/unused-doc-comments-edge-cases.rs new file mode 100644 index 00000000000..fd9baf8c6b9 --- /dev/null +++ b/src/test/ui/lint/unused/unused-doc-comments-edge-cases.rs @@ -0,0 +1,29 @@ +#![deny(unused_doc_comments)] + +fn doc_comment_on_match_arms(num: u8) -> bool { + match num { + 3 => true, + /// useless doc comment + //~^ ERROR: unused doc comment + _ => false, + } +} + +fn doc_comment_between_if_else(num: u8) -> bool { + if num == 3 { + true //~ ERROR: mismatched types + } + /// useless doc comment + else { //~ ERROR: expected expression, found keyword `else` + false + } +} + +fn doc_comment_on_expr(num: u8) -> bool { + /// useless doc comment + //~^ ERROR: attributes on expressions are experimental + //~| ERROR: unused doc comment + num == 3 +} + +fn main() {} diff --git a/src/test/ui/lint/unused/unused-doc-comments-edge-cases.stderr b/src/test/ui/lint/unused/unused-doc-comments-edge-cases.stderr new file mode 100644 index 00000000000..14db5f64b0c --- /dev/null +++ b/src/test/ui/lint/unused/unused-doc-comments-edge-cases.stderr @@ -0,0 +1,61 @@ +error: expected expression, found keyword `else` + --> $DIR/unused-doc-comments-edge-cases.rs:17:5 + | +LL | else { + | ^^^^ expected expression + +error[E0658]: attributes on expressions are experimental + --> $DIR/unused-doc-comments-edge-cases.rs:23:5 + | +LL | /// useless doc comment + | ^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: see issue #15701 for more information + = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable + = help: `///` is for documentation comments. For a plain comment, use `//`. + +error: unused doc comment + --> $DIR/unused-doc-comments-edge-cases.rs:6:9 + | +LL | /// useless doc comment + | ^^^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | _ => false, + | ---------- rustdoc does not generate documentation for match arms + | +note: the lint level is defined here + --> $DIR/unused-doc-comments-edge-cases.rs:1:9 + | +LL | #![deny(unused_doc_comments)] + | ^^^^^^^^^^^^^^^^^^^ + = help: use `//` for a plain comment + +error: unused doc comment + --> $DIR/unused-doc-comments-edge-cases.rs:23:5 + | +LL | /// useless doc comment + | ^^^^^^^^^^^^^^^^^^^^^^^ +... +LL | num == 3 + | --- rustdoc does not generate documentation for expressions + | + = help: use `//` for a plain comment + +error[E0308]: mismatched types + --> $DIR/unused-doc-comments-edge-cases.rs:14:9 + | +LL | / if num == 3 { +LL | | true + | | ^^^^ expected `()`, found `bool` +LL | | } + | |_____- expected this to be `()` + | +help: you might have meant to return this value + | +LL | return true; + | ^^^^^^ ^ + +error: aborting due to 5 previous errors + +Some errors have detailed explanations: E0308, E0658. +For more information about an error, try `rustc --explain E0308`. diff --git a/src/test/ui/lint/unused/unused-doc-comments-for-macros.rs b/src/test/ui/lint/unused/unused-doc-comments-for-macros.rs new file mode 100644 index 00000000000..05828ebb2c3 --- /dev/null +++ b/src/test/ui/lint/unused/unused-doc-comments-for-macros.rs @@ -0,0 +1,17 @@ +#![deny(unused_doc_comments)] +#![feature(rustc_attrs)] + +macro_rules! foo { () => {}; } + +fn main() { + /// line1 //~ ERROR: unused doc comment + /// line2 + /// line3 + foo!(); + + // Ensure we still detect another doc-comment block. + /// line1 //~ ERROR: unused doc comment + /// line2 + /// line3 + foo!(); +} diff --git a/src/test/ui/lint/unused/unused-doc-comments-for-macros.stderr b/src/test/ui/lint/unused/unused-doc-comments-for-macros.stderr new file mode 100644 index 00000000000..f4f5bb71e55 --- /dev/null +++ b/src/test/ui/lint/unused/unused-doc-comments-for-macros.stderr @@ -0,0 +1,31 @@ +error: unused doc comment + --> $DIR/unused-doc-comments-for-macros.rs:7:5 + | +LL | / /// line1 +LL | | /// line2 +LL | | /// line3 + | |_____--------^ + | | + | rustdoc does not generate documentation for macro invocations + | +note: the lint level is defined here + --> $DIR/unused-doc-comments-for-macros.rs:1:9 + | +LL | #![deny(unused_doc_comments)] + | ^^^^^^^^^^^^^^^^^^^ + = help: to document an item produced by a macro, the macro must produce the documentation as part of its expansion + +error: unused doc comment + --> $DIR/unused-doc-comments-for-macros.rs:13:5 + | +LL | / /// line1 +LL | | /// line2 +LL | | /// line3 + | |_____--------^ + | | + | rustdoc does not generate documentation for macro invocations + | + = help: to document an item produced by a macro, the macro must produce the documentation as part of its expansion + +error: aborting due to 2 previous errors + diff --git a/src/test/ui/lint/unused/unused-macro-rules.rs b/src/test/ui/lint/unused/unused-macro-rules.rs new file mode 100644 index 00000000000..1a714b8f0a0 --- /dev/null +++ b/src/test/ui/lint/unused/unused-macro-rules.rs @@ -0,0 +1,29 @@ +#![deny(unused_macros)] + +// Most simple case +macro_rules! unused { //~ ERROR: unused macro definition + () => {}; +} + +// Test macros created by macros +macro_rules! create_macro { + () => { + macro_rules! m { //~ ERROR: unused macro definition + () => {}; + } + }; +} +create_macro!(); + +#[allow(unused_macros)] +mod bar { + // Test that putting the #[deny] close to the macro's definition + // works. + + #[deny(unused_macros)] + macro_rules! unused { //~ ERROR: unused macro definition + () => {}; + } +} + +fn main() {} diff --git a/src/test/ui/lint/unused/unused-macro-rules.stderr b/src/test/ui/lint/unused/unused-macro-rules.stderr new file mode 100644 index 00000000000..55072bd81bf --- /dev/null +++ b/src/test/ui/lint/unused/unused-macro-rules.stderr @@ -0,0 +1,43 @@ +error: unused macro definition + --> $DIR/unused-macro-rules.rs:4:1 + | +LL | / macro_rules! unused { +LL | | () => {}; +LL | | } + | |_^ + | +note: the lint level is defined here + --> $DIR/unused-macro-rules.rs:1:9 + | +LL | #![deny(unused_macros)] + | ^^^^^^^^^^^^^ + +error: unused macro definition + --> $DIR/unused-macro-rules.rs:11:9 + | +LL | / macro_rules! m { +LL | | () => {}; +LL | | } + | |_________^ +... +LL | create_macro!(); + | ---------------- in this macro invocation + | + = note: this error originates in the macro `create_macro` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: unused macro definition + --> $DIR/unused-macro-rules.rs:24:5 + | +LL | / macro_rules! unused { +LL | | () => {}; +LL | | } + | |_____^ + | +note: the lint level is defined here + --> $DIR/unused-macro-rules.rs:23:12 + | +LL | #[deny(unused_macros)] + | ^^^^^^^^^^^^^ + +error: aborting due to 3 previous errors + diff --git a/src/test/ui/lint/unused/unused-macro-with-bad-frag-spec.rs b/src/test/ui/lint/unused/unused-macro-with-bad-frag-spec.rs new file mode 100644 index 00000000000..ce187047bb7 --- /dev/null +++ b/src/test/ui/lint/unused/unused-macro-with-bad-frag-spec.rs @@ -0,0 +1,9 @@ +#![allow(unused_macros)] + +// Issue #21370 + +macro_rules! test { + ($wrong:t_ty) => () //~ ERROR invalid fragment specifier `t_ty` +} + +fn main() { } diff --git a/src/test/ui/lint/unused/unused-macro-with-bad-frag-spec.stderr b/src/test/ui/lint/unused/unused-macro-with-bad-frag-spec.stderr new file mode 100644 index 00000000000..6edf0a2cf8d --- /dev/null +++ b/src/test/ui/lint/unused/unused-macro-with-bad-frag-spec.stderr @@ -0,0 +1,10 @@ +error: invalid fragment specifier `t_ty` + --> $DIR/unused-macro-with-bad-frag-spec.rs:6:6 + | +LL | ($wrong:t_ty) => () + | ^^^^^^^^^^^ + | + = help: valid fragment specifiers are `ident`, `block`, `stmt`, `expr`, `pat`, `ty`, `lifetime`, `literal`, `path`, `meta`, `tt`, `item` and `vis` + +error: aborting due to previous error + diff --git a/src/test/ui/lint/unused/unused-macro-with-follow-violation.rs b/src/test/ui/lint/unused/unused-macro-with-follow-violation.rs new file mode 100644 index 00000000000..1666dae69b9 --- /dev/null +++ b/src/test/ui/lint/unused/unused-macro-with-follow-violation.rs @@ -0,0 +1,7 @@ +#![allow(unused_macros)] + +macro_rules! test { + ($e:expr +) => () //~ ERROR not allowed for `expr` fragments +} + +fn main() { } diff --git a/src/test/ui/lint/unused/unused-macro-with-follow-violation.stderr b/src/test/ui/lint/unused/unused-macro-with-follow-violation.stderr new file mode 100644 index 00000000000..5eced4f06c0 --- /dev/null +++ b/src/test/ui/lint/unused/unused-macro-with-follow-violation.stderr @@ -0,0 +1,10 @@ +error: `$e:expr` is followed by `+`, which is not allowed for `expr` fragments + --> $DIR/unused-macro-with-follow-violation.rs:4:14 + | +LL | ($e:expr +) => () + | ^ not allowed after `expr` fragments + | + = note: allowed there are: `=>`, `,` or `;` + +error: aborting due to previous error + diff --git a/src/test/ui/lint/unused/unused-macro.rs b/src/test/ui/lint/unused/unused-macro.rs new file mode 100644 index 00000000000..302b0727d77 --- /dev/null +++ b/src/test/ui/lint/unused/unused-macro.rs @@ -0,0 +1,26 @@ +#![feature(decl_macro)] +#![deny(unused_macros)] + +// Most simple case +macro unused { //~ ERROR: unused macro definition + () => {} +} + +#[allow(unused_macros)] +mod bar { + // Test that putting the #[deny] close to the macro's definition + // works. + + #[deny(unused_macros)] + macro unused { //~ ERROR: unused macro definition + () => {} + } +} + +mod boo { + pub(crate) macro unused { //~ ERROR: unused macro definition + () => {} + } +} + +fn main() {} diff --git a/src/test/ui/lint/unused/unused-macro.stderr b/src/test/ui/lint/unused/unused-macro.stderr new file mode 100644 index 00000000000..f5eb76179bf --- /dev/null +++ b/src/test/ui/lint/unused/unused-macro.stderr @@ -0,0 +1,38 @@ +error: unused macro definition + --> $DIR/unused-macro.rs:5:1 + | +LL | / macro unused { +LL | | () => {} +LL | | } + | |_^ + | +note: the lint level is defined here + --> $DIR/unused-macro.rs:2:9 + | +LL | #![deny(unused_macros)] + | ^^^^^^^^^^^^^ + +error: unused macro definition + --> $DIR/unused-macro.rs:15:5 + | +LL | / macro unused { +LL | | () => {} +LL | | } + | |_____^ + | +note: the lint level is defined here + --> $DIR/unused-macro.rs:14:12 + | +LL | #[deny(unused_macros)] + | ^^^^^^^^^^^^^ + +error: unused macro definition + --> $DIR/unused-macro.rs:21:5 + | +LL | / pub(crate) macro unused { +LL | | () => {} +LL | | } + | |_____^ + +error: aborting due to 3 previous errors + diff --git a/src/test/ui/lint/unused/unused-mut-warning-captured-var.fixed b/src/test/ui/lint/unused/unused-mut-warning-captured-var.fixed new file mode 100644 index 00000000000..c21f18015c1 --- /dev/null +++ b/src/test/ui/lint/unused/unused-mut-warning-captured-var.fixed @@ -0,0 +1,9 @@ +// run-rustfix + +#![forbid(unused_mut)] + +fn main() { + let x = 1; + //~^ ERROR: variable does not need to be mutable + (move|| { println!("{}", x); })(); +} diff --git a/src/test/ui/lint/unused/unused-mut-warning-captured-var.rs b/src/test/ui/lint/unused/unused-mut-warning-captured-var.rs new file mode 100644 index 00000000000..3119d83a0eb --- /dev/null +++ b/src/test/ui/lint/unused/unused-mut-warning-captured-var.rs @@ -0,0 +1,9 @@ +// run-rustfix + +#![forbid(unused_mut)] + +fn main() { + let mut x = 1; + //~^ ERROR: variable does not need to be mutable + (move|| { println!("{}", x); })(); +} diff --git a/src/test/ui/lint/unused/unused-mut-warning-captured-var.stderr b/src/test/ui/lint/unused/unused-mut-warning-captured-var.stderr new file mode 100644 index 00000000000..20aeedcc241 --- /dev/null +++ b/src/test/ui/lint/unused/unused-mut-warning-captured-var.stderr @@ -0,0 +1,16 @@ +error: variable does not need to be mutable + --> $DIR/unused-mut-warning-captured-var.rs:6:9 + | +LL | let mut x = 1; + | ----^ + | | + | help: remove this `mut` + | +note: the lint level is defined here + --> $DIR/unused-mut-warning-captured-var.rs:3:11 + | +LL | #![forbid(unused_mut)] + | ^^^^^^^^^^ + +error: aborting due to previous error + diff --git a/src/test/ui/lint/unused/unused-result.rs b/src/test/ui/lint/unused/unused-result.rs new file mode 100644 index 00000000000..a65e98990dc --- /dev/null +++ b/src/test/ui/lint/unused/unused-result.rs @@ -0,0 +1,42 @@ +#![allow(dead_code)] +#![deny(unused_results, unused_must_use)] +//~^ NOTE: the lint level is defined here +//~| NOTE: the lint level is defined here + +#[must_use] +enum MustUse { Test } + +#[must_use = "some message"] +enum MustUseMsg { Test2 } + +fn foo() -> T { panic!() } + +fn bar() -> isize { return foo::(); } +fn baz() -> MustUse { return foo::(); } +fn qux() -> MustUseMsg { return foo::(); } + +#[allow(unused_results)] +fn test() { + foo::(); + foo::(); //~ ERROR: unused `MustUse` that must be used + foo::(); //~ ERROR: unused `MustUseMsg` that must be used + //~^ NOTE: some message +} + +#[allow(unused_results, unused_must_use)] +fn test2() { + foo::(); + foo::(); + foo::(); +} + +fn main() { + foo::(); //~ ERROR: unused result + foo::(); //~ ERROR: unused `MustUse` that must be used + foo::(); //~ ERROR: unused `MustUseMsg` that must be used + //~^ NOTE: some message + + let _ = foo::(); + let _ = foo::(); + let _ = foo::(); +} diff --git a/src/test/ui/lint/unused/unused-result.stderr b/src/test/ui/lint/unused/unused-result.stderr new file mode 100644 index 00000000000..1b1dcab3a1b --- /dev/null +++ b/src/test/ui/lint/unused/unused-result.stderr @@ -0,0 +1,48 @@ +error: unused `MustUse` that must be used + --> $DIR/unused-result.rs:21:5 + | +LL | foo::(); + | ^^^^^^^^^^^^^^^^^ + | +note: the lint level is defined here + --> $DIR/unused-result.rs:2:25 + | +LL | #![deny(unused_results, unused_must_use)] + | ^^^^^^^^^^^^^^^ + +error: unused `MustUseMsg` that must be used + --> $DIR/unused-result.rs:22:5 + | +LL | foo::(); + | ^^^^^^^^^^^^^^^^^^^^ + | + = note: some message + +error: unused result + --> $DIR/unused-result.rs:34:5 + | +LL | foo::(); + | ^^^^^^^^^^^^^^^ + | +note: the lint level is defined here + --> $DIR/unused-result.rs:2:9 + | +LL | #![deny(unused_results, unused_must_use)] + | ^^^^^^^^^^^^^^ + +error: unused `MustUse` that must be used + --> $DIR/unused-result.rs:35:5 + | +LL | foo::(); + | ^^^^^^^^^^^^^^^^^ + +error: unused `MustUseMsg` that must be used + --> $DIR/unused-result.rs:36:5 + | +LL | foo::(); + | ^^^^^^^^^^^^^^^^^^^^ + | + = note: some message + +error: aborting due to 5 previous errors + diff --git a/src/test/ui/lint/unused/useless-comment.rs b/src/test/ui/lint/unused/useless-comment.rs new file mode 100644 index 00000000000..7d2e5ab6f2b --- /dev/null +++ b/src/test/ui/lint/unused/useless-comment.rs @@ -0,0 +1,45 @@ +#![feature(stmt_expr_attributes)] + +#![deny(unused_doc_comments)] + +macro_rules! mac { + () => {} +} + +/// foo //~ ERROR unused doc comment +mac!(); + +fn foo() { + /// a //~ ERROR unused doc comment + let x = 12; + + /// multi-line //~ unused doc comment + /// doc comment + /// that is unused + match x { + /// c //~ ERROR unused doc comment + 1 => {}, + _ => {} + } + + /// foo //~ ERROR unused doc comment + unsafe {} + + #[doc = "foo"] //~ ERROR unused doc comment + #[doc = "bar"] //~ ERROR unused doc comment + 3; + + /// bar //~ ERROR unused doc comment + mac!(); + + let x = /** comment */ 47; //~ ERROR unused doc comment + + /// dox //~ ERROR unused doc comment + { + + } +} + +fn main() { + foo(); +} diff --git a/src/test/ui/lint/unused/useless-comment.stderr b/src/test/ui/lint/unused/useless-comment.stderr new file mode 100644 index 00000000000..0054426fb1e --- /dev/null +++ b/src/test/ui/lint/unused/useless-comment.stderr @@ -0,0 +1,110 @@ +error: unused doc comment + --> $DIR/useless-comment.rs:9:1 + | +LL | /// foo + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ rustdoc does not generate documentation for macro invocations + | +note: the lint level is defined here + --> $DIR/useless-comment.rs:3:9 + | +LL | #![deny(unused_doc_comments)] + | ^^^^^^^^^^^^^^^^^^^ + = help: to document an item produced by a macro, the macro must produce the documentation as part of its expansion + +error: unused doc comment + --> $DIR/useless-comment.rs:32:5 + | +LL | /// bar + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ rustdoc does not generate documentation for macro invocations + | + = help: to document an item produced by a macro, the macro must produce the documentation as part of its expansion + +error: unused doc comment + --> $DIR/useless-comment.rs:13:5 + | +LL | /// a + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | let x = 12; + | ----------- rustdoc does not generate documentation for statements + | + = help: use `//` for a plain comment + +error: unused doc comment + --> $DIR/useless-comment.rs:16:5 + | +LL | / /// multi-line +LL | | /// doc comment +LL | | /// that is unused + | |______________________^ +LL | / match x { +LL | | /// c +LL | | 1 => {}, +LL | | _ => {} +LL | | } + | |_____- rustdoc does not generate documentation for expressions + | + = help: use `//` for a plain comment + +error: unused doc comment + --> $DIR/useless-comment.rs:20:9 + | +LL | /// c + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | 1 => {}, + | ------- rustdoc does not generate documentation for match arms + | + = help: use `//` for a plain comment + +error: unused doc comment + --> $DIR/useless-comment.rs:25:5 + | +LL | /// foo + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | unsafe {} + | --------- rustdoc does not generate documentation for expressions + | + = help: use `//` for a plain comment + +error: unused doc comment + --> $DIR/useless-comment.rs:28:5 + | +LL | #[doc = "foo"] + | ^^^^^^^^^^^^^^ +LL | #[doc = "bar"] +LL | 3; + | - rustdoc does not generate documentation for expressions + | + = help: use `//` for a plain comment + +error: unused doc comment + --> $DIR/useless-comment.rs:29:5 + | +LL | #[doc = "bar"] + | ^^^^^^^^^^^^^^ +LL | 3; + | - rustdoc does not generate documentation for expressions + | + = help: use `//` for a plain comment + +error: unused doc comment + --> $DIR/useless-comment.rs:35:13 + | +LL | let x = /** comment */ 47; + | ^^^^^^^^^^^^^^ -- rustdoc does not generate documentation for expressions + | + = help: use `/* */` for a plain comment + +error: unused doc comment + --> $DIR/useless-comment.rs:37:5 + | +LL | /// dox + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | / { +LL | | +LL | | } + | |_____- rustdoc does not generate documentation for expressions + | + = help: use `//` for a plain comment + +error: aborting due to 10 previous errors + diff --git a/src/test/ui/unused/issue-30730.rs b/src/test/ui/unused/issue-30730.rs deleted file mode 100644 index d6be90c8148..00000000000 --- a/src/test/ui/unused/issue-30730.rs +++ /dev/null @@ -1,5 +0,0 @@ -#![warn(unused)] -#![deny(warnings)] -use std::thread; -//~^ ERROR: unused import -fn main() {} diff --git a/src/test/ui/unused/issue-30730.stderr b/src/test/ui/unused/issue-30730.stderr deleted file mode 100644 index b299e99a3a9..00000000000 --- a/src/test/ui/unused/issue-30730.stderr +++ /dev/null @@ -1,15 +0,0 @@ -error: unused import: `std::thread` - --> $DIR/issue-30730.rs:3:5 - | -LL | use std::thread; - | ^^^^^^^^^^^ - | -note: the lint level is defined here - --> $DIR/issue-30730.rs:2:9 - | -LL | #![deny(warnings)] - | ^^^^^^^^ - = note: `#[deny(unused_imports)]` implied by `#[deny(warnings)]` - -error: aborting due to previous error - diff --git a/src/test/ui/unused/issue-46576.rs b/src/test/ui/unused/issue-46576.rs deleted file mode 100644 index 15f458f3844..00000000000 --- a/src/test/ui/unused/issue-46576.rs +++ /dev/null @@ -1,21 +0,0 @@ -#![allow(dead_code)] -#![deny(unused_imports)] - -use std::fs::File; -use std::io::{BufRead, BufReader, Read}; -//~^ ERROR unused import: `BufRead` - -pub fn read_from_file(path: &str) { - let file = File::open(&path).unwrap(); - let mut reader = BufReader::new(file); - let mut s = String::new(); - reader.read_to_string(&mut s).unwrap(); -} - -pub fn read_lines(s: &str) { - for _line in s.lines() { - - } -} - -fn main() {} diff --git a/src/test/ui/unused/issue-46576.stderr b/src/test/ui/unused/issue-46576.stderr deleted file mode 100644 index 6f4d97068b3..00000000000 --- a/src/test/ui/unused/issue-46576.stderr +++ /dev/null @@ -1,14 +0,0 @@ -error: unused import: `BufRead` - --> $DIR/issue-46576.rs:5:15 - | -LL | use std::io::{BufRead, BufReader, Read}; - | ^^^^^^^ - | -note: the lint level is defined here - --> $DIR/issue-46576.rs:2:9 - | -LL | #![deny(unused_imports)] - | ^^^^^^^^^^^^^^ - -error: aborting due to previous error - diff --git a/src/test/ui/unused/issue-59896.rs b/src/test/ui/unused/issue-59896.rs deleted file mode 100644 index ff9f19acf84..00000000000 --- a/src/test/ui/unused/issue-59896.rs +++ /dev/null @@ -1,9 +0,0 @@ -#![deny(unused_imports)] - -struct S; - -fn main() { - use S; //~ ERROR the item `S` is imported redundantly - - let _s = S; -} diff --git a/src/test/ui/unused/issue-59896.stderr b/src/test/ui/unused/issue-59896.stderr deleted file mode 100644 index 95b7938ae03..00000000000 --- a/src/test/ui/unused/issue-59896.stderr +++ /dev/null @@ -1,17 +0,0 @@ -error: the item `S` is imported redundantly - --> $DIR/issue-59896.rs:6:9 - | -LL | struct S; - | --------- the item `S` is already defined here -... -LL | use S; - | ^ - | -note: the lint level is defined here - --> $DIR/issue-59896.rs:1:9 - | -LL | #![deny(unused_imports)] - | ^^^^^^^^^^^^^^ - -error: aborting due to previous error - diff --git a/src/test/ui/unused/issue-70041.rs b/src/test/ui/unused/issue-70041.rs deleted file mode 100644 index 22e42295eed..00000000000 --- a/src/test/ui/unused/issue-70041.rs +++ /dev/null @@ -1,13 +0,0 @@ -// compile-flags: --edition=2018 -// run-pass - -macro_rules! regex { - //~^ WARN unused macro definition - () => {}; -} - -#[allow(dead_code)] -use regex; -//~^ WARN unused import - -fn main() {} diff --git a/src/test/ui/unused/issue-70041.stderr b/src/test/ui/unused/issue-70041.stderr deleted file mode 100644 index ecd618eae8b..00000000000 --- a/src/test/ui/unused/issue-70041.stderr +++ /dev/null @@ -1,21 +0,0 @@ -warning: unused macro definition - --> $DIR/issue-70041.rs:4:1 - | -LL | / macro_rules! regex { -LL | | -LL | | () => {}; -LL | | } - | |_^ - | - = note: `#[warn(unused_macros)]` on by default - -warning: unused import: `regex` - --> $DIR/issue-70041.rs:10:5 - | -LL | use regex; - | ^^^^^ - | - = note: `#[warn(unused_imports)]` on by default - -warning: 2 warnings emitted - diff --git a/src/test/ui/unused/issue-85913.rs b/src/test/ui/unused/issue-85913.rs deleted file mode 100644 index 7f3817b6ef1..00000000000 --- a/src/test/ui/unused/issue-85913.rs +++ /dev/null @@ -1,13 +0,0 @@ -#![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() {} diff --git a/src/test/ui/unused/issue-85913.stderr b/src/test/ui/unused/issue-85913.stderr deleted file mode 100644 index d5d99f0f7d3..00000000000 --- a/src/test/ui/unused/issue-85913.stderr +++ /dev/null @@ -1,15 +0,0 @@ -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` - | -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 - -error: aborting due to previous error - diff --git a/src/test/ui/unused/unused-attr-macro-rules.rs b/src/test/ui/unused/unused-attr-macro-rules.rs deleted file mode 100644 index 396137a11d0..00000000000 --- a/src/test/ui/unused/unused-attr-macro-rules.rs +++ /dev/null @@ -1,34 +0,0 @@ -#![deny(unused_attributes)] -// Unused attributes on macro_rules requires special handling since the -// macro_rules definition does not survive towards HIR. - -// A sample of various built-in attributes. -#[macro_export] -#[macro_use] //~ ERROR unused attribute -#[path="foo"] //~ ERROR unused attribute -#[recursion_limit="1"] //~ ERROR unused attribute - //~| ERROR crate-level attribute should be an inner attribute -macro_rules! foo { - () => {}; -} - -// The following should not warn about unused attributes. -#[allow(unused)] -macro_rules! foo2 { - () => {}; -} - -#[cfg(FALSE)] -macro_rules! foo { - () => {}; -} - -/// Some docs -#[deprecated] -#[doc = "more docs"] -#[macro_export] -macro_rules! bar { - () => {}; -} - -fn main() {} diff --git a/src/test/ui/unused/unused-attr-macro-rules.stderr b/src/test/ui/unused/unused-attr-macro-rules.stderr deleted file mode 100644 index 4606be01ac0..00000000000 --- a/src/test/ui/unused/unused-attr-macro-rules.stderr +++ /dev/null @@ -1,32 +0,0 @@ -error: unused attribute - --> $DIR/unused-attr-macro-rules.rs:7:1 - | -LL | #[macro_use] - | ^^^^^^^^^^^^ - | -note: the lint level is defined here - --> $DIR/unused-attr-macro-rules.rs:1:9 - | -LL | #![deny(unused_attributes)] - | ^^^^^^^^^^^^^^^^^ - -error: unused attribute - --> $DIR/unused-attr-macro-rules.rs:8:1 - | -LL | #[path="foo"] - | ^^^^^^^^^^^^^ - -error: unused attribute - --> $DIR/unused-attr-macro-rules.rs:9:1 - | -LL | #[recursion_limit="1"] - | ^^^^^^^^^^^^^^^^^^^^^^ - -error: crate-level attribute should be an inner attribute: add an exclamation mark: `#![foo]` - --> $DIR/unused-attr-macro-rules.rs:9:1 - | -LL | #[recursion_limit="1"] - | ^^^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to 4 previous errors - diff --git a/src/test/ui/unused/unused-attr.rs b/src/test/ui/unused/unused-attr.rs deleted file mode 100644 index cb8ac0e6a05..00000000000 --- a/src/test/ui/unused/unused-attr.rs +++ /dev/null @@ -1,49 +0,0 @@ -#![deny(unused_attributes)] -#![feature(rustc_attrs)] - -#![rustc_dummy] //~ ERROR unused attribute - -#[rustc_dummy] //~ ERROR unused attribute -extern crate core; - -#[rustc_dummy] //~ ERROR unused attribute -use std::collections; - -#[rustc_dummy] //~ ERROR unused attribute -extern "C" { - #[rustc_dummy] //~ ERROR unused attribute - fn foo(); -} - -#[rustc_dummy] //~ ERROR unused attribute -mod foo { - #[rustc_dummy] //~ ERROR unused attribute - pub enum Foo { - #[rustc_dummy] //~ ERROR unused attribute - Bar, - } -} - -#[rustc_dummy] //~ ERROR unused attribute -fn bar(f: foo::Foo) { - match f { - #[rustc_dummy] //~ ERROR unused attribute - foo::Foo::Bar => {} - } -} - -#[rustc_dummy] //~ ERROR unused attribute -struct Foo { - #[rustc_dummy] //~ ERROR unused attribute - a: isize -} - -#[rustc_dummy] //~ ERROR unused attribute -trait Baz { - #[rustc_dummy] //~ ERROR unused attribute - fn blah(&self); - #[rustc_dummy] //~ ERROR unused attribute - fn blah2(&self) {} -} - -fn main() {} diff --git a/src/test/ui/unused/unused-attr.stderr b/src/test/ui/unused/unused-attr.stderr deleted file mode 100644 index 707521b7802..00000000000 --- a/src/test/ui/unused/unused-attr.stderr +++ /dev/null @@ -1,98 +0,0 @@ -error: unused attribute - --> $DIR/unused-attr.rs:4:1 - | -LL | #![rustc_dummy] - | ^^^^^^^^^^^^^^^ - | -note: the lint level is defined here - --> $DIR/unused-attr.rs:1:9 - | -LL | #![deny(unused_attributes)] - | ^^^^^^^^^^^^^^^^^ - -error: unused attribute - --> $DIR/unused-attr.rs:6:1 - | -LL | #[rustc_dummy] - | ^^^^^^^^^^^^^^ - -error: unused attribute - --> $DIR/unused-attr.rs:9:1 - | -LL | #[rustc_dummy] - | ^^^^^^^^^^^^^^ - -error: unused attribute - --> $DIR/unused-attr.rs:12:1 - | -LL | #[rustc_dummy] - | ^^^^^^^^^^^^^^ - -error: unused attribute - --> $DIR/unused-attr.rs:14:5 - | -LL | #[rustc_dummy] - | ^^^^^^^^^^^^^^ - -error: unused attribute - --> $DIR/unused-attr.rs:18:1 - | -LL | #[rustc_dummy] - | ^^^^^^^^^^^^^^ - -error: unused attribute - --> $DIR/unused-attr.rs:20:5 - | -LL | #[rustc_dummy] - | ^^^^^^^^^^^^^^ - -error: unused attribute - --> $DIR/unused-attr.rs:22:9 - | -LL | #[rustc_dummy] - | ^^^^^^^^^^^^^^ - -error: unused attribute - --> $DIR/unused-attr.rs:27:1 - | -LL | #[rustc_dummy] - | ^^^^^^^^^^^^^^ - -error: unused attribute - --> $DIR/unused-attr.rs:30:9 - | -LL | #[rustc_dummy] - | ^^^^^^^^^^^^^^ - -error: unused attribute - --> $DIR/unused-attr.rs:35:1 - | -LL | #[rustc_dummy] - | ^^^^^^^^^^^^^^ - -error: unused attribute - --> $DIR/unused-attr.rs:37:5 - | -LL | #[rustc_dummy] - | ^^^^^^^^^^^^^^ - -error: unused attribute - --> $DIR/unused-attr.rs:41:1 - | -LL | #[rustc_dummy] - | ^^^^^^^^^^^^^^ - -error: unused attribute - --> $DIR/unused-attr.rs:43:5 - | -LL | #[rustc_dummy] - | ^^^^^^^^^^^^^^ - -error: unused attribute - --> $DIR/unused-attr.rs:45:5 - | -LL | #[rustc_dummy] - | ^^^^^^^^^^^^^^ - -error: aborting due to 15 previous errors - diff --git a/src/test/ui/unused/unused-closure.rs b/src/test/ui/unused/unused-closure.rs deleted file mode 100644 index c96c907318c..00000000000 --- a/src/test/ui/unused/unused-closure.rs +++ /dev/null @@ -1,35 +0,0 @@ -// Test that closures and generators are "must use" types. -// edition:2018 - -#![feature(async_closure)] -#![feature(generators)] -#![deny(unused_must_use)] - -fn unused() { - || { //~ ERROR unused closure that must be used - println!("Hello!"); - }; - - async {}; //~ ERROR unused implementer of `Future` that must be used - || async {}; //~ ERROR unused closure that must be used - async || {}; //~ ERROR unused closure that must be used - - - [Box::new([|| {}; 10]); 1]; //~ ERROR unused array of boxed arrays of closures that must be used - - vec![|| "a"].pop().unwrap(); //~ ERROR unused closure that must be used - - let b = false; - || true; //~ ERROR unused closure that must be used - println!("{}", b); -} - -fn ignored() { - let _ = || {}; - let _ = || yield 42; -} - -fn main() { - unused(); - ignored(); -} diff --git a/src/test/ui/unused/unused-closure.stderr b/src/test/ui/unused/unused-closure.stderr deleted file mode 100644 index 265d3e8e075..00000000000 --- a/src/test/ui/unused/unused-closure.stderr +++ /dev/null @@ -1,65 +0,0 @@ -error: unused closure that must be used - --> $DIR/unused-closure.rs:9:5 - | -LL | / || { -LL | | println!("Hello!"); -LL | | }; - | |______^ - | -note: the lint level is defined here - --> $DIR/unused-closure.rs:6:9 - | -LL | #![deny(unused_must_use)] - | ^^^^^^^^^^^^^^^ - = note: closures are lazy and do nothing unless called - -error: unused implementer of `Future` that must be used - --> $DIR/unused-closure.rs:13:5 - | -LL | async {}; - | ^^^^^^^^^ - | - = note: futures do nothing unless you `.await` or poll them - -error: unused closure that must be used - --> $DIR/unused-closure.rs:14:5 - | -LL | || async {}; - | ^^^^^^^^^^^^ - | - = note: closures are lazy and do nothing unless called - -error: unused closure that must be used - --> $DIR/unused-closure.rs:15:5 - | -LL | async || {}; - | ^^^^^^^^^^^^ - | - = note: closures are lazy and do nothing unless called - -error: unused array of boxed arrays of closures that must be used - --> $DIR/unused-closure.rs:18:5 - | -LL | [Box::new([|| {}; 10]); 1]; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: closures are lazy and do nothing unless called - -error: unused closure that must be used - --> $DIR/unused-closure.rs:20:5 - | -LL | vec![|| "a"].pop().unwrap(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: closures are lazy and do nothing unless called - -error: unused closure that must be used - --> $DIR/unused-closure.rs:23:9 - | -LL | || true; - | ^^^^^^^^ - | - = note: closures are lazy and do nothing unless called - -error: aborting due to 7 previous errors - diff --git a/src/test/ui/unused/unused-doc-comments-edge-cases.rs b/src/test/ui/unused/unused-doc-comments-edge-cases.rs deleted file mode 100644 index fd9baf8c6b9..00000000000 --- a/src/test/ui/unused/unused-doc-comments-edge-cases.rs +++ /dev/null @@ -1,29 +0,0 @@ -#![deny(unused_doc_comments)] - -fn doc_comment_on_match_arms(num: u8) -> bool { - match num { - 3 => true, - /// useless doc comment - //~^ ERROR: unused doc comment - _ => false, - } -} - -fn doc_comment_between_if_else(num: u8) -> bool { - if num == 3 { - true //~ ERROR: mismatched types - } - /// useless doc comment - else { //~ ERROR: expected expression, found keyword `else` - false - } -} - -fn doc_comment_on_expr(num: u8) -> bool { - /// useless doc comment - //~^ ERROR: attributes on expressions are experimental - //~| ERROR: unused doc comment - num == 3 -} - -fn main() {} diff --git a/src/test/ui/unused/unused-doc-comments-edge-cases.stderr b/src/test/ui/unused/unused-doc-comments-edge-cases.stderr deleted file mode 100644 index 14db5f64b0c..00000000000 --- a/src/test/ui/unused/unused-doc-comments-edge-cases.stderr +++ /dev/null @@ -1,61 +0,0 @@ -error: expected expression, found keyword `else` - --> $DIR/unused-doc-comments-edge-cases.rs:17:5 - | -LL | else { - | ^^^^ expected expression - -error[E0658]: attributes on expressions are experimental - --> $DIR/unused-doc-comments-edge-cases.rs:23:5 - | -LL | /// useless doc comment - | ^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #15701 for more information - = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable - = help: `///` is for documentation comments. For a plain comment, use `//`. - -error: unused doc comment - --> $DIR/unused-doc-comments-edge-cases.rs:6:9 - | -LL | /// useless doc comment - | ^^^^^^^^^^^^^^^^^^^^^^^ -LL | -LL | _ => false, - | ---------- rustdoc does not generate documentation for match arms - | -note: the lint level is defined here - --> $DIR/unused-doc-comments-edge-cases.rs:1:9 - | -LL | #![deny(unused_doc_comments)] - | ^^^^^^^^^^^^^^^^^^^ - = help: use `//` for a plain comment - -error: unused doc comment - --> $DIR/unused-doc-comments-edge-cases.rs:23:5 - | -LL | /// useless doc comment - | ^^^^^^^^^^^^^^^^^^^^^^^ -... -LL | num == 3 - | --- rustdoc does not generate documentation for expressions - | - = help: use `//` for a plain comment - -error[E0308]: mismatched types - --> $DIR/unused-doc-comments-edge-cases.rs:14:9 - | -LL | / if num == 3 { -LL | | true - | | ^^^^ expected `()`, found `bool` -LL | | } - | |_____- expected this to be `()` - | -help: you might have meant to return this value - | -LL | return true; - | ^^^^^^ ^ - -error: aborting due to 5 previous errors - -Some errors have detailed explanations: E0308, E0658. -For more information about an error, try `rustc --explain E0308`. diff --git a/src/test/ui/unused/unused-doc-comments-for-macros.rs b/src/test/ui/unused/unused-doc-comments-for-macros.rs deleted file mode 100644 index 05828ebb2c3..00000000000 --- a/src/test/ui/unused/unused-doc-comments-for-macros.rs +++ /dev/null @@ -1,17 +0,0 @@ -#![deny(unused_doc_comments)] -#![feature(rustc_attrs)] - -macro_rules! foo { () => {}; } - -fn main() { - /// line1 //~ ERROR: unused doc comment - /// line2 - /// line3 - foo!(); - - // Ensure we still detect another doc-comment block. - /// line1 //~ ERROR: unused doc comment - /// line2 - /// line3 - foo!(); -} diff --git a/src/test/ui/unused/unused-doc-comments-for-macros.stderr b/src/test/ui/unused/unused-doc-comments-for-macros.stderr deleted file mode 100644 index f4f5bb71e55..00000000000 --- a/src/test/ui/unused/unused-doc-comments-for-macros.stderr +++ /dev/null @@ -1,31 +0,0 @@ -error: unused doc comment - --> $DIR/unused-doc-comments-for-macros.rs:7:5 - | -LL | / /// line1 -LL | | /// line2 -LL | | /// line3 - | |_____--------^ - | | - | rustdoc does not generate documentation for macro invocations - | -note: the lint level is defined here - --> $DIR/unused-doc-comments-for-macros.rs:1:9 - | -LL | #![deny(unused_doc_comments)] - | ^^^^^^^^^^^^^^^^^^^ - = help: to document an item produced by a macro, the macro must produce the documentation as part of its expansion - -error: unused doc comment - --> $DIR/unused-doc-comments-for-macros.rs:13:5 - | -LL | / /// line1 -LL | | /// line2 -LL | | /// line3 - | |_____--------^ - | | - | rustdoc does not generate documentation for macro invocations - | - = help: to document an item produced by a macro, the macro must produce the documentation as part of its expansion - -error: aborting due to 2 previous errors - diff --git a/src/test/ui/unused/unused-macro-rules.rs b/src/test/ui/unused/unused-macro-rules.rs deleted file mode 100644 index 1a714b8f0a0..00000000000 --- a/src/test/ui/unused/unused-macro-rules.rs +++ /dev/null @@ -1,29 +0,0 @@ -#![deny(unused_macros)] - -// Most simple case -macro_rules! unused { //~ ERROR: unused macro definition - () => {}; -} - -// Test macros created by macros -macro_rules! create_macro { - () => { - macro_rules! m { //~ ERROR: unused macro definition - () => {}; - } - }; -} -create_macro!(); - -#[allow(unused_macros)] -mod bar { - // Test that putting the #[deny] close to the macro's definition - // works. - - #[deny(unused_macros)] - macro_rules! unused { //~ ERROR: unused macro definition - () => {}; - } -} - -fn main() {} diff --git a/src/test/ui/unused/unused-macro-rules.stderr b/src/test/ui/unused/unused-macro-rules.stderr deleted file mode 100644 index 55072bd81bf..00000000000 --- a/src/test/ui/unused/unused-macro-rules.stderr +++ /dev/null @@ -1,43 +0,0 @@ -error: unused macro definition - --> $DIR/unused-macro-rules.rs:4:1 - | -LL | / macro_rules! unused { -LL | | () => {}; -LL | | } - | |_^ - | -note: the lint level is defined here - --> $DIR/unused-macro-rules.rs:1:9 - | -LL | #![deny(unused_macros)] - | ^^^^^^^^^^^^^ - -error: unused macro definition - --> $DIR/unused-macro-rules.rs:11:9 - | -LL | / macro_rules! m { -LL | | () => {}; -LL | | } - | |_________^ -... -LL | create_macro!(); - | ---------------- in this macro invocation - | - = note: this error originates in the macro `create_macro` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: unused macro definition - --> $DIR/unused-macro-rules.rs:24:5 - | -LL | / macro_rules! unused { -LL | | () => {}; -LL | | } - | |_____^ - | -note: the lint level is defined here - --> $DIR/unused-macro-rules.rs:23:12 - | -LL | #[deny(unused_macros)] - | ^^^^^^^^^^^^^ - -error: aborting due to 3 previous errors - diff --git a/src/test/ui/unused/unused-macro-with-bad-frag-spec.rs b/src/test/ui/unused/unused-macro-with-bad-frag-spec.rs deleted file mode 100644 index ce187047bb7..00000000000 --- a/src/test/ui/unused/unused-macro-with-bad-frag-spec.rs +++ /dev/null @@ -1,9 +0,0 @@ -#![allow(unused_macros)] - -// Issue #21370 - -macro_rules! test { - ($wrong:t_ty) => () //~ ERROR invalid fragment specifier `t_ty` -} - -fn main() { } diff --git a/src/test/ui/unused/unused-macro-with-bad-frag-spec.stderr b/src/test/ui/unused/unused-macro-with-bad-frag-spec.stderr deleted file mode 100644 index 6edf0a2cf8d..00000000000 --- a/src/test/ui/unused/unused-macro-with-bad-frag-spec.stderr +++ /dev/null @@ -1,10 +0,0 @@ -error: invalid fragment specifier `t_ty` - --> $DIR/unused-macro-with-bad-frag-spec.rs:6:6 - | -LL | ($wrong:t_ty) => () - | ^^^^^^^^^^^ - | - = help: valid fragment specifiers are `ident`, `block`, `stmt`, `expr`, `pat`, `ty`, `lifetime`, `literal`, `path`, `meta`, `tt`, `item` and `vis` - -error: aborting due to previous error - diff --git a/src/test/ui/unused/unused-macro-with-follow-violation.rs b/src/test/ui/unused/unused-macro-with-follow-violation.rs deleted file mode 100644 index 1666dae69b9..00000000000 --- a/src/test/ui/unused/unused-macro-with-follow-violation.rs +++ /dev/null @@ -1,7 +0,0 @@ -#![allow(unused_macros)] - -macro_rules! test { - ($e:expr +) => () //~ ERROR not allowed for `expr` fragments -} - -fn main() { } diff --git a/src/test/ui/unused/unused-macro-with-follow-violation.stderr b/src/test/ui/unused/unused-macro-with-follow-violation.stderr deleted file mode 100644 index 5eced4f06c0..00000000000 --- a/src/test/ui/unused/unused-macro-with-follow-violation.stderr +++ /dev/null @@ -1,10 +0,0 @@ -error: `$e:expr` is followed by `+`, which is not allowed for `expr` fragments - --> $DIR/unused-macro-with-follow-violation.rs:4:14 - | -LL | ($e:expr +) => () - | ^ not allowed after `expr` fragments - | - = note: allowed there are: `=>`, `,` or `;` - -error: aborting due to previous error - diff --git a/src/test/ui/unused/unused-macro.rs b/src/test/ui/unused/unused-macro.rs deleted file mode 100644 index 302b0727d77..00000000000 --- a/src/test/ui/unused/unused-macro.rs +++ /dev/null @@ -1,26 +0,0 @@ -#![feature(decl_macro)] -#![deny(unused_macros)] - -// Most simple case -macro unused { //~ ERROR: unused macro definition - () => {} -} - -#[allow(unused_macros)] -mod bar { - // Test that putting the #[deny] close to the macro's definition - // works. - - #[deny(unused_macros)] - macro unused { //~ ERROR: unused macro definition - () => {} - } -} - -mod boo { - pub(crate) macro unused { //~ ERROR: unused macro definition - () => {} - } -} - -fn main() {} diff --git a/src/test/ui/unused/unused-macro.stderr b/src/test/ui/unused/unused-macro.stderr deleted file mode 100644 index f5eb76179bf..00000000000 --- a/src/test/ui/unused/unused-macro.stderr +++ /dev/null @@ -1,38 +0,0 @@ -error: unused macro definition - --> $DIR/unused-macro.rs:5:1 - | -LL | / macro unused { -LL | | () => {} -LL | | } - | |_^ - | -note: the lint level is defined here - --> $DIR/unused-macro.rs:2:9 - | -LL | #![deny(unused_macros)] - | ^^^^^^^^^^^^^ - -error: unused macro definition - --> $DIR/unused-macro.rs:15:5 - | -LL | / macro unused { -LL | | () => {} -LL | | } - | |_____^ - | -note: the lint level is defined here - --> $DIR/unused-macro.rs:14:12 - | -LL | #[deny(unused_macros)] - | ^^^^^^^^^^^^^ - -error: unused macro definition - --> $DIR/unused-macro.rs:21:5 - | -LL | / pub(crate) macro unused { -LL | | () => {} -LL | | } - | |_____^ - -error: aborting due to 3 previous errors - diff --git a/src/test/ui/unused/unused-mut-warning-captured-var.fixed b/src/test/ui/unused/unused-mut-warning-captured-var.fixed deleted file mode 100644 index c21f18015c1..00000000000 --- a/src/test/ui/unused/unused-mut-warning-captured-var.fixed +++ /dev/null @@ -1,9 +0,0 @@ -// run-rustfix - -#![forbid(unused_mut)] - -fn main() { - let x = 1; - //~^ ERROR: variable does not need to be mutable - (move|| { println!("{}", x); })(); -} diff --git a/src/test/ui/unused/unused-mut-warning-captured-var.rs b/src/test/ui/unused/unused-mut-warning-captured-var.rs deleted file mode 100644 index 3119d83a0eb..00000000000 --- a/src/test/ui/unused/unused-mut-warning-captured-var.rs +++ /dev/null @@ -1,9 +0,0 @@ -// run-rustfix - -#![forbid(unused_mut)] - -fn main() { - let mut x = 1; - //~^ ERROR: variable does not need to be mutable - (move|| { println!("{}", x); })(); -} diff --git a/src/test/ui/unused/unused-mut-warning-captured-var.stderr b/src/test/ui/unused/unused-mut-warning-captured-var.stderr deleted file mode 100644 index 20aeedcc241..00000000000 --- a/src/test/ui/unused/unused-mut-warning-captured-var.stderr +++ /dev/null @@ -1,16 +0,0 @@ -error: variable does not need to be mutable - --> $DIR/unused-mut-warning-captured-var.rs:6:9 - | -LL | let mut x = 1; - | ----^ - | | - | help: remove this `mut` - | -note: the lint level is defined here - --> $DIR/unused-mut-warning-captured-var.rs:3:11 - | -LL | #![forbid(unused_mut)] - | ^^^^^^^^^^ - -error: aborting due to previous error - diff --git a/src/test/ui/unused/unused-result.rs b/src/test/ui/unused/unused-result.rs deleted file mode 100644 index a65e98990dc..00000000000 --- a/src/test/ui/unused/unused-result.rs +++ /dev/null @@ -1,42 +0,0 @@ -#![allow(dead_code)] -#![deny(unused_results, unused_must_use)] -//~^ NOTE: the lint level is defined here -//~| NOTE: the lint level is defined here - -#[must_use] -enum MustUse { Test } - -#[must_use = "some message"] -enum MustUseMsg { Test2 } - -fn foo() -> T { panic!() } - -fn bar() -> isize { return foo::(); } -fn baz() -> MustUse { return foo::(); } -fn qux() -> MustUseMsg { return foo::(); } - -#[allow(unused_results)] -fn test() { - foo::(); - foo::(); //~ ERROR: unused `MustUse` that must be used - foo::(); //~ ERROR: unused `MustUseMsg` that must be used - //~^ NOTE: some message -} - -#[allow(unused_results, unused_must_use)] -fn test2() { - foo::(); - foo::(); - foo::(); -} - -fn main() { - foo::(); //~ ERROR: unused result - foo::(); //~ ERROR: unused `MustUse` that must be used - foo::(); //~ ERROR: unused `MustUseMsg` that must be used - //~^ NOTE: some message - - let _ = foo::(); - let _ = foo::(); - let _ = foo::(); -} diff --git a/src/test/ui/unused/unused-result.stderr b/src/test/ui/unused/unused-result.stderr deleted file mode 100644 index 1b1dcab3a1b..00000000000 --- a/src/test/ui/unused/unused-result.stderr +++ /dev/null @@ -1,48 +0,0 @@ -error: unused `MustUse` that must be used - --> $DIR/unused-result.rs:21:5 - | -LL | foo::(); - | ^^^^^^^^^^^^^^^^^ - | -note: the lint level is defined here - --> $DIR/unused-result.rs:2:25 - | -LL | #![deny(unused_results, unused_must_use)] - | ^^^^^^^^^^^^^^^ - -error: unused `MustUseMsg` that must be used - --> $DIR/unused-result.rs:22:5 - | -LL | foo::(); - | ^^^^^^^^^^^^^^^^^^^^ - | - = note: some message - -error: unused result - --> $DIR/unused-result.rs:34:5 - | -LL | foo::(); - | ^^^^^^^^^^^^^^^ - | -note: the lint level is defined here - --> $DIR/unused-result.rs:2:9 - | -LL | #![deny(unused_results, unused_must_use)] - | ^^^^^^^^^^^^^^ - -error: unused `MustUse` that must be used - --> $DIR/unused-result.rs:35:5 - | -LL | foo::(); - | ^^^^^^^^^^^^^^^^^ - -error: unused `MustUseMsg` that must be used - --> $DIR/unused-result.rs:36:5 - | -LL | foo::(); - | ^^^^^^^^^^^^^^^^^^^^ - | - = note: some message - -error: aborting due to 5 previous errors - diff --git a/src/test/ui/unused/useless-comment.rs b/src/test/ui/unused/useless-comment.rs deleted file mode 100644 index 7d2e5ab6f2b..00000000000 --- a/src/test/ui/unused/useless-comment.rs +++ /dev/null @@ -1,45 +0,0 @@ -#![feature(stmt_expr_attributes)] - -#![deny(unused_doc_comments)] - -macro_rules! mac { - () => {} -} - -/// foo //~ ERROR unused doc comment -mac!(); - -fn foo() { - /// a //~ ERROR unused doc comment - let x = 12; - - /// multi-line //~ unused doc comment - /// doc comment - /// that is unused - match x { - /// c //~ ERROR unused doc comment - 1 => {}, - _ => {} - } - - /// foo //~ ERROR unused doc comment - unsafe {} - - #[doc = "foo"] //~ ERROR unused doc comment - #[doc = "bar"] //~ ERROR unused doc comment - 3; - - /// bar //~ ERROR unused doc comment - mac!(); - - let x = /** comment */ 47; //~ ERROR unused doc comment - - /// dox //~ ERROR unused doc comment - { - - } -} - -fn main() { - foo(); -} diff --git a/src/test/ui/unused/useless-comment.stderr b/src/test/ui/unused/useless-comment.stderr deleted file mode 100644 index 0054426fb1e..00000000000 --- a/src/test/ui/unused/useless-comment.stderr +++ /dev/null @@ -1,110 +0,0 @@ -error: unused doc comment - --> $DIR/useless-comment.rs:9:1 - | -LL | /// foo - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ rustdoc does not generate documentation for macro invocations - | -note: the lint level is defined here - --> $DIR/useless-comment.rs:3:9 - | -LL | #![deny(unused_doc_comments)] - | ^^^^^^^^^^^^^^^^^^^ - = help: to document an item produced by a macro, the macro must produce the documentation as part of its expansion - -error: unused doc comment - --> $DIR/useless-comment.rs:32:5 - | -LL | /// bar - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ rustdoc does not generate documentation for macro invocations - | - = help: to document an item produced by a macro, the macro must produce the documentation as part of its expansion - -error: unused doc comment - --> $DIR/useless-comment.rs:13:5 - | -LL | /// a - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | let x = 12; - | ----------- rustdoc does not generate documentation for statements - | - = help: use `//` for a plain comment - -error: unused doc comment - --> $DIR/useless-comment.rs:16:5 - | -LL | / /// multi-line -LL | | /// doc comment -LL | | /// that is unused - | |______________________^ -LL | / match x { -LL | | /// c -LL | | 1 => {}, -LL | | _ => {} -LL | | } - | |_____- rustdoc does not generate documentation for expressions - | - = help: use `//` for a plain comment - -error: unused doc comment - --> $DIR/useless-comment.rs:20:9 - | -LL | /// c - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | 1 => {}, - | ------- rustdoc does not generate documentation for match arms - | - = help: use `//` for a plain comment - -error: unused doc comment - --> $DIR/useless-comment.rs:25:5 - | -LL | /// foo - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | unsafe {} - | --------- rustdoc does not generate documentation for expressions - | - = help: use `//` for a plain comment - -error: unused doc comment - --> $DIR/useless-comment.rs:28:5 - | -LL | #[doc = "foo"] - | ^^^^^^^^^^^^^^ -LL | #[doc = "bar"] -LL | 3; - | - rustdoc does not generate documentation for expressions - | - = help: use `//` for a plain comment - -error: unused doc comment - --> $DIR/useless-comment.rs:29:5 - | -LL | #[doc = "bar"] - | ^^^^^^^^^^^^^^ -LL | 3; - | - rustdoc does not generate documentation for expressions - | - = help: use `//` for a plain comment - -error: unused doc comment - --> $DIR/useless-comment.rs:35:13 - | -LL | let x = /** comment */ 47; - | ^^^^^^^^^^^^^^ -- rustdoc does not generate documentation for expressions - | - = help: use `/* */` for a plain comment - -error: unused doc comment - --> $DIR/useless-comment.rs:37:5 - | -LL | /// dox - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | / { -LL | | -LL | | } - | |_____- rustdoc does not generate documentation for expressions - | - = help: use `//` for a plain comment - -error: aborting due to 10 previous errors - -- cgit 1.4.1-3-g733a5 From 924eddf30d0e72b61aa753daf8dc0c75790a8730 Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Sat, 31 Jul 2021 06:21:52 +0900 Subject: Apply review suggestion --- compiler/rustc_lint/src/unused.rs | 17 ++-- src/test/ui/lint/fn_must_use.stderr | 14 ++- src/test/ui/lint/unused-borrows.stderr | 42 +++++--- src/test/ui/lint/unused/issue-85913.stderr | 7 +- src/test/ui/lint/unused/must-use-ops.stderr | 147 ++++++++++++++++++++-------- 5 files changed, 157 insertions(+), 70 deletions(-) (limited to 'src/test') 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 -- cgit 1.4.1-3-g733a5