-
Notifications
You must be signed in to change notification settings - Fork 12.3k
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 #105147 - nbdd0121:inline_const_unsafe, r=oli-obk
Allow unsafe through inline const Handle similar to closures. Address #104087 (comment) Note that this PR does not fix the issue for `unsafe { [0; function_requiring_unsafe()] }`. This is fundamentally unfixable for MIR unsafeck IMO. This PR also does not fix unsafety checking for inline const in pattern position. It actually breaks it, allowing unsafe functions to be used in inline const in pattern position without unsafe blocks. Inline const in pattern position is not visible in MIR so ignored by MIR unsafety checking (currently it is also not checked by borrow checker, which is the reason why it's considered an incomplete feature). `@rustbot` label: +T-lang +F-inline_const
- Loading branch information
Showing
12 changed files
with
177 additions
and
19 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
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
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]: call to unsafe function is unsafe and requires unsafe function or block | ||
--> $DIR/expr-unsafe-err.rs:8:9 | ||
| | ||
LL | require_unsafe(); | ||
| ^^^^^^^^^^^^^^^^ call to unsafe function | ||
| | ||
= note: consult the function's documentation for information on how to avoid 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// revisions: mir thir | ||
// [thir]compile-flags: -Z thir-unsafeck | ||
#![feature(inline_const)] | ||
const unsafe fn require_unsafe() -> usize { 1 } | ||
|
||
fn main() { | ||
const { | ||
require_unsafe(); | ||
//~^ ERROR [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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
error[E0133]: call to unsafe function `require_unsafe` is unsafe and requires unsafe function or block | ||
--> $DIR/expr-unsafe-err.rs:8:9 | ||
| | ||
LL | require_unsafe(); | ||
| ^^^^^^^^^^^^^^^^ call to unsafe function | ||
| | ||
= note: consult the function's documentation for information on how to avoid 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
warning: unnecessary `unsafe` block | ||
--> $DIR/expr-unsafe.rs:12:13 | ||
| | ||
LL | unsafe {} | ||
| ^^^^^^ unnecessary `unsafe` block | ||
| | ||
note: the lint level is defined here | ||
--> $DIR/expr-unsafe.rs:4:9 | ||
| | ||
LL | #![warn(unused_unsafe)] | ||
| ^^^^^^^^^^^^^ | ||
|
||
warning: 1 warning emitted | ||
|
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,16 @@ | ||
// check-pass | ||
// revisions: mir thir | ||
// [thir]compile-flags: -Z thir-unsafeck | ||
#![warn(unused_unsafe)] | ||
#![feature(inline_const)] | ||
const unsafe fn require_unsafe() -> usize { 1 } | ||
|
||
fn main() { | ||
unsafe { | ||
const { | ||
require_unsafe(); | ||
unsafe {} | ||
//~^ WARNING unnecessary `unsafe` block | ||
} | ||
} | ||
} |
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,17 @@ | ||
warning: unnecessary `unsafe` block | ||
--> $DIR/expr-unsafe.rs:12:13 | ||
| | ||
LL | unsafe { | ||
| ------ because it's nested under this `unsafe` block | ||
... | ||
LL | unsafe {} | ||
| ^^^^^^ unnecessary `unsafe` block | ||
| | ||
note: the lint level is defined here | ||
--> $DIR/expr-unsafe.rs:4:9 | ||
| | ||
LL | #![warn(unused_unsafe)] | ||
| ^^^^^^^^^^^^^ | ||
|
||
warning: 1 warning emitted | ||
|
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,17 @@ | ||
// ignore-test This is currently broken | ||
// revisions: mir thir | ||
// [thir]compile-flags: -Z thir-unsafeck | ||
|
||
#![allow(incomplete_features)] | ||
#![feature(inline_const_pat)] | ||
|
||
const unsafe fn require_unsafe() -> usize { 1 } | ||
|
||
fn main() { | ||
match () { | ||
const { | ||
require_unsafe(); | ||
//~^ ERROR [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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// ignore-test This is currently broken | ||
// check-pass | ||
// revisions: mir thir | ||
// [thir]compile-flags: -Z thir-unsafeck | ||
|
||
#![allow(incomplete_features)] | ||
#![warn(unused_unsafe)] | ||
#![feature(inline_const_pat)] | ||
|
||
const unsafe fn require_unsafe() -> usize { 1 } | ||
|
||
fn main() { | ||
unsafe { | ||
match () { | ||
const { | ||
require_unsafe(); | ||
unsafe {} | ||
//~^ WARNING unnecessary `unsafe` block | ||
} => (), | ||
} | ||
} | ||
} |