diff options
| author | sapir <yasapir@gmail.com> | 2020-01-01 01:20:34 +0200 |
|---|---|---|
| committer | sapir <yasapir@gmail.com> | 2020-04-10 03:54:45 +0300 |
| commit | e22e443208b4e6e1f0bf430877b19ecbf7a3d0ca (patch) | |
| tree | 9128b95b15fa976f32f22501b4eeaaa984a965ea /src/test | |
| parent | 0c156af20d74b2e23c2b862110a5ed5fa8d65a51 (diff) | |
| download | rust-e22e443208b4e6e1f0bf430877b19ecbf7a3d0ca.tar.gz rust-e22e443208b4e6e1f0bf430877b19ecbf7a3d0ca.zip | |
Try to fix warning for unused variables in or patterns, issue #67691
Diffstat (limited to 'src/test')
7 files changed, 95 insertions, 31 deletions
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 index cc675a709a2..413a51d4e5d 100644 --- 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 @@ -12,16 +12,16 @@ 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 + --> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:33:9 | LL | let mut mut_unused_var = 1; - | ^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_mut_unused_var` + | ^^^^^^^^^^^^^^^^^^ 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 + --> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:37:10 | LL | let (mut var, unused_var) = (1, 2); - | ^^^ help: if this is intentional, prefix it with an underscore: `_var` + | ^^^^^^^ 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 @@ -36,10 +36,10 @@ 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 + --> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:46:26 | LL | mut hours_are_suns, - | ^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^ | = note: consider using `_hours_are_suns` instead diff --git a/src/test/ui/lint/issue-54180-unused-ref-field.stderr b/src/test/ui/lint/issue-54180-unused-ref-field.stderr index 840ecc0ce09..c501aa25f13 100644 --- a/src/test/ui/lint/issue-54180-unused-ref-field.stderr +++ b/src/test/ui/lint/issue-54180-unused-ref-field.stderr @@ -1,10 +1,8 @@ error: unused variable: `field` - --> $DIR/issue-54180-unused-ref-field.rs:20:26 + --> $DIR/issue-54180-unused-ref-field.rs:20:22 | LL | E::Variant { ref field } => (), - | ----^^^^^ - | | - | help: try ignoring the field: `field: _` + | ^^^^^^^^^ help: try ignoring the field: `field: _` | note: the lint level is defined here --> $DIR/issue-54180-unused-ref-field.rs:3:9 @@ -20,20 +18,16 @@ 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:17 + --> $DIR/issue-54180-unused-ref-field.rs:26:13 | LL | let S { ref f1 } = s; - | ----^^ - | | - | help: try ignoring the field: `f1: _` + | ^^^^^^ help: try ignoring the field: `f1: _` error: unused variable: `x` - --> $DIR/issue-54180-unused-ref-field.rs:32:28 + --> $DIR/issue-54180-unused-ref-field.rs:32:20 | LL | Point { y, ref mut x } => y, - | --------^ - | | - | help: try ignoring the field: `x: _` + | ^^^^^^^^^ help: try ignoring the field: `x: _` error: aborting due to 4 previous errors diff --git a/src/test/ui/lint/issue-67691-unused-field-in-or-pattern.fixed b/src/test/ui/lint/issue-67691-unused-field-in-or-pattern.fixed index 7ec0b33f919..cfe37606202 100644 --- a/src/test/ui/lint/issue-67691-unused-field-in-or-pattern.fixed +++ b/src/test/ui/lint/issue-67691-unused-field-in-or-pattern.fixed @@ -8,6 +8,11 @@ pub enum MyEnum { B { i: i32, j: i32 }, } +pub enum MixedEnum { + A { i: i32 }, + B(i32), +} + pub fn no_ref(x: MyEnum) { use MyEnum::*; @@ -52,10 +57,29 @@ pub fn inner_with_ref(x: Option<MyEnum>) { } } +pub fn mixed_no_ref(x: MixedEnum) { + match x { + MixedEnum::A { i: _ } | MixedEnum::B(_i) => { + println!("match"); + } + } +} + +pub fn mixed_with_ref(x: MixedEnum) { + match x { + MixedEnum::A { i: _ } | MixedEnum::B(_i) => { + 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.rs b/src/test/ui/lint/issue-67691-unused-field-in-or-pattern.rs index d43c637767a..4b19f85dfa4 100644 --- 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 @@ -8,6 +8,11 @@ pub enum MyEnum { B { i: i32, j: i32 }, } +pub enum MixedEnum { + A { i: i32 }, + B(i32), +} + pub fn no_ref(x: MyEnum) { use MyEnum::*; @@ -52,10 +57,29 @@ pub fn inner_with_ref(x: Option<MyEnum>) { } } +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 index bda53c67331..4e9d02abacd 100644 --- 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 @@ -1,5 +1,5 @@ error: unused variable: `j` - --> $DIR/issue-67691-unused-field-in-or-pattern.rs:15:16 + --> $DIR/issue-67691-unused-field-in-or-pattern.rs:20:16 | LL | A { i, j } | B { i, j } => { | ^ ^ @@ -16,7 +16,7 @@ LL | A { i, j: _ } | B { i, j: _ } => { | ^^^^ ^^^^ error: unused variable: `j` - --> $DIR/issue-67691-unused-field-in-or-pattern.rs:25:16 + --> $DIR/issue-67691-unused-field-in-or-pattern.rs:30:16 | LL | A { i, ref j } | B { i, ref j } => { | ^^^^^ ^^^^^ @@ -27,7 +27,7 @@ LL | A { i, j: _ } | B { i, j: _ } => { | ^^^^ ^^^^ error: unused variable: `j` - --> $DIR/issue-67691-unused-field-in-or-pattern.rs:35:21 + --> $DIR/issue-67691-unused-field-in-or-pattern.rs:40:21 | LL | Some(A { i, j } | B { i, j }) => { | ^ ^ @@ -38,7 +38,7 @@ LL | Some(A { i, j: _ } | B { i, j: _ }) => { | ^^^^ ^^^^ error: unused variable: `j` - --> $DIR/issue-67691-unused-field-in-or-pattern.rs:47:21 + --> $DIR/issue-67691-unused-field-in-or-pattern.rs:52:21 | LL | Some(A { i, ref j } | B { i, ref j }) => { | ^^^^^ ^^^^^ @@ -48,5 +48,27 @@ help: try ignoring the field LL | Some(A { i, j: _ } | B { i, j: _ }) => { | ^^^^ ^^^^ -error: aborting due to 5 previous errors +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(_i) => { + | ^^^^ ^^ + +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(_i) => { + | ^^^^ ^^ + +error: aborting due to 6 previous errors diff --git a/src/test/ui/liveness/liveness-dead.stderr b/src/test/ui/liveness/liveness-dead.stderr index 12680ab1156..e9d20cf981f 100644 --- a/src/test/ui/liveness/liveness-dead.stderr +++ b/src/test/ui/liveness/liveness-dead.stderr @@ -1,8 +1,8 @@ error: value assigned to `x` is never read - --> $DIR/liveness-dead.rs:9:13 + --> $DIR/liveness-dead.rs:9:9 | LL | let mut x: isize = 3; - | ^ + | ^^^^^ | note: the lint level is defined here --> $DIR/liveness-dead.rs:2:9 @@ -20,10 +20,10 @@ LL | x = 4; = help: maybe it is overwritten before being read? error: value passed to `x` is never read - --> $DIR/liveness-dead.rs:20:11 + --> $DIR/liveness-dead.rs:20:7 | LL | fn f4(mut x: i32) { - | ^ + | ^^^^^ | = help: maybe it is overwritten before being read? diff --git a/src/test/ui/liveness/liveness-unused.stderr b/src/test/ui/liveness/liveness-unused.stderr index 42187330a3e..1ea84614393 100644 --- a/src/test/ui/liveness/liveness-unused.stderr +++ b/src/test/ui/liveness/liveness-unused.stderr @@ -44,10 +44,10 @@ LL | let x = 3; | ^ help: if this is intentional, prefix it with an underscore: `_x` error: variable `x` is assigned to, but never used - --> $DIR/liveness-unused.rs:30:13 + --> $DIR/liveness-unused.rs:30:9 | LL | let mut x = 3; - | ^ + | ^^^^^ | = note: consider using `_x` instead @@ -65,10 +65,10 @@ LL | #![deny(unused_assignments)] = help: maybe it is overwritten before being read? error: variable `z` is assigned to, but never used - --> $DIR/liveness-unused.rs:37:13 + --> $DIR/liveness-unused.rs:37:9 | LL | let mut z = 3; - | ^ + | ^^^^^ | = note: consider using `_z` instead |
