-
-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added lint trait_associated_const_now_doc_hidden (#779)
- Loading branch information
Showing
8 changed files
with
168 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}}"), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
test_crates/trait_associated_const_now_doc_hidden/new/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
38
test_crates/trait_associated_const_now_doc_hidden/new/src/lib.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
7 changes: 7 additions & 0 deletions
7
test_crates/trait_associated_const_now_doc_hidden/old/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
33
test_crates/trait_associated_const_now_doc_hidden/old/src/lib.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
14
test_outputs/trait_associated_const_now_doc_hidden.output.ron
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"), | ||
}, | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters