-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #85555 - LeSeulArtichaut:thir-unsafeck, r=nikomatsakis
Check for more things in THIR unsafeck Reunion of #85306, #85381 and #85419 with conflicts resolved. r? `@nikomatsakis`
- Loading branch information
Showing
67 changed files
with
645 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
error[E0133]: cast of pointer to int is unsafe and requires unsafe function or block | ||
--> $DIR/cast-ptr-to-int-const.rs:10:9 | ||
| | ||
LL | &Y as *const u32 as usize | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ cast of pointer to int | ||
| | ||
= note: casting pointers to integers in constants | ||
|
||
error[E0133]: cast of pointer to int is unsafe and requires unsafe function or block | ||
--> $DIR/cast-ptr-to-int-const.rs:17:5 | ||
| | ||
LL | &0 as *const i32 as usize | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ cast of pointer to int | ||
| | ||
= note: casting pointers to integers in constants | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0133`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,19 @@ | ||
// gate-test-const_raw_ptr_to_usize_cast | ||
// revisions: with_feature without_feature | ||
// revisions: mir thir | ||
// [thir]compile-flags: -Z thir-unsafeck | ||
|
||
#![cfg_attr(with_feature, feature(const_raw_ptr_to_usize_cast))] | ||
#![feature(const_raw_ptr_to_usize_cast)] | ||
|
||
fn main() { | ||
const X: usize = unsafe { | ||
main as usize //[without_feature]~ ERROR casting pointers to integers in constants is unstable | ||
}; | ||
const Y: u32 = 0; | ||
const Z: usize = unsafe { | ||
&Y as *const u32 as usize //[without_feature]~ ERROR is unstable | ||
}; | ||
// Cast in `const` without `unsafe` block | ||
const SAFE: usize = { | ||
&Y as *const u32 as usize //[without_feature]~ ERROR is unstable | ||
//[with_feature]~^ ERROR cast of pointer to int is unsafe and requires unsafe | ||
&Y as *const u32 as usize | ||
//~^ ERROR cast of pointer to int is unsafe and requires unsafe | ||
}; | ||
} | ||
|
||
// Cast in `const fn` without `unsafe` block | ||
const fn test() -> usize { | ||
&0 as *const i32 as usize //[without_feature]~ ERROR is unstable | ||
//[with_feature]~^ ERROR cast of pointer to int is unsafe and requires unsafe | ||
&0 as *const i32 as usize | ||
//~^ ERROR cast of pointer to int is unsafe and requires unsafe | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
error[E0133]: cast of pointer to int is unsafe and requires unsafe function or block | ||
--> $DIR/cast-ptr-to-int-const.rs:10:9 | ||
| | ||
LL | &Y as *const u32 as usize | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ cast of pointer to int | ||
| | ||
= note: casting pointers to integers in constants | ||
|
||
error[E0133]: cast of pointer to int is unsafe and requires unsafe function or block | ||
--> $DIR/cast-ptr-to-int-const.rs:17:5 | ||
| | ||
LL | &0 as *const i32 as usize | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ cast of pointer to int | ||
| | ||
= note: casting pointers to integers in constants | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0133`. |
13 changes: 13 additions & 0 deletions
13
src/test/ui/cast/feature-gate-const_raw_ptr_to_usize_cast.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
fn main() { | ||
const X: usize = unsafe { | ||
main as usize //~ ERROR casting pointers to integers in constants is unstable | ||
}; | ||
const Y: u32 = 0; | ||
const Z: usize = unsafe { | ||
&Y as *const u32 as usize //~ ERROR is unstable | ||
}; | ||
} | ||
|
||
const fn test() -> usize { | ||
&0 as *const i32 as usize //~ ERROR is unstable | ||
} |
30 changes: 30 additions & 0 deletions
30
src/test/ui/cast/feature-gate-const_raw_ptr_to_usize_cast.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
error[E0658]: casting pointers to integers in constants is unstable | ||
--> $DIR/feature-gate-const_raw_ptr_to_usize_cast.rs:3:9 | ||
| | ||
LL | main as usize | ||
| ^^^^^^^^^^^^^ | ||
| | ||
= note: see issue #51910 <https://github.com/rust-lang/rust/issues/51910> for more information | ||
= help: add `#![feature(const_raw_ptr_to_usize_cast)]` to the crate attributes to enable | ||
|
||
error[E0658]: casting pointers to integers in constants is unstable | ||
--> $DIR/feature-gate-const_raw_ptr_to_usize_cast.rs:7:9 | ||
| | ||
LL | &Y as *const u32 as usize | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: see issue #51910 <https://github.com/rust-lang/rust/issues/51910> for more information | ||
= help: add `#![feature(const_raw_ptr_to_usize_cast)]` to the crate attributes to enable | ||
|
||
error[E0658]: casting pointers to integers in constant functions is unstable | ||
--> $DIR/feature-gate-const_raw_ptr_to_usize_cast.rs:12:5 | ||
| | ||
LL | &0 as *const i32 as usize | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: see issue #51910 <https://github.com/rust-lang/rust/issues/51910> for more information | ||
= help: add `#![feature(const_raw_ptr_to_usize_cast)]` to the crate attributes to enable | ||
|
||
error: aborting due to 3 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0658`. |
2 changes: 1 addition & 1 deletion
2
...or/issue-45729-unsafe-in-generator.stderr → ...ssue-45729-unsafe-in-generator.mir.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
// revisions: mir thir | ||
// [thir]compile-flags: -Z thir-unsafeck | ||
|
||
#![feature(generators)] | ||
|
||
fn main() { | ||
|
11 changes: 11 additions & 0 deletions
11
src/test/ui/generator/issue-45729-unsafe-in-generator.thir.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
error[E0133]: dereference of raw pointer is unsafe and requires unsafe function or block | ||
--> $DIR/issue-45729-unsafe-in-generator.rs:8:9 | ||
| | ||
LL | *(1 as *mut u32) = 42; | ||
| ^^^^^^^^^^^^^^^^ dereference of raw pointer | ||
| | ||
= note: raw pointers may be NULL, dangling or unaligned; they can violate aliasing rules and cause data races: all of these are undefined behavior | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0133`. |
2 changes: 1 addition & 1 deletion
2
src/test/ui/intrinsics/issue-28575.stderr → ...test/ui/intrinsics/issue-28575.mir.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
// revisions: mir thir | ||
// [thir]compile-flags: -Z thir-unsafeck | ||
|
||
#![feature(intrinsics)] | ||
|
||
extern "C" { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
error[E0133]: use of extern static is unsafe and requires unsafe function or block | ||
--> $DIR/issue-28575.rs:11:5 | ||
| | ||
LL | FOO() | ||
| ^^^ use of extern static | ||
| | ||
= note: extern statics are not controlled by the Rust type system: invalid data, aliasing violations or data races will cause undefined behavior | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0133`. |
2 changes: 1 addition & 1 deletion
2
src/test/ui/issues/issue-14227.stderr → src/test/ui/issues/issue-14227.mir.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
// revisions: mir thir | ||
// [thir]compile-flags: -Z thir-unsafeck | ||
|
||
extern "C" { | ||
pub static symbol: u32; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
error[E0133]: use of extern static is unsafe and requires unsafe function or block | ||
--> $DIR/issue-14227.rs:7:21 | ||
| | ||
LL | static CRASH: u32 = symbol; | ||
| ^^^^^^ use of extern static | ||
| | ||
= note: extern statics are not controlled by the Rust type system: invalid data, aliasing violations or data races will cause undefined behavior | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0133`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
// revisions: mir thir | ||
// [thir]compile-flags: -Z thir-unsafeck | ||
|
||
mod Y { | ||
pub type X = usize; | ||
extern "C" { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
error[E0015]: calls in statics are limited to constant functions, tuple structs and tuple variants | ||
--> $DIR/issue-16538.rs:14:27 | ||
| | ||
LL | static foo: *const Y::X = Y::foo(Y::x as *const Y::X); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error[E0277]: `*const usize` cannot be shared between threads safely | ||
--> $DIR/issue-16538.rs:14:1 | ||
| | ||
LL | static foo: *const Y::X = Y::foo(Y::x as *const Y::X); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `*const usize` cannot be shared between threads safely | ||
| | ||
= help: the trait `Sync` is not implemented for `*const usize` | ||
= note: shared static variables must have a type that implements `Sync` | ||
|
||
error[E0133]: use of extern static is unsafe and requires unsafe function or block | ||
--> $DIR/issue-16538.rs:14:34 | ||
| | ||
LL | static foo: *const Y::X = Y::foo(Y::x as *const Y::X); | ||
| ^^^^ use of extern static | ||
| | ||
= note: extern statics are not controlled by the Rust type system: invalid data, aliasing violations or data races will cause undefined behavior | ||
|
||
error: aborting due to 3 previous errors | ||
|
||
Some errors have detailed explanations: E0015, E0133, E0277. | ||
For more information about an error, try `rustc --explain E0015`. |
Oops, something went wrong.