Rollup merge of #71026 - seiyab:issue-64362-adhoc, r=varkor

Fix false "never constructed" warnings for `Self::` variant paths

Closes #64362 .
This commit is contained in:
Dylan DPC 2020-04-19 21:11:22 +02:00 committed by GitHub
commit 9c5da9afa9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 2 deletions

View File

@ -255,7 +255,9 @@ fn visit_expr(&mut self, expr: &'tcx hir::Expr<'tcx>) {
hir::ExprKind::Field(ref lhs, ..) => {
self.handle_field_access(&lhs, expr.hir_id);
}
hir::ExprKind::Struct(_, ref fields, _) => {
hir::ExprKind::Struct(ref qpath, ref fields, _) => {
let res = self.tables.qpath_res(qpath, expr.hir_id);
self.handle_res(res);
if let ty::Adt(ref adt, _) = self.tables.expr_ty(expr).kind {
self.mark_as_used_if_union(adt, fields);
}

View File

@ -13,6 +13,23 @@ enum Enum2 {
Variant5 { _x: isize }, //~ ERROR: variant is never constructed: `Variant5`
Variant6(isize), //~ ERROR: variant is never constructed: `Variant6`
_Variant7,
Variant8 { _field: bool },
Variant9,
Variant10(usize)
}
impl Enum2 {
fn new_variant8() -> Enum2 {
Self::Variant8 { _field: true }
}
fn new_variant9() -> Enum2 {
Self::Variant9
}
fn new_variant10() -> Enum2 {
Self::Variant10(10)
}
}
enum Enum3 { //~ ERROR: enum is never used
@ -27,4 +44,7 @@ fn main() {
Enum1::Variant2 => ()
}
let x = Enum2::Variant3(true);
let _ = Enum2::new_variant8();
let _ = Enum2::new_variant9();
let _ = Enum2::new_variant10();
}

View File

@ -23,7 +23,7 @@ LL | Variant6(isize),
| ^^^^^^^^^^^^^^^
error: enum is never used: `Enum3`
--> $DIR/lint-dead-code-5.rs:18:6
--> $DIR/lint-dead-code-5.rs:35:6
|
LL | enum Enum3 {
| ^^^^^