Skip to content

Add support for making lib features internal #118123

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions compiler/rustc_feature/src/unstable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@ macro_rules! declare_features {
#[derive(Clone, Default, Debug)]
pub struct Features {
/// `#![feature]` attrs for language features, for error reporting.
/// "declared" here means that the feature is actually enabled in the current crate.
pub declared_lang_features: Vec<(Symbol, Span, Option<Symbol>)>,
/// `#![feature]` attrs for non-language (library) features.
/// "declared" here means that the feature is actually enabled in the current crate.
pub declared_lib_features: Vec<(Symbol, Span)>,
/// `declared_lang_features` + `declared_lib_features`.
pub declared_features: FxHashSet<Symbol>,
Expand Down Expand Up @@ -125,9 +127,18 @@ macro_rules! declare_features {
$(
sym::$feature => status_to_enum!($status) == FeatureStatus::Internal,
)*
// Accepted/removed features aren't in this file but are never internal
// (a removed feature might have been internal, but that's now irrelevant).
_ if self.declared_features.contains(&feature) => false,
_ if self.declared_features.contains(&feature) => {
// This could be accepted/removed, or a libs feature.
// Accepted/removed features aren't in this file but are never internal
// (a removed feature might have been internal, but that's now irrelevant).
// Libs features are internal if they end in `_internal` or `_internals`.
// As a special exception we also consider `core_intrinsics` internal;
// renaming that age-old feature is just not worth the hassle.
// We just always test the name; it's not a big deal if we accidentally hit
// an accepted/removed lang feature that way.
let name = feature.as_str();
name == "core_intrinsics" || name.ends_with("_internal") || name.ends_with("_internals")
}
_ => panic!("`{}` was not listed in `declare_features`", feature),
}
}
Expand Down Expand Up @@ -207,9 +218,6 @@ declare_features! (
(internal, test_2018_feature, "1.31.0", None, Some(Edition::Edition2018)),
/// Added for testing unstable lints; perma-unstable.
(internal, test_unstable_lint, "1.60.0", None, None),
/// Allows non-`unsafe` —and thus, unsound— access to `Pin` constructions.
/// Marked `internal` since perma-unstable and unsound.
(internal, unsafe_pin_internals, "1.60.0", None, None),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a libs feature that was added here solely to make it "incomplete" (c93968a), and then later "internal". That's not needed any more.

/// Use for stable + negative coherence and strict coherence depending on trait's
/// rustc_strict_coherence value.
(unstable, with_negative_coherence, "1.60.0", None, None),
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_query_system/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#![feature(hash_raw_entry)]
#![feature(min_specialization)]
#![feature(let_chains)]
#![allow(rustc::potential_query_instability)]
#![allow(rustc::potential_query_instability, internal_features)]
#![deny(rustc::untranslatable_diagnostic)]
#![deny(rustc::diagnostic_outside_of_impl)]

Expand Down
1 change: 1 addition & 0 deletions library/alloc/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#![feature(thin_box)]
#![feature(strict_provenance)]
#![feature(drain_keep_rest)]
#![allow(internal_features)]
#![deny(fuzzy_provenance_casts)]
#![deny(unsafe_op_in_unsafe_fn)]

Expand Down
7 changes: 7 additions & 0 deletions library/core/src/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1900,6 +1900,7 @@ extern "rust-intrinsic" {
///
/// ```
/// #![feature(core_intrinsics)]
/// # #![allow(internal_features)]
///
/// use std::intrinsics::ctlz;
///
Expand All @@ -1912,6 +1913,7 @@ extern "rust-intrinsic" {
///
/// ```
/// #![feature(core_intrinsics)]
/// # #![allow(internal_features)]
///
/// use std::intrinsics::ctlz;
///
Expand All @@ -1933,6 +1935,7 @@ extern "rust-intrinsic" {
///
/// ```
/// #![feature(core_intrinsics)]
/// # #![allow(internal_features)]
///
/// use std::intrinsics::ctlz_nonzero;
///
Expand All @@ -1959,6 +1962,7 @@ extern "rust-intrinsic" {
///
/// ```
/// #![feature(core_intrinsics)]
/// # #![allow(internal_features)]
///
/// use std::intrinsics::cttz;
///
Expand All @@ -1971,6 +1975,7 @@ extern "rust-intrinsic" {
///
/// ```
/// #![feature(core_intrinsics)]
/// # #![allow(internal_features)]
///
/// use std::intrinsics::cttz;
///
Expand All @@ -1992,6 +1997,7 @@ extern "rust-intrinsic" {
///
/// ```
/// #![feature(core_intrinsics)]
/// # #![allow(internal_features)]
///
/// use std::intrinsics::cttz_nonzero;
///
Expand Down Expand Up @@ -2453,6 +2459,7 @@ extern "rust-intrinsic" {
/// ```no_run
/// #![feature(const_eval_select)]
/// #![feature(core_intrinsics)]
/// # #![allow(internal_features)]
/// use std::hint::unreachable_unchecked;
/// use std::intrinsics::const_eval_select;
///
Expand Down
1 change: 1 addition & 0 deletions library/core/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@
#![feature(get_many_mut)]
#![feature(offset_of)]
#![feature(iter_map_windows)]
#![allow(internal_features)]
#![deny(unsafe_op_in_unsafe_fn)]
#![deny(fuzzy_provenance_casts)]

Expand Down
2 changes: 1 addition & 1 deletion src/tools/rust-analyzer/crates/proc-macro-srv/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#![cfg(feature = "sysroot-abi")]
#![feature(proc_macro_internals, proc_macro_diagnostic, proc_macro_span)]
#![warn(rust_2018_idioms, unused_lifetimes, semicolon_in_expressions_from_macros)]
#![allow(unreachable_pub)]
#![allow(unreachable_pub, internal_features)]

extern crate proc_macro;

Expand Down
11 changes: 11 additions & 0 deletions tests/ui/lint/internal_features.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#![forbid(internal_features)]
// A lang feature and a lib feature.
#![feature(intrinsics, panic_internals)]
//~^ ERROR: internal
//~| ERROR: internal

extern "rust-intrinsic" {
fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize);
}

fn main() {}
23 changes: 23 additions & 0 deletions tests/ui/lint/internal_features.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
error: the feature `intrinsics` is internal to the compiler or standard library
--> $DIR/internal_features.rs:3:12
|
LL | #![feature(intrinsics, panic_internals)]
| ^^^^^^^^^^
|
= note: using it is strongly discouraged
note: the lint level is defined here
--> $DIR/internal_features.rs:1:11
|
LL | #![forbid(internal_features)]
| ^^^^^^^^^^^^^^^^^

error: the feature `panic_internals` is internal to the compiler or standard library
--> $DIR/internal_features.rs:3:24
|
LL | #![feature(intrinsics, panic_internals)]
| ^^^^^^^^^^^^^^^
|
= note: using it is strongly discouraged

error: aborting due to 2 previous errors