diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index c1d9d18539bb..c246f425dd26 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -498,6 +498,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: { store.register_early_pass(|| Box::new(utils::internal_lints::ClippyLintsInternal)); store.register_early_pass(|| Box::new(utils::internal_lints::ProduceIce)); + store.register_early_pass(|| Box::new(utils::internal_lints::ForeverNightlyLint)); store.register_late_pass(|| Box::new(utils::inspector::DeepCodeInspector)); store.register_late_pass(|| Box::new(utils::internal_lints::CollapsibleCalls)); store.register_late_pass(|| Box::new(utils::internal_lints::CompilerLintFunctions::new())); diff --git a/clippy_lints/src/utils/internal_lints.rs b/clippy_lints/src/utils/internal_lints.rs index 11c90647ccc0..849c9b9f3f76 100644 --- a/clippy_lints/src/utils/internal_lints.rs +++ b/clippy_lints/src/utils/internal_lints.rs @@ -338,6 +338,21 @@ declare_clippy_lint! { "found clippy lint without `clippy::version` attribute" } +declare_clippy_lint! { + /// ### What it does + /// Not an actual lint. This lint is only meant for testing lints with the + /// version set to `nightly` + /// + /// ### Why is this bad? + /// This lint will never be seen by the end user. This text is therefore just + /// waisted storage space ^^ + /// + #[clippy::version = "nightly"] + pub FOREVER_NIGHTLY_LINT, + internal_warn, + "achivement: you found a nightly lint (+1xp)" +} + declare_lint_pass!(ClippyLintsInternal => [CLIPPY_LINTS_INTERNAL]); impl EarlyLintPass for ClippyLintsInternal { @@ -652,6 +667,24 @@ fn is_trigger_fn(fn_kind: FnKind<'_>) -> bool { } } +declare_lint_pass!(ForeverNightlyLint => [FOREVER_NIGHTLY_LINT]); + +impl EarlyLintPass for ForeverNightlyLint { + fn check_fn(&mut self, cx: &EarlyContext<'_>, fn_kind: FnKind<'_>, _: Span, _: NodeId) { + match fn_kind { + FnKind::Fn(_, ident, ..) if ident.name.as_str() == "trigger_forever_nightly_lint" => { + span_lint( + cx, + FOREVER_NIGHTLY_LINT, + ident.span, + "this triggered a lint that should only be available on nightly", + ); + }, + _ => {}, + } + } +} + declare_lint_pass!(CollapsibleCalls => [COLLAPSIBLE_SPAN_LINT_CALLS]); impl<'tcx> LateLintPass<'tcx> for CollapsibleCalls { diff --git a/tests/ui-internal/clippy_nightly_lints_disabled.rs b/tests/ui-internal/clippy_nightly_lints_disabled.rs new file mode 100644 index 000000000000..c4054c83a96a --- /dev/null +++ b/tests/ui-internal/clippy_nightly_lints_disabled.rs @@ -0,0 +1,8 @@ +// rustc-env:CLIPPY_NIGHTLY=0 + +// This should trigger `clippy::forever_nightly_lint` +// The lint is warn by default + +fn trigger_forever_nightly_lint() {} + +fn main() {} diff --git a/tests/ui-internal/clippy_nightly_lints_enabled.rs b/tests/ui-internal/clippy_nightly_lints_enabled.rs new file mode 100644 index 000000000000..3bb51cd69ccc --- /dev/null +++ b/tests/ui-internal/clippy_nightly_lints_enabled.rs @@ -0,0 +1,8 @@ +// rustc-env:CLIPPY_NIGHTLY=1 + +// This should trigger `clippy::forever_nightly_lint` +// The lint is warn by default + +fn trigger_forever_nightly_lint() {} + +fn main() {} diff --git a/tests/ui-internal/clippy_nightly_lints_enabled.stderr b/tests/ui-internal/clippy_nightly_lints_enabled.stderr new file mode 100644 index 000000000000..22d3ddb3ed31 --- /dev/null +++ b/tests/ui-internal/clippy_nightly_lints_enabled.stderr @@ -0,0 +1,10 @@ +error: this triggered a lint that should only be available on nightly + --> $DIR/clippy_nightly_lints_enabled.rs:6:4 + | +LL | fn trigger_forever_nightly_lint() {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `-D clippy::forever-nightly-lint` implied by `-D warnings` + +error: aborting due to previous error +