Skip to content

Commit 6632ba1

Browse files
committed
allow rustc_private feature in force-unstable-if-unmarked crates
1 parent 658a329 commit 6632ba1

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

library/std/src/lib.rs

-5
Original file line numberDiff line numberDiff line change
@@ -391,11 +391,6 @@
391391
#![feature(stdarch_internal)]
392392
// tidy-alphabetical-end
393393
//
394-
// Library features (crates without staged_api):
395-
// tidy-alphabetical-start
396-
#![feature(rustc_private)]
397-
// tidy-alphabetical-end
398-
//
399394
// Only for re-exporting:
400395
// tidy-alphabetical-start
401396
#![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)