From 631b868d155e283bdde6353d5f042c2591e09442 Mon Sep 17 00:00:00 2001 From: vasu Date: Fri, 1 Mar 2024 23:10:39 +0530 Subject: [PATCH 1/4] rule init --- src/lints/union_now_doc_hidden.ron | 48 +++++++++++++++++++ src/query.rs | 1 + .../union_now_doc_hidden/new/cargo.toml | 7 +++ .../union_now_doc_hidden/new/src/lib.rs | 5 ++ .../union_now_doc_hidden/old/cargo.toml | 7 +++ .../union_now_doc_hidden/old/src/lib.rs | 4 ++ test_outputs/union_now_doc_hidden.output.ron | 24 ++++++++++ 7 files changed, 96 insertions(+) create mode 100644 src/lints/union_now_doc_hidden.ron create mode 100644 test_crates/union_now_doc_hidden/new/cargo.toml create mode 100644 test_crates/union_now_doc_hidden/new/src/lib.rs create mode 100644 test_crates/union_now_doc_hidden/old/cargo.toml create mode 100644 test_crates/union_now_doc_hidden/old/src/lib.rs create mode 100644 test_outputs/union_now_doc_hidden.output.ron diff --git a/src/lints/union_now_doc_hidden.ron b/src/lints/union_now_doc_hidden.ron new file mode 100644 index 00000000..577297c1 --- /dev/null +++ b/src/lints/union_now_doc_hidden.ron @@ -0,0 +1,48 @@ +SemverQuery( + id: "union_now_doc_hidden", + human_readable_name: "pub union is now #[doc(hidden)]", + description: "A pub union is now marked #[doc(hidden)] and is thus no longer part of the public API.", + required_update: Major, + reference_link: Some("https://doc.rust-lang.org/rustdoc/write-documentation/the-doc-attribute.html#hidden"), + query: r#" + { + CrateDiff { + baseline { + item { + ... on Union { + visibility_limit @filter(op: "=", value: ["$public"]) + + importable_path { + path @output @tag + public_api @filter(op: "=", value: ["$true"]) + } + } + } + } + current { + item { + ... on Union { + visibility_limit @filter(op: "=", value: ["$public"]) + union_name: 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 pub union is now #[doc(hidden)], removing it from the crate's public API.", + per_result_error_template: Some("union {{union_name}} in file {{span_filename}}:{{span_begin_line}}"), +) diff --git a/src/query.rs b/src/query.rs index c6eefa38..4fd83e15 100644 --- a/src/query.rs +++ b/src/query.rs @@ -531,4 +531,5 @@ add_lints!( repr_packed_added, repr_packed_removed, exported_function_changed_abi, + union_now_doc_hidden, ); diff --git a/test_crates/union_now_doc_hidden/new/cargo.toml b/test_crates/union_now_doc_hidden/new/cargo.toml new file mode 100644 index 00000000..9b68ff87 --- /dev/null +++ b/test_crates/union_now_doc_hidden/new/cargo.toml @@ -0,0 +1,7 @@ +[package] +publish = false +name = "union_now_doc_hidden" +version = "0.1.0" +edition = "2021" + +[dependencies] \ No newline at end of file diff --git a/test_crates/union_now_doc_hidden/new/src/lib.rs b/test_crates/union_now_doc_hidden/new/src/lib.rs new file mode 100644 index 00000000..45f519f1 --- /dev/null +++ b/test_crates/union_now_doc_hidden/new/src/lib.rs @@ -0,0 +1,5 @@ +#[doc(hidden)] +pub union MyUnion { + f1: u32, + f2: f32, +} \ No newline at end of file diff --git a/test_crates/union_now_doc_hidden/old/cargo.toml b/test_crates/union_now_doc_hidden/old/cargo.toml new file mode 100644 index 00000000..9b68ff87 --- /dev/null +++ b/test_crates/union_now_doc_hidden/old/cargo.toml @@ -0,0 +1,7 @@ +[package] +publish = false +name = "union_now_doc_hidden" +version = "0.1.0" +edition = "2021" + +[dependencies] \ No newline at end of file diff --git a/test_crates/union_now_doc_hidden/old/src/lib.rs b/test_crates/union_now_doc_hidden/old/src/lib.rs new file mode 100644 index 00000000..21a73059 --- /dev/null +++ b/test_crates/union_now_doc_hidden/old/src/lib.rs @@ -0,0 +1,4 @@ +pub union MyUnion { + f1: u32, + f2: f32, +} \ No newline at end of file diff --git a/test_outputs/union_now_doc_hidden.output.ron b/test_outputs/union_now_doc_hidden.output.ron new file mode 100644 index 00000000..55ba0023 --- /dev/null +++ b/test_outputs/union_now_doc_hidden.output.ron @@ -0,0 +1,24 @@ +{ + "./test_crates/type_hidden_from_public_api/": [ + { + "path": List([ + String("type_hidden_from_public_api"), + String("ExampleUnion"), + ]), + "span_begin_line": Uint64(19), + "span_filename": String("src/lib.rs"), + "union_name": String("ExampleUnion"), + }, + ], + "./test_crates/union_now_doc_hidden/": [ + { + "path": List([ + String("union_now_doc_hidden"), + String("MyUnion"), + ]), + "span_begin_line": Uint64(2), + "span_filename": String("src/lib.rs"), + "union_name": String("MyUnion"), + }, + ], +} From 89c5a662e409aa27851606e40dcc79df73c25f63 Mon Sep 17 00:00:00 2001 From: vasu Date: Sat, 2 Mar 2024 05:31:34 +0530 Subject: [PATCH 2/4] file renaming --- test_crates/union_now_doc_hidden/new/cargo.toml | 2 +- test_crates/union_now_doc_hidden/new/src/lib.rs | 17 ++++++++++++++++- test_crates/union_now_doc_hidden/old/cargo.toml | 2 +- test_crates/union_now_doc_hidden/old/src/lib.rs | 11 ++++++++++- 4 files changed, 28 insertions(+), 4 deletions(-) diff --git a/test_crates/union_now_doc_hidden/new/cargo.toml b/test_crates/union_now_doc_hidden/new/cargo.toml index 9b68ff87..c73bc2a7 100644 --- a/test_crates/union_now_doc_hidden/new/cargo.toml +++ b/test_crates/union_now_doc_hidden/new/cargo.toml @@ -4,4 +4,4 @@ name = "union_now_doc_hidden" version = "0.1.0" edition = "2021" -[dependencies] \ No newline at end of file +[dependencies] diff --git a/test_crates/union_now_doc_hidden/new/src/lib.rs b/test_crates/union_now_doc_hidden/new/src/lib.rs index 45f519f1..46b3fd71 100644 --- a/test_crates/union_now_doc_hidden/new/src/lib.rs +++ b/test_crates/union_now_doc_hidden/new/src/lib.rs @@ -2,4 +2,19 @@ pub union MyUnion { f1: u32, f2: f32, -} \ No newline at end of file +} + +pub union PublicUnionHiddenField { + // shouldn't flag `Union_now_doc_hidden` rule + // as this is a field that's hidden, + // not the entire Union + #[doc(hidden)] + pub my_field: i8, +} + +#[doc = "hidden"] // shouldn't flag, this is just documented with the string "hidden", + // it's not actually #[doc(hidden)] +pub union PublicUnionDocumentedWithStringHidden { + f1: u32, + f2: f32, +} diff --git a/test_crates/union_now_doc_hidden/old/cargo.toml b/test_crates/union_now_doc_hidden/old/cargo.toml index 9b68ff87..c73bc2a7 100644 --- a/test_crates/union_now_doc_hidden/old/cargo.toml +++ b/test_crates/union_now_doc_hidden/old/cargo.toml @@ -4,4 +4,4 @@ name = "union_now_doc_hidden" version = "0.1.0" edition = "2021" -[dependencies] \ No newline at end of file +[dependencies] diff --git a/test_crates/union_now_doc_hidden/old/src/lib.rs b/test_crates/union_now_doc_hidden/old/src/lib.rs index 21a73059..0b8c254d 100644 --- a/test_crates/union_now_doc_hidden/old/src/lib.rs +++ b/test_crates/union_now_doc_hidden/old/src/lib.rs @@ -1,4 +1,13 @@ pub union MyUnion { f1: u32, f2: f32, -} \ No newline at end of file +} + +pub union PublicUnionHiddenField { + pub my_field: i8, +} + +pub union PublicUnionDocumentedWithStringHidden { + f1: u32, + f2: f32, +} From 9bbe088360193f313e9b154c394967f3cf015f75 Mon Sep 17 00:00:00 2001 From: Vasu Singh Date: Sat, 2 Mar 2024 05:49:49 +0530 Subject: [PATCH 3/4] Rename cargo.toml to Cargo.toml --- test_crates/union_now_doc_hidden/old/{cargo.toml => Cargo.toml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename test_crates/union_now_doc_hidden/old/{cargo.toml => Cargo.toml} (100%) diff --git a/test_crates/union_now_doc_hidden/old/cargo.toml b/test_crates/union_now_doc_hidden/old/Cargo.toml similarity index 100% rename from test_crates/union_now_doc_hidden/old/cargo.toml rename to test_crates/union_now_doc_hidden/old/Cargo.toml From 0b8a3401b6205b4373544977e5e7bb88837b40d0 Mon Sep 17 00:00:00 2001 From: Vasu Singh Date: Sat, 2 Mar 2024 05:50:13 +0530 Subject: [PATCH 4/4] Rename cargo.toml to Cargo.toml --- test_crates/union_now_doc_hidden/new/{cargo.toml => Cargo.toml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename test_crates/union_now_doc_hidden/new/{cargo.toml => Cargo.toml} (100%) diff --git a/test_crates/union_now_doc_hidden/new/cargo.toml b/test_crates/union_now_doc_hidden/new/Cargo.toml similarity index 100% rename from test_crates/union_now_doc_hidden/new/cargo.toml rename to test_crates/union_now_doc_hidden/new/Cargo.toml