Skip to content

Commit

Permalink
Use importable_path data in proc macro lints. (#1047)
Browse files Browse the repository at this point in the history
  • Loading branch information
obi1kenobi authored Dec 15, 2024
1 parent a6a9445 commit 2fcfccd
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 10 deletions.
14 changes: 12 additions & 2 deletions src/lints/attribute_proc_macro_missing.ron
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ SemverQuery(
item {
... on AttributeProcMacro {
visibility_limit @filter(op: "=", value: ["$public"])
name @output @tag
name @output
importable_path {
path @output @tag
public_api @filter(op: "=", value: ["$true"])
}
span_: span @optional {
filename @output
begin_line @output
Expand All @@ -24,7 +30,10 @@ SemverQuery(
item {
... on AttributeProcMacro {
visibility_limit @filter(op: "=", value: ["$public"])
name @filter(op: "=", value: ["%name"])
importable_path {
path @filter(op: "=", value: ["%path"])
}
}
}
}
Expand All @@ -33,6 +42,7 @@ SemverQuery(
arguments: {
"public": "public",
"zero": 0,
"true": true,
},
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}}"),
Expand Down
13 changes: 11 additions & 2 deletions src/lints/derive_helper_attr_removed.ron
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,14 @@ SemverQuery(
baseline {
item {
... on DeriveProcMacro {
name @output @tag
name @output
visibility_limit @filter(op: "=", value: ["$public"])
importable_path {
path @output @tag
public_api @filter(op: "=", value: ["$true"])
}
helper_attribute {
helper_name: name @output @tag
}
Expand All @@ -28,9 +33,12 @@ SemverQuery(
current {
item {
... on DeriveProcMacro {
name @filter(op: "=", value: ["%name"])
visibility_limit @filter(op: "=", value: ["$public"])
importable_path {
path @filter(op: "=", value: ["%path"])
}
helper_attribute @fold @transform(op: "count") @filter(op: "=", value: ["$zero"]) {
name @filter(op: "=", value: ["%helper_name"])
}
Expand All @@ -42,6 +50,7 @@ SemverQuery(
arguments: {
"public": "public",
"zero": 0,
"true": true,
},
error_message: "A helper attribute was removed from a derive proc macro, which will prevent downstream code using this attribute with #[derive] invocations from compiling.",
per_result_error_template: Some("helper attribute #[{{helper_name}}] removed from derive macro {{name}} in {{span_filename}}:{{span_begin_line}}"),
Expand Down
13 changes: 11 additions & 2 deletions src/lints/derive_proc_macro_missing.ron
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,14 @@ SemverQuery(
baseline {
item {
... on DeriveProcMacro {
macro_name: name @output @tag
macro_name: name @output
visibility_limit @filter(op: "=", value: ["$public"])
importable_path {
path @output @tag
public_api @filter(op: "=", value: ["$true"])
}
span_: span @optional {
filename @output
begin_line @output
Expand All @@ -25,7 +30,10 @@ SemverQuery(
item {
... on DeriveProcMacro {
visibility_limit @filter(op: "=", value: ["$public"])
name @filter(op: "=", value: ["%macro_name"])
importable_path {
path @filter(op: "=", value: ["%path"])
}
}
}
}
Expand All @@ -34,6 +42,7 @@ SemverQuery(
arguments: {
"public": "public",
"zero": 0,
"true": true,
},
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}}"),
Expand Down
16 changes: 12 additions & 4 deletions src/lints/function_like_proc_macro_missing.ron
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,14 @@ SemverQuery(
baseline {
item {
... on FunctionLikeProcMacro {
macro_name: name @output @tag
macro_name: name @output
visibility_limit @filter(op: "=", value: ["$public"])
importable_path {
path @output @tag
public_api @filter(op: "=", value: ["$true"])
}
# Get span info from the baseline for error reporting
span_: span @optional {
filename @output
Expand All @@ -22,11 +27,13 @@ SemverQuery(
}
}
}
current @fold @transform(op: "count") @filter(op: "=", value: ["$zero"]) {
item {
... on FunctionLikeProcMacro {
name @filter(op: "=", value: ["%macro_name"])
importable_path {
path @filter(op: "=", value: ["%path"])
}
}
}
}
Expand All @@ -35,6 +42,7 @@ SemverQuery(
arguments: {
"public": "public",
"zero": 0,
"true": true,
},
error_message: "A function-like procedural macro has been removed. Any code that invokes this macro will fail to compile.",
per_result_error_template: Some("macro {{macro_name}} in file {{span_filename}}:{{span_begin_line}}"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ snapshot_kind: text
"./test_crates/attribute_proc_macro_missing/": [
{
"name": String("logging"),
"path": List([
String("attribute_proc_macro_missing"),
String("logging"),
]),
"span_begin_line": Uint64(4),
"span_filename": String("src/lib.rs"),
},
Expand Down
4 changes: 4 additions & 0 deletions test_outputs/query_execution/derive_helper_attr_removed.snap
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ snapshot_kind: text
{
"helper_name": String("helper"),
"name": String("MyDerive"),
"path": List([
String("derive_helper_attr_removed"),
String("MyDerive"),
]),
"span_begin_line": Uint64(5),
"span_filename": String("src/lib.rs"),
},
Expand Down
4 changes: 4 additions & 0 deletions test_outputs/query_execution/derive_proc_macro_missing.snap
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ snapshot_kind: text
"./test_crates/derive_proc_macro_missing/": [
{
"macro_name": String("MyDerive"),
"path": List([
String("derive_proc_macro_missing"),
String("MyDerive"),
]),
"span_begin_line": Uint64(4),
"span_filename": String("src/lib.rs"),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ snapshot_kind: text
"./test_crates/function_like_proc_macro_missing/": [
{
"macro_name": String("make_answer"),
"path": List([
String("function_like_proc_macro_missing"),
String("make_answer"),
]),
"span_begin_line": Uint64(4),
"span_filename": String("src/lib.rs"),
},
Expand Down

0 comments on commit 2fcfccd

Please sign in to comment.