-
-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add lint derive_proc_macro_missing (#1027)
Addresses a checkbox in #946
- Loading branch information
Showing
7 changed files
with
113 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
SemverQuery( | ||
id: "derive_proc_macro_missing", | ||
human_readable_name: "derive macro removed", | ||
description: "A derive macro that was previously available can no longer be used.", | ||
required_update: Major, | ||
lint_level: Deny, | ||
reference_link: Some("https://doc.rust-lang.org/reference/procedural-macros.html#derive-macros"), | ||
query: r#" | ||
{ | ||
CrateDiff { | ||
baseline { | ||
item { | ||
... on DeriveProcMacro { | ||
macro_name: name @output @tag | ||
visibility_limit @filter(op: "=", value: ["$public"]) | ||
span_: span @optional { | ||
filename @output | ||
begin_line @output | ||
} | ||
} | ||
} | ||
} | ||
current @fold @transform(op: "count") @filter(op: "=", value: ["$zero"]) { | ||
item { | ||
... on DeriveProcMacro { | ||
visibility_limit @filter(op: "=", value: ["$public"]) | ||
name @filter(op: "=", value: ["%macro_name"]) | ||
} | ||
} | ||
} | ||
} | ||
}"#, | ||
arguments: { | ||
"public": "public", | ||
"zero": 0, | ||
}, | ||
error_message: "A derive macro has been removed. Type definitions using #[derive(...)] with this macro will fail to compile.", | ||
per_result_error_template: Some("macro {{macro_name}} in {{span_filename}}:{{span_begin_line}}"), | ||
witness: None, | ||
) |
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,10 @@ | ||
[package] | ||
publish = false | ||
name = "derive_proc_macro_missing" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[lib] | ||
proc-macro = true | ||
|
||
[dependencies] |
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,16 @@ | ||
use proc_macro::TokenStream; | ||
|
||
#[proc_macro_derive(StaysPresent)] | ||
pub fn stays_present(_input: TokenStream) -> TokenStream { | ||
TokenStream::new() | ||
} | ||
|
||
#[proc_macro_attribute] | ||
pub fn my_attribute(_attr: TokenStream, _item: TokenStream) -> TokenStream { | ||
TokenStream::new() | ||
} | ||
|
||
#[proc_macro] | ||
pub fn my_macro(_input: TokenStream) -> TokenStream { | ||
TokenStream::new() | ||
} |
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,10 @@ | ||
[package] | ||
publish = false | ||
name = "derive_proc_macro_missing" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[lib] | ||
proc-macro = true | ||
|
||
[dependencies] |
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,21 @@ | ||
use proc_macro::TokenStream; | ||
|
||
#[proc_macro_derive(MyDerive)] | ||
pub fn my_derive(_input: TokenStream) -> TokenStream { | ||
TokenStream::new() | ||
} | ||
|
||
#[proc_macro_derive(StaysPresent)] | ||
pub fn stays_present(_input: TokenStream) -> TokenStream { | ||
TokenStream::new() | ||
} | ||
|
||
#[proc_macro_attribute] | ||
pub fn my_attribute(_attr: TokenStream, _item: TokenStream) -> TokenStream { | ||
TokenStream::new() | ||
} | ||
|
||
#[proc_macro] | ||
pub fn my_macro(_input: TokenStream) -> TokenStream { | ||
TokenStream::new() | ||
} |
14 changes: 14 additions & 0 deletions
14
test_outputs/query_execution/derive_proc_macro_missing.snap
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,14 @@ | ||
--- | ||
source: src/query.rs | ||
expression: "&query_execution_results" | ||
snapshot_kind: text | ||
--- | ||
{ | ||
"./test_crates/derive_proc_macro_missing/": [ | ||
{ | ||
"macro_name": String("MyDerive"), | ||
"span_begin_line": Uint64(4), | ||
"span_filename": String("src/lib.rs"), | ||
}, | ||
], | ||
} |