Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add lint derive_proc_macro_missing #1027

Merged
merged 1 commit into from
Dec 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions src/lints/derive_proc_macro_missing.ron
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,
)
1 change: 1 addition & 0 deletions src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1053,6 +1053,7 @@ add_lints!(
constructible_struct_adds_private_field,
constructible_struct_changed_type,
declarative_macro_missing,
derive_proc_macro_missing,
derive_trait_impl_removed,
enum_marked_non_exhaustive,
enum_missing,
Expand Down
10 changes: 10 additions & 0 deletions test_crates/derive_proc_macro_missing/new/Cargo.toml
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]
16 changes: 16 additions & 0 deletions test_crates/derive_proc_macro_missing/new/src/lib.rs
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()
}
10 changes: 10 additions & 0 deletions test_crates/derive_proc_macro_missing/old/Cargo.toml
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]
21 changes: 21 additions & 0 deletions test_crates/derive_proc_macro_missing/old/src/lib.rs
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 test_outputs/query_execution/derive_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/derive_proc_macro_missing/": [
{
"macro_name": String("MyDerive"),
"span_begin_line": Uint64(4),
"span_filename": String("src/lib.rs"),
},
],
}
Loading