commit
9ea4b4f01f
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
26
src/test/compile-fail/issue-30302.rs
Normal file
26
src/test/compile-fail/issue-30302.rs
Normal file
@ -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() {}
|
Loading…
x
Reference in New Issue
Block a user