Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add internal nightly lint to test nightly features
Browse files Browse the repository at this point in the history
xFrednet committed Feb 14, 2022
1 parent 56a5ba9 commit fc36a7c
Showing 5 changed files with 60 additions and 0 deletions.
1 change: 1 addition & 0 deletions clippy_lints/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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()));
33 changes: 33 additions & 0 deletions clippy_lints/src/utils/internal_lints.rs
Original file line number Diff line number Diff line change
@@ -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 {
8 changes: 8 additions & 0 deletions tests/ui-internal/clippy_nightly_lints_disabled.rs
Original file line number Diff line number Diff line change
@@ -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() {}
8 changes: 8 additions & 0 deletions tests/ui-internal/clippy_nightly_lints_enabled.rs
Original file line number Diff line number Diff line change
@@ -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() {}
10 changes: 10 additions & 0 deletions tests/ui-internal/clippy_nightly_lints_enabled.stderr
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit fc36a7c

Please sign in to comment.