Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 24699bc

Browse files
committedJul 14, 2022
Auto merge of rust-lang#95956 - yaahc:stable-in-unstable, r=cjgillot
Support unstable moves via stable in unstable items part of https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/moving.20items.20to.20core.20unstably and a blocker of rust-lang#90328. The libs-api team needs the ability to move an already stable item to a new location unstably, in this case for Error in core. Otherwise these changes are insta-stable making them much harder to merge. This PR attempts to solve the problem by checking the stability of path segments as well as the last item in the path itself, which is currently the only thing checked.
2 parents f1a8854 + 3e2c5b5 commit 24699bc

34 files changed

+304
-33
lines changed
 

‎compiler/rustc_attr/src/builtin.rs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ impl ConstStability {
137137
pub enum StabilityLevel {
138138
// Reason for the current stability level and the relevant rust-lang issue
139139
Unstable { reason: Option<Symbol>, issue: Option<NonZeroU32>, is_soft: bool },
140-
Stable { since: Symbol },
140+
Stable { since: Symbol, allowed_through_unstable_modules: bool },
141141
}
142142

143143
impl StabilityLevel {
@@ -172,6 +172,7 @@ where
172172
let mut stab: Option<(Stability, Span)> = None;
173173
let mut const_stab: Option<(ConstStability, Span)> = None;
174174
let mut promotable = false;
175+
let mut allowed_through_unstable_modules = false;
175176

176177
let diagnostic = &sess.parse_sess.span_diagnostic;
177178

@@ -182,6 +183,7 @@ where
182183
sym::unstable,
183184
sym::stable,
184185
sym::rustc_promotable,
186+
sym::rustc_allowed_through_unstable_modules,
185187
]
186188
.iter()
187189
.any(|&s| attr.has_name(s))
@@ -193,6 +195,8 @@ where
193195

194196
if attr.has_name(sym::rustc_promotable) {
195197
promotable = true;
198+
} else if attr.has_name(sym::rustc_allowed_through_unstable_modules) {
199+
allowed_through_unstable_modules = true;
196200
}
197201
// attributes with data
198202
else if let Some(MetaItem { kind: MetaItemKind::List(ref metas), .. }) = meta {
@@ -406,7 +410,7 @@ where
406410

407411
match (feature, since) {
408412
(Some(feature), Some(since)) => {
409-
let level = Stable { since };
413+
let level = Stable { since, allowed_through_unstable_modules: false };
410414
if sym::stable == meta_name {
411415
stab = Some((Stability { level, feature }, attr.span));
412416
} else {
@@ -447,6 +451,27 @@ where
447451
}
448452
}
449453

454+
if allowed_through_unstable_modules {
455+
if let Some((
456+
Stability {
457+
level: StabilityLevel::Stable { ref mut allowed_through_unstable_modules, .. },
458+
..
459+
},
460+
_,
461+
)) = stab
462+
{
463+
*allowed_through_unstable_modules = true;
464+
} else {
465+
struct_span_err!(
466+
diagnostic,
467+
item_sp,
468+
E0789,
469+
"`rustc_allowed_through_unstable_modules` attribute must be paired with a `stable` attribute"
470+
)
471+
.emit();
472+
}
473+
}
474+
450475
(stab, const_stab)
451476
}
452477

‎compiler/rustc_error_codes/src/error_codes.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,4 +644,5 @@ E0788: include_str!("./error_codes/E0788.md"),
644644
// E0721, // `await` keyword
645645
// E0723, // unstable feature in `const` context
646646
// E0738, // Removed; errored on `#[track_caller] fn`s in `extern "Rust" { ... }`.
647+
E0789, // rustc_allowed_through_unstable_modules without stability attribute
647648
}

‎compiler/rustc_feature/src/builtin_attrs.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,9 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
512512
allow_internal_unsafe, Normal, template!(Word), WarnFollowing,
513513
"allow_internal_unsafe side-steps the unsafe_code lint",
514514
),
515+
rustc_attr!(rustc_allowed_through_unstable_modules, Normal, template!(Word), WarnFollowing,
516+
"rustc_allowed_through_unstable_modules special cases accidental stabilizations of stable items \
517+
through unstable paths"),
515518

516519
// ==========================================================================
517520
// Internal attributes: Type system related:

‎compiler/rustc_middle/src/middle/stability.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -471,13 +471,15 @@ impl<'tcx> TyCtxt<'tcx> {
471471
///
472472
/// This function will also check if the item is deprecated.
473473
/// If so, and `id` is not `None`, a deprecated lint attached to `id` will be emitted.
474+
///
475+
/// Returns `true` if item is allowed aka, stable or unstable under an enabled feature.
474476
pub fn check_stability(
475477
self,
476478
def_id: DefId,
477479
id: Option<HirId>,
478480
span: Span,
479481
method_span: Option<Span>,
480-
) {
482+
) -> bool {
481483
self.check_stability_allow_unstable(def_id, id, span, method_span, AllowUnstable::No)
482484
}
483485

@@ -490,14 +492,16 @@ impl<'tcx> TyCtxt<'tcx> {
490492
/// If so, and `id` is not `None`, a deprecated lint attached to `id` will be emitted.
491493
///
492494
/// Pass `AllowUnstable::Yes` to `allow_unstable` to force an unstable item to be allowed. Deprecation warnings will be emitted normally.
495+
///
496+
/// Returns `true` if item is allowed aka, stable or unstable under an enabled feature.
493497
pub fn check_stability_allow_unstable(
494498
self,
495499
def_id: DefId,
496500
id: Option<HirId>,
497501
span: Span,
498502
method_span: Option<Span>,
499503
allow_unstable: AllowUnstable,
500-
) {
504+
) -> bool {
501505
self.check_optional_stability(
502506
def_id,
503507
id,
@@ -516,6 +520,8 @@ impl<'tcx> TyCtxt<'tcx> {
516520
/// missing stability attributes (not necessarily just emit a `bug!`). This is necessary
517521
/// for default generic parameters, which only have stability attributes if they were
518522
/// added after the type on which they're defined.
523+
///
524+
/// Returns `true` if item is allowed aka, stable or unstable under an enabled feature.
519525
pub fn check_optional_stability(
520526
self,
521527
def_id: DefId,
@@ -524,13 +530,16 @@ impl<'tcx> TyCtxt<'tcx> {
524530
method_span: Option<Span>,
525531
allow_unstable: AllowUnstable,
526532
unmarked: impl FnOnce(Span, DefId),
527-
) {
533+
) -> bool {
528534
let soft_handler = |lint, span, msg: &_| {
529535
self.struct_span_lint_hir(lint, id.unwrap_or(hir::CRATE_HIR_ID), span, |lint| {
530536
lint.build(msg).emit();
531537
})
532538
};
533-
match self.eval_stability_allow_unstable(def_id, id, span, method_span, allow_unstable) {
539+
let eval_result =
540+
self.eval_stability_allow_unstable(def_id, id, span, method_span, allow_unstable);
541+
let is_allowed = matches!(eval_result, EvalResult::Allow);
542+
match eval_result {
534543
EvalResult::Allow => {}
535544
EvalResult::Deny { feature, reason, issue, suggestion, is_soft } => report_unstable(
536545
self.sess,
@@ -544,6 +553,8 @@ impl<'tcx> TyCtxt<'tcx> {
544553
),
545554
EvalResult::Unmarked => unmarked(span, def_id),
546555
}
556+
557+
is_allowed
547558
}
548559

549560
pub fn lookup_deprecation(self, id: DefId) -> Option<Deprecation> {

‎compiler/rustc_passes/src/check_attr.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ impl CheckAttrVisitor<'_> {
139139
| sym::rustc_const_stable
140140
| sym::unstable
141141
| sym::stable
142+
| sym::rustc_allowed_through_unstable_modules
142143
| sym::rustc_promotable => self.check_stability_promotable(&attr, span, target),
143144
_ => true,
144145
};

‎compiler/rustc_passes/src/stability.rs

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! A pass that annotates every item and method with its stability level,
22
//! propagating default levels lexically from parent to children ast nodes.
33
4+
use attr::StabilityLevel;
45
use rustc_attr::{self as attr, ConstStability, Stability};
56
use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
67
use rustc_errors::struct_span_err;
@@ -223,7 +224,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
223224

224225
// Check if deprecated_since < stable_since. If it is,
225226
// this is *almost surely* an accident.
226-
if let (&Some(dep_since), &attr::Stable { since: stab_since }) =
227+
if let (&Some(dep_since), &attr::Stable { since: stab_since, .. }) =
227228
(&depr.as_ref().and_then(|(d, _)| d.since), &stab.level)
228229
{
229230
// Explicit version of iter::order::lt to handle parse errors properly
@@ -773,7 +774,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'tcx> {
773774
fn visit_path(&mut self, path: &'tcx hir::Path<'tcx>, id: hir::HirId) {
774775
if let Some(def_id) = path.res.opt_def_id() {
775776
let method_span = path.segments.last().map(|s| s.ident.span);
776-
self.tcx.check_stability_allow_unstable(
777+
let item_is_allowed = self.tcx.check_stability_allow_unstable(
777778
def_id,
778779
Some(id),
779780
path.span,
@@ -783,8 +784,52 @@ impl<'tcx> Visitor<'tcx> for Checker<'tcx> {
783784
} else {
784785
AllowUnstable::No
785786
},
786-
)
787+
);
788+
789+
let is_allowed_through_unstable_modules = |def_id| {
790+
self.tcx
791+
.lookup_stability(def_id)
792+
.map(|stab| match stab.level {
793+
StabilityLevel::Stable { allowed_through_unstable_modules, .. } => {
794+
allowed_through_unstable_modules
795+
}
796+
_ => false,
797+
})
798+
.unwrap_or(false)
799+
};
800+
801+
if item_is_allowed && !is_allowed_through_unstable_modules(def_id) {
802+
// Check parent modules stability as well if the item the path refers to is itself
803+
// stable. We only emit warnings for unstable path segments if the item is stable
804+
// or allowed because stability is often inherited, so the most common case is that
805+
// both the segments and the item are unstable behind the same feature flag.
806+
//
807+
// We check here rather than in `visit_path_segment` to prevent visiting the last
808+
// path segment twice
809+
//
810+
// We include special cases via #[rustc_allowed_through_unstable_modules] for items
811+
// that were accidentally stabilized through unstable paths before this check was
812+
// added, such as `core::intrinsics::transmute`
813+
let parents = path.segments.iter().rev().skip(1);
814+
for path_segment in parents {
815+
if let Some(def_id) = path_segment.res.as_ref().and_then(Res::opt_def_id) {
816+
// use `None` for id to prevent deprecation check
817+
self.tcx.check_stability_allow_unstable(
818+
def_id,
819+
None,
820+
path.span,
821+
None,
822+
if is_unstable_reexport(self.tcx, id) {
823+
AllowUnstable::Yes
824+
} else {
825+
AllowUnstable::No
826+
},
827+
);
828+
}
829+
}
830+
}
787831
}
832+
788833
intravisit::walk_path(self, path)
789834
}
790835
}

‎compiler/rustc_span/src/symbol.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,6 +1191,7 @@ symbols! {
11911191
rustc_allocator_nounwind,
11921192
rustc_allow_const_fn_unstable,
11931193
rustc_allow_incoherent_impl,
1194+
rustc_allowed_through_unstable_modules,
11941195
rustc_attrs,
11951196
rustc_box,
11961197
rustc_builtin_macro,

‎compiler/rustc_typeck/src/astconv/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
439439
// as the rest of the type. As such, we ignore missing
440440
// stability attributes.
441441
},
442-
)
442+
);
443443
}
444444
if let (hir::TyKind::Infer, false) = (&ty.kind, self.astconv.allow_ty_infer()) {
445445
self.inferred_params.push(ty.span);

‎library/core/src/intrinsics.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1457,6 +1457,7 @@ extern "rust-intrinsic" {
14571457
/// }
14581458
/// ```
14591459
#[stable(feature = "rust1", since = "1.0.0")]
1460+
#[cfg_attr(not(bootstrap), rustc_allowed_through_unstable_modules)]
14601461
#[rustc_const_stable(feature = "const_transmute", since = "1.56.0")]
14611462
#[rustc_diagnostic_item = "transmute"]
14621463
pub fn transmute<T, U>(e: T) -> U;
@@ -2649,6 +2650,7 @@ pub const unsafe fn write_bytes<T>(dst: *mut T, val: u8, count: usize) {
26492650
/// Here is an example of how this could cause a problem:
26502651
/// ```no_run
26512652
/// #![feature(const_eval_select)]
2653+
/// #![feature(core_intrinsics)]
26522654
/// use std::hint::unreachable_unchecked;
26532655
/// use std::intrinsics::const_eval_select;
26542656
///

‎library/core/src/macros/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1537,7 +1537,7 @@ pub(crate) mod builtin {
15371537
/// Unstable implementation detail of the `rustc` compiler, do not use.
15381538
#[rustc_builtin_macro]
15391539
#[stable(feature = "rust1", since = "1.0.0")]
1540-
#[allow_internal_unstable(core_intrinsics, libstd_sys_internals)]
1540+
#[allow_internal_unstable(core_intrinsics, libstd_sys_internals, rt)]
15411541
#[deprecated(since = "1.52.0", note = "rustc-serialize is deprecated and no longer supported")]
15421542
#[doc(hidden)] // While technically stable, using it is unstable, and deprecated. Hide it.
15431543
pub macro RustcDecodable($item:item) {
@@ -1547,7 +1547,7 @@ pub(crate) mod builtin {
15471547
/// Unstable implementation detail of the `rustc` compiler, do not use.
15481548
#[rustc_builtin_macro]
15491549
#[stable(feature = "rust1", since = "1.0.0")]
1550-
#[allow_internal_unstable(core_intrinsics)]
1550+
#[allow_internal_unstable(core_intrinsics, rt)]
15511551
#[deprecated(since = "1.52.0", note = "rustc-serialize is deprecated and no longer supported")]
15521552
#[doc(hidden)] // While technically stable, using it is unstable, and deprecated. Hide it.
15531553
pub macro RustcEncodable($item:item) {

‎library/core/tests/unicode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#[test]
22
pub fn version() {
3-
let (major, _minor, _update) = core::unicode::UNICODE_VERSION;
3+
let (major, _minor, _update) = core::char::UNICODE_VERSION;
44
assert!(major >= 10);
55
}

‎library/std/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@
214214
#![cfg_attr(not(bootstrap), deny(ffi_unwind_calls))]
215215
// std may use features in a platform-specific way
216216
#![allow(unused_features)]
217-
#![cfg_attr(test, feature(internal_output_capture, print_internals, update_panic_count))]
217+
#![cfg_attr(test, feature(internal_output_capture, print_internals, update_panic_count, rt))]
218218
#![cfg_attr(
219219
all(target_vendor = "fortanix", target_env = "sgx"),
220220
feature(slice_index_methods, coerce_unsized, sgx_platform)
@@ -297,6 +297,7 @@
297297
// Library features (alloc):
298298
#![feature(alloc_layout_extra)]
299299
#![feature(alloc_c_string)]
300+
#![feature(alloc_ffi)]
300301
#![feature(allocator_api)]
301302
#![feature(get_mut_unchecked)]
302303
#![feature(map_try_insert)]

‎library/std/src/panic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::thread::Result;
1111

1212
#[doc(hidden)]
1313
#[unstable(feature = "edition_panic", issue = "none", reason = "use panic!() instead")]
14-
#[allow_internal_unstable(libstd_sys_internals, const_format_args, core_panic)]
14+
#[allow_internal_unstable(libstd_sys_internals, const_format_args, core_panic, rt)]
1515
#[cfg_attr(not(test), rustc_diagnostic_item = "std_panic_2015_macro")]
1616
#[rustc_macro_transparency = "semitransparent"]
1717
pub macro panic_2015 {

‎src/librustdoc/html/render/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -854,7 +854,7 @@ fn render_stability_since_raw(
854854
}
855855

856856
let const_title_and_stability = match const_stability {
857-
Some(ConstStability { level: StabilityLevel::Stable { since }, .. })
857+
Some(ConstStability { level: StabilityLevel::Stable { since, .. }, .. })
858858
if Some(since) != containing_const_ver =>
859859
{
860860
Some((format!("const since {}", since), format!("const: {}", since)))

‎src/test/codegen/intrinsics/const_eval_select.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#![crate_type = "lib"]
44
#![feature(const_eval_select)]
5+
#![feature(core_intrinsics)]
56

67
use std::intrinsics::const_eval_select;
78

‎src/test/ui/intrinsics/const-eval-select-bad.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#![feature(const_eval_select)]
2+
#![feature(core_intrinsics)]
23

34
use std::intrinsics::const_eval_select;
45

‎src/test/ui/intrinsics/const-eval-select-bad.stderr

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
error[E0277]: the trait bound `[closure@$DIR/const-eval-select-bad.rs:6:27: 6:29]: ~const FnOnce<()>` is not satisfied
2-
--> $DIR/const-eval-select-bad.rs:6:27
1+
error[E0277]: the trait bound `[closure@$DIR/const-eval-select-bad.rs:7:27: 7:29]: ~const FnOnce<()>` is not satisfied
2+
--> $DIR/const-eval-select-bad.rs:7:27
33
|
44
LL | const_eval_select((), || {}, || {});
5-
| ----------------- ^^^^^ expected an `FnOnce<()>` closure, found `[closure@$DIR/const-eval-select-bad.rs:6:27: 6:29]`
5+
| ----------------- ^^^^^ expected an `FnOnce<()>` closure, found `[closure@$DIR/const-eval-select-bad.rs:7:27: 7:29]`
66
| |
77
| required by a bound introduced by this call
88
|
9-
= help: the trait `~const FnOnce<()>` is not implemented for `[closure@$DIR/const-eval-select-bad.rs:6:27: 6:29]`
10-
note: the trait `FnOnce<()>` is implemented for `[closure@$DIR/const-eval-select-bad.rs:6:27: 6:29]`, but that implementation is not `const`
11-
--> $DIR/const-eval-select-bad.rs:6:27
9+
= help: the trait `~const FnOnce<()>` is not implemented for `[closure@$DIR/const-eval-select-bad.rs:7:27: 7:29]`
10+
note: the trait `FnOnce<()>` is implemented for `[closure@$DIR/const-eval-select-bad.rs:7:27: 7:29]`, but that implementation is not `const`
11+
--> $DIR/const-eval-select-bad.rs:7:27
1212
|
1313
LL | const_eval_select((), || {}, || {});
1414
| ^^^^^
15-
= note: wrap the `[closure@$DIR/const-eval-select-bad.rs:6:27: 6:29]` in a closure with no arguments: `|| { /* code */ }`
15+
= note: wrap the `[closure@$DIR/const-eval-select-bad.rs:7:27: 7:29]` in a closure with no arguments: `|| { /* code */ }`
1616
note: required by a bound in `const_eval_select`
1717
--> $SRC_DIR/core/src/intrinsics.rs:LL:COL
1818
|
1919
LL | F: ~const FnOnce<ARG, Output = RET>,
2020
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `const_eval_select`
2121

2222
error[E0277]: the trait bound `{integer}: ~const FnOnce<()>` is not satisfied
23-
--> $DIR/const-eval-select-bad.rs:8:27
23+
--> $DIR/const-eval-select-bad.rs:9:27
2424
|
2525
LL | const_eval_select((), 42, 0xDEADBEEF);
2626
| ----------------- ^^ expected an `FnOnce<()>` closure, found `{integer}`
@@ -36,7 +36,7 @@ LL | F: ~const FnOnce<ARG, Output = RET>,
3636
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `const_eval_select`
3737

3838
error[E0277]: expected a `FnOnce<()>` closure, found `{integer}`
39-
--> $DIR/const-eval-select-bad.rs:8:31
39+
--> $DIR/const-eval-select-bad.rs:9:31
4040
|
4141
LL | const_eval_select((), 42, 0xDEADBEEF);
4242
| ----------------- ^^^^^^^^^^ expected an `FnOnce<()>` closure, found `{integer}`
@@ -52,7 +52,7 @@ LL | G: FnOnce<ARG, Output = RET> + ~const Destruct,
5252
| ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `const_eval_select`
5353

5454
error[E0271]: type mismatch resolving `<fn(i32) -> bool {bar} as FnOnce<(i32,)>>::Output == i32`
55-
--> $DIR/const-eval-select-bad.rs:28:5
55+
--> $DIR/const-eval-select-bad.rs:29:5
5656
|
5757
LL | const_eval_select((1,), foo, bar);
5858
| ^^^^^^^^^^^^^^^^^ expected `i32`, found `bool`
@@ -64,7 +64,7 @@ LL | G: FnOnce<ARG, Output = RET> + ~const Destruct,
6464
| ^^^^^^^^^^^^ required by this bound in `const_eval_select`
6565

6666
error[E0631]: type mismatch in function arguments
67-
--> $DIR/const-eval-select-bad.rs:33:32
67+
--> $DIR/const-eval-select-bad.rs:34:32
6868
|
6969
LL | const fn foo(n: i32) -> i32 {
7070
| --------------------------- found signature of `fn(i32) -> _`

‎src/test/ui/intrinsics/const-eval-select-stability.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#![feature(staged_api)]
22
#![feature(const_eval_select)]
3+
#![feature(core_intrinsics)]
34
#![stable(since = "1.0", feature = "ui_test")]
45

56
use std::intrinsics::const_eval_select;

‎src/test/ui/intrinsics/const-eval-select-stability.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: `const_eval_select` is not yet stable as a const fn
2-
--> $DIR/const-eval-select-stability.rs:16:5
2+
--> $DIR/const-eval-select-stability.rs:17:5
33
|
44
LL | const_eval_select((), nothing, log);
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

‎src/test/ui/intrinsics/const-eval-select-x86_64.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// only-x86_64
33

44
#![feature(const_eval_select)]
5+
#![feature(core_intrinsics)]
56
use std::intrinsics::const_eval_select;
67
use std::arch::x86_64::*;
78
use std::mem::transmute;

‎src/test/ui/intrinsics/const-eval-select.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// run-pass
22

33
#![feature(const_eval_select)]
4+
#![feature(core_intrinsics)]
45

56
use std::intrinsics::const_eval_select;
67

‎src/test/ui/lint/lint-stability.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,11 +191,11 @@ mod inheritance {
191191
stable_mod::unstable(); //~ ERROR use of unstable library feature
192192
stable_mod::stable();
193193

194-
unstable_mod::deprecated();
194+
unstable_mod::deprecated(); //~ ERROR use of unstable library feature
195195
unstable_mod::unstable(); //~ ERROR use of unstable library feature
196196

197197
let _ = Unstable::UnstableVariant; //~ ERROR use of unstable library feature
198-
let _ = Unstable::StableVariant;
198+
let _ = Unstable::StableVariant; //~ ERROR use of unstable library feature
199199

200200
let x: usize = 0;
201201
x.stable();

‎src/test/ui/lint/lint-stability.stderr

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,14 @@ LL | stable_mod::unstable();
294294
|
295295
= help: add `#![feature(unstable_test_feature)]` to the crate attributes to enable
296296

297+
error[E0658]: use of unstable library feature 'unstable_test_feature'
298+
--> $DIR/lint-stability.rs:194:9
299+
|
300+
LL | unstable_mod::deprecated();
301+
| ^^^^^^^^^^^^^^^^^^^^^^^^
302+
|
303+
= help: add `#![feature(unstable_test_feature)]` to the crate attributes to enable
304+
297305
error[E0658]: use of unstable library feature 'unstable_test_feature'
298306
--> $DIR/lint-stability.rs:195:9
299307
|
@@ -310,6 +318,14 @@ LL | let _ = Unstable::UnstableVariant;
310318
|
311319
= help: add `#![feature(unstable_test_feature)]` to the crate attributes to enable
312320

321+
error[E0658]: use of unstable library feature 'unstable_test_feature'
322+
--> $DIR/lint-stability.rs:198:17
323+
|
324+
LL | let _ = Unstable::StableVariant;
325+
| ^^^^^^^^^^^^^^^^^^^^^^^
326+
|
327+
= help: add `#![feature(unstable_test_feature)]` to the crate attributes to enable
328+
313329
error[E0658]: use of unstable library feature 'unstable_test_feature'
314330
--> $DIR/lint-stability.rs:88:48
315331
|
@@ -326,6 +342,6 @@ LL | TypeUnstable = u8,
326342
|
327343
= help: add `#![feature(unstable_test_feature)]` to the crate attributes to enable
328344

329-
error: aborting due to 41 previous errors
345+
error: aborting due to 43 previous errors
330346

331347
For more information about this error, try `rustc --explain E0658`.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#![crate_type = "lib"]
2+
extern crate core;
3+
4+
// Known accidental stabilizations with no known users, slated for un-stabilization
5+
// fully stable @ core::char::UNICODE_VERSION
6+
use core::unicode::UNICODE_VERSION; //~ ERROR use of unstable library feature 'unicode_internals'
7+
8+
// Known accidental stabilizations with known users
9+
// fully stable @ core::mem::transmute
10+
use core::intrinsics::transmute; // depended upon by rand_core
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0658]: use of unstable library feature 'unicode_internals'
2+
--> $DIR/accidental-stable-in-unstable.rs:6:5
3+
|
4+
LL | use core::unicode::UNICODE_VERSION;
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= help: add `#![feature(unicode_internals)]` to the crate attributes to enable
8+
9+
error: aborting due to previous error
10+
11+
For more information about this error, try `rustc --explain E0658`.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Test for new `#[rustc_allowed_through_unstable_modules]` attribute
2+
//
3+
// aux-build:allowed-through-unstable-core.rs
4+
#![crate_type = "lib"]
5+
6+
extern crate allowed_through_unstable_core;
7+
8+
use allowed_through_unstable_core::unstable_module::OldStableTraitAllowedThoughUnstable;
9+
use allowed_through_unstable_core::unstable_module::NewStableTraitNotAllowedThroughUnstable; //~ ERROR use of unstable library feature 'unstable_test_feature'
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0658]: use of unstable library feature 'unstable_test_feature'
2+
--> $DIR/allowed-through-unstable.rs:9:5
3+
|
4+
LL | use allowed_through_unstable_core::unstable_module::NewStableTraitNotAllowedThroughUnstable;
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: see issue #1 <https://github.com/rust-lang/rust/issues/1> for more information
8+
= help: add `#![feature(unstable_test_feature)]` to the crate attributes to enable
9+
10+
error: aborting due to previous error
11+
12+
For more information about this error, try `rustc --explain E0658`.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#![crate_type = "lib"]
2+
#![feature(staged_api)]
3+
#![feature(rustc_attrs)]
4+
#![stable(feature = "stable_test_feature", since = "1.2.0")]
5+
6+
#[unstable(feature = "unstable_test_feature", issue = "1")]
7+
pub mod unstable_module {
8+
#[stable(feature = "stable_test_feature", since = "1.2.0")]
9+
#[rustc_allowed_through_unstable_modules]
10+
pub trait OldStableTraitAllowedThoughUnstable {}
11+
12+
#[stable(feature = "stable_test_feature", since = "1.2.0")]
13+
pub trait NewStableTraitNotAllowedThroughUnstable {}
14+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#![feature(staged_api)]
2+
#![stable(feature = "stable_test_feature", since = "1.2.0")]
3+
4+
#[unstable(feature = "unstable_test_feature", issue = "1")]
5+
pub mod new_unstable_module {
6+
#[stable(feature = "stable_test_feature", since = "1.2.0")]
7+
pub trait OldTrait {}
8+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#![feature(staged_api)]
2+
#![feature(unstable_test_feature)]
3+
#![stable(feature = "stable_test_feature", since = "1.2.0")]
4+
5+
extern crate stable_in_unstable_core;
6+
7+
#[stable(feature = "stable_test_feature", since = "1.2.0")]
8+
pub mod old_stable_module {
9+
#[stable(feature = "stable_test_feature", since = "1.2.0")]
10+
pub use stable_in_unstable_core::new_unstable_module::OldTrait;
11+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// This test is meant to test that we can have a stable item in an unstable module, and that
2+
// calling that item through the unstable module is unstable, but that re-exporting it from another
3+
// crate in a stable module is fine.
4+
//
5+
// This is necessary to support moving items from `std` into `core` or `alloc` unstably while still
6+
// exporting the original stable interface in `std`, such as moving `Error` into `core`.
7+
//
8+
// aux-build:stable-in-unstable-core.rs
9+
// aux-build:stable-in-unstable-std.rs
10+
#![crate_type = "lib"]
11+
12+
extern crate stable_in_unstable_core;
13+
extern crate stable_in_unstable_std;
14+
15+
mod isolated1 {
16+
use stable_in_unstable_core::new_unstable_module; //~ ERROR use of unstable library feature 'unstable_test_feature'
17+
use stable_in_unstable_core::new_unstable_module::OldTrait; //~ ERROR use of unstable library feature 'unstable_test_feature'
18+
}
19+
20+
mod isolated2 {
21+
use stable_in_unstable_std::old_stable_module::OldTrait;
22+
23+
struct LocalType;
24+
25+
impl OldTrait for LocalType {}
26+
}
27+
28+
mod isolated3 {
29+
use stable_in_unstable_core::new_unstable_module::OldTrait; //~ ERROR use of unstable library feature 'unstable_test_feature'
30+
31+
struct LocalType;
32+
33+
impl OldTrait for LocalType {}
34+
}
35+
36+
mod isolated4 {
37+
struct LocalType;
38+
39+
impl stable_in_unstable_core::new_unstable_module::OldTrait for LocalType {} //~ ERROR use of unstable library feature 'unstable_test_feature'
40+
}
41+
42+
mod isolated5 {
43+
struct LocalType;
44+
45+
impl stable_in_unstable_std::old_stable_module::OldTrait for LocalType {}
46+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
error[E0658]: use of unstable library feature 'unstable_test_feature'
2+
--> $DIR/stable-in-unstable.rs:16:9
3+
|
4+
LL | use stable_in_unstable_core::new_unstable_module;
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: see issue #1 <https://github.com/rust-lang/rust/issues/1> for more information
8+
= help: add `#![feature(unstable_test_feature)]` to the crate attributes to enable
9+
10+
error[E0658]: use of unstable library feature 'unstable_test_feature'
11+
--> $DIR/stable-in-unstable.rs:17:9
12+
|
13+
LL | use stable_in_unstable_core::new_unstable_module::OldTrait;
14+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15+
|
16+
= note: see issue #1 <https://github.com/rust-lang/rust/issues/1> for more information
17+
= help: add `#![feature(unstable_test_feature)]` to the crate attributes to enable
18+
19+
error[E0658]: use of unstable library feature 'unstable_test_feature'
20+
--> $DIR/stable-in-unstable.rs:29:9
21+
|
22+
LL | use stable_in_unstable_core::new_unstable_module::OldTrait;
23+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24+
|
25+
= note: see issue #1 <https://github.com/rust-lang/rust/issues/1> for more information
26+
= help: add `#![feature(unstable_test_feature)]` to the crate attributes to enable
27+
28+
error[E0658]: use of unstable library feature 'unstable_test_feature'
29+
--> $DIR/stable-in-unstable.rs:39:10
30+
|
31+
LL | impl stable_in_unstable_core::new_unstable_module::OldTrait for LocalType {}
32+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
33+
|
34+
= note: see issue #1 <https://github.com/rust-lang/rust/issues/1> for more information
35+
= help: add `#![feature(unstable_test_feature)]` to the crate attributes to enable
36+
37+
error: aborting due to 4 previous errors
38+
39+
For more information about this error, try `rustc --explain E0658`.

‎src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ fn check_terminator<'a, 'tcx>(
354354
fn is_const_fn(tcx: TyCtxt<'_>, def_id: DefId, msrv: Option<RustcVersion>) -> bool {
355355
tcx.is_const_fn(def_id)
356356
&& tcx.lookup_const_stability(def_id).map_or(true, |const_stab| {
357-
if let rustc_attr::StabilityLevel::Stable { since } = const_stab.level {
357+
if let rustc_attr::StabilityLevel::Stable { since, .. } = const_stab.level {
358358
// Checking MSRV is manually necessary because `rustc` has no such concept. This entire
359359
// function could be removed if `rustc` provided a MSRV-aware version of `is_const_fn`.
360360
// as a part of an unimplemented MSRV check https://github.com/rust-lang/rust/issues/65262.

‎src/tools/tidy/src/error_codes_check.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use regex::Regex;
1111
// A few of those error codes can't be tested but all the others can and *should* be tested!
1212
const EXEMPTED_FROM_TEST: &[&str] = &[
1313
"E0279", "E0313", "E0377", "E0461", "E0462", "E0465", "E0476", "E0490", "E0514", "E0519",
14-
"E0523", "E0554", "E0640", "E0717", "E0729",
14+
"E0523", "E0554", "E0640", "E0717", "E0729", "E0789",
1515
];
1616

1717
// Some error codes don't have any tests apparently...

0 commit comments

Comments
 (0)
This repository has been archived.