From ecf2c2595940d7758f5c1a6d1802e3ac42ef6fd6 Mon Sep 17 00:00:00 2001 From: Seo Sanghyeon Date: Fri, 11 Dec 2015 17:43:04 +0900 Subject: [PATCH] Do not include generics in suggestion to qualify enum variants --- src/librustc/middle/check_match.rs | 5 +++-- src/test/compile-fail/issue-30302.rs | 26 ++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 src/test/compile-fail/issue-30302.rs diff --git a/src/librustc/middle/check_match.rs b/src/librustc/middle/check_match.rs index 04f907af70bbc..ba4bdccb20b80 100644 --- a/src/librustc/middle/check_match.rs +++ b/src/librustc/middle/check_match.rs @@ -250,14 +250,15 @@ fn check_for_bindings_named_the_same_as_variants(cx: &MatchCheckCtxt, pat: &Pat) variant.name == ident.node.unhygienic_name && variant.kind() == VariantKind::Unit ) { + let ty_path = cx.tcx.item_path_str(edef.did); span_warn!(cx.tcx.sess, p.span, E0170, "pattern binding `{}` is named the same as one \ of the variants of the type `{}`", - ident.node, pat_ty); + ident.node, ty_path); fileline_help!(cx.tcx.sess, p.span, "if you meant to match on a variant, \ consider making the path in the pattern qualified: `{}::{}`", - pat_ty, ident.node); + ty_path, ident.node); } } } diff --git a/src/test/compile-fail/issue-30302.rs b/src/test/compile-fail/issue-30302.rs new file mode 100644 index 0000000000000..26508a4722425 --- /dev/null +++ b/src/test/compile-fail/issue-30302.rs @@ -0,0 +1,26 @@ +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +enum Stack { + Nil, + Cons(T, Box>) +} + +fn is_empty(s: Stack) -> bool { + match s { + Nil => true, +//~^ WARN pattern binding `Nil` is named the same as one of the variants of the type `Stack` +//~| HELP consider making the path in the pattern qualified: `Stack::Nil` + _ => false +//~^ ERROR unreachable pattern + } +} + +fn main() {}