Skip to content

Commit 6fcf628

Browse files
committed
Auto merge of #27349 - arielb1:constant-at, r=alexcrichton
Fixes #27033 Fixes #27077 r? @alexcrichton
2 parents d576ef3 + 757b0c1 commit 6fcf628

File tree

2 files changed

+30
-9
lines changed

2 files changed

+30
-9
lines changed

src/librustc_resolve/lib.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2654,23 +2654,22 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
26542654
let pat_id = pattern.id;
26552655
walk_pat(pattern, |pattern| {
26562656
match pattern.node {
2657-
PatIdent(binding_mode, ref path1, _) => {
2658-
2659-
// The meaning of pat_ident with no type parameters
2657+
PatIdent(binding_mode, ref path1, ref at_rhs) => {
2658+
// The meaning of PatIdent with no type parameters
26602659
// depends on whether an enum variant or unit-like struct
26612660
// with that name is in scope. The probing lookup has to
26622661
// be careful not to emit spurious errors. Only matching
26632662
// patterns (match) can match nullary variants or
2664-
// unit-like structs. For binding patterns (let), matching
2665-
// such a value is simply disallowed (since it's rarely
2666-
// what you want).
2663+
// unit-like structs. For binding patterns (let
2664+
// and the LHS of @-patterns), matching such a value is
2665+
// simply disallowed (since it's rarely what you want).
2666+
let const_ok = mode == RefutableMode && at_rhs.is_none();
26672667

26682668
let ident = path1.node;
26692669
let renamed = mtwt::resolve(ident);
26702670

26712671
match self.resolve_bare_identifier_pattern(ident.name, pattern.span) {
2672-
FoundStructOrEnumVariant(def, lp)
2673-
if mode == RefutableMode => {
2672+
FoundStructOrEnumVariant(def, lp) if const_ok => {
26742673
debug!("(resolving pattern) resolving `{}` to \
26752674
struct or enum variant",
26762675
renamed);
@@ -2693,7 +2692,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
26932692
renamed)
26942693
);
26952694
}
2696-
FoundConst(def, lp) if mode == RefutableMode => {
2695+
FoundConst(def, lp) if const_ok => {
26972696
debug!("(resolving pattern) resolving `{}` to \
26982697
constant",
26992698
renamed);

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
fn main() {
12+
match Some(1) {
13+
None @ _ => {} //~ ERROR declaration of `None` shadows an enum variant
14+
};
15+
const C: u8 = 1;
16+
match 1 {
17+
C @ 2 => { //~ ERROR only irrefutable patterns allowed here
18+
println!("{}", C);
19+
}
20+
_ => {}
21+
};
22+
}

0 commit comments

Comments
 (0)