Skip to content

Commit 04ddf42

Browse files
Rollup merge of #81310 - tmiasko:in-pattern, r=petrochenkov
Do not mark unit variants as used when in path pattern Record that we are processing a pattern so that code responsible for handling path resolution can correctly decide whether to mark it as used or not. Closes #76788.
2 parents ee4461a + 99a1dea commit 04ddf42

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

compiler/rustc_passes/src/dead.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ impl<'tcx> Visitor<'tcx> for MarkSymbolVisitor<'tcx> {
290290
}
291291

292292
fn visit_pat(&mut self, pat: &'tcx hir::Pat<'tcx>) {
293+
self.in_pat = true;
293294
match pat.kind {
294295
PatKind::Struct(ref path, ref fields, _) => {
295296
let res = self.typeck_results().qpath_res(path, pat.hir_id);
@@ -302,7 +303,6 @@ impl<'tcx> Visitor<'tcx> for MarkSymbolVisitor<'tcx> {
302303
_ => (),
303304
}
304305

305-
self.in_pat = true;
306306
intravisit::walk_pat(self, pat);
307307
self.in_pat = false;
308308
}

src/test/ui/lint/dead-code/const-and-self.rs

+20-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// check-pass
22

3-
#![deny(dead_code)]
3+
#![warn(dead_code)]
44

55
const TLC: usize = 4;
66

@@ -28,8 +28,27 @@ impl Foo<Y> for X {
2828
}
2929
}
3030

31+
enum E {
32+
A,
33+
B, //~ WARN variant is never constructed: `B`
34+
C, //~ WARN variant is never constructed: `C`
35+
}
36+
37+
type F = E;
38+
39+
impl E {
40+
fn check(&self) -> bool {
41+
match self {
42+
Self::A => true,
43+
Self::B => false,
44+
F::C => false,
45+
}
46+
}
47+
}
48+
3149
fn main() {
3250
let s = [0,1,2,3];
3351
s.doit();
3452
X::foo();
53+
E::A.check();
3554
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
warning: variant is never constructed: `B`
2+
--> $DIR/const-and-self.rs:33:5
3+
|
4+
LL | B,
5+
| ^
6+
|
7+
note: the lint level is defined here
8+
--> $DIR/const-and-self.rs:3:9
9+
|
10+
LL | #![warn(dead_code)]
11+
| ^^^^^^^^^
12+
13+
warning: variant is never constructed: `C`
14+
--> $DIR/const-and-self.rs:34:5
15+
|
16+
LL | C,
17+
| ^
18+
19+
warning: 2 warnings emitted
20+

0 commit comments

Comments
 (0)