Skip to content

Commit fc36a7c

Browse files
committed
Add internal nightly lint to test nightly features
1 parent 56a5ba9 commit fc36a7c

File tree

5 files changed

+60
-0
lines changed

5 files changed

+60
-0
lines changed

clippy_lints/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
498498
{
499499
store.register_early_pass(|| Box::new(utils::internal_lints::ClippyLintsInternal));
500500
store.register_early_pass(|| Box::new(utils::internal_lints::ProduceIce));
501+
store.register_early_pass(|| Box::new(utils::internal_lints::ForeverNightlyLint));
501502
store.register_late_pass(|| Box::new(utils::inspector::DeepCodeInspector));
502503
store.register_late_pass(|| Box::new(utils::internal_lints::CollapsibleCalls));
503504
store.register_late_pass(|| Box::new(utils::internal_lints::CompilerLintFunctions::new()));

clippy_lints/src/utils/internal_lints.rs

+33
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,21 @@ declare_clippy_lint! {
338338
"found clippy lint without `clippy::version` attribute"
339339
}
340340

341+
declare_clippy_lint! {
342+
/// ### What it does
343+
/// Not an actual lint. This lint is only meant for testing lints with the
344+
/// version set to `nightly`
345+
///
346+
/// ### Why is this bad?
347+
/// This lint will never be seen by the end user. This text is therefore just
348+
/// waisted storage space ^^
349+
///
350+
#[clippy::version = "nightly"]
351+
pub FOREVER_NIGHTLY_LINT,
352+
internal_warn,
353+
"achivement: you found a nightly lint (+1xp)"
354+
}
355+
341356
declare_lint_pass!(ClippyLintsInternal => [CLIPPY_LINTS_INTERNAL]);
342357

343358
impl EarlyLintPass for ClippyLintsInternal {
@@ -652,6 +667,24 @@ fn is_trigger_fn(fn_kind: FnKind<'_>) -> bool {
652667
}
653668
}
654669

670+
declare_lint_pass!(ForeverNightlyLint => [FOREVER_NIGHTLY_LINT]);
671+
672+
impl EarlyLintPass for ForeverNightlyLint {
673+
fn check_fn(&mut self, cx: &EarlyContext<'_>, fn_kind: FnKind<'_>, _: Span, _: NodeId) {
674+
match fn_kind {
675+
FnKind::Fn(_, ident, ..) if ident.name.as_str() == "trigger_forever_nightly_lint" => {
676+
span_lint(
677+
cx,
678+
FOREVER_NIGHTLY_LINT,
679+
ident.span,
680+
"this triggered a lint that should only be available on nightly",
681+
);
682+
},
683+
_ => {},
684+
}
685+
}
686+
}
687+
655688
declare_lint_pass!(CollapsibleCalls => [COLLAPSIBLE_SPAN_LINT_CALLS]);
656689

657690
impl<'tcx> LateLintPass<'tcx> for CollapsibleCalls {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// rustc-env:CLIPPY_NIGHTLY=0
2+
3+
// This should trigger `clippy::forever_nightly_lint`
4+
// The lint is warn by default
5+
6+
fn trigger_forever_nightly_lint() {}
7+
8+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// rustc-env:CLIPPY_NIGHTLY=1
2+
3+
// This should trigger `clippy::forever_nightly_lint`
4+
// The lint is warn by default
5+
6+
fn trigger_forever_nightly_lint() {}
7+
8+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error: this triggered a lint that should only be available on nightly
2+
--> $DIR/clippy_nightly_lints_enabled.rs:6:4
3+
|
4+
LL | fn trigger_forever_nightly_lint() {}
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: `-D clippy::forever-nightly-lint` implied by `-D warnings`
8+
9+
error: aborting due to previous error
10+

0 commit comments

Comments
 (0)