]> git.lizzy.rs Git - rust.git/blob - tests/ui/invalid_ref.rs
Merge pull request #3269 from rust-lang-nursery/relicense
[rust.git] / tests / ui / invalid_ref.rs
1 // Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution.
3 //
4 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7 // option. This file may not be copied, modified, or distributed
8 // except according to those terms.
9
10
11
12
13
14 #![allow(unused)]
15 #![feature(core_intrinsics)]
16
17 extern crate core;
18 use std::intrinsics::{init, uninit};
19
20 fn main() {
21     let x = 1; 
22     unsafe { 
23         ref_to_zeroed_std(&x);
24         ref_to_zeroed_core(&x);
25         ref_to_zeroed_intr(&x);
26         ref_to_uninit_std(&x);
27         ref_to_uninit_core(&x);
28         ref_to_uninit_intr(&x);
29         some_ref();
30         std_zeroed_no_ref();
31         core_zeroed_no_ref();
32         intr_init_no_ref();
33     }
34 }
35
36 unsafe fn ref_to_zeroed_std<T: ?Sized>(t: &T) {
37     let ref_zero: &T = std::mem::zeroed();     // warning
38 }
39
40 unsafe fn ref_to_zeroed_core<T: ?Sized>(t: &T) {
41     let ref_zero: &T = core::mem::zeroed();   // warning
42 }
43
44 unsafe fn ref_to_zeroed_intr<T: ?Sized>(t: &T) {
45     let ref_zero: &T = std::intrinsics::init();   // warning
46 }
47
48 unsafe fn ref_to_uninit_std<T: ?Sized>(t: &T) {
49     let ref_uninit: &T = std::mem::uninitialized();   // warning
50 }
51
52 unsafe fn ref_to_uninit_core<T: ?Sized>(t: &T) {
53     let ref_uninit: &T = core::mem::uninitialized();   // warning
54 }
55
56 unsafe fn ref_to_uninit_intr<T: ?Sized>(t: &T) {
57     let ref_uninit: &T = std::intrinsics::uninit();   // warning
58 }
59
60 fn some_ref() {
61     let some_ref = &1; 
62 }
63
64 unsafe fn std_zeroed_no_ref() {
65     let mem_zero: usize = std::mem::zeroed();  // no warning
66 }
67
68 unsafe fn core_zeroed_no_ref() {
69     let mem_zero: usize = core::mem::zeroed();  // no warning
70 }
71
72 unsafe fn intr_init_no_ref() {
73     let mem_zero: usize = std::intrinsics::init(); // no warning
74 }
75
76