Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added lint trait_associated_type_now_doc_hidden #776

Merged
merged 11 commits into from
May 11, 2024
57 changes: 57 additions & 0 deletions src/lints/trait_associated_type_now_doc_hidden.ron
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
SemverQuery(
id: "trait_associated_type_now_doc_hidden",
human_readable_name: "trait associated type is now #[doc(hidden)]",
description: "A public trait associated type is now marked as #[doc(hidden)] and has thus been removed from 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 Trait {
trait_name: name @output
visibility_limit @filter(op: "=", value: ["$public"])

importable_path {
path @output @tag
public_api @filter(op: "=", value: ["$true"])
}

associated_type {
associated_type: name @output @tag
public_api_eligible @filter(op: "=", value: ["$true"])
}
}
}
}
current {
item {
... on Trait {
visibility_limit @filter(op: "=", value: ["$public"])

importable_path {
path @filter(op: "=", value: ["%path"])
public_api @filter(op: "=", value: ["$true"])
}

associated_type{
public_api_eligible @filter(op: "!=", value: ["$true"])
name @filter(op: "=", value: ["%associated_type"])
span_: span @optional {
filename @output
begin_line @output
}
}
}
}
}
}
}"#,
arguments: {
"public": "public",
"true": true
},
error_message: "A type in a pub trait is now #[doc(hidden)], which removes it from the crate's public API",
per_result_error_template: Some("associated type {{trait_name}}::{{associated_type}} in {{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 @@ -530,6 +530,7 @@ add_lints!(
struct_pub_field_now_doc_hidden,
struct_repr_transparent_removed,
struct_with_pub_fields_changed_type,
trait_associated_type_now_doc_hidden,
trait_method_missing,
trait_method_now_doc_hidden,
trait_method_unsafe_added,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
publish = false
name = "trait_associated_type_now_doc_hidden"
version = "0.1.0"
edition = "2021"

[dependencies]
38 changes: 38 additions & 0 deletions test_crates/trait_associated_type_now_doc_hidden/new/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Basic test case
pub trait PUB_TRAIT_A {
#[doc(hidden)]
type TYPE_A;
// Should not flag already #[doc(hidden)] type
#[doc(hidden)]
type DOC_HIDDEN_TYPE;
}

// Trait is private so it should not trigger the lint
trait TRAIT_A {
#[doc(hidden)]
type TYPE_B;
}

// Trait is #[doc(hidden)] along with the type, only trait_now_doc_hidden should be triggered
#[doc(hidden)]
pub trait PUB_TRAIT_B {
#[doc(hidden)]
type TYPE_C;
}

// Test cases when trait is #[doc(hidden)]
#[doc(hidden)]
pub trait DOC_HIDDEN_TRAIT {
#[doc(hidden)]
type TYPE_D;
#[doc(hidden)]
type TYPE_E;
}

// Test cases when #[doc(hidden)] from trait is removed
pub trait PUB_TRAIT_C {
#[doc(hidden)]
type TYPE_F;
#[doc(hidden)]
type TYPE_G;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
publish = false
name = "trait_associated_type_now_doc_hidden"
version = "0.1.0"
edition = "2021"

[dependencies]
33 changes: 33 additions & 0 deletions test_crates/trait_associated_type_now_doc_hidden/old/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Basic test case
pub trait PUB_TRAIT_A {
type TYPE_A;
// Should not flag already #[doc(hidden)] type
#[doc(hidden)]
type DOC_HIDDEN_TYPE;
}
obi1kenobi marked this conversation as resolved.
Show resolved Hide resolved

// Trait is private so it should not trigger the lint
trait TRAIT_A {
type TYPE_B;
}

// Trait is #[doc(hidden)] along with the type, only trait_now_doc_hidden should be triggered
pub trait PUB_TRAIT_B {
type TYPE_C;
}

// Test cases when trait is #[doc(hidden)]
#[doc(hidden)]
pub trait DOC_HIDDEN_TRAIT {
type TYPE_D;
#[doc(hidden)]
type TYPE_E;
}

// Test cases when #[doc(hidden)] from trait is removed
#[doc(hidden)]
pub trait PUB_TRAIT_C {
type TYPE_F;
#[doc(hidden)]
type TYPE_G;
}
14 changes: 14 additions & 0 deletions test_outputs/trait_associated_type_now_doc_hidden.output.ron
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"./test_crates/trait_associated_type_now_doc_hidden/": [
{
"associated_type": String("TYPE_A"),
"path": List([
String("trait_associated_type_now_doc_hidden"),
String("PUB_TRAIT_A"),
]),
"span_begin_line": Uint64(4),
"span_filename": String("src/lib.rs"),
"trait_name": String("PUB_TRAIT_A"),
},
],
}
11 changes: 11 additions & 0 deletions test_outputs/trait_now_doc_hidden.output.ron
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
{
"./test_crates/trait_associated_type_now_doc_hidden/": [
{
"path": List([
String("trait_associated_type_now_doc_hidden"),
String("PUB_TRAIT_B"),
]),
"span_begin_line": Uint64(18),
"span_filename": String("src/lib.rs"),
"trait_name": String("PUB_TRAIT_B"),
},
],
"./test_crates/trait_now_doc_hidden/": [
{
"path": List([
Expand Down
Loading