-
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.
honor rustc_const_stable_indirect in non-staged_api crate with -Zforc…
…e-unstable-if-unmarked
- Loading branch information
Showing
10 changed files
with
155 additions
and
3 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
1 change: 1 addition & 0 deletions
1
tests/ui/consts/min_const_fn/auxiliary/unmarked_const_fn_crate.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 @@ | ||
pub const fn just_a_fn() {} |
8 changes: 8 additions & 0 deletions
8
tests/ui/consts/min_const_fn/auxiliary/unstable_if_unmarked_const_fn_crate.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,8 @@ | ||
//@ compile-flags: -Zforce-unstable-if-unmarked | ||
|
||
#![feature(rustc_attrs)] | ||
|
||
pub const fn not_stably_const() {} | ||
|
||
#[rustc_const_stable_indirect] | ||
pub const fn expose_on_stable() {} |
23 changes: 23 additions & 0 deletions
23
tests/ui/consts/min_const_fn/recursive_const_stab_unmarked_crate_imports.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,23 @@ | ||
//@ aux-build:unstable_if_unmarked_const_fn_crate.rs | ||
//@ aux-build:unmarked_const_fn_crate.rs | ||
#![feature(staged_api, rustc_private)] | ||
#![stable(since="1.0.0", feature = "stable")] | ||
|
||
extern crate unstable_if_unmarked_const_fn_crate; | ||
extern crate unmarked_const_fn_crate; | ||
|
||
#[stable(feature = "rust1", since = "1.0.0")] | ||
#[rustc_const_stable(feature = "rust1", since = "1.0.0")] | ||
const fn stable_fn() { | ||
// This one is fine. | ||
unstable_if_unmarked_const_fn_crate::expose_on_stable(); | ||
// This one is not. | ||
unstable_if_unmarked_const_fn_crate::not_stably_const(); | ||
//~^ERROR: cannot use `#[feature(rustc_private)]` | ||
unmarked_const_fn_crate::just_a_fn(); | ||
//~^ERROR: cannot be (indirectly) exposed to stable | ||
} | ||
|
||
fn main() { | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
tests/ui/consts/min_const_fn/recursive_const_stab_unmarked_crate_imports.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,28 @@ | ||
error: const function that might be (indirectly) exposed to stable cannot use `#[feature(rustc_private)]` | ||
--> $DIR/recursive_const_stab_unmarked_crate_imports.rs:15:5 | ||
| | ||
LL | unstable_if_unmarked_const_fn_crate::not_stably_const(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= help: mark the callee as `#[rustc_const_stable_indirect]` if it does not itself require any unsafe features | ||
help: if the caller is not (yet) meant to be exposed to stable, add `#[rustc_const_unstable]` (this is what you probably want to do) | ||
| | ||
LL + #[rustc_const_unstable(feature = "...", issue = "...")] | ||
LL | const fn stable_fn() { | ||
| | ||
help: otherwise, as a last resort `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks (this requires team approval) | ||
| | ||
LL + #[rustc_allow_const_fn_unstable(rustc_private)] | ||
LL | const fn stable_fn() { | ||
| | ||
|
||
error: `just_a_fn` cannot be (indirectly) exposed to stable | ||
--> $DIR/recursive_const_stab_unmarked_crate_imports.rs:17:5 | ||
| | ||
LL | unmarked_const_fn_crate::just_a_fn(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= help: either mark the callee as `#[rustc_const_stable_indirect]`, or the caller as `#[rustc_const_unstable]` | ||
|
||
error: aborting due to 2 previous errors | ||
|
24 changes: 24 additions & 0 deletions
24
tests/ui/consts/min_const_fn/recursive_const_stab_unstable_if_unmarked.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,24 @@ | ||
//@ compile-flags: -Zforce-unstable-if-unmarked | ||
//@ edition: 2021 | ||
#![feature(const_async_blocks, rustc_attrs, rustc_private)] | ||
|
||
pub const fn not_stably_const() { | ||
// We need to do something const-unstable here. | ||
// For now we use `async`, eventually we might have to add a auxiliary crate | ||
// as a dependency just to be sure we have something const-unstable. | ||
let _x = async { 15 }; | ||
} | ||
|
||
#[rustc_const_stable_indirect] | ||
pub const fn expose_on_stable() { | ||
// Calling `not_stably_const` here is *not* okay. | ||
not_stably_const(); | ||
//~^ERROR: cannot use `#[feature(rustc_private)]` | ||
// Also directly using const-unstable things is not okay. | ||
let _x = async { 15 }; | ||
//~^ERROR: cannot use `#[feature(const_async_blocks)]` | ||
} | ||
|
||
fn main() { | ||
const { expose_on_stable() }; | ||
} |
37 changes: 37 additions & 0 deletions
37
tests/ui/consts/min_const_fn/recursive_const_stab_unstable_if_unmarked.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,37 @@ | ||
error: const function that might be (indirectly) exposed to stable cannot use `#[feature(rustc_private)]` | ||
--> $DIR/recursive_const_stab_unstable_if_unmarked.rs:15:5 | ||
| | ||
LL | not_stably_const(); | ||
| ^^^^^^^^^^^^^^^^^^ | ||
| | ||
= help: mark the callee as `#[rustc_const_stable_indirect]` if it does not itself require any unsafe features | ||
help: if the caller is not (yet) meant to be exposed to stable, add `#[rustc_const_unstable]` (this is what you probably want to do) | ||
| | ||
LL + #[rustc_const_unstable(feature = "...", issue = "...")] | ||
LL | pub const fn expose_on_stable() { | ||
| | ||
help: otherwise, as a last resort `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks (this requires team approval) | ||
| | ||
LL + #[rustc_allow_const_fn_unstable(rustc_private)] | ||
LL | pub const fn expose_on_stable() { | ||
| | ||
|
||
error: const function that might be (indirectly) exposed to stable cannot use `#[feature(const_async_blocks)]` | ||
--> $DIR/recursive_const_stab_unstable_if_unmarked.rs:18:14 | ||
| | ||
LL | let _x = async { 15 }; | ||
| ^^^^^^^^^^^^ | ||
| | ||
help: if the function is not (yet) meant to be exposed to stable, add `#[rustc_const_unstable]` (this is what you probably want to do) | ||
| | ||
LL + #[rustc_const_unstable(feature = "...", issue = "...")] | ||
LL | pub const fn expose_on_stable() { | ||
| | ||
help: otherwise, as a last resort `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks (this requires team approval) | ||
| | ||
LL + #[rustc_allow_const_fn_unstable(const_async_blocks)] | ||
LL | pub const fn expose_on_stable() { | ||
| | ||
|
||
error: aborting due to 2 previous errors | ||
|