Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not mark unit variants as used when in path pattern #81310

Merged
merged 1 commit into from
Jan 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_passes/src/dead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ impl<'tcx> Visitor<'tcx> for MarkSymbolVisitor<'tcx> {
}

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

self.in_pat = true;
intravisit::walk_pat(self, pat);
self.in_pat = false;
}
Expand Down
21 changes: 20 additions & 1 deletion src/test/ui/lint/dead-code/const-and-self.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// check-pass

#![deny(dead_code)]
#![warn(dead_code)]

const TLC: usize = 4;

Expand Down Expand Up @@ -28,8 +28,27 @@ impl Foo<Y> for X {
}
}

enum E {
A,
B, //~ WARN variant is never constructed: `B`
C, //~ WARN variant is never constructed: `C`
}

type F = E;

impl E {
fn check(&self) -> bool {
match self {
Self::A => true,
Self::B => false,
F::C => false,
}
}
}

fn main() {
let s = [0,1,2,3];
s.doit();
X::foo();
E::A.check();
}
20 changes: 20 additions & 0 deletions src/test/ui/lint/dead-code/const-and-self.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
warning: variant is never constructed: `B`
--> $DIR/const-and-self.rs:33:5
|
LL | B,
| ^
|
note: the lint level is defined here
--> $DIR/const-and-self.rs:3:9
|
LL | #![warn(dead_code)]
| ^^^^^^^^^

warning: variant is never constructed: `C`
--> $DIR/const-and-self.rs:34:5
|
LL | C,
| ^

warning: 2 warnings emitted