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

RFC2229: Use the correct place type #87161

Merged
merged 1 commit into from
Jul 16, 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
8 changes: 6 additions & 2 deletions compiler/rustc_typeck/src/expr_use_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,12 +256,16 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
| PatKind::Path(..)
| PatKind::Struct(..)
| PatKind::Tuple(..) => {
// If the PatKind is a TupleStruct, Struct or Tuple then we want to check
// If the PatKind is a TupleStruct, Path, Struct or Tuple then we want to check
// whether the Variant is a MultiVariant or a SingleVariant. We only want
// to borrow discr if it is a MultiVariant.
// If it is a SingleVariant and creates a binding we will handle that when
// this callback gets called again.
if let ty::Adt(def, _) = place.place.base_ty.kind() {

// Get the type of the Place after all projections have been applied
let place_ty = place.place.ty();

if let ty::Adt(def, _) = place_ty.kind() {
if def.variants.len() > 1 {
needs_to_be_read = true;
}
Expand Down
35 changes: 35 additions & 0 deletions src/test/ui/closures/2229_closure_analysis/issue-87097.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// run-pass
// edition:2021

enum Variant {
A,
B, //~ WARNING: variant is never constructed: `B`
}

struct A {
field: Variant,
}

fn discriminant_is_a_ref() {
let here = A { field: Variant::A };
let out_ref = &here.field;

|| match out_ref { //~ WARNING: unused closure that must be used
Variant::A => (),
Variant::B => (),
};
}

fn discriminant_is_a_field() {
let here = A { field: Variant::A };

|| match here.field { //~ WARNING: unused closure that must be used
Variant::A => (),
Variant::B => (),
};
}

fn main() {
discriminant_is_a_ref();
discriminant_is_a_field();
}
33 changes: 33 additions & 0 deletions src/test/ui/closures/2229_closure_analysis/issue-87097.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
warning: variant is never constructed: `B`
--> $DIR/issue-87097.rs:6:5
|
LL | B,
| ^
|
= note: `#[warn(dead_code)]` on by default

warning: unused closure that must be used
--> $DIR/issue-87097.rs:17:5
|
LL | / || match out_ref {
LL | | Variant::A => (),
LL | | Variant::B => (),
LL | | };
| |______^
|
= note: `#[warn(unused_must_use)]` on by default
= note: closures are lazy and do nothing unless called

warning: unused closure that must be used
--> $DIR/issue-87097.rs:26:5
|
LL | / || match here.field {
LL | | Variant::A => (),
LL | | Variant::B => (),
LL | | };
| |______^
|
= note: closures are lazy and do nothing unless called

warning: 3 warnings emitted