From e7730dcb7eb29a10ee73f269f4dc6e9d606db0da Mon Sep 17 00:00:00 2001 From: est31 Date: Mon, 21 Feb 2022 04:38:39 +0100 Subject: [PATCH] Expand let-else allow tests The #[allow(...)] directive was tested for the body and the pattern, but non-presence of it wasn't tested. Furthermore, it wasn't tested for the expression. We add expression tests as well as ones checking the non-presence of the directive. --- .../ui/let-else/let-else-allow-in-expr.rs | 30 +++++++++++++++++++ .../ui/let-else/let-else-allow-in-expr.stderr | 20 +++++++++++++ src/test/ui/let-else/let-else-allow-unused.rs | 5 ++-- .../ui/let-else/let-else-allow-unused.stderr | 14 +++++++++ src/test/ui/let-else/let-else-check.rs | 5 ++++ src/test/ui/let-else/let-else-check.stderr | 10 +++++-- 6 files changed, 80 insertions(+), 4 deletions(-) create mode 100644 src/test/ui/let-else/let-else-allow-in-expr.rs create mode 100644 src/test/ui/let-else/let-else-allow-in-expr.stderr create mode 100644 src/test/ui/let-else/let-else-allow-unused.stderr diff --git a/src/test/ui/let-else/let-else-allow-in-expr.rs b/src/test/ui/let-else/let-else-allow-in-expr.rs new file mode 100644 index 0000000000000..39f4c9060fea5 --- /dev/null +++ b/src/test/ui/let-else/let-else-allow-in-expr.rs @@ -0,0 +1,30 @@ +#![feature(let_else)] + +#![deny(unused_variables)] + +fn main() { + let Some(_): Option = ({ + let x = 1; //~ ERROR unused variable: `x` + Some(1) + }) else { + return; + }; + + #[allow(unused_variables)] + let Some(_): Option = ({ + let x = 1; + Some(1) + }) else { + return; + }; + + let Some(_): Option = ({ + #[allow(unused_variables)] + let x = 1; + Some(1) + }) else { + return; + }; + + let x = 1; //~ ERROR unused variable: `x` +} diff --git a/src/test/ui/let-else/let-else-allow-in-expr.stderr b/src/test/ui/let-else/let-else-allow-in-expr.stderr new file mode 100644 index 0000000000000..e86bcbc850029 --- /dev/null +++ b/src/test/ui/let-else/let-else-allow-in-expr.stderr @@ -0,0 +1,20 @@ +error: unused variable: `x` + --> $DIR/let-else-allow-in-expr.rs:7:13 + | +LL | let x = 1; + | ^ help: if this is intentional, prefix it with an underscore: `_x` + | +note: the lint level is defined here + --> $DIR/let-else-allow-in-expr.rs:3:9 + | +LL | #![deny(unused_variables)] + | ^^^^^^^^^^^^^^^^ + +error: unused variable: `x` + --> $DIR/let-else-allow-in-expr.rs:29:9 + | +LL | let x = 1; + | ^ help: if this is intentional, prefix it with an underscore: `_x` + +error: aborting due to 2 previous errors + diff --git a/src/test/ui/let-else/let-else-allow-unused.rs b/src/test/ui/let-else/let-else-allow-unused.rs index bcd8c987628b3..86ebacfa7b7d1 100644 --- a/src/test/ui/let-else/let-else-allow-unused.rs +++ b/src/test/ui/let-else/let-else-allow-unused.rs @@ -1,4 +1,3 @@ -// check-pass // issue #89807 #![feature(let_else)] @@ -10,5 +9,7 @@ fn main() { #[allow(unused)] let banana = 1; #[allow(unused)] - let Some(chaenomeles) = value else { return }; // OK + let Some(chaenomeles) = value.clone() else { return }; // OK + + let Some(chaenomeles) = value else { return }; //~ ERROR unused variable: `chaenomeles` } diff --git a/src/test/ui/let-else/let-else-allow-unused.stderr b/src/test/ui/let-else/let-else-allow-unused.stderr new file mode 100644 index 0000000000000..05b8a9169fb70 --- /dev/null +++ b/src/test/ui/let-else/let-else-allow-unused.stderr @@ -0,0 +1,14 @@ +error: unused variable: `chaenomeles` + --> $DIR/let-else-allow-unused.rs:14:14 + | +LL | let Some(chaenomeles) = value else { return }; + | ^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_chaenomeles` + | +note: the lint level is defined here + --> $DIR/let-else-allow-unused.rs:5:8 + | +LL | #[deny(unused_variables)] + | ^^^^^^^^^^^^^^^^ + +error: aborting due to previous error + diff --git a/src/test/ui/let-else/let-else-check.rs b/src/test/ui/let-else/let-else-check.rs index ab763447ef7e1..9e32cbef742a2 100644 --- a/src/test/ui/let-else/let-else-check.rs +++ b/src/test/ui/let-else/let-else-check.rs @@ -10,5 +10,10 @@ fn main() { return; }; + let Some(_): Option = Some(Default::default()) else { + let x = 1; //~ ERROR unused variable: `x` + return; + }; + let x = 1; //~ ERROR unused variable: `x` } diff --git a/src/test/ui/let-else/let-else-check.stderr b/src/test/ui/let-else/let-else-check.stderr index 50e54d320b006..b3da412ec280e 100644 --- a/src/test/ui/let-else/let-else-check.stderr +++ b/src/test/ui/let-else/let-else-check.stderr @@ -1,5 +1,5 @@ error: unused variable: `x` - --> $DIR/let-else-check.rs:13:9 + --> $DIR/let-else-check.rs:18:9 | LL | let x = 1; | ^ help: if this is intentional, prefix it with an underscore: `_x` @@ -10,5 +10,11 @@ note: the lint level is defined here LL | #![deny(unused_variables)] | ^^^^^^^^^^^^^^^^ -error: aborting due to previous error +error: unused variable: `x` + --> $DIR/let-else-check.rs:14:13 + | +LL | let x = 1; + | ^ help: if this is intentional, prefix it with an underscore: `_x` + +error: aborting due to 2 previous errors