Skip to content

Commit 9ea4b4f

Browse files
committed
Auto merge of #30321 - sanxiyn:E0170, r=alexcrichton
Fix #30302.
2 parents 50a02b4 + ecf2c25 commit 9ea4b4f

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

src/librustc/middle/check_match.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -250,14 +250,15 @@ fn check_for_bindings_named_the_same_as_variants(cx: &MatchCheckCtxt, pat: &Pat)
250250
variant.name == ident.node.unhygienic_name
251251
&& variant.kind() == VariantKind::Unit
252252
) {
253+
let ty_path = cx.tcx.item_path_str(edef.did);
253254
span_warn!(cx.tcx.sess, p.span, E0170,
254255
"pattern binding `{}` is named the same as one \
255256
of the variants of the type `{}`",
256-
ident.node, pat_ty);
257+
ident.node, ty_path);
257258
fileline_help!(cx.tcx.sess, p.span,
258259
"if you meant to match on a variant, \
259260
consider making the path in the pattern qualified: `{}::{}`",
260-
pat_ty, ident.node);
261+
ty_path, ident.node);
261262
}
262263
}
263264
}

src/test/compile-fail/issue-30302.rs

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
enum Stack<T> {
12+
Nil,
13+
Cons(T, Box<Stack<T>>)
14+
}
15+
16+
fn is_empty<T>(s: Stack<T>) -> bool {
17+
match s {
18+
Nil => true,
19+
//~^ WARN pattern binding `Nil` is named the same as one of the variants of the type `Stack`
20+
//~| HELP consider making the path in the pattern qualified: `Stack::Nil`
21+
_ => false
22+
//~^ ERROR unreachable pattern
23+
}
24+
}
25+
26+
fn main() {}

0 commit comments

Comments
 (0)