Skip to content

Commit

Permalink
Add lint declarative_macro_missing
Browse files Browse the repository at this point in the history
  • Loading branch information
miikka committed Oct 10, 2024
1 parent e29056d commit 5247a26
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/lints/declarative_macro_missing.ron
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
SemverQuery(
id: "declarative_macro_missing",
human_readable_name: "macro_rules declaration removed or renamed",
description: "A declarative macro marked with #[macro_export] can no longer imported by its prior name.",
required_update: Major,
lint_level: Deny,
reference_link: Some("https://doc.rust-lang.org/reference/macros-by-example.html#path-based-scope"),
query: r#"
{
CrateDiff {
baseline {
item {
... on Macro {
visibility_limit @filter(op: "=", value: ["$public"])
public_api_eligible @filter(op: "=", value: ["$true"])
name @output @tag
span_: span @optional {
filename @output
begin_line @output
}
}
}
}
current @fold @transform(op: "count") @filter(op: "=", value: ["$zero"]) {
item {
... on Macro {
visibility_limit @filter(op: "=", value: ["$public"])
public_api_eligible @filter(op: "=", value: ["$true"])
name @filter(op: "=", value: ["%name"])
}
}
}
}
}"#,
arguments: {
"public": "public",
"zero": 0,
"true": true,
},
error_message: "A publicly-visible `macro_rules` declarative macro cannot be imported by its prior name. A `#[macro_export]` may have been removed, or the macro itself may have been renamed or removed entirely.",
per_result_error_template: Some("macro_rules! {{name}}, previously in file {{span_filename}}:{{span_begin_line}}"),
witness: (
hint_template: r#"{{name}}!(...);"#
),
)
1 change: 1 addition & 0 deletions src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1009,6 +1009,7 @@ add_lints!(
constructible_struct_adds_field,
constructible_struct_adds_private_field,
constructible_struct_changed_type,
declarative_macro_missing,
derive_trait_impl_removed,
enum_marked_non_exhaustive,
enum_missing,
Expand Down
7 changes: 7 additions & 0 deletions test_crates/declarative_macro_missing/new/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
publish = false
name = "declarative_macro_missing"
version = "0.1.0"
edition = "2021"

[dependencies]
3 changes: 3 additions & 0 deletions test_crates/declarative_macro_missing/new/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
macro_rules! will_no_longer_be_exported {
() => {};
}
7 changes: 7 additions & 0 deletions test_crates/declarative_macro_missing/old/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
publish = false
name = "declarative_macro_missing"
version = "0.1.0"
edition = "2021"

[dependencies]
13 changes: 13 additions & 0 deletions test_crates/declarative_macro_missing/old/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#[macro_export]
macro_rules! will_be_removed {
() => {};
}

#[macro_export]
macro_rules! will_no_longer_be_exported {
() => {};
}

macro_rules! textual_scope_macro_removed {
() => {};
}
18 changes: 18 additions & 0 deletions test_outputs/query_execution/declarative_macro_missing.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
source: src/query.rs
expression: "&query_execution_results"
---
{
"./test_crates/declarative_macro_missing/": [
{
"name": String("will_be_removed"),
"span_begin_line": Uint64(2),
"span_filename": String("src/lib.rs"),
},
{
"name": String("will_no_longer_be_exported"),
"span_begin_line": Uint64(7),
"span_filename": String("src/lib.rs"),
},
],
}
14 changes: 14 additions & 0 deletions test_outputs/witnesses/declarative_macro_missing.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
source: src/query.rs
description: "Lint `declarative_macro_missing` did not have the expected witness output.\nSee https://github.com/obi1kenobi/cargo-semver-checks/blob/main/CONTRIBUTING.md#testing-witnesses\nfor more information."
expression: "&actual_witnesses"
---
[["./test_crates/declarative_macro_missing/"]]
filename = 'src/lib.rs'
begin_line = 2
hint = 'will_be_removed!(...);'

[["./test_crates/declarative_macro_missing/"]]
filename = 'src/lib.rs'
begin_line = 7
hint = 'will_no_longer_be_exported!(...);'

0 comments on commit 5247a26

Please sign in to comment.