Skip to content

Commit

Permalink
Do not include generics in suggestion to qualify enum variants
Browse files Browse the repository at this point in the history
  • Loading branch information
sanxiyn committed Dec 11, 2015
1 parent 672a3d9 commit ecf2c25
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/librustc/middle/check_match.rs
Expand Up @@ -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);
}
}
}
Expand Down
26 changes: 26 additions & 0 deletions 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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

enum Stack<T> {
Nil,
Cons(T, Box<Stack<T>>)
}

fn is_empty<T>(s: Stack<T>) -> 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() {}

0 comments on commit ecf2c25

Please sign in to comment.