]> git.lizzy.rs Git - rust.git/blob - tests/ui/invalid_ref.rs
Auto merge of #3603 - xfix:random-state-lint, r=phansch
[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 #![allow(unused)]
11 #![feature(core_intrinsics)]
12
13 extern crate core;
14 use std::intrinsics::{init, uninit};
15
16 fn main() {
17     let x = 1;
18     unsafe {
19         ref_to_zeroed_std(&x);
20         ref_to_zeroed_core(&x);
21         ref_to_zeroed_intr(&x);
22         ref_to_uninit_std(&x);
23         ref_to_uninit_core(&x);
24         ref_to_uninit_intr(&x);
25         some_ref();
26         std_zeroed_no_ref();
27         core_zeroed_no_ref();
28         intr_init_no_ref();
29     }
30 }
31
32 unsafe fn ref_to_zeroed_std<T: ?Sized>(t: &T) {
33     let ref_zero: &T = std::mem::zeroed(); // warning
34 }
35
36 unsafe fn ref_to_zeroed_core<T: ?Sized>(t: &T) {
37     let ref_zero: &T = core::mem::zeroed(); // warning
38 }
39
40 unsafe fn ref_to_zeroed_intr<T: ?Sized>(t: &T) {
41     let ref_zero: &T = std::intrinsics::init(); // warning
42 }
43
44 unsafe fn ref_to_uninit_std<T: ?Sized>(t: &T) {
45     let ref_uninit: &T = std::mem::uninitialized(); // warning
46 }
47
48 unsafe fn ref_to_uninit_core<T: ?Sized>(t: &T) {
49     let ref_uninit: &T = core::mem::uninitialized(); // warning
50 }
51
52 unsafe fn ref_to_uninit_intr<T: ?Sized>(t: &T) {
53     let ref_uninit: &T = std::intrinsics::uninit(); // warning
54 }
55
56 fn some_ref() {
57     let some_ref = &1;
58 }
59
60 unsafe fn std_zeroed_no_ref() {
61     let mem_zero: usize = std::mem::zeroed(); // no warning
62 }
63
64 unsafe fn core_zeroed_no_ref() {
65     let mem_zero: usize = core::mem::zeroed(); // no warning
66 }
67
68 unsafe fn intr_init_no_ref() {
69     let mem_zero: usize = std::intrinsics::init(); // no warning
70 }