Skip to content

Commit

Permalink
Add lint attribute_proc_macro_missing (#1026)
Browse files Browse the repository at this point in the history
Addresses a checkbox in
#946
  • Loading branch information
malenaohl authored Dec 7, 2024
1 parent f0d7df7 commit 965d62a
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/lints/attribute_proc_macro_missing.ron
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
SemverQuery(
id: "attribute_proc_macro_missing",
human_readable_name: "attribute proc macro removed",
description: "An attribute proc macro that previously existed is no longer available.",
required_update: Major,
lint_level: Deny,
reference_link: Some("https://doc.rust-lang.org/reference/procedural-macros.html#attribute-macros"),
query: r#"
{
CrateDiff {
baseline {
item {
... on AttributeProcMacro {
visibility_limit @filter(op: "=", value: ["$public"])
name @output @tag
span_: span @optional {
filename @output
begin_line @output
}
}
}
}
current @fold @transform(op: "count") @filter(op: "=", value: ["$zero"]) {
item {
... on AttributeProcMacro {
visibility_limit @filter(op: "=", value: ["$public"])
name @filter(op: "=", value: ["%name"])
}
}
}
}
}"#,
arguments: {
"public": "public",
"zero": 0,
},
error_message: "A previously available attribute macro has been removed, breaking code that uses attribute syntax on annotated items.",
per_result_error_template: Some("macro #[{{name}}] in {{span_filename}}:{{span_begin_line}}"),
witness: None,
)
1 change: 1 addition & 0 deletions src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1048,6 +1048,7 @@ macro_rules! add_lints {
// The following add_lints! invocation is programmatically edited by scripts/make_new_lint.sh
// If you must manually edit it, be sure to read the "Requirements" comments in that script first
add_lints!(
attribute_proc_macro_missing,
auto_trait_impl_removed,
constructible_struct_adds_field,
constructible_struct_adds_private_field,
Expand Down
10 changes: 10 additions & 0 deletions test_crates/attribute_proc_macro_missing/new/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
publish = false
name = "attribute_proc_macro_missing"
version = "0.1.0"
edition = "2021"

[lib]
proc-macro = true

[dependencies]
12 changes: 12 additions & 0 deletions test_crates/attribute_proc_macro_missing/new/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use proc_macro::TokenStream;

// Keep other macro types to verify specific detection
#[proc_macro]
pub fn sql(_item: TokenStream) -> TokenStream {
TokenStream::new()
}

#[proc_macro_derive(MyDerive)]
pub fn my_derive(_item: TokenStream) -> TokenStream {
TokenStream::new()
}
10 changes: 10 additions & 0 deletions test_crates/attribute_proc_macro_missing/old/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
publish = false
name = "attribute_proc_macro_missing"
version = "0.1.0"
edition = "2021"

[lib]
proc-macro = true

[dependencies]
18 changes: 18 additions & 0 deletions test_crates/attribute_proc_macro_missing/old/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use proc_macro::TokenStream;

#[proc_macro_attribute]
pub fn logging(_attr: TokenStream, item: TokenStream) -> TokenStream {
item
}

// Keep this to verify we don't trigger on function-like macros
#[proc_macro]
pub fn sql(_item: TokenStream) -> TokenStream {
TokenStream::new()
}

// Keep this to verify we don't trigger on derive macros
#[proc_macro_derive(MyDerive)]
pub fn my_derive(_item: TokenStream) -> TokenStream {
TokenStream::new()
}
14 changes: 14 additions & 0 deletions test_outputs/query_execution/attribute_proc_macro_missing.snap
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/attribute_proc_macro_missing/": [
{
"name": String("logging"),
"span_begin_line": Uint64(4),
"span_filename": String("src/lib.rs"),
},
],
}

0 comments on commit 965d62a

Please sign in to comment.