Skip to content
This repository was archived by the owner on Feb 18, 2022. It is now read-only.

Commit dbf4847

Browse files
committed
Registered pre-expansion lint for checking macro invocations
1 parent e988498 commit dbf4847

File tree

6 files changed

+56
-2
lines changed

6 files changed

+56
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1281,6 +1281,8 @@ Released 2018-09-13
12811281
[`forget_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#forget_ref
12821282
[`get_last_with_len`]: https://rust-lang.github.io/rust-clippy/master/index.html#get_last_with_len
12831283
[`get_unwrap`]: https://rust-lang.github.io/rust-clippy/master/index.html#get_unwrap
1284+
[`hacspec`]: https://rust-lang.github.io/rust-clippy/master/index.html#hacspec
1285+
[`hacspec_macros`]: https://rust-lang.github.io/rust-clippy/master/index.html#hacspec_macros
12841286
[`identity_conversion`]: https://rust-lang.github.io/rust-clippy/master/index.html#identity_conversion
12851287
[`identity_op`]: https://rust-lang.github.io/rust-clippy/master/index.html#identity_op
12861288
[`if_let_redundant_pattern_matching`]: https://rust-lang.github.io/rust-clippy/master/index.html#if_let_redundant_pattern_matching

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
A collection of lints to catch common mistakes and improve your [Rust](https://github.com/rust-lang/rust) code.
77

8-
[There are 362 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html)
8+
[There are 364 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html)
99

1010
We have a bunch of lint categories to allow you to choose how much Clippy is supposed to ~~annoy~~ help you:
1111

clippy_lints/src/hacspec_macros.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
use crate::utils::span_lint;
2+
use rustc_lint::{EarlyLintPass, EarlyContext};
3+
use rustc_session::{declare_lint_pass, declare_tool_lint};
4+
// use rustc_span::Span;
5+
use rustc_ast::{
6+
ast::{MacCall, PathSegment},
7+
};
8+
9+
declare_clippy_lint! {
10+
/// **What it does:**
11+
///
12+
/// **Why is this bad?**
13+
///
14+
/// **Known problems:** None.
15+
///
16+
/// **Example:**
17+
///
18+
/// ```rust
19+
/// // example code
20+
/// ```
21+
pub HACSPEC_MACROS,
22+
nursery, //pedantic, corectness or restriction, but shouldn't interfere with other lints ? or shipped completely separately
23+
"default lint description"
24+
}
25+
26+
declare_lint_pass!(HacspecMacros => [HACSPEC_MACROS]);
27+
28+
impl EarlyLintPass for HacspecMacros {
29+
fn check_mac(&mut self, _cx: &EarlyContext<'_>, mac: &MacCall) {
30+
}
31+
}

clippy_lints/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ pub mod formatting;
217217
pub mod functions;
218218
pub mod get_last_with_len;
219219
pub mod hacspec;
220+
pub mod hacspec_macros;
220221
pub mod identity_conversion;
221222
pub mod identity_op;
222223
pub mod if_let_some_result;
@@ -338,6 +339,7 @@ mod reexport {
338339
/// Used in `./src/driver.rs`.
339340
pub fn register_pre_expansion_lints(store: &mut rustc_lint::LintStore, conf: &Conf) {
340341
store.register_pre_expansion_pass(|| box write::Write::default());
342+
store.register_pre_expansion_pass(|| box hacspec_macros::HacspecMacros);
341343
store.register_pre_expansion_pass(|| box redundant_field_names::RedundantFieldNames);
342344
let single_char_binding_names_threshold = conf.single_char_binding_names_threshold;
343345
store.register_pre_expansion_pass(move || box non_expressive_names::NonExpressiveNames {
@@ -560,6 +562,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
560562
&functions::TOO_MANY_LINES,
561563
&get_last_with_len::GET_LAST_WITH_LEN,
562564
&hacspec::HACSPEC,
565+
&hacspec_macros::HACSPEC_MACROS,
563566
&identity_conversion::IDENTITY_CONVERSION,
564567
&identity_op::IDENTITY_OP,
565568
&if_let_some_result::IF_LET_SOME_RESULT,
@@ -1023,6 +1026,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
10231026
store.register_early_pass(move || box excessive_bools::ExcessiveBools::new(max_struct_bools, max_fn_params_bools));
10241027
store.register_early_pass(|| box option_env_unwrap::OptionEnvUnwrap);
10251028
// store.register_early_pass(|| box hacspec::Hacspec);
1029+
// store.register_early_pass(|| box hacspec_macros::HacspecMacros);
10261030
store.register_late_pass(|| box hacspec::Hacspec);
10271031
store.register_late_pass(|| box wildcard_imports::WildcardImports);
10281032
store.register_early_pass(|| box macro_use::MacroUseImports);
@@ -1088,6 +1092,8 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
10881092
LintId::of(&excessive_bools::STRUCT_EXCESSIVE_BOOLS),
10891093
LintId::of(&functions::MUST_USE_CANDIDATE),
10901094
LintId::of(&functions::TOO_MANY_LINES),
1095+
LintId::of(&hacspec::HACSPEC),
1096+
LintId::of(&hacspec_macros::HACSPEC_MACROS),
10911097
LintId::of(&if_not_else::IF_NOT_ELSE),
10921098
LintId::of(&infinite_iter::MAYBE_INFINITE_ITER),
10931099
LintId::of(&items_after_statements::ITEMS_AFTER_STATEMENTS),

src/lintlist/mod.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ pub use lint::Lint;
66
pub use lint::LINT_LEVELS;
77

88
// begin lint list, do not remove this comment, it’s used in `update_lints`
9-
pub const ALL_LINTS: [Lint; 362] = [
9+
pub const ALL_LINTS: [Lint; 364] = [
1010
Lint {
1111
name: "absurd_extreme_comparisons",
1212
group: "correctness",
@@ -693,6 +693,20 @@ pub const ALL_LINTS: [Lint; 362] = [
693693
deprecation: None,
694694
module: "methods",
695695
},
696+
Lint {
697+
name: "hacspec",
698+
group: "pedantic",
699+
desc: "Checks whether the code belongs to the hacspec subset of Rust",
700+
deprecation: None,
701+
module: "hacspec",
702+
},
703+
Lint {
704+
name: "hacspec_macros",
705+
group: "pedantic",
706+
desc: "default lint description",
707+
deprecation: None,
708+
module: "hacspec_macros",
709+
},
696710
Lint {
697711
name: "identity_conversion",
698712
group: "complexity",

tests/ui/hacspec/aes.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#![allow(clippy::all)]
22
#![deny(clippy::hacspec)]
3+
#![deny(clippy::hacspec_macros)]
34

45
extern crate hacspec;
56
extern crate contracts;

0 commit comments

Comments
 (0)