Skip to content

Commit a307b47

Browse files
committed
allow rustc_private feature in force-unstable-if-unmarked crates
1 parent 2aa6ea5 commit a307b47

File tree

3 files changed

+22
-12
lines changed

3 files changed

+22
-12
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};
@@ -816,7 +817,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
816817
}
817818
}
818819
Some(ConstStability {
819-
level: StabilityLevel::Unstable { implied_by: implied_feature, .. },
820+
level: StabilityLevel::Unstable { implied_by: implied_feature, issue, .. },
820821
feature,
821822
..
822823
}) => {
@@ -839,7 +840,23 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
839840
// to allow this.
840841
let feature_enabled = callee.is_local()
841842
|| tcx.features().enabled(feature)
842-
|| implied_feature.is_some_and(|f| tcx.features().enabled(f));
843+
|| implied_feature.is_some_and(|f| tcx.features().enabled(f))
844+
|| {
845+
// When we're compiling the compiler itself we may pull in
846+
// crates from crates.io, but those crates may depend on other
847+
// crates also pulled in from crates.io. We want to ideally be
848+
// able to compile everything without requiring upstream
849+
// modifications, so in the case that this looks like a
850+
// `rustc_private` crate (e.g., a compiler crate) and we also have
851+
// the `-Z force-unstable-if-unmarked` flag present (we're
852+
// compiling a compiler crate), then let this missing feature
853+
// annotation slide.
854+
// This matches what we do in `eval_stability_allow_unstable` for
855+
// regular stability.
856+
feature == sym::rustc_private
857+
&& issue == NonZero::new(27812)
858+
&& self.tcx.sess.opts.unstable_opts.force_unstable_if_unmarked
859+
};
843860
// We do *not* honor this if we are in the "danger zone": we have to enforce
844861
// recursive const-stability and the callee is not safe-to-expose. In that
845862
// case we need `check_op` to do the check.

library/std/src/lib.rs

-5
Original file line numberDiff line numberDiff line change
@@ -393,11 +393,6 @@
393393
#![feature(stdarch_internal)]
394394
// tidy-alphabetical-end
395395
//
396-
// Library features (crates without staged_api):
397-
// tidy-alphabetical-start
398-
#![feature(rustc_private)]
399-
// tidy-alphabetical-end
400-
//
401396
// Only for re-exporting:
402397
// tidy-alphabetical-start
403398
#![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() {}

0 commit comments

Comments
 (0)