Skip to content

Commit

Permalink
Add proc_macro_now_doc_hidden lint.
Browse files Browse the repository at this point in the history
Resolves #946.
  • Loading branch information
obi1kenobi committed Dec 16, 2024
1 parent 87ee410 commit 19c02a8
Show file tree
Hide file tree
Showing 7 changed files with 172 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/lints/proc_macro_now_doc_hidden.ron
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
SemverQuery(
id: "proc_macro_now_doc_hidden",
human_readable_name: "proc macro became #[doc(hidden)]",
description: "A procedural macro has become #[doc(hidden)] and is no longer public API.",
required_update: Major,
lint_level: Deny,
reference_link: Some("https://doc.rust-lang.org/rustdoc/write-documentation/the-doc-attribute.html#hidden"),
query: r#"
{
CrateDiff {
baseline {
item {
... on ProcMacro {
kind: __typename @output @tag
visibility_limit @filter(op: "=", value: ["$public"])
importable_path {
path @output @tag
public_api @filter(op: "=", value: ["$true"])
}
}
}
}
current {
item {
... on ProcMacro {
__typename @filter(op: "=", value: ["%kind"])
name @output
importable_path {
path @filter(op: "=", value: ["%path"])
public_api @filter(op: "!=", value: ["$true"])
}
span_: span @optional {
filename @output
begin_line @output
}
}
}
}
}
}"#,
arguments: {
"public": "public",
"true": true,
},
error_message: "A public procedural macro is now #[doc(hidden)], removing it from the crate's public API.",
per_result_error_template: Some("proc macro {{name}} in file {{span_filename}}:{{span_begin_line}}"),
)
1 change: 1 addition & 0 deletions src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1172,6 +1172,7 @@ add_lints!(
method_parameter_count_changed,
module_missing,
non_exhaustive_struct_changed_type,
proc_macro_now_doc_hidden,
pub_module_level_const_missing,
pub_module_level_const_now_doc_hidden,
pub_static_missing,
Expand Down
10 changes: 10 additions & 0 deletions test_crates/proc_macro_now_doc_hidden/new/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
publish = false
name = "proc_macro_now_doc_hidden"
version = "0.1.0"
edition = "2021"

[lib]
proc-macro = true

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

// An attribute macro we'll hide. Should trigger the lint.
#[doc(hidden)]
#[proc_macro_attribute]
pub fn logging(_attr: TokenStream, item: TokenStream) -> TokenStream {
item
}

// A function-like macro we'll hide. Should trigger the lint.
#[doc(hidden)]
#[proc_macro]
pub fn sql(_item: TokenStream) -> TokenStream {
TokenStream::new()
}

// A derive macro we'll hide. Should trigger the lint.
#[doc(hidden)]
#[proc_macro_derive(MyDerive)]
pub fn my_derive(_item: TokenStream) -> TokenStream {
TokenStream::new()
}
10 changes: 10 additions & 0 deletions test_crates/proc_macro_now_doc_hidden/old/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
publish = false
name = "proc_macro_now_doc_hidden"
version = "0.1.0"
edition = "2021"

[lib]
proc-macro = true

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

// An attribute macro we'll hide. Should trigger the lint.
#[proc_macro_attribute]
pub fn logging(_attr: TokenStream, item: TokenStream) -> TokenStream {
item
}

// A function-like macro we'll hide. Should trigger the lint.
#[proc_macro]
pub fn sql(_item: TokenStream) -> TokenStream {
TokenStream::new()
}

// A derive macro we'll hide. Should trigger the lint.
#[proc_macro_derive(MyDerive)]
pub fn my_derive(_item: TokenStream) -> TokenStream {
TokenStream::new()
}

// A hidden attribute macro we'll delete. Shouldn't trigger any lint.
#[doc(hidden)]
#[proc_macro_attribute]
pub fn hidden_logging(_attr: TokenStream, item: TokenStream) -> TokenStream {
item
}

// A hidden function-like macro we'll delete. Shouldn't trigger any lint.
#[doc(hidden)]
#[proc_macro]
pub fn hidden_sql(_item: TokenStream) -> TokenStream {
TokenStream::new()
}

// A hidden derive macro we'll delete. Shouldn't trigger any lint.
#[doc(hidden)]
#[proc_macro_derive(MyHiddenDerive)]
pub fn hidden_derive(item: TokenStream) -> TokenStream {
item
}
39 changes: 39 additions & 0 deletions test_outputs/query_execution/proc_macro_now_doc_hidden.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
source: src/query.rs
expression: "&query_execution_results"
snapshot_kind: text
---
{
"./test_crates/proc_macro_now_doc_hidden/": [
{
"kind": String("AttributeProcMacro"),
"name": String("logging"),
"path": List([
String("proc_macro_now_doc_hidden"),
String("logging"),
]),
"span_begin_line": Uint64(6),
"span_filename": String("src/lib.rs"),
},
{
"kind": String("FunctionLikeProcMacro"),
"name": String("sql"),
"path": List([
String("proc_macro_now_doc_hidden"),
String("sql"),
]),
"span_begin_line": Uint64(13),
"span_filename": String("src/lib.rs"),
},
{
"kind": String("DeriveProcMacro"),
"name": String("MyDerive"),
"path": List([
String("proc_macro_now_doc_hidden"),
String("MyDerive"),
]),
"span_begin_line": Uint64(20),
"span_filename": String("src/lib.rs"),
},
],
}

0 comments on commit 19c02a8

Please sign in to comment.