-
-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
109 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,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}}!(...);"# | ||
), | ||
) |
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,7 @@ | ||
[package] | ||
publish = false | ||
name = "declarative_macro_missing" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[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,3 @@ | ||
macro_rules! will_no_longer_be_exported { | ||
() => {}; | ||
} |
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,7 @@ | ||
[package] | ||
publish = false | ||
name = "declarative_macro_missing" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[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,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
18
test_outputs/query_execution/declarative_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,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"), | ||
}, | ||
], | ||
} |
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 | ||
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!(...);' |