]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/issue-20427.rs
Rollup merge of #32131 - petrochenkov:prim, r=eddyb
[rust.git] / src / test / run-pass / issue-20427.rs
1 // Copyright 2016 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 // aux-build:i8.rs
12 // ignore-pretty (#23623)
13
14 extern crate i8;
15 use std::string as i16;
16 static i32: i32 = 0;
17 const i64: i64 = 0;
18 fn u8(f32: f32) {}
19 fn f<f64>(f64: f64) {}
20 enum u32 {}
21 struct u64;
22 trait bool {}
23
24 mod char {
25     extern crate i8;
26     static i32_: i32 = 0;
27     const i64_: i64 = 0;
28     fn u8_(f32: f32) {}
29     fn f_<f64_>(f64: f64_) {}
30     type u16_ = u16;
31     enum u32_ {}
32     struct u64_;
33     trait bool_ {}
34     mod char_ {}
35
36     mod str {
37         use super::i8 as i8;
38         use super::i32_ as i32;
39         use super::i64_ as i64;
40         use super::u8_ as u8;
41         use super::f_ as f64;
42         use super::u16_ as u16;
43         use super::u32_ as u32;
44         use super::u64_ as u64;
45         use super::bool_ as bool;
46         use super::{bool_ as str};
47         use super::char_ as char;
48     }
49 }
50
51 trait isize_ {
52     type isize;
53 }
54
55 fn usize<'usize>(usize: &'usize usize) -> &'usize usize { usize }
56
57 mod reuse {
58     use std::mem::size_of;
59
60     type u8 = u64;
61     use std::string::String as i16;
62
63     pub fn check<u16>() {
64         assert_eq!(size_of::<u8>(), 8);
65         assert_eq!(size_of::<::u64>(), 0);
66         assert_eq!(size_of::<i16>(), 3 * size_of::<*const ()>());
67         assert_eq!(size_of::<u16>(), 0);
68     }
69 }
70
71 mod guard {
72     pub fn check() {
73         use std::u8; // bring module u8 in scope
74         fn f() -> u8 { // OK, resolves to primitive u8, not to std::u8
75             u8::max_value() // OK, resolves to associated function <u8>::max_value,
76                             // not to non-existent std::u8::max_value
77         }
78         assert_eq!(f(), u8::MAX); // OK, resolves to std::u8::MAX
79     }
80 }
81
82 fn main() {
83     let bool = true;
84     let _ = match bool {
85         str @ true => if str { i32 as i64 } else { i64 },
86         false => i64,
87     };
88
89     reuse::check::<u64>();
90     guard::check();
91 }