-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #8313 - flip1995:msrv-internal-lint, r=xFrednet
Implement internal lint for MSRV lints This internal lint checks if the `extract_msrv_attrs!` macro is used if a lint has a MSRV. If not, it suggests to add this attribute to the lint pass implementation. Following up #8280 (comment). This currently doesn't implement the documentation check. But since this is just an extension of this lint, I think this is a good MVP of this lint. r? `@camsteffen` cc `@xFrednet` changelog: none
- Loading branch information
Showing
10 changed files
with
177 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// run-rustfix | ||
|
||
#![deny(clippy::internal)] | ||
#![allow(clippy::missing_clippy_version_attribute)] | ||
#![feature(rustc_private)] | ||
|
||
extern crate rustc_ast; | ||
extern crate rustc_hir; | ||
extern crate rustc_lint; | ||
extern crate rustc_middle; | ||
#[macro_use] | ||
extern crate rustc_session; | ||
use clippy_utils::extract_msrv_attr; | ||
use rustc_hir::Expr; | ||
use rustc_lint::{EarlyContext, EarlyLintPass, LateContext, LateLintPass}; | ||
use rustc_semver::RustcVersion; | ||
|
||
declare_lint! { | ||
pub TEST_LINT, | ||
Warn, | ||
"" | ||
} | ||
|
||
struct Pass { | ||
msrv: Option<RustcVersion>, | ||
} | ||
|
||
impl_lint_pass!(Pass => [TEST_LINT]); | ||
|
||
impl LateLintPass<'_> for Pass { | ||
extract_msrv_attr!(LateContext); | ||
fn check_expr(&mut self, _: &LateContext<'_>, _: &Expr<'_>) {} | ||
} | ||
|
||
impl EarlyLintPass for Pass { | ||
extract_msrv_attr!(EarlyContext); | ||
fn check_expr(&mut self, _: &EarlyContext<'_>, _: &rustc_ast::Expr) {} | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// run-rustfix | ||
|
||
#![deny(clippy::internal)] | ||
#![allow(clippy::missing_clippy_version_attribute)] | ||
#![feature(rustc_private)] | ||
|
||
extern crate rustc_ast; | ||
extern crate rustc_hir; | ||
extern crate rustc_lint; | ||
extern crate rustc_middle; | ||
#[macro_use] | ||
extern crate rustc_session; | ||
use clippy_utils::extract_msrv_attr; | ||
use rustc_hir::Expr; | ||
use rustc_lint::{EarlyContext, EarlyLintPass, LateContext, LateLintPass}; | ||
use rustc_semver::RustcVersion; | ||
|
||
declare_lint! { | ||
pub TEST_LINT, | ||
Warn, | ||
"" | ||
} | ||
|
||
struct Pass { | ||
msrv: Option<RustcVersion>, | ||
} | ||
|
||
impl_lint_pass!(Pass => [TEST_LINT]); | ||
|
||
impl LateLintPass<'_> for Pass { | ||
fn check_expr(&mut self, _: &LateContext<'_>, _: &Expr<'_>) {} | ||
} | ||
|
||
impl EarlyLintPass for Pass { | ||
fn check_expr(&mut self, _: &EarlyContext<'_>, _: &rustc_ast::Expr) {} | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
error: `extract_msrv_attr!` macro missing from `LateLintPass` implementation | ||
--> $DIR/invalid_msrv_attr_impl.rs:30:1 | ||
| | ||
LL | impl LateLintPass<'_> for Pass { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
note: the lint level is defined here | ||
--> $DIR/invalid_msrv_attr_impl.rs:3:9 | ||
| | ||
LL | #![deny(clippy::internal)] | ||
| ^^^^^^^^^^^^^^^^ | ||
= note: `#[deny(clippy::missing_msrv_attr_impl)]` implied by `#[deny(clippy::internal)]` | ||
help: add `extract_msrv_attr!(LateContext)` to the `LateLintPass` implementation | ||
| | ||
LL + impl LateLintPass<'_> for Pass { | ||
LL + extract_msrv_attr!(LateContext); | ||
| | ||
|
||
error: `extract_msrv_attr!` macro missing from `EarlyLintPass` implementation | ||
--> $DIR/invalid_msrv_attr_impl.rs:34:1 | ||
| | ||
LL | impl EarlyLintPass for Pass { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
help: add `extract_msrv_attr!(EarlyContext)` to the `EarlyLintPass` implementation | ||
| | ||
LL + impl EarlyLintPass for Pass { | ||
LL + extract_msrv_attr!(EarlyContext); | ||
| | ||
|
||
error: aborting due to 2 previous errors | ||
|