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_const_now_doc_hidden #779

Merged
merged 1 commit into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions src/lints/trait_associated_const_now_doc_hidden.ron
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
SemverQuery(
id: "trait_associated_const_now_doc_hidden",
human_readable_name: "trait associated const is now #[doc(hidden)]",
description: "A public trait associated const 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_constant {
associated_constant: 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_constant {
public_api_eligible @filter(op: "!=", value: ["$true"])
name @filter(op: "=", value: ["%associated_constant"])
span_: span @optional {
filename @output
begin_line @output
}
}
}
}
}
}
}"#,
arguments: {
"public": "public",
"true": true
},
error_message: "A const in a pub trait is now #[doc(hidden)], which removes it from the crate's public API",
per_result_error_template: Some("associated constant {{trait_name}}::{{associated_constant}} 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_const_now_doc_hidden,
trait_associated_type_now_doc_hidden,
trait_method_missing,
trait_method_now_doc_hidden,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
publish = false
name = "trait_associated_const_now_doc_hidden"
version = "0.1.0"
edition = "2021"

[dependencies]
38 changes: 38 additions & 0 deletions test_crates/trait_associated_const_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 PubTraitA {
#[doc(hidden)]
const CONST_A: u8 = 0;
// Should not flag already #[doc(hidden)] const
#[doc(hidden)]
const DOC_HIDDEN_CONST_A: u8 = 0;
}

// Trait is private so it should not trigger the lint
trait TraitA {
#[doc(hidden)]
const CONST_B: u8 = 0;
}

// Trait is #[doc(hidden)] along with the const, only trait_now_doc_hidden should be triggered
#[doc(hidden)]
pub trait PubTraitB {
#[doc(hidden)]
const CONST_C: u8 = 0;
}

// Test cases when trait is #[doc(hidden)]
#[doc(hidden)]
pub trait DocHiddenTrait {
#[doc(hidden)]
const CONST_D: u8 = 0;
#[doc(hidden)]
const DOC_HIDDEN_CONST_B: u8 = 0;
}

// Test cases when #[doc(hidden)] from trait is removed
pub trait PubTraitC {
#[doc(hidden)]
const CONST_E: u8 = 0;
#[doc(hidden)]
const DOC_HIDDEN_CONST_C: u8 = 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
publish = false
name = "trait_associated_const_now_doc_hidden"
version = "0.1.0"
edition = "2021"

[dependencies]
33 changes: 33 additions & 0 deletions test_crates/trait_associated_const_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 PubTraitA {
const CONST_A: u8 = 0;
// Should not flag already #[doc(hidden)] const
#[doc(hidden)]
const DOC_HIDDEN_CONST_A: u8 = 0;
}

// Trait is private so it should not trigger the lint
trait TraitA {
const CONST_B: u8 = 0;
}

// Trait is #[doc(hidden)] along with the const, only trait_now_doc_hidden should be triggered
pub trait PubTraitB {
const CONST_C: u8 = 0;
}

// Test cases when trait is #[doc(hidden)]
#[doc(hidden)]
pub trait DocHiddenTrait {
const CONST_D: u8 = 0;
#[doc(hidden)]
const DOC_HIDDEN_CONST_B: u8 = 0;
}

// Test cases when #[doc(hidden)] from trait is removed
#[doc(hidden)]
pub trait PubTraitC {
const CONST_E: u8 = 0;
#[doc(hidden)]
const DOC_HIDDEN_CONST_C: u8 = 0;
}
14 changes: 14 additions & 0 deletions test_outputs/trait_associated_const_now_doc_hidden.output.ron
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"./test_crates/trait_associated_const_now_doc_hidden/": [
{
"associated_constant": String("CONST_A"),
"path": List([
String("trait_associated_const_now_doc_hidden"),
String("PubTraitA"),
]),
"span_begin_line": Uint64(4),
"span_filename": String("src/lib.rs"),
"trait_name": String("PubTraitA"),
},
]
}
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_const_now_doc_hidden/": [
{
"path": List([
String("trait_associated_const_now_doc_hidden"),
String("PubTraitB"),
]),
"span_begin_line": Uint64(18),
"span_filename": String("src/lib.rs"),
"trait_name": String("PubTraitB"),
},
],
"./test_crates/trait_associated_type_now_doc_hidden/": [
{
"path": List([
Expand Down
Loading