Skip to content

Commit fdc1eea

Browse files
author
Jakub Wieczorek
committed
Make the diagnostic for static variables in patterns better
Fixes #17933.
1 parent 86509d8 commit fdc1eea

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

src/librustc/middle/resolve.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5112,10 +5112,15 @@ impl<'a> Resolver<'a> {
51125112
Some(def @ (DefFn(..), _)) |
51135113
Some(def @ (DefVariant(..), _)) |
51145114
Some(def @ (DefStruct(..), _)) |
5115-
Some(def @ (DefConst(..), _)) |
5116-
Some(def @ (DefStatic(..), _)) => {
5115+
Some(def @ (DefConst(..), _)) => {
51175116
self.record_def(pattern.id, def);
51185117
}
5118+
Some((DefStatic(..), _)) => {
5119+
self.resolve_error(path.span,
5120+
"static variables cannot be \
5121+
referenced in a pattern, \
5122+
use a `const` instead");
5123+
}
51195124
Some(_) => {
51205125
self.resolve_error(path.span,
51215126
format!("`{}` is not an enum variant, struct or const",

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2014 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+
pub static X: uint = 1u;
12+
13+
fn main() {
14+
match 1u {
15+
self::X => { },
16+
//~^ ERROR static variables cannot be referenced in a pattern, use a `const` instead
17+
_ => { },
18+
}
19+
}

0 commit comments

Comments
 (0)