Skip to content

Commit 8e8fe90

Browse files
committed
Correct unused field warning on box struct match
1 parent cc53db8 commit 8e8fe90

File tree

3 files changed

+24
-11
lines changed

3 files changed

+24
-11
lines changed

src/librustc/middle/liveness.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -430,8 +430,9 @@ fn visit_arm<'a, 'tcx>(ir: &mut IrMaps<'a, 'tcx>, arm: &'tcx hir::Arm) {
430430
}
431431
break;
432432
}
433-
hir::PatKind::Ref(ref deref_pat, _) => {
434-
pat = deref_pat;
433+
hir::PatKind::Ref(ref inner_pat, _) |
434+
hir::PatKind::Box(ref inner_pat) => {
435+
pat = inner_pat;
435436
}
436437
_ => break
437438
}

src/test/ui/lint/issue-47390-unused-variable-in-struct-pattern.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
// compile-pass
1212

13+
#![feature(box_syntax)]
14+
#![feature(box_patterns)]
1315
#![warn(unused)] // UI tests pass `-A unused` (#43896)
1416

1517
struct SoulHistory {
@@ -36,11 +38,15 @@ fn main() {
3638
hours_are_suns = false;
3739
}
3840

39-
let bag = &Large::Suit {
41+
let bag = Large::Suit {
4042
case: ()
4143
};
4244

43-
match bag {
45+
match &bag {
4446
&Large::Suit { case } => {}
4547
};
48+
49+
match box bag {
50+
box Large::Suit { case } => {}
51+
};
4652
}
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,52 @@
11
warning: unused variable: `i_think_continually`
2-
--> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:26:9
2+
--> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:28:9
33
|
44
LL | let i_think_continually = 2;
55
| ^^^^^^^^^^^^^^^^^^^ help: consider using `_i_think_continually` instead
66
|
77
note: lint level defined here
8-
--> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:13:9
8+
--> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:15:9
99
|
1010
LL | #![warn(unused)] // UI tests pass `-A unused` (#43896)
1111
| ^^^^^^
1212
= note: #[warn(unused_variables)] implied by #[warn(unused)]
1313

1414
warning: unused variable: `corridors_of_light`
15-
--> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:33:26
15+
--> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:35:26
1616
|
1717
LL | if let SoulHistory { corridors_of_light,
1818
| ^^^^^^^^^^^^^^^^^^ help: try ignoring the field: `corridors_of_light: _`
1919

2020
warning: variable `hours_are_suns` is assigned to, but never used
21-
--> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:34:26
21+
--> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:36:26
2222
|
2323
LL | mut hours_are_suns,
2424
| ^^^^^^^^^^^^^^^^^^
2525
|
2626
= note: consider using `_hours_are_suns` instead
2727

2828
warning: value assigned to `hours_are_suns` is never read
29-
--> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:36:9
29+
--> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:38:9
3030
|
3131
LL | hours_are_suns = false;
3232
| ^^^^^^^^^^^^^^
3333
|
3434
note: lint level defined here
35-
--> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:13:9
35+
--> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:15:9
3636
|
3737
LL | #![warn(unused)] // UI tests pass `-A unused` (#43896)
3838
| ^^^^^^
3939
= note: #[warn(unused_assignments)] implied by #[warn(unused)]
4040

4141
warning: unused variable: `case`
42-
--> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:44:24
42+
--> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:46:24
4343
|
4444
LL | &Large::Suit { case } => {}
4545
| ^^^^ help: try ignoring the field: `case: _`
4646

47+
warning: unused variable: `case`
48+
--> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:50:27
49+
|
50+
LL | box Large::Suit { case } => {}
51+
| ^^^^ help: try ignoring the field: `case: _`
52+

0 commit comments

Comments
 (0)