]> git.proxmox.com Git - rustc.git/blob - src/test/run-pass/match-static-const-rename.rs
08f3182900fc2bba9fdd135c319b34c4e8e1c0c7
[rustc.git] / src / test / run-pass / match-static-const-rename.rs
1 // Copyright 2012-2013 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 // Issue #7526: lowercase static constants in patterns look like bindings
12
13 // This is similar to compile-fail/match-static-const-lc, except it
14 // shows the expected usual workaround (choosing a different name for
15 // the static definition) and also demonstrates that one can work
16 // around this problem locally by renaming the constant in the `use`
17 // form to an uppercase identifier that placates the lint.
18
19
20 #![deny(non_upper_case_globals)]
21
22 pub const A : isize = 97;
23
24 fn f() {
25 let r = match (0,0) {
26 (0, A) => 0,
27 (x, y) => 1 + x + y,
28 };
29 assert!(r == 1);
30 let r = match (0,97) {
31 (0, A) => 0,
32 (x, y) => 1 + x + y,
33 };
34 assert!(r == 0);
35 }
36
37 mod m {
38 #[allow(non_upper_case_globals)]
39 pub const aha : isize = 7;
40 }
41
42 fn g() {
43 use self::m::aha as AHA;
44 let r = match (0,0) {
45 (0, AHA) => 0,
46 (x, y) => 1 + x + y,
47 };
48 assert!(r == 1);
49 let r = match (0,7) {
50 (0, AHA) => 0,
51 (x, y) => 1 + x + y,
52 };
53 assert!(r == 0);
54 }
55
56 fn h() {
57 let r = match (0,0) {
58 (0, self::m::aha) => 0,
59 (x, y) => 1 + x + y,
60 };
61 assert!(r == 1);
62 let r = match (0,7) {
63 (0, self::m::aha) => 0,
64 (x, y) => 1 + x + y,
65 };
66 assert!(r == 0);
67 }
68
69 pub fn main () {
70 f();
71 g();
72 h();
73 }