fork/rust

git clone https://git.julia.blue/fork/rust

borsAuto merge of #103046 - JanBeh:PR_clarify_cmp_terminology, r=workingjubilee3bcad65fbf6

master
8.5 KiB168 linesraw
1error[E0080]: it is undefined behavior to use this value
2  --> $DIR/ub-ref-ptr.rs:15:1
3   |
4LL | const UNALIGNED: &u16 = unsafe { mem::transmute(&[0u8; 4]) };
5   | ^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered an unaligned reference (required 2 byte alignment but found 1)
6   |
7   = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
8   = note: the raw bytes of the constant (size: $SIZE, align: $ALIGN) {
9               HEX_DUMP
10           }
11
12error[E0080]: it is undefined behavior to use this value
13  --> $DIR/ub-ref-ptr.rs:19:1
14   |
15LL | const UNALIGNED_BOX: Box<u16> = unsafe { mem::transmute(&[0u8; 4]) };
16   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered an unaligned box (required 2 byte alignment but found 1)
17   |
18   = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
19   = note: the raw bytes of the constant (size: $SIZE, align: $ALIGN) {
20               HEX_DUMP
21           }
22
23error[E0080]: it is undefined behavior to use this value
24  --> $DIR/ub-ref-ptr.rs:23:1
25   |
26LL | const NULL: &u16 = unsafe { mem::transmute(0usize) };
27   | ^^^^^^^^^^^^^^^^ constructing invalid value: encountered a null reference
28   |
29   = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
30   = note: the raw bytes of the constant (size: $SIZE, align: $ALIGN) {
31               HEX_DUMP
32           }
33
34error[E0080]: it is undefined behavior to use this value
35  --> $DIR/ub-ref-ptr.rs:26:1
36   |
37LL | const NULL_BOX: Box<u16> = unsafe { mem::transmute(0usize) };
38   | ^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a null box
39   |
40   = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
41   = note: the raw bytes of the constant (size: $SIZE, align: $ALIGN) {
42               HEX_DUMP
43           }
44
45error[E0080]: evaluation of constant value failed
46  --> $DIR/ub-ref-ptr.rs:33:1
47   |
48LL | const REF_AS_USIZE: usize = unsafe { mem::transmute(&0) };
49   | ^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into integer
50   |
51   = help: this code performed an operation that depends on the underlying bytes representing a pointer
52   = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
53
54error[E0080]: evaluation of constant value failed
55  --> $DIR/ub-ref-ptr.rs:36:39
56   |
57LL | const REF_AS_USIZE_SLICE: &[usize] = &[unsafe { mem::transmute(&0) }];
58   |                                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into integer
59   |
60   = help: this code performed an operation that depends on the underlying bytes representing a pointer
61   = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
62
63note: erroneous constant encountered
64  --> $DIR/ub-ref-ptr.rs:36:38
65   |
66LL | const REF_AS_USIZE_SLICE: &[usize] = &[unsafe { mem::transmute(&0) }];
67   |                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
68
69error[E0080]: evaluation of constant value failed
70  --> $DIR/ub-ref-ptr.rs:39:86
71   |
72LL | const REF_AS_USIZE_BOX_SLICE: Box<[usize]> = unsafe { mem::transmute::<&[usize], _>(&[mem::transmute(&0)]) };
73   |                                                                                      ^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into integer
74   |
75   = help: this code performed an operation that depends on the underlying bytes representing a pointer
76   = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
77
78note: erroneous constant encountered
79  --> $DIR/ub-ref-ptr.rs:39:85
80   |
81LL | const REF_AS_USIZE_BOX_SLICE: Box<[usize]> = unsafe { mem::transmute::<&[usize], _>(&[mem::transmute(&0)]) };
82   |                                                                                     ^^^^^^^^^^^^^^^^^^^^^
83
84error[E0080]: it is undefined behavior to use this value
85  --> $DIR/ub-ref-ptr.rs:42:1
86   |
87LL | const USIZE_AS_REF: &'static u8 = unsafe { mem::transmute(1337usize) };
88   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a dangling reference (0x539[noalloc] has no provenance)
89   |
90   = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
91   = note: the raw bytes of the constant (size: $SIZE, align: $ALIGN) {
92               HEX_DUMP
93           }
94
95error[E0080]: it is undefined behavior to use this value
96  --> $DIR/ub-ref-ptr.rs:45:1
97   |
98LL | const USIZE_AS_BOX: Box<u8> = unsafe { mem::transmute(1337usize) };
99   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a dangling box (0x539[noalloc] has no provenance)
100   |
101   = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
102   = note: the raw bytes of the constant (size: $SIZE, align: $ALIGN) {
103               HEX_DUMP
104           }
105
106error[E0080]: evaluation of constant value failed
107  --> $DIR/ub-ref-ptr.rs:48:41
108   |
109LL | const UNINIT_PTR: *const i32 = unsafe { MaybeUninit { uninit: () }.init };
110   |                                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ using uninitialized data, but this operation requires initialized memory
111
112error[E0080]: it is undefined behavior to use this value
113  --> $DIR/ub-ref-ptr.rs:52:1
114   |
115LL | const NULL_FN_PTR: fn() = unsafe { mem::transmute(0usize) };
116   | ^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered null pointer, but expected a function pointer
117   |
118   = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
119   = note: the raw bytes of the constant (size: $SIZE, align: $ALIGN) {
120               HEX_DUMP
121           }
122
123error[E0080]: evaluation of constant value failed
124  --> $DIR/ub-ref-ptr.rs:54:38
125   |
126LL | const UNINIT_FN_PTR: fn() = unsafe { MaybeUninit { uninit: () }.init };
127   |                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ using uninitialized data, but this operation requires initialized memory
128
129error[E0080]: it is undefined behavior to use this value
130  --> $DIR/ub-ref-ptr.rs:57:1
131   |
132LL | const DANGLING_FN_PTR: fn() = unsafe { mem::transmute(13usize) };
133   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered 0xd[noalloc], but expected a function pointer
134   |
135   = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
136   = note: the raw bytes of the constant (size: $SIZE, align: $ALIGN) {
137               HEX_DUMP
138           }
139
140error[E0080]: it is undefined behavior to use this value
141  --> $DIR/ub-ref-ptr.rs:59:1
142   |
143LL | const DATA_FN_PTR: fn() = unsafe { mem::transmute(&13) };
144   | ^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered alloc39, but expected a function pointer
145   |
146   = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
147   = note: the raw bytes of the constant (size: $SIZE, align: $ALIGN) {
148               HEX_DUMP
149           }
150
151error[E0080]: evaluation of constant value failed
152  --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL
153   |
154   = note: accessing memory with alignment 1, but alignment 4 is required
155   |
156note: inside `std::ptr::read::<u32>`
157  --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL
158note: inside `ptr::const_ptr::<impl *const u32>::read`
159  --> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
160note: inside `UNALIGNED_READ`
161  --> $DIR/ub-ref-ptr.rs:66:5
162   |
163LL |     ptr.read();
164   |     ^^^^^^^^^^
165
166error: aborting due to 15 previous errors
167
168For more information about this error, try `rustc --explain E0080`.