Skip to content

Commit 8bf4b22

Browse files
committed
allow rustc_private feature in force-unstable-if-unmarked crates
1 parent 96f9ada commit 8bf4b22

File tree

4 files changed

+61
-22
lines changed

4 files changed

+61
-22
lines changed

compiler/rustc_const_eval/src/check_consts/check.rs

+19-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
use std::assert_matches::assert_matches;
44
use std::borrow::Cow;
55
use std::mem;
6+
use std::num::NonZero;
67
use std::ops::Deref;
78

89
use rustc_attr::{ConstStability, StabilityLevel};
@@ -780,7 +781,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
780781
}
781782
}
782783
Some(ConstStability {
783-
level: StabilityLevel::Unstable { implied_by: implied_feature, .. },
784+
level: StabilityLevel::Unstable { implied_by: implied_feature, issue, .. },
784785
feature,
785786
..
786787
}) => {
@@ -803,7 +804,23 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
803804
// to allow this.
804805
let feature_enabled = callee.is_local()
805806
|| tcx.features().enabled(feature)
806-
|| implied_feature.is_some_and(|f| tcx.features().enabled(f));
807+
|| implied_feature.is_some_and(|f| tcx.features().enabled(f))
808+
|| {
809+
// When we're compiling the compiler itself we may pull in
810+
// crates from crates.io, but those crates may depend on other
811+
// crates also pulled in from crates.io. We want to ideally be
812+
// able to compile everything without requiring upstream
813+
// modifications, so in the case that this looks like a
814+
// `rustc_private` crate (e.g., a compiler crate) and we also have
815+
// the `-Z force-unstable-if-unmarked` flag present (we're
816+
// compiling a compiler crate), then let this missing feature
817+
// annotation slide.
818+
// This matches what we do in `eval_stability_allow_unstable` for
819+
// regular stability.
820+
feature == sym::rustc_private
821+
&& issue == NonZero::new(27812)
822+
&& self.tcx.sess.opts.unstable_opts.force_unstable_if_unmarked
823+
};
807824
// We do *not* honor this if we are in the "danger zone": we have to enforce
808825
// recursive const-stability and the callee is not safe-to-expose. In that
809826
// case we need `check_op` to do the check.

library/std/src/lib.rs

-5
Original file line numberDiff line numberDiff line change
@@ -392,11 +392,6 @@
392392
#![feature(stdarch_internal)]
393393
// tidy-alphabetical-end
394394
//
395-
// Library features (crates without staged_api):
396-
// tidy-alphabetical-start
397-
#![feature(rustc_private)]
398-
// tidy-alphabetical-end
399-
//
400395
// Only for re-exporting:
401396
// tidy-alphabetical-start
402397
#![feature(assert_matches)]

tests/ui/consts/min_const_fn/recursive_const_stab_unmarked_crate_imports.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
//@ aux-build:unstable_if_unmarked_const_fn_crate.rs
22
//@ aux-build:unmarked_const_fn_crate.rs
33
#![feature(staged_api, rustc_private)]
4-
#![stable(since="1.0.0", feature = "stable")]
4+
#![stable(since = "1.0.0", feature = "stable")]
55

6-
extern crate unstable_if_unmarked_const_fn_crate;
76
extern crate unmarked_const_fn_crate;
7+
extern crate unstable_if_unmarked_const_fn_crate;
88

99
#[stable(feature = "rust1", since = "1.0.0")]
1010
#[rustc_const_stable(feature = "rust1", since = "1.0.0")]
@@ -18,6 +18,4 @@ const fn stable_fn() {
1818
//~^ERROR: cannot be (indirectly) exposed to stable
1919
}
2020

21-
fn main() {
22-
23-
}
21+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,48 @@
1-
error: const function that might be (indirectly) exposed to stable cannot use `#[feature(rustc_private)]`
1+
error[E0658]: use of unstable library feature 'rustc_private': this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via `Cargo.toml` instead?
2+
--> $DIR/recursive_const_stab_unmarked_crate_imports.rs:6:1
3+
|
4+
LL | extern crate unstable_if_unmarked_const_fn_crate;
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: see issue #27812 <https://github.com/rust-lang/rust/issues/27812> for more information
8+
= help: add `#![feature(rustc_private)]` to the crate attributes to enable
9+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
10+
11+
error[E0658]: use of unstable library feature 'rustc_private': this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via `Cargo.toml` instead?
12+
--> $DIR/recursive_const_stab_unmarked_crate_imports.rs:13:5
13+
|
14+
LL | unstable_if_unmarked_const_fn_crate::expose_on_stable();
15+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16+
|
17+
= note: see issue #27812 <https://github.com/rust-lang/rust/issues/27812> for more information
18+
= help: add `#![feature(rustc_private)]` to the crate attributes to enable
19+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
20+
21+
error[E0658]: use of unstable library feature 'rustc_private': this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via `Cargo.toml` instead?
222
--> $DIR/recursive_const_stab_unmarked_crate_imports.rs:15:5
323
|
424
LL | unstable_if_unmarked_const_fn_crate::not_stably_const();
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
626
|
7-
= help: mark the callee as `#[rustc_const_stable_indirect]` if it does not itself require any unsafe features
8-
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)
27+
= note: see issue #27812 <https://github.com/rust-lang/rust/issues/27812> for more information
28+
= help: add `#![feature(rustc_private)]` to the crate attributes to enable
29+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
30+
31+
error: `expose_on_stable` is not yet stable as a const fn
32+
--> $DIR/recursive_const_stab_unmarked_crate_imports.rs:13:5
933
|
10-
LL + #[rustc_const_unstable(feature = "...", issue = "...")]
11-
LL | const fn stable_fn() {
34+
LL | unstable_if_unmarked_const_fn_crate::expose_on_stable();
35+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1236
|
13-
help: otherwise, as a last resort `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks (this requires team approval)
37+
= help: add `#![feature(rustc_private)]` to the crate attributes to enable
38+
39+
error: `not_stably_const` is not yet stable as a const fn
40+
--> $DIR/recursive_const_stab_unmarked_crate_imports.rs:15:5
1441
|
15-
LL + #[rustc_allow_const_fn_unstable(rustc_private)]
16-
LL | const fn stable_fn() {
42+
LL | unstable_if_unmarked_const_fn_crate::not_stably_const();
43+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1744
|
45+
= help: add `#![feature(rustc_private)]` to the crate attributes to enable
1846

1947
error: `just_a_fn` cannot be (indirectly) exposed to stable
2048
--> $DIR/recursive_const_stab_unmarked_crate_imports.rs:17:5
@@ -24,5 +52,6 @@ LL | unmarked_const_fn_crate::just_a_fn();
2452
|
2553
= help: either mark the callee as `#[rustc_const_stable_indirect]`, or the caller as `#[rustc_const_unstable]`
2654

27-
error: aborting due to 2 previous errors
55+
error: aborting due to 6 previous errors
2856

57+
For more information about this error, try `rustc --explain E0658`.

0 commit comments

Comments
 (0)