]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/uniform-paths/same-crate.rs
#[feature(uniform_paths)]: allow `use x::y;` to resolve through `self::x`, not just...
[rust.git] / src / test / run-pass / uniform-paths / same-crate.rs
1 // Copyright 2018 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 // edition:2018
12
13 #![feature(uniform_paths)]
14
15 pub const A: usize = 0;
16
17 pub mod foo {
18     pub const B: usize = 1;
19
20     pub mod bar {
21         pub const C: usize = 2;
22
23         pub enum E {
24             V1(usize),
25             V2(String),
26         }
27
28         pub fn test() -> String {
29             format!("{} {} {}", crate::A, crate::foo::B, C)
30         }
31
32         pub fn test_use() -> String {
33             use crate::A;
34             use crate::foo::B;
35
36             format!("{} {} {}", A, B, C)
37         }
38
39         pub fn test_enum() -> String {
40             use E::*;
41             match E::V1(10) {
42                 V1(i) => { format!("V1: {}", i) }
43                 V2(s) => { format!("V2: {}", s) }
44             }
45         }
46     }
47
48     pub fn test() -> String {
49         format!("{} {} {}", crate::A, B, bar::C)
50     }
51
52     pub fn test_use() -> String {
53         use crate::A;
54         use bar::C;
55
56         format!("{} {} {}", A, B, C)
57     }
58
59     pub fn test_enum() -> String {
60         use bar::E::*;
61         match bar::E::V1(10) {
62             V1(i) => { format!("V1: {}", i) }
63             V2(s) => { format!("V2: {}", s) }
64         }
65     }
66 }
67
68 pub fn test() -> String {
69     format!("{} {} {}", A, foo::B, foo::bar::C)
70 }
71
72 pub fn test_use() -> String {
73     use foo::B;
74     use foo::bar::C;
75
76     format!("{} {} {}", A, B, C)
77 }
78
79 pub fn test_enum() -> String {
80     use foo::bar::E::*;
81     match foo::bar::E::V1(10) {
82         V1(i) => { format!("V1: {}", i) }
83         V2(s) => { format!("V2: {}", s) }
84     }
85 }
86
87 fn main() {
88     let output = [
89         test(),
90         foo::test(),
91         foo::bar::test(),
92         test_use(),
93         foo::test_use(),
94         foo::bar::test_use(),
95         test_enum(),
96         foo::test_enum(),
97         foo::bar::test_enum(),
98     ].join("\n");
99     assert_eq!(output, "\
100 0 1 2
101 0 1 2
102 0 1 2
103 0 1 2
104 0 1 2
105 0 1 2
106 V1: 10
107 V1: 10
108 V1: 10");
109 }