1
Fork 0

Auto merge of #108955 - Nilstrieb:dont-use-me-pls, r=oli-obk

Add `internal_features` lint

Implements https://github.com/rust-lang/compiler-team/issues/596

Also requires some more test blessing for codegen tests etc

`@jyn514` had the idea of just `allow`ing the lint by default in the test suite. I'm not sure whether this is a good idea, but it's definitely one worth considering. Additional input encouraged.
This commit is contained in:
bors 2023-08-03 22:58:02 +00:00
commit 1fe384649a
68 changed files with 209 additions and 49 deletions

View file

@ -28,8 +28,8 @@ use crate::{
BuiltinClashingExternSub, BuiltinConstNoMangle, BuiltinDeprecatedAttrLink,
BuiltinDeprecatedAttrLinkSuggestion, BuiltinDeprecatedAttrUsed, BuiltinDerefNullptr,
BuiltinEllipsisInclusiveRangePatternsLint, BuiltinExplicitOutlives,
BuiltinExplicitOutlivesSuggestion, BuiltinIncompleteFeatures,
BuiltinIncompleteFeaturesHelp, BuiltinIncompleteFeaturesNote, BuiltinKeywordIdents,
BuiltinExplicitOutlivesSuggestion, BuiltinFeatureIssueNote, BuiltinIncompleteFeatures,
BuiltinIncompleteFeaturesHelp, BuiltinInternalFeatures, BuiltinKeywordIdents,
BuiltinMissingCopyImpl, BuiltinMissingDebugImpl, BuiltinMissingDoc,
BuiltinMutablesTransmutes, BuiltinNoMangleGeneric, BuiltinNonShorthandFieldPatterns,
BuiltinSpecialModuleNameUsed, BuiltinTrivialBounds, BuiltinTypeAliasGenericBounds,
@ -2301,12 +2301,36 @@ declare_lint! {
"incomplete features that may function improperly in some or all cases"
}
declare_lint! {
/// The `internal_features` lint detects unstable features enabled with
/// the [`feature` attribute] that are internal to the compiler or standard
/// library.
///
/// [`feature` attribute]: https://doc.rust-lang.org/nightly/unstable-book/
///
/// ### Example
///
/// ```rust,compile_fail
/// #![feature(rustc_attrs)]
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// These features are an implementation detail of the compiler and standard
/// library and are not supposed to be used in user code.
pub INTERNAL_FEATURES,
Deny,
"internal features are not supposed to be used"
}
declare_lint_pass!(
/// Check for used feature gates in `INCOMPLETE_FEATURES` in `rustc_feature/src/active.rs`.
IncompleteFeatures => [INCOMPLETE_FEATURES]
IncompleteInternalFeatures => [INCOMPLETE_FEATURES, INTERNAL_FEATURES]
);
impl EarlyLintPass for IncompleteFeatures {
impl EarlyLintPass for IncompleteInternalFeatures {
fn check_crate(&mut self, cx: &EarlyContext<'_>, _: &ast::Crate) {
let features = cx.sess().features_untracked();
features
@ -2314,17 +2338,26 @@ impl EarlyLintPass for IncompleteFeatures {
.iter()
.map(|(name, span, _)| (name, span))
.chain(features.declared_lib_features.iter().map(|(name, span)| (name, span)))
.filter(|(&name, _)| features.incomplete(name))
.filter(|(&name, _)| features.incomplete(name) || features.internal(name))
.for_each(|(&name, &span)| {
let note = rustc_feature::find_feature_issue(name, GateIssue::Language)
.map(|n| BuiltinIncompleteFeaturesNote { n });
let help =
HAS_MIN_FEATURES.contains(&name).then_some(BuiltinIncompleteFeaturesHelp);
cx.emit_spanned_lint(
INCOMPLETE_FEATURES,
span,
BuiltinIncompleteFeatures { name, note, help },
);
.map(|n| BuiltinFeatureIssueNote { n });
if features.incomplete(name) {
let help =
HAS_MIN_FEATURES.contains(&name).then_some(BuiltinIncompleteFeaturesHelp);
cx.emit_spanned_lint(
INCOMPLETE_FEATURES,
span,
BuiltinIncompleteFeatures { name, note, help },
);
} else {
cx.emit_spanned_lint(
INTERNAL_FEATURES,
span,
BuiltinInternalFeatures { name, note },
);
}
});
}
}

View file

@ -40,6 +40,7 @@
#![recursion_limit = "256"]
#![deny(rustc::untranslatable_diagnostic)]
#![deny(rustc::diagnostic_outside_of_impl)]
#![cfg_attr(not(bootstrap), allow(internal_features))]
#[macro_use]
extern crate rustc_middle;
@ -173,7 +174,7 @@ early_lint_methods!(
WhileTrue: WhileTrue,
NonAsciiIdents: NonAsciiIdents,
HiddenUnicodeCodepoints: HiddenUnicodeCodepoints,
IncompleteFeatures: IncompleteFeatures,
IncompleteInternalFeatures: IncompleteInternalFeatures,
RedundantSemicolons: RedundantSemicolons,
UnusedDocComment: UnusedDocComment,
UnexpectedCfgs: UnexpectedCfgs,

View file

@ -405,18 +405,27 @@ pub struct BuiltinExplicitOutlivesSuggestion {
pub struct BuiltinIncompleteFeatures {
pub name: Symbol,
#[subdiagnostic]
pub note: Option<BuiltinIncompleteFeaturesNote>,
pub note: Option<BuiltinFeatureIssueNote>,
#[subdiagnostic]
pub help: Option<BuiltinIncompleteFeaturesHelp>,
}
#[derive(LintDiagnostic)]
#[diag(lint_builtin_internal_features)]
#[note]
pub struct BuiltinInternalFeatures {
pub name: Symbol,
#[subdiagnostic]
pub note: Option<BuiltinFeatureIssueNote>,
}
#[derive(Subdiagnostic)]
#[help(lint_help)]
pub struct BuiltinIncompleteFeaturesHelp;
#[derive(Subdiagnostic)]
#[note(lint_note)]
pub struct BuiltinIncompleteFeaturesNote {
pub struct BuiltinFeatureIssueNote {
pub n: NonZeroU32,
}