From e7fe5456c53a8cc620a10f6284c366d6de0b7df0 Mon Sep 17 00:00:00 2001 From: Jane Lusby Date: Mon, 11 Apr 2022 18:12:26 -0700 Subject: [PATCH 01/10] Support unstable moves via stable in unstable items --- compiler/rustc_middle/src/middle/stability.rs | 17 +++++-- compiler/rustc_passes/src/stability.rs | 29 +++++++++++- compiler/rustc_typeck/src/astconv/mod.rs | 2 +- library/core/src/intrinsics.rs | 1 + library/core/src/unicode/mod.rs | 5 +- library/std/src/lib.rs | 3 +- library/std/src/panic.rs | 2 +- .../codegen/intrinsics/const_eval_select.rs | 1 + .../ui/intrinsics/const-eval-select-bad.rs | 1 + .../intrinsics/const-eval-select-bad.stderr | 26 +++++++++-- .../intrinsics/const-eval-select-stability.rs | 1 + .../const-eval-select-stability.stderr | 2 +- .../ui/intrinsics/const-eval-select-x86_64.rs | 1 + src/test/ui/intrinsics/const-eval-select.rs | 1 + src/test/ui/lint/lint-stability.rs | 4 +- src/test/ui/lint/lint-stability.stderr | 18 +++++++- .../auxiliary/stable-in-unstable-core.rs | 8 ++++ .../auxiliary/stable-in-unstable-std.rs | 11 +++++ .../stability-attribute/stable-in-unstable.rs | 46 +++++++++++++++++++ .../stable-in-unstable.stderr | 39 ++++++++++++++++ 20 files changed, 200 insertions(+), 18 deletions(-) create mode 100644 src/test/ui/stability-attribute/auxiliary/stable-in-unstable-core.rs create mode 100644 src/test/ui/stability-attribute/auxiliary/stable-in-unstable-std.rs create mode 100644 src/test/ui/stability-attribute/stable-in-unstable.rs create mode 100644 src/test/ui/stability-attribute/stable-in-unstable.stderr diff --git a/compiler/rustc_middle/src/middle/stability.rs b/compiler/rustc_middle/src/middle/stability.rs index 802b7852bace1..9f00c6ac1126a 100644 --- a/compiler/rustc_middle/src/middle/stability.rs +++ b/compiler/rustc_middle/src/middle/stability.rs @@ -471,13 +471,15 @@ impl<'tcx> TyCtxt<'tcx> { /// /// This function will also check if the item is deprecated. /// If so, and `id` is not `None`, a deprecated lint attached to `id` will be emitted. + /// + /// Returns `true` if item is allowed aka, stable or unstable under an enabled feature. pub fn check_stability( self, def_id: DefId, id: Option, span: Span, method_span: Option, - ) { + ) -> bool { self.check_stability_allow_unstable(def_id, id, span, method_span, AllowUnstable::No) } @@ -497,7 +499,7 @@ impl<'tcx> TyCtxt<'tcx> { span: Span, method_span: Option, allow_unstable: AllowUnstable, - ) { + ) -> bool { self.check_optional_stability( def_id, id, @@ -516,6 +518,8 @@ impl<'tcx> TyCtxt<'tcx> { /// missing stability attributes (not necessarily just emit a `bug!`). This is necessary /// for default generic parameters, which only have stability attributes if they were /// added after the type on which they're defined. + /// + /// Returns `true` if item is allowed aka, stable or unstable under an enabled feature. pub fn check_optional_stability( self, def_id: DefId, @@ -524,13 +528,16 @@ impl<'tcx> TyCtxt<'tcx> { method_span: Option, allow_unstable: AllowUnstable, unmarked: impl FnOnce(Span, DefId), - ) { + ) -> bool { let soft_handler = |lint, span, msg: &_| { self.struct_span_lint_hir(lint, id.unwrap_or(hir::CRATE_HIR_ID), span, |lint| { lint.build(msg).emit(); }) }; - match self.eval_stability_allow_unstable(def_id, id, span, method_span, allow_unstable) { + let eval_result = + self.eval_stability_allow_unstable(def_id, id, span, method_span, allow_unstable); + let is_allowed = matches!(eval_result, EvalResult::Allow); + match eval_result { EvalResult::Allow => {} EvalResult::Deny { feature, reason, issue, suggestion, is_soft } => report_unstable( self.sess, @@ -544,6 +551,8 @@ impl<'tcx> TyCtxt<'tcx> { ), EvalResult::Unmarked => unmarked(span, def_id), } + + is_allowed } pub fn lookup_deprecation(self, id: DefId) -> Option { diff --git a/compiler/rustc_passes/src/stability.rs b/compiler/rustc_passes/src/stability.rs index 12050dceb60a6..df6051bb59a6a 100644 --- a/compiler/rustc_passes/src/stability.rs +++ b/compiler/rustc_passes/src/stability.rs @@ -807,7 +807,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'tcx> { fn visit_path(&mut self, path: &'tcx hir::Path<'tcx>, id: hir::HirId) { if let Some(def_id) = path.res.opt_def_id() { let method_span = path.segments.last().map(|s| s.ident.span); - self.tcx.check_stability_allow_unstable( + let item_is_allowed = self.tcx.check_stability_allow_unstable( def_id, Some(id), path.span, @@ -817,8 +817,33 @@ impl<'tcx> Visitor<'tcx> for Checker<'tcx> { } else { AllowUnstable::No }, - ) + ); + + if item_is_allowed { + // Check parent modules stability as well + // + // We check here rather than in `visit_path_segment` to prevent visiting the last + // path segment twice + let parents = path.segments.iter().rev().skip(1); + for path_segment in parents { + if let Some(def_id) = path_segment.res.as_ref().and_then(Res::opt_def_id) { + // use `None` for id to prevent deprecation check + self.tcx.check_stability_allow_unstable( + def_id, + None, + path.span, + None, + if is_unstable_reexport(self.tcx, id) { + AllowUnstable::Yes + } else { + AllowUnstable::No + }, + ) + } + } + } } + intravisit::walk_path(self, path) } } diff --git a/compiler/rustc_typeck/src/astconv/mod.rs b/compiler/rustc_typeck/src/astconv/mod.rs index 0a2b54eec47cd..b5b90b389d977 100644 --- a/compiler/rustc_typeck/src/astconv/mod.rs +++ b/compiler/rustc_typeck/src/astconv/mod.rs @@ -439,7 +439,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { // as the rest of the type. As such, we ignore missing // stability attributes. }, - ) + ); } if let (hir::TyKind::Infer, false) = (&ty.kind, self.astconv.allow_ty_infer()) { self.inferred_params.push(ty.span); diff --git a/library/core/src/intrinsics.rs b/library/core/src/intrinsics.rs index 2895c923adc13..cb6f42f1cc021 100644 --- a/library/core/src/intrinsics.rs +++ b/library/core/src/intrinsics.rs @@ -2649,6 +2649,7 @@ pub const unsafe fn write_bytes(dst: *mut T, val: u8, count: usize) { /// Here is an example of how this could cause a problem: /// ```no_run /// #![feature(const_eval_select)] +/// #![feature(core_intrinsics)] /// use std::hint::unreachable_unchecked; /// use std::intrinsics::const_eval_select; /// diff --git a/library/core/src/unicode/mod.rs b/library/core/src/unicode/mod.rs index 72fa059b787df..e8b888c950700 100644 --- a/library/core/src/unicode/mod.rs +++ b/library/core/src/unicode/mod.rs @@ -1,7 +1,9 @@ -#![unstable(feature = "unicode_internals", issue = "none")] +#![stable(feature = "unicode_version", since = "1.45.0")] #![allow(missing_docs)] +#[unstable(feature = "unicode_internals", issue = "none")] pub(crate) mod printable; +#[unstable(feature = "unicode_internals", issue = "none")] mod unicode_data; /// The version of [Unicode](https://www.unicode.org/) that the Unicode parts of @@ -18,6 +20,7 @@ mod unicode_data; pub const UNICODE_VERSION: (u8, u8, u8) = unicode_data::UNICODE_VERSION; // For use in liballoc, not re-exported in libstd. +#[unstable(feature = "unicode_internals", issue = "none")] pub use unicode_data::{ case_ignorable::lookup as Case_Ignorable, cased::lookup as Cased, conversions, }; diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index 298321f41e400..8bd597d49aa5e 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -214,7 +214,7 @@ #![cfg_attr(not(bootstrap), deny(ffi_unwind_calls))] // std may use features in a platform-specific way #![allow(unused_features)] -#![cfg_attr(test, feature(internal_output_capture, print_internals, update_panic_count))] +#![cfg_attr(test, feature(internal_output_capture, print_internals, update_panic_count, rt))] #![cfg_attr( all(target_vendor = "fortanix", target_env = "sgx"), feature(slice_index_methods, coerce_unsized, sgx_platform) @@ -297,6 +297,7 @@ // Library features (alloc): #![feature(alloc_layout_extra)] #![feature(alloc_c_string)] +#![feature(alloc_ffi)] #![feature(allocator_api)] #![feature(get_mut_unchecked)] #![feature(map_try_insert)] diff --git a/library/std/src/panic.rs b/library/std/src/panic.rs index ac16f476143ce..45bc56efb3b99 100644 --- a/library/std/src/panic.rs +++ b/library/std/src/panic.rs @@ -11,7 +11,7 @@ use crate::thread::Result; #[doc(hidden)] #[unstable(feature = "edition_panic", issue = "none", reason = "use panic!() instead")] -#[allow_internal_unstable(libstd_sys_internals, const_format_args, core_panic)] +#[allow_internal_unstable(libstd_sys_internals, const_format_args, core_panic, rt)] #[cfg_attr(not(test), rustc_diagnostic_item = "std_panic_2015_macro")] #[rustc_macro_transparency = "semitransparent"] pub macro panic_2015 { diff --git a/src/test/codegen/intrinsics/const_eval_select.rs b/src/test/codegen/intrinsics/const_eval_select.rs index 34e653b4b9dd4..db8a04763d35d 100644 --- a/src/test/codegen/intrinsics/const_eval_select.rs +++ b/src/test/codegen/intrinsics/const_eval_select.rs @@ -2,6 +2,7 @@ #![crate_type = "lib"] #![feature(const_eval_select)] +#![feature(core_intrinsics)] use std::intrinsics::const_eval_select; diff --git a/src/test/ui/intrinsics/const-eval-select-bad.rs b/src/test/ui/intrinsics/const-eval-select-bad.rs index 7d924e2b7f366..52f4e594f1a0a 100644 --- a/src/test/ui/intrinsics/const-eval-select-bad.rs +++ b/src/test/ui/intrinsics/const-eval-select-bad.rs @@ -1,4 +1,5 @@ #![feature(const_eval_select)] +#![feature(core_intrinsics)] use std::intrinsics::const_eval_select; diff --git a/src/test/ui/intrinsics/const-eval-select-bad.stderr b/src/test/ui/intrinsics/const-eval-select-bad.stderr index 1d3bff3a724ba..bdd5b700a92e2 100644 --- a/src/test/ui/intrinsics/const-eval-select-bad.stderr +++ b/src/test/ui/intrinsics/const-eval-select-bad.stderr @@ -1,3 +1,4 @@ +<<<<<<< HEAD error[E0277]: the trait bound `[closure@$DIR/const-eval-select-bad.rs:6:27: 6:29]: ~const FnOnce<()>` is not satisfied --> $DIR/const-eval-select-bad.rs:6:27 | @@ -13,6 +14,23 @@ note: the trait `FnOnce<()>` is implemented for `[closure@$DIR/const-eval-select LL | const_eval_select((), || {}, || {}); | ^^^^^ = note: wrap the `[closure@$DIR/const-eval-select-bad.rs:6:27: 6:29]` in a closure with no arguments: `|| { /* code */ }` +======= +error[E0277]: the trait bound `[closure@$DIR/const-eval-select-bad.rs:7:27: 7:32]: ~const FnOnce<()>` is not satisfied + --> $DIR/const-eval-select-bad.rs:7:27 + | +LL | const_eval_select((), || {}, || {}); + | ----------------- ^^^^^ expected an `FnOnce<()>` closure, found `[closure@$DIR/const-eval-select-bad.rs:7:27: 7:32]` + | | + | required by a bound introduced by this call + | + = help: the trait `~const FnOnce<()>` is not implemented for `[closure@$DIR/const-eval-select-bad.rs:7:27: 7:32]` +note: the trait `FnOnce<()>` is implemented for `[closure@$DIR/const-eval-select-bad.rs:7:27: 7:32]`, but that implementation is not `const` + --> $DIR/const-eval-select-bad.rs:7:27 + | +LL | const_eval_select((), || {}, || {}); + | ^^^^^ + = note: wrap the `[closure@$DIR/const-eval-select-bad.rs:7:27: 7:32]` in a closure with no arguments: `|| { /* code */ }` +>>>>>>> c1798b7c60e... Support unstable moves via stable in unstable items note: required by a bound in `const_eval_select` --> $SRC_DIR/core/src/intrinsics.rs:LL:COL | @@ -20,7 +38,7 @@ LL | F: ~const FnOnce, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `const_eval_select` error[E0277]: the trait bound `{integer}: ~const FnOnce<()>` is not satisfied - --> $DIR/const-eval-select-bad.rs:8:27 + --> $DIR/const-eval-select-bad.rs:9:27 | LL | const_eval_select((), 42, 0xDEADBEEF); | ----------------- ^^ expected an `FnOnce<()>` closure, found `{integer}` @@ -36,7 +54,7 @@ LL | F: ~const FnOnce, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `const_eval_select` error[E0277]: expected a `FnOnce<()>` closure, found `{integer}` - --> $DIR/const-eval-select-bad.rs:8:31 + --> $DIR/const-eval-select-bad.rs:9:31 | LL | const_eval_select((), 42, 0xDEADBEEF); | ----------------- ^^^^^^^^^^ expected an `FnOnce<()>` closure, found `{integer}` @@ -52,7 +70,7 @@ LL | G: FnOnce + ~const Destruct, | ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `const_eval_select` error[E0271]: type mismatch resolving ` bool {bar} as FnOnce<(i32,)>>::Output == i32` - --> $DIR/const-eval-select-bad.rs:28:5 + --> $DIR/const-eval-select-bad.rs:29:5 | LL | const_eval_select((1,), foo, bar); | ^^^^^^^^^^^^^^^^^ expected `i32`, found `bool` @@ -64,7 +82,7 @@ LL | G: FnOnce + ~const Destruct, | ^^^^^^^^^^^^ required by this bound in `const_eval_select` error[E0631]: type mismatch in function arguments - --> $DIR/const-eval-select-bad.rs:33:32 + --> $DIR/const-eval-select-bad.rs:34:32 | LL | const fn foo(n: i32) -> i32 { | --------------------------- found signature of `fn(i32) -> _` diff --git a/src/test/ui/intrinsics/const-eval-select-stability.rs b/src/test/ui/intrinsics/const-eval-select-stability.rs index db2462aee5922..f9554decec16b 100644 --- a/src/test/ui/intrinsics/const-eval-select-stability.rs +++ b/src/test/ui/intrinsics/const-eval-select-stability.rs @@ -1,5 +1,6 @@ #![feature(staged_api)] #![feature(const_eval_select)] +#![feature(core_intrinsics)] #![stable(since = "1.0", feature = "ui_test")] use std::intrinsics::const_eval_select; diff --git a/src/test/ui/intrinsics/const-eval-select-stability.stderr b/src/test/ui/intrinsics/const-eval-select-stability.stderr index 79641bbb46abe..65b507b887b46 100644 --- a/src/test/ui/intrinsics/const-eval-select-stability.stderr +++ b/src/test/ui/intrinsics/const-eval-select-stability.stderr @@ -1,5 +1,5 @@ error: `const_eval_select` is not yet stable as a const fn - --> $DIR/const-eval-select-stability.rs:16:5 + --> $DIR/const-eval-select-stability.rs:17:5 | LL | const_eval_select((), nothing, log); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/test/ui/intrinsics/const-eval-select-x86_64.rs b/src/test/ui/intrinsics/const-eval-select-x86_64.rs index afec8e054bb76..f3924acf0fa8b 100644 --- a/src/test/ui/intrinsics/const-eval-select-x86_64.rs +++ b/src/test/ui/intrinsics/const-eval-select-x86_64.rs @@ -2,6 +2,7 @@ // only-x86_64 #![feature(const_eval_select)] +#![feature(core_intrinsics)] use std::intrinsics::const_eval_select; use std::arch::x86_64::*; use std::mem::transmute; diff --git a/src/test/ui/intrinsics/const-eval-select.rs b/src/test/ui/intrinsics/const-eval-select.rs index 744db2f15b056..9ff20d3fbdd9e 100644 --- a/src/test/ui/intrinsics/const-eval-select.rs +++ b/src/test/ui/intrinsics/const-eval-select.rs @@ -1,6 +1,7 @@ // run-pass #![feature(const_eval_select)] +#![feature(core_intrinsics)] use std::intrinsics::const_eval_select; diff --git a/src/test/ui/lint/lint-stability.rs b/src/test/ui/lint/lint-stability.rs index 464b32c5f43ed..d0f0e9f807123 100644 --- a/src/test/ui/lint/lint-stability.rs +++ b/src/test/ui/lint/lint-stability.rs @@ -191,11 +191,11 @@ mod inheritance { stable_mod::unstable(); //~ ERROR use of unstable library feature stable_mod::stable(); - unstable_mod::deprecated(); + unstable_mod::deprecated(); //~ ERROR use of unstable library feature unstable_mod::unstable(); //~ ERROR use of unstable library feature let _ = Unstable::UnstableVariant; //~ ERROR use of unstable library feature - let _ = Unstable::StableVariant; + let _ = Unstable::StableVariant; //~ ERROR use of unstable library feature let x: usize = 0; x.stable(); diff --git a/src/test/ui/lint/lint-stability.stderr b/src/test/ui/lint/lint-stability.stderr index 167140ef92b46..bd1a57dc4cc50 100644 --- a/src/test/ui/lint/lint-stability.stderr +++ b/src/test/ui/lint/lint-stability.stderr @@ -294,6 +294,14 @@ LL | stable_mod::unstable(); | = help: add `#![feature(unstable_test_feature)]` to the crate attributes to enable +error[E0658]: use of unstable library feature 'unstable_test_feature' + --> $DIR/lint-stability.rs:194:9 + | +LL | unstable_mod::deprecated(); + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: add `#![feature(unstable_test_feature)]` to the crate attributes to enable + error[E0658]: use of unstable library feature 'unstable_test_feature' --> $DIR/lint-stability.rs:195:9 | @@ -310,6 +318,14 @@ LL | let _ = Unstable::UnstableVariant; | = help: add `#![feature(unstable_test_feature)]` to the crate attributes to enable +error[E0658]: use of unstable library feature 'unstable_test_feature' + --> $DIR/lint-stability.rs:198:17 + | +LL | let _ = Unstable::StableVariant; + | ^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: add `#![feature(unstable_test_feature)]` to the crate attributes to enable + error[E0658]: use of unstable library feature 'unstable_test_feature' --> $DIR/lint-stability.rs:88:48 | @@ -326,6 +342,6 @@ LL | TypeUnstable = u8, | = help: add `#![feature(unstable_test_feature)]` to the crate attributes to enable -error: aborting due to 41 previous errors +error: aborting due to 43 previous errors For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/stability-attribute/auxiliary/stable-in-unstable-core.rs b/src/test/ui/stability-attribute/auxiliary/stable-in-unstable-core.rs new file mode 100644 index 0000000000000..e45b00f994af4 --- /dev/null +++ b/src/test/ui/stability-attribute/auxiliary/stable-in-unstable-core.rs @@ -0,0 +1,8 @@ +#![feature(staged_api)] +#![stable(feature = "stable_test_feature", since = "1.2.0")] + +#[unstable(feature = "unstable_test_feature", issue = "1")] +pub mod new_unstable_module { + #[stable(feature = "stable_test_feature", since = "1.2.0")] + pub trait OldTrait {} +} diff --git a/src/test/ui/stability-attribute/auxiliary/stable-in-unstable-std.rs b/src/test/ui/stability-attribute/auxiliary/stable-in-unstable-std.rs new file mode 100644 index 0000000000000..28ad8c28da158 --- /dev/null +++ b/src/test/ui/stability-attribute/auxiliary/stable-in-unstable-std.rs @@ -0,0 +1,11 @@ +#![feature(staged_api)] +#![feature(unstable_test_feature)] +#![stable(feature = "stable_test_feature", since = "1.2.0")] + +extern crate stable_in_unstable_core; + +#[stable(feature = "stable_test_feature", since = "1.2.0")] +pub mod old_stable_module { + #[stable(feature = "stable_test_feature", since = "1.2.0")] + pub use stable_in_unstable_core::new_unstable_module::OldTrait; +} diff --git a/src/test/ui/stability-attribute/stable-in-unstable.rs b/src/test/ui/stability-attribute/stable-in-unstable.rs new file mode 100644 index 0000000000000..272a1a972340c --- /dev/null +++ b/src/test/ui/stability-attribute/stable-in-unstable.rs @@ -0,0 +1,46 @@ +// This test is meant to test that we can have a stable item in an unstable module, and that +// calling that item through the unstable module is unstable, but that re-exporting it from another +// crate in a stable module is fine. +// +// This is necessary to support moving items from `std` into `core` or `alloc` unstably while still +// exporting the original stable interface in `std`, such as moving `Error` into `core`. +// +// aux-build:stable-in-unstable-core.rs +// aux-build:stable-in-unstable-std.rs +#![crate_type = "lib"] + +extern crate stable_in_unstable_core; +extern crate stable_in_unstable_std; + +mod isolated1 { + use stable_in_unstable_core::new_unstable_module; //~ ERROR use of unstable library feature 'unstable_test_feature' + use stable_in_unstable_core::new_unstable_module::OldTrait; //~ ERROR use of unstable library feature 'unstable_test_feature' +} + +mod isolated2 { + use stable_in_unstable_std::old_stable_module::OldTrait; + + struct LocalType; + + impl OldTrait for LocalType {} +} + +mod isolated3 { + use stable_in_unstable_core::new_unstable_module::OldTrait; //~ ERROR use of unstable library feature 'unstable_test_feature' + + struct LocalType; + + impl OldTrait for LocalType {} +} + +mod isolated4 { + struct LocalType; + + impl stable_in_unstable_core::new_unstable_module::OldTrait for LocalType {} //~ ERROR use of unstable library feature 'unstable_test_feature' +} + +mod isolated5 { + struct LocalType; + + impl stable_in_unstable_std::old_stable_module::OldTrait for LocalType {} +} diff --git a/src/test/ui/stability-attribute/stable-in-unstable.stderr b/src/test/ui/stability-attribute/stable-in-unstable.stderr new file mode 100644 index 0000000000000..e123d83584c81 --- /dev/null +++ b/src/test/ui/stability-attribute/stable-in-unstable.stderr @@ -0,0 +1,39 @@ +error[E0658]: use of unstable library feature 'unstable_test_feature' + --> $DIR/stable-in-unstable.rs:16:9 + | +LL | use stable_in_unstable_core::new_unstable_module; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: see issue #1 for more information + = help: add `#![feature(unstable_test_feature)]` to the crate attributes to enable + +error[E0658]: use of unstable library feature 'unstable_test_feature' + --> $DIR/stable-in-unstable.rs:17:9 + | +LL | use stable_in_unstable_core::new_unstable_module::OldTrait; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: see issue #1 for more information + = help: add `#![feature(unstable_test_feature)]` to the crate attributes to enable + +error[E0658]: use of unstable library feature 'unstable_test_feature' + --> $DIR/stable-in-unstable.rs:29:9 + | +LL | use stable_in_unstable_core::new_unstable_module::OldTrait; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: see issue #1 for more information + = help: add `#![feature(unstable_test_feature)]` to the crate attributes to enable + +error[E0658]: use of unstable library feature 'unstable_test_feature' + --> $DIR/stable-in-unstable.rs:39:10 + | +LL | impl stable_in_unstable_core::new_unstable_module::OldTrait for LocalType {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: see issue #1 for more information + = help: add `#![feature(unstable_test_feature)]` to the crate attributes to enable + +error: aborting due to 4 previous errors + +For more information about this error, try `rustc --explain E0658`. From d68cb1f9a3b7c066332d9f86f2a6884badce6e4b Mon Sep 17 00:00:00 2001 From: Jane Losare-Lusby Date: Fri, 29 Apr 2022 22:35:11 +0000 Subject: [PATCH 02/10] revert changes to unicode stability --- library/core/src/unicode/mod.rs | 5 +---- library/core/tests/unicode.rs | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/library/core/src/unicode/mod.rs b/library/core/src/unicode/mod.rs index e8b888c950700..72fa059b787df 100644 --- a/library/core/src/unicode/mod.rs +++ b/library/core/src/unicode/mod.rs @@ -1,9 +1,7 @@ -#![stable(feature = "unicode_version", since = "1.45.0")] +#![unstable(feature = "unicode_internals", issue = "none")] #![allow(missing_docs)] -#[unstable(feature = "unicode_internals", issue = "none")] pub(crate) mod printable; -#[unstable(feature = "unicode_internals", issue = "none")] mod unicode_data; /// The version of [Unicode](https://www.unicode.org/) that the Unicode parts of @@ -20,7 +18,6 @@ mod unicode_data; pub const UNICODE_VERSION: (u8, u8, u8) = unicode_data::UNICODE_VERSION; // For use in liballoc, not re-exported in libstd. -#[unstable(feature = "unicode_internals", issue = "none")] pub use unicode_data::{ case_ignorable::lookup as Case_Ignorable, cased::lookup as Cased, conversions, }; diff --git a/library/core/tests/unicode.rs b/library/core/tests/unicode.rs index c28ea859115e1..bbace0ef66ca3 100644 --- a/library/core/tests/unicode.rs +++ b/library/core/tests/unicode.rs @@ -1,5 +1,5 @@ #[test] pub fn version() { - let (major, _minor, _update) = core::unicode::UNICODE_VERSION; + let (major, _minor, _update) = core::char::UNICODE_VERSION; assert!(major >= 10); } From 67fe8423a358e03a661d2c18e643572db4e00157 Mon Sep 17 00:00:00 2001 From: Jane Lusby Date: Sat, 7 May 2022 11:08:31 -0700 Subject: [PATCH 03/10] update comment --- compiler/rustc_passes/src/stability.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_passes/src/stability.rs b/compiler/rustc_passes/src/stability.rs index df6051bb59a6a..30f34d96f1212 100644 --- a/compiler/rustc_passes/src/stability.rs +++ b/compiler/rustc_passes/src/stability.rs @@ -820,7 +820,10 @@ impl<'tcx> Visitor<'tcx> for Checker<'tcx> { ); if item_is_allowed { - // Check parent modules stability as well + // Check parent modules stability as well if the item the path refers to is itself + // stable. We only emit warnings for unstable path segments if the item is stable + // because stability is often inherited, so the most common case is that both the + // segments and the item are unstable behind the same feature flag. // // We check here rather than in `visit_path_segment` to prevent visiting the last // path segment twice From a13f30036aed7151f77a04d227501bfb822c8cb5 Mon Sep 17 00:00:00 2001 From: Jane Lusby Date: Sat, 7 May 2022 11:31:53 -0700 Subject: [PATCH 04/10] clarify comment --- compiler/rustc_passes/src/stability.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_passes/src/stability.rs b/compiler/rustc_passes/src/stability.rs index 30f34d96f1212..046fdc3dbf49c 100644 --- a/compiler/rustc_passes/src/stability.rs +++ b/compiler/rustc_passes/src/stability.rs @@ -822,8 +822,8 @@ impl<'tcx> Visitor<'tcx> for Checker<'tcx> { if item_is_allowed { // Check parent modules stability as well if the item the path refers to is itself // stable. We only emit warnings for unstable path segments if the item is stable - // because stability is often inherited, so the most common case is that both the - // segments and the item are unstable behind the same feature flag. + // or allowed because stability is often inherited, so the most common case is that + // both the segments and the item are unstable behind the same feature flag. // // We check here rather than in `visit_path_segment` to prevent visiting the last // path segment twice From b55453dbad4fb032d5b00c218146e1b053774a08 Mon Sep 17 00:00:00 2001 From: Jane Lusby Date: Mon, 9 May 2022 15:18:53 -0700 Subject: [PATCH 05/10] add opt in attribute for stable-in-unstable items --- compiler/rustc_attr/src/builtin.rs | 29 +++++++++++++++++-- compiler/rustc_error_codes/src/error_codes.rs | 1 + compiler/rustc_feature/src/builtin_attrs.rs | 3 ++ compiler/rustc_passes/src/check_attr.rs | 1 + compiler/rustc_passes/src/stability.rs | 21 ++++++++++++-- compiler/rustc_span/src/symbol.rs | 1 + library/core/src/intrinsics.rs | 1 + src/librustdoc/html/render/mod.rs | 2 +- .../accidental-stable-in-unstable.rs | 10 +++++++ .../accidental-stable-in-unstable.stderr | 11 +++++++ .../allow-through-unstable-misuse.rs | 8 +++++ .../allowed-through-unstable.rs | 9 ++++++ .../allowed-through-unstable.stderr | 12 ++++++++ .../allowed-through-unstable-core.rs | 14 +++++++++ .../clippy_utils/src/qualify_min_const_fn.rs | 2 +- 15 files changed, 119 insertions(+), 6 deletions(-) create mode 100644 src/test/ui/stability-attribute/accidental-stable-in-unstable.rs create mode 100644 src/test/ui/stability-attribute/accidental-stable-in-unstable.stderr create mode 100644 src/test/ui/stability-attribute/allow-through-unstable-misuse.rs create mode 100644 src/test/ui/stability-attribute/allowed-through-unstable.rs create mode 100644 src/test/ui/stability-attribute/allowed-through-unstable.stderr create mode 100644 src/test/ui/stability-attribute/auxiliary/allowed-through-unstable-core.rs diff --git a/compiler/rustc_attr/src/builtin.rs b/compiler/rustc_attr/src/builtin.rs index ce7c0eb72cd24..46643df84ccdd 100644 --- a/compiler/rustc_attr/src/builtin.rs +++ b/compiler/rustc_attr/src/builtin.rs @@ -137,7 +137,7 @@ impl ConstStability { pub enum StabilityLevel { // Reason for the current stability level and the relevant rust-lang issue Unstable { reason: Option, issue: Option, is_soft: bool }, - Stable { since: Symbol }, + Stable { since: Symbol, allowed_through_unstable_modules: bool }, } impl StabilityLevel { @@ -172,6 +172,7 @@ where let mut stab: Option<(Stability, Span)> = None; let mut const_stab: Option<(ConstStability, Span)> = None; let mut promotable = false; + let mut allowed_through_unstable_modules = false; let diagnostic = &sess.parse_sess.span_diagnostic; @@ -182,6 +183,7 @@ where sym::unstable, sym::stable, sym::rustc_promotable, + sym::rustc_allowed_through_unstable_modules, ] .iter() .any(|&s| attr.has_name(s)) @@ -193,6 +195,8 @@ where if attr.has_name(sym::rustc_promotable) { promotable = true; + } else if attr.has_name(sym::rustc_allowed_through_unstable_modules) { + allowed_through_unstable_modules = true; } // attributes with data else if let Some(MetaItem { kind: MetaItemKind::List(ref metas), .. }) = meta { @@ -406,7 +410,7 @@ where match (feature, since) { (Some(feature), Some(since)) => { - let level = Stable { since }; + let level = Stable { since, allowed_through_unstable_modules: false }; if sym::stable == meta_name { stab = Some((Stability { level, feature }, attr.span)); } else { @@ -447,6 +451,27 @@ where } } + if allowed_through_unstable_modules { + if let Some(( + Stability { + level: StabilityLevel::Stable { ref mut allowed_through_unstable_modules, .. }, + .. + }, + _, + )) = stab + { + *allowed_through_unstable_modules = true; + } else { + struct_span_err!( + diagnostic, + item_sp, + E0788, + "`rustc_allowed_through_unstable_modules` attribute must be paired with a `stable` attribute" + ) + .emit(); + } + } + (stab, const_stab) } diff --git a/compiler/rustc_error_codes/src/error_codes.rs b/compiler/rustc_error_codes/src/error_codes.rs index d507293ccb0d7..56f29dcc5ce9f 100644 --- a/compiler/rustc_error_codes/src/error_codes.rs +++ b/compiler/rustc_error_codes/src/error_codes.rs @@ -644,4 +644,5 @@ E0788: include_str!("./error_codes/E0788.md"), // E0721, // `await` keyword // E0723, // unstable feature in `const` context // E0738, // Removed; errored on `#[track_caller] fn`s in `extern "Rust" { ... }`. + E0788, // rustc_allowed_through_unstable_modules without stability attribute } diff --git a/compiler/rustc_feature/src/builtin_attrs.rs b/compiler/rustc_feature/src/builtin_attrs.rs index 6fcdfe44d8f64..c806df8214586 100644 --- a/compiler/rustc_feature/src/builtin_attrs.rs +++ b/compiler/rustc_feature/src/builtin_attrs.rs @@ -512,6 +512,9 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[ allow_internal_unsafe, Normal, template!(Word), WarnFollowing, "allow_internal_unsafe side-steps the unsafe_code lint", ), + rustc_attr!(rustc_allowed_through_unstable_modules, Normal, template!(Word), WarnFollowing, + "rustc_allowed_through_unstable_modules special cases accidental stabilizations of stable items \ + through unstable paths"), // ========================================================================== // Internal attributes: Type system related: diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index d0723c68a77e8..7bfa4d37e8c40 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -139,6 +139,7 @@ impl CheckAttrVisitor<'_> { | sym::rustc_const_stable | sym::unstable | sym::stable + | sym::rustc_allowed_through_unstable_modules | sym::rustc_promotable => self.check_stability_promotable(&attr, span, target), _ => true, }; diff --git a/compiler/rustc_passes/src/stability.rs b/compiler/rustc_passes/src/stability.rs index 046fdc3dbf49c..cf23e0ae5ef23 100644 --- a/compiler/rustc_passes/src/stability.rs +++ b/compiler/rustc_passes/src/stability.rs @@ -1,6 +1,7 @@ //! A pass that annotates every item and method with its stability level, //! propagating default levels lexically from parent to children ast nodes. +use attr::StabilityLevel; use rustc_attr::{self as attr, ConstStability, Stability}; use rustc_data_structures::fx::{FxHashSet, FxIndexMap}; use rustc_errors::struct_span_err; @@ -224,7 +225,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> { // Check if deprecated_since < stable_since. If it is, // this is *almost surely* an accident. - if let (&Some(dep_since), &attr::Stable { since: stab_since }) = + if let (&Some(dep_since), &attr::Stable { since: stab_since, .. }) = (&depr.as_ref().and_then(|(d, _)| d.since), &stab.level) { // Explicit version of iter::order::lt to handle parse errors properly @@ -819,7 +820,19 @@ impl<'tcx> Visitor<'tcx> for Checker<'tcx> { }, ); - if item_is_allowed { + let is_allowed_through_unstable_modules = |def_id| { + self.tcx + .lookup_stability(def_id) + .map(|stab| match stab.level { + StabilityLevel::Stable { allowed_through_unstable_modules, .. } => { + allowed_through_unstable_modules + } + _ => false, + }) + .unwrap_or(false) + }; + + if item_is_allowed && !is_allowed_through_unstable_modules(def_id) { // Check parent modules stability as well if the item the path refers to is itself // stable. We only emit warnings for unstable path segments if the item is stable // or allowed because stability is often inherited, so the most common case is that @@ -827,6 +840,10 @@ impl<'tcx> Visitor<'tcx> for Checker<'tcx> { // // We check here rather than in `visit_path_segment` to prevent visiting the last // path segment twice + // + // We include special cases via #[rustc_allowed_through_unstable_modules] for items + // that were accidentally stabilized through unstable paths before this check was + // added, such as `core::intrinsics::transmute` let parents = path.segments.iter().rev().skip(1); for path_segment in parents { if let Some(def_id) = path_segment.res.as_ref().and_then(Res::opt_def_id) { diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 9b6967621f1dc..61a3100c04920 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -1191,6 +1191,7 @@ symbols! { rustc_allocator_nounwind, rustc_allow_const_fn_unstable, rustc_allow_incoherent_impl, + rustc_allowed_through_unstable_modules, rustc_attrs, rustc_box, rustc_builtin_macro, diff --git a/library/core/src/intrinsics.rs b/library/core/src/intrinsics.rs index cb6f42f1cc021..9097ffc2cc5a7 100644 --- a/library/core/src/intrinsics.rs +++ b/library/core/src/intrinsics.rs @@ -1457,6 +1457,7 @@ extern "rust-intrinsic" { /// } /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[cfg_attr(not(bootstrap), rustc_allowed_through_unstable_modules)] #[rustc_const_stable(feature = "const_transmute", since = "1.56.0")] #[rustc_diagnostic_item = "transmute"] pub fn transmute(e: T) -> U; diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index 459b0fed6e872..c1fdece9ec6da 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -854,7 +854,7 @@ fn render_stability_since_raw( } let const_title_and_stability = match const_stability { - Some(ConstStability { level: StabilityLevel::Stable { since }, .. }) + Some(ConstStability { level: StabilityLevel::Stable { since, .. }, .. }) if Some(since) != containing_const_ver => { Some((format!("const since {}", since), format!("const: {}", since))) diff --git a/src/test/ui/stability-attribute/accidental-stable-in-unstable.rs b/src/test/ui/stability-attribute/accidental-stable-in-unstable.rs new file mode 100644 index 0000000000000..f8bbe90cfc53b --- /dev/null +++ b/src/test/ui/stability-attribute/accidental-stable-in-unstable.rs @@ -0,0 +1,10 @@ +#![crate_type = "lib"] +extern crate core; + +// Known accidental stabilizations with no known users, slated for un-stabilization +// fully stable @ core::char::UNICODE_VERSION +use core::unicode::UNICODE_VERSION; //~ ERROR use of unstable library feature 'unicode_internals' + +// Known accidental stabilizations with known users +// fully stable @ core::mem::transmute +use core::intrinsics::transmute; // depended upon by rand_core diff --git a/src/test/ui/stability-attribute/accidental-stable-in-unstable.stderr b/src/test/ui/stability-attribute/accidental-stable-in-unstable.stderr new file mode 100644 index 0000000000000..ff733822cab98 --- /dev/null +++ b/src/test/ui/stability-attribute/accidental-stable-in-unstable.stderr @@ -0,0 +1,11 @@ +error[E0658]: use of unstable library feature 'unicode_internals' + --> $DIR/accidental-stable-in-unstable.rs:6:5 + | +LL | use core::unicode::UNICODE_VERSION; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: add `#![feature(unicode_internals)]` to the crate attributes to enable + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/stability-attribute/allow-through-unstable-misuse.rs b/src/test/ui/stability-attribute/allow-through-unstable-misuse.rs new file mode 100644 index 0000000000000..7f942309e049b --- /dev/null +++ b/src/test/ui/stability-attribute/allow-through-unstable-misuse.rs @@ -0,0 +1,8 @@ +#![crate_type = "lib"] +#![feature(staged_api)] +#![feature(rustc_attrs)] +#![stable(feature = "foo", since = "1.0.0")] + +#[unstable(feature = "bar", issue = "none")] +#[rustc_allowed_through_unstable_modules] +pub struct UnstableType(()); diff --git a/src/test/ui/stability-attribute/allowed-through-unstable.rs b/src/test/ui/stability-attribute/allowed-through-unstable.rs new file mode 100644 index 0000000000000..ff0228e4da6a8 --- /dev/null +++ b/src/test/ui/stability-attribute/allowed-through-unstable.rs @@ -0,0 +1,9 @@ +// Test for new `#[rustc_allowed_through_unstable_modules]` attribute +// +// aux-build:allowed-through-unstable-core.rs +#![crate_type = "lib"] + +extern crate allowed_through_unstable_core; + +use allowed_through_unstable_core::unstable_module::OldStableTraitAllowedThoughUnstable; +use allowed_through_unstable_core::unstable_module::NewStableTraitNotAllowedThroughUnstable; //~ ERROR use of unstable library feature 'unstable_test_feature' diff --git a/src/test/ui/stability-attribute/allowed-through-unstable.stderr b/src/test/ui/stability-attribute/allowed-through-unstable.stderr new file mode 100644 index 0000000000000..70b1dc3010a40 --- /dev/null +++ b/src/test/ui/stability-attribute/allowed-through-unstable.stderr @@ -0,0 +1,12 @@ +error[E0658]: use of unstable library feature 'unstable_test_feature' + --> $DIR/allowed-through-unstable.rs:10:5 + | +LL | use allowed_through_unstable_core::unstable_module::NewStableTraitNotAllowedThroughUnstable; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: see issue #1 for more information + = help: add `#![feature(unstable_test_feature)]` to the crate attributes to enable + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/stability-attribute/auxiliary/allowed-through-unstable-core.rs b/src/test/ui/stability-attribute/auxiliary/allowed-through-unstable-core.rs new file mode 100644 index 0000000000000..b597009a309c9 --- /dev/null +++ b/src/test/ui/stability-attribute/auxiliary/allowed-through-unstable-core.rs @@ -0,0 +1,14 @@ +#![crate_type = "lib"] +#![feature(staged_api)] +#![feature(rustc_attrs)] +#![stable(feature = "stable_test_feature", since = "1.2.0")] + +#[unstable(feature = "unstable_test_feature", issue = "1")] +pub mod unstable_module { + #[stable(feature = "stable_test_feature", since = "1.2.0")] + #[rustc_allowed_through_unstable_modules] + pub trait OldStableTraitAllowedThoughUnstable {} + + #[stable(feature = "stable_test_feature", since = "1.2.0")] + pub trait NewStableTraitNotAllowedThroughUnstable {} +} diff --git a/src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs b/src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs index 498dcbb89006d..0e19b0296f6ed 100644 --- a/src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs +++ b/src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs @@ -353,7 +353,7 @@ fn check_terminator<'a, 'tcx>( fn is_const_fn(tcx: TyCtxt<'_>, def_id: DefId, msrv: Option) -> bool { tcx.is_const_fn(def_id) && tcx.lookup_const_stability(def_id).map_or(true, |const_stab| { - if let rustc_attr::StabilityLevel::Stable { since } = const_stab.level { + if let rustc_attr::StabilityLevel::Stable { since, .. } = const_stab.level { // Checking MSRV is manually necessary because `rustc` has no such concept. This entire // function could be removed if `rustc` provided a MSRV-aware version of `is_const_fn`. // as a part of an unimplemented MSRV check https://github.com/rust-lang/rust/issues/65262. From 0715616b51dd7d3254c1259420aa1461716cc56b Mon Sep 17 00:00:00 2001 From: Jane Lusby Date: Mon, 13 Jun 2022 15:05:19 -0700 Subject: [PATCH 06/10] add rt flag to allowed internal unstable for RustcEncodable/Decodable --- library/core/src/macros/mod.rs | 4 ++-- .../ui/stability-attribute/rustc-encodable-stability.rs | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 src/test/ui/stability-attribute/rustc-encodable-stability.rs diff --git a/library/core/src/macros/mod.rs b/library/core/src/macros/mod.rs index 673a39c298f7d..bd62bc5c3056c 100644 --- a/library/core/src/macros/mod.rs +++ b/library/core/src/macros/mod.rs @@ -1537,7 +1537,7 @@ pub(crate) mod builtin { /// Unstable implementation detail of the `rustc` compiler, do not use. #[rustc_builtin_macro] #[stable(feature = "rust1", since = "1.0.0")] - #[allow_internal_unstable(core_intrinsics, libstd_sys_internals)] + #[allow_internal_unstable(core_intrinsics, libstd_sys_internals, rt)] #[deprecated(since = "1.52.0", note = "rustc-serialize is deprecated and no longer supported")] #[doc(hidden)] // While technically stable, using it is unstable, and deprecated. Hide it. pub macro RustcDecodable($item:item) { @@ -1547,7 +1547,7 @@ pub(crate) mod builtin { /// Unstable implementation detail of the `rustc` compiler, do not use. #[rustc_builtin_macro] #[stable(feature = "rust1", since = "1.0.0")] - #[allow_internal_unstable(core_intrinsics)] + #[allow_internal_unstable(core_intrinsics, rt)] #[deprecated(since = "1.52.0", note = "rustc-serialize is deprecated and no longer supported")] #[doc(hidden)] // While technically stable, using it is unstable, and deprecated. Hide it. pub macro RustcEncodable($item:item) { diff --git a/src/test/ui/stability-attribute/rustc-encodable-stability.rs b/src/test/ui/stability-attribute/rustc-encodable-stability.rs new file mode 100644 index 0000000000000..18eff27d9a53c --- /dev/null +++ b/src/test/ui/stability-attribute/rustc-encodable-stability.rs @@ -0,0 +1,8 @@ +// edition:2018 +#![allow(deprecated)] +extern crate rustc_serialize; + +#[derive(RustcDecodable, RustcEncodable)] +struct ArbitraryTestType(()); + +fn main() {} From 87eafe82e88074fe6e850919a84f44c5e895b71b Mon Sep 17 00:00:00 2001 From: Jane Losare-Lusby Date: Thu, 7 Jul 2022 18:50:28 +0000 Subject: [PATCH 07/10] wip test --- .../stability-attribute/rustc-encodable-stability.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 src/test/ui-fulldeps/stability-attribute/rustc-encodable-stability.rs diff --git a/src/test/ui-fulldeps/stability-attribute/rustc-encodable-stability.rs b/src/test/ui-fulldeps/stability-attribute/rustc-encodable-stability.rs new file mode 100644 index 0000000000000..072b9387119ae --- /dev/null +++ b/src/test/ui-fulldeps/stability-attribute/rustc-encodable-stability.rs @@ -0,0 +1,12 @@ +// edition:2018 +#![allow(deprecated)] +#![feature(rustc_private)] + +extern crate rustc_serialize; + +#[derive(RustcDecodable, RustcEncodable)] +struct ArbitraryTestType { + +} + +fn main() {} From e4e6b1ebc6e75b44f5543eb72964f3716b0b7d07 Mon Sep 17 00:00:00 2001 From: Jane Losare-Lusby Date: Thu, 7 Jul 2022 22:29:38 +0000 Subject: [PATCH 08/10] fixes post rebase --- compiler/rustc_attr/src/builtin.rs | 2 +- compiler/rustc_error_codes/src/error_codes.rs | 2 +- compiler/rustc_middle/src/middle/stability.rs | 2 ++ compiler/rustc_passes/src/stability.rs | 2 +- .../rustc-encodable-stability.rs | 0 .../stability-attribute/allow-through-unstable-misuse.rs | 8 -------- .../stability-attribute/allowed-through-unstable.stderr | 2 +- .../ui/stability-attribute/rustc-encodable-stability.rs | 8 -------- src/tools/tidy/src/error_codes_check.rs | 2 +- 9 files changed, 7 insertions(+), 21 deletions(-) rename src/test/ui-fulldeps/{stability-attribute => }/rustc-encodable-stability.rs (100%) delete mode 100644 src/test/ui/stability-attribute/allow-through-unstable-misuse.rs delete mode 100644 src/test/ui/stability-attribute/rustc-encodable-stability.rs diff --git a/compiler/rustc_attr/src/builtin.rs b/compiler/rustc_attr/src/builtin.rs index 46643df84ccdd..6397d4e236a07 100644 --- a/compiler/rustc_attr/src/builtin.rs +++ b/compiler/rustc_attr/src/builtin.rs @@ -465,7 +465,7 @@ where struct_span_err!( diagnostic, item_sp, - E0788, + E0789, "`rustc_allowed_through_unstable_modules` attribute must be paired with a `stable` attribute" ) .emit(); diff --git a/compiler/rustc_error_codes/src/error_codes.rs b/compiler/rustc_error_codes/src/error_codes.rs index 56f29dcc5ce9f..977318b85895e 100644 --- a/compiler/rustc_error_codes/src/error_codes.rs +++ b/compiler/rustc_error_codes/src/error_codes.rs @@ -644,5 +644,5 @@ E0788: include_str!("./error_codes/E0788.md"), // E0721, // `await` keyword // E0723, // unstable feature in `const` context // E0738, // Removed; errored on `#[track_caller] fn`s in `extern "Rust" { ... }`. - E0788, // rustc_allowed_through_unstable_modules without stability attribute + E0789, // rustc_allowed_through_unstable_modules without stability attribute } diff --git a/compiler/rustc_middle/src/middle/stability.rs b/compiler/rustc_middle/src/middle/stability.rs index 9f00c6ac1126a..91f6cdd0877e1 100644 --- a/compiler/rustc_middle/src/middle/stability.rs +++ b/compiler/rustc_middle/src/middle/stability.rs @@ -492,6 +492,8 @@ impl<'tcx> TyCtxt<'tcx> { /// If so, and `id` is not `None`, a deprecated lint attached to `id` will be emitted. /// /// Pass `AllowUnstable::Yes` to `allow_unstable` to force an unstable item to be allowed. Deprecation warnings will be emitted normally. + /// + /// Returns `true` if item is allowed aka, stable or unstable under an enabled feature. pub fn check_stability_allow_unstable( self, def_id: DefId, diff --git a/compiler/rustc_passes/src/stability.rs b/compiler/rustc_passes/src/stability.rs index cf23e0ae5ef23..ef7c3fc0966fa 100644 --- a/compiler/rustc_passes/src/stability.rs +++ b/compiler/rustc_passes/src/stability.rs @@ -858,7 +858,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'tcx> { } else { AllowUnstable::No }, - ) + ); } } } diff --git a/src/test/ui-fulldeps/stability-attribute/rustc-encodable-stability.rs b/src/test/ui-fulldeps/rustc-encodable-stability.rs similarity index 100% rename from src/test/ui-fulldeps/stability-attribute/rustc-encodable-stability.rs rename to src/test/ui-fulldeps/rustc-encodable-stability.rs diff --git a/src/test/ui/stability-attribute/allow-through-unstable-misuse.rs b/src/test/ui/stability-attribute/allow-through-unstable-misuse.rs deleted file mode 100644 index 7f942309e049b..0000000000000 --- a/src/test/ui/stability-attribute/allow-through-unstable-misuse.rs +++ /dev/null @@ -1,8 +0,0 @@ -#![crate_type = "lib"] -#![feature(staged_api)] -#![feature(rustc_attrs)] -#![stable(feature = "foo", since = "1.0.0")] - -#[unstable(feature = "bar", issue = "none")] -#[rustc_allowed_through_unstable_modules] -pub struct UnstableType(()); diff --git a/src/test/ui/stability-attribute/allowed-through-unstable.stderr b/src/test/ui/stability-attribute/allowed-through-unstable.stderr index 70b1dc3010a40..132c00b89b229 100644 --- a/src/test/ui/stability-attribute/allowed-through-unstable.stderr +++ b/src/test/ui/stability-attribute/allowed-through-unstable.stderr @@ -1,5 +1,5 @@ error[E0658]: use of unstable library feature 'unstable_test_feature' - --> $DIR/allowed-through-unstable.rs:10:5 + --> $DIR/allowed-through-unstable.rs:9:5 | LL | use allowed_through_unstable_core::unstable_module::NewStableTraitNotAllowedThroughUnstable; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/test/ui/stability-attribute/rustc-encodable-stability.rs b/src/test/ui/stability-attribute/rustc-encodable-stability.rs deleted file mode 100644 index 18eff27d9a53c..0000000000000 --- a/src/test/ui/stability-attribute/rustc-encodable-stability.rs +++ /dev/null @@ -1,8 +0,0 @@ -// edition:2018 -#![allow(deprecated)] -extern crate rustc_serialize; - -#[derive(RustcDecodable, RustcEncodable)] -struct ArbitraryTestType(()); - -fn main() {} diff --git a/src/tools/tidy/src/error_codes_check.rs b/src/tools/tidy/src/error_codes_check.rs index e56ce3329cc47..4ffa1fa8b28d3 100644 --- a/src/tools/tidy/src/error_codes_check.rs +++ b/src/tools/tidy/src/error_codes_check.rs @@ -11,7 +11,7 @@ use regex::Regex; // A few of those error codes can't be tested but all the others can and *should* be tested! const EXEMPTED_FROM_TEST: &[&str] = &[ "E0279", "E0313", "E0377", "E0461", "E0462", "E0465", "E0476", "E0490", "E0514", "E0519", - "E0523", "E0554", "E0640", "E0717", "E0729", + "E0523", "E0554", "E0640", "E0717", "E0729", "E0789", ]; // Some error codes don't have any tests apparently... From 7d328fe28b0218added51e83ed18351c5075605d Mon Sep 17 00:00:00 2001 From: Jane Losare-Lusby Date: Fri, 8 Jul 2022 22:22:19 +0000 Subject: [PATCH 09/10] fix stderr output file after rebase --- .../intrinsics/const-eval-select-bad.stderr | 28 ++++--------------- 1 file changed, 5 insertions(+), 23 deletions(-) diff --git a/src/test/ui/intrinsics/const-eval-select-bad.stderr b/src/test/ui/intrinsics/const-eval-select-bad.stderr index bdd5b700a92e2..6103d6c6e3a6f 100644 --- a/src/test/ui/intrinsics/const-eval-select-bad.stderr +++ b/src/test/ui/intrinsics/const-eval-select-bad.stderr @@ -1,36 +1,18 @@ -<<<<<<< HEAD -error[E0277]: the trait bound `[closure@$DIR/const-eval-select-bad.rs:6:27: 6:29]: ~const FnOnce<()>` is not satisfied - --> $DIR/const-eval-select-bad.rs:6:27 - | -LL | const_eval_select((), || {}, || {}); - | ----------------- ^^^^^ expected an `FnOnce<()>` closure, found `[closure@$DIR/const-eval-select-bad.rs:6:27: 6:29]` - | | - | required by a bound introduced by this call - | - = help: the trait `~const FnOnce<()>` is not implemented for `[closure@$DIR/const-eval-select-bad.rs:6:27: 6:29]` -note: the trait `FnOnce<()>` is implemented for `[closure@$DIR/const-eval-select-bad.rs:6:27: 6:29]`, but that implementation is not `const` - --> $DIR/const-eval-select-bad.rs:6:27 - | -LL | const_eval_select((), || {}, || {}); - | ^^^^^ - = note: wrap the `[closure@$DIR/const-eval-select-bad.rs:6:27: 6:29]` in a closure with no arguments: `|| { /* code */ }` -======= -error[E0277]: the trait bound `[closure@$DIR/const-eval-select-bad.rs:7:27: 7:32]: ~const FnOnce<()>` is not satisfied +error[E0277]: the trait bound `[closure@$DIR/const-eval-select-bad.rs:7:27: 7:29]: ~const FnOnce<()>` is not satisfied --> $DIR/const-eval-select-bad.rs:7:27 | LL | const_eval_select((), || {}, || {}); - | ----------------- ^^^^^ expected an `FnOnce<()>` closure, found `[closure@$DIR/const-eval-select-bad.rs:7:27: 7:32]` + | ----------------- ^^^^^ expected an `FnOnce<()>` closure, found `[closure@$DIR/const-eval-select-bad.rs:7:27: 7:29]` | | | required by a bound introduced by this call | - = help: the trait `~const FnOnce<()>` is not implemented for `[closure@$DIR/const-eval-select-bad.rs:7:27: 7:32]` -note: the trait `FnOnce<()>` is implemented for `[closure@$DIR/const-eval-select-bad.rs:7:27: 7:32]`, but that implementation is not `const` + = help: the trait `~const FnOnce<()>` is not implemented for `[closure@$DIR/const-eval-select-bad.rs:7:27: 7:29]` +note: the trait `FnOnce<()>` is implemented for `[closure@$DIR/const-eval-select-bad.rs:7:27: 7:29]`, but that implementation is not `const` --> $DIR/const-eval-select-bad.rs:7:27 | LL | const_eval_select((), || {}, || {}); | ^^^^^ - = note: wrap the `[closure@$DIR/const-eval-select-bad.rs:7:27: 7:32]` in a closure with no arguments: `|| { /* code */ }` ->>>>>>> c1798b7c60e... Support unstable moves via stable in unstable items + = note: wrap the `[closure@$DIR/const-eval-select-bad.rs:7:27: 7:29]` in a closure with no arguments: `|| { /* code */ }` note: required by a bound in `const_eval_select` --> $SRC_DIR/core/src/intrinsics.rs:LL:COL | From 3e2c5b5f751c3375c2ce4a2d2f54e4d8499e454d Mon Sep 17 00:00:00 2001 From: Jane Losare-Lusby Date: Fri, 8 Jul 2022 23:22:14 +0000 Subject: [PATCH 10/10] remove broken test --- src/test/ui-fulldeps/rustc-encodable-stability.rs | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 src/test/ui-fulldeps/rustc-encodable-stability.rs diff --git a/src/test/ui-fulldeps/rustc-encodable-stability.rs b/src/test/ui-fulldeps/rustc-encodable-stability.rs deleted file mode 100644 index 072b9387119ae..0000000000000 --- a/src/test/ui-fulldeps/rustc-encodable-stability.rs +++ /dev/null @@ -1,12 +0,0 @@ -// edition:2018 -#![allow(deprecated)] -#![feature(rustc_private)] - -extern crate rustc_serialize; - -#[derive(RustcDecodable, RustcEncodable)] -struct ArbitraryTestType { - -} - -fn main() {}