-
-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Inherent method now doc hidden (#821)
* Added inherent_method_now_doc_hidden * Update src/lints/inherent_method_now_doc_hidden.ron Co-authored-by: Predrag Gruevski <2348618+obi1kenobi@users.noreply.github.com> * Update src/lints/inherent_method_now_doc_hidden.ron Co-authored-by: Predrag Gruevski <2348618+obi1kenobi@users.noreply.github.com> * WIP try doc hidden for struct as well as methods --------- Co-authored-by: Predrag Gruevski <2348618+obi1kenobi@users.noreply.github.com>
- Loading branch information
1 parent
781fda5
commit 6173c4f
Showing
18 changed files
with
339 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,65 @@ | ||
SemverQuery( | ||
id: "inherent_method_now_doc_hidden", | ||
human_readable_name: "inherent method #[doc(hidden)] added", | ||
description: "A method or associated fn is now marked #[doc(hidden)] and is thus no longer part of the 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 ImplOwner { | ||
visibility_limit @filter(op: "=", value: ["$public"]) @output | ||
importable_path { | ||
path @output @tag | ||
public_api @filter(op: "=", value: ["$true"]) | ||
} | ||
inherent_impl { | ||
method { | ||
method_visibility: visibility_limit @filter(op: "=", value: ["$public"]) @output | ||
method_name: name @output @tag | ||
public_api_eligible @filter(op: "=", value: ["$true"]) | ||
span_: span @optional { | ||
filename @output | ||
begin_line @output | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
current { | ||
item { | ||
... on ImplOwner { | ||
visibility_limit @filter(op: "=", value: ["$public"]) | ||
name @output | ||
importable_path { | ||
path @filter(op: "=", value: ["%path"]) | ||
public_api @filter(op: "=", value: ["$true"]) | ||
} | ||
inherent_impl { | ||
method { | ||
method_visibility: visibility_limit @filter(op: "=", value: ["$public"]) | ||
name @filter(op: "=", value: ["%method_name"]) | ||
public_api_eligible @filter(op: "!=", value: ["$true"]) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}"#, | ||
arguments: { | ||
"public": "public", | ||
"true": true | ||
}, | ||
error_message: "A method or associated fn is now #[doc(hidden)], removing it from the crate's public API.", | ||
per_result_error_template: Some("{{name}}::{{method_name}} in file {{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
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 = "inherent_method_now_doc_hidden" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] |
17 changes: 17 additions & 0 deletions
17
...nherent_method_now_doc_hidden/new/src/doc_hidden_struct_inherent_method_now_doc_hidden.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,17 @@ | ||
// Tests false positives. If the struct is #[doc(hidden)], changing hidden state of methods should | ||
// have no effect. | ||
|
||
#[doc(hidden)] | ||
pub struct Foo; | ||
|
||
impl Foo { | ||
#[doc(hidden)] | ||
pub fn associated_fn(x: i64, y: i64) -> i64 { | ||
x + y | ||
} | ||
|
||
#[doc(hidden)] | ||
pub fn method(&self, x: i64) -> i64 { | ||
x | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
test_crates/inherent_method_now_doc_hidden/new/src/enum_inherent_method_now_doc_hidden.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,15 @@ | ||
pub enum Foo { | ||
Bar, | ||
} | ||
|
||
impl Foo { | ||
#[doc(hidden)] | ||
pub fn associated_fn(x: i64, y: i64) -> i64 { | ||
x + y | ||
} | ||
|
||
#[doc(hidden)] | ||
pub fn method(&self, x: i64) -> i64 { | ||
x | ||
} | ||
} |
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,10 @@ | ||
|
||
pub mod union_inherent_method_now_doc_hidden; | ||
|
||
pub mod enum_inherent_method_now_doc_hidden; | ||
|
||
pub mod struct_inherent_method_now_doc_hidden; | ||
|
||
pub mod doc_hidden_struct_inherent_method_now_doc_hidden; | ||
|
||
pub mod struct_and_inherent_method_now_doc_hidden; |
17 changes: 17 additions & 0 deletions
17
...rates/inherent_method_now_doc_hidden/new/src/struct_and_inherent_method_now_doc_hidden.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,17 @@ | ||
// Tests false positives. If the struct becomes #[doc(hidden)], it should trigger | ||
// struct_now_doc_hidden, and changing hidden state of methods should have no further effect. | ||
|
||
#[doc(hidden)] | ||
pub struct Foo; | ||
|
||
impl Foo { | ||
#[doc(hidden)] | ||
pub fn associated_fn(x: i64, y: i64) -> i64 { | ||
x + y | ||
} | ||
|
||
#[doc(hidden)] | ||
pub fn method(&self, x: i64) -> i64 { | ||
x | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
test_crates/inherent_method_now_doc_hidden/new/src/struct_inherent_method_now_doc_hidden.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,13 @@ | ||
pub struct Foo; | ||
|
||
impl Foo { | ||
#[doc(hidden)] | ||
pub fn associated_fn(x: i64, y: i64) -> i64 { | ||
x + y | ||
} | ||
|
||
#[doc(hidden)] | ||
pub fn method(&self, x: i64) -> i64 { | ||
x | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
test_crates/inherent_method_now_doc_hidden/new/src/union_inherent_method_now_doc_hidden.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,16 @@ | ||
pub union Foo { | ||
f1: u32, | ||
f2: f32, | ||
} | ||
|
||
impl Foo { | ||
#[doc(hidden)] | ||
pub fn associated_fn(x: i64, y: i64) -> i64 { | ||
x + y | ||
} | ||
|
||
#[doc(hidden)] | ||
pub fn method(&self, x: i64) -> i64 { | ||
x | ||
} | ||
} |
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 = "inherent_method_now_doc_hidden" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] |
15 changes: 15 additions & 0 deletions
15
...nherent_method_now_doc_hidden/old/src/doc_hidden_struct_inherent_method_now_doc_hidden.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,15 @@ | ||
// Tests false positives. If the struct is #[doc(hidden)], changing hidden state of methods should | ||
// have no effect. | ||
|
||
#[doc(hidden)] | ||
pub struct Foo; | ||
|
||
impl Foo { | ||
pub fn associated_fn(x: i64, y: i64) -> i64 { | ||
x + y | ||
} | ||
|
||
pub fn method(&self, x: i64) -> i64 { | ||
x | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
test_crates/inherent_method_now_doc_hidden/old/src/enum_inherent_method_now_doc_hidden.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,13 @@ | ||
pub enum Foo { | ||
Bar, | ||
} | ||
|
||
impl Foo { | ||
pub fn associated_fn(x: i64, y: i64) -> i64 { | ||
x + y | ||
} | ||
|
||
pub fn method(&self, x: i64) -> i64 { | ||
x | ||
} | ||
} |
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,10 @@ | ||
|
||
pub mod union_inherent_method_now_doc_hidden; | ||
|
||
pub mod enum_inherent_method_now_doc_hidden; | ||
|
||
pub mod struct_inherent_method_now_doc_hidden; | ||
|
||
pub mod doc_hidden_struct_inherent_method_now_doc_hidden; | ||
|
||
pub mod struct_and_inherent_method_now_doc_hidden; |
14 changes: 14 additions & 0 deletions
14
...rates/inherent_method_now_doc_hidden/old/src/struct_and_inherent_method_now_doc_hidden.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,14 @@ | ||
// Tests false positives. If the struct becomes #[doc(hidden)], it should trigger | ||
// struct_now_doc_hidden, and changing hidden state of methods should have no further effect. | ||
|
||
pub struct Foo; | ||
|
||
impl Foo { | ||
pub fn associated_fn(x: i64, y: i64) -> i64 { | ||
x + y | ||
} | ||
|
||
pub fn method(&self, x: i64) -> i64 { | ||
x | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
test_crates/inherent_method_now_doc_hidden/old/src/struct_inherent_method_now_doc_hidden.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,11 @@ | ||
pub struct Foo; | ||
|
||
impl Foo { | ||
pub fn associated_fn(x: i64, y: i64) -> i64 { | ||
x + y | ||
} | ||
|
||
pub fn method(&self, x: i64) -> i64 { | ||
x | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
test_crates/inherent_method_now_doc_hidden/old/src/union_inherent_method_now_doc_hidden.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,14 @@ | ||
pub union Foo { | ||
f1: u32, | ||
f2: f32, | ||
} | ||
|
||
impl Foo { | ||
pub fn associated_fn(x: i64, y: i64) -> i64 { | ||
x + y | ||
} | ||
|
||
pub fn method(&self, x: i64) -> i64 { | ||
x | ||
} | ||
} |
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,82 @@ | ||
{ | ||
"./test_crates/inherent_method_now_doc_hidden/": [ | ||
{ | ||
"method_name": String("associated_fn"), | ||
"method_visibility": String("public"), | ||
"name": String("Foo"), | ||
"path": List([ | ||
String("inherent_method_now_doc_hidden"), | ||
String("enum_inherent_method_now_doc_hidden"), | ||
String("Foo"), | ||
]), | ||
"span_begin_line": Uint64(6), | ||
"span_filename": String("src/enum_inherent_method_now_doc_hidden.rs"), | ||
"visibility_limit": String("public"), | ||
}, | ||
{ | ||
"method_name": String("method"), | ||
"method_visibility": String("public"), | ||
"name": String("Foo"), | ||
"path": List([ | ||
String("inherent_method_now_doc_hidden"), | ||
String("enum_inherent_method_now_doc_hidden"), | ||
String("Foo"), | ||
]), | ||
"span_begin_line": Uint64(10), | ||
"span_filename": String("src/enum_inherent_method_now_doc_hidden.rs"), | ||
"visibility_limit": String("public"), | ||
}, | ||
{ | ||
"method_name": String("associated_fn"), | ||
"method_visibility": String("public"), | ||
"name": String("Foo"), | ||
"path": List([ | ||
String("inherent_method_now_doc_hidden"), | ||
String("struct_inherent_method_now_doc_hidden"), | ||
String("Foo"), | ||
]), | ||
"span_begin_line": Uint64(4), | ||
"span_filename": String("src/struct_inherent_method_now_doc_hidden.rs"), | ||
"visibility_limit": String("public"), | ||
}, | ||
{ | ||
"method_name": String("method"), | ||
"method_visibility": String("public"), | ||
"name": String("Foo"), | ||
"path": List([ | ||
String("inherent_method_now_doc_hidden"), | ||
String("struct_inherent_method_now_doc_hidden"), | ||
String("Foo"), | ||
]), | ||
"span_begin_line": Uint64(8), | ||
"span_filename": String("src/struct_inherent_method_now_doc_hidden.rs"), | ||
"visibility_limit": String("public"), | ||
}, | ||
{ | ||
"method_name": String("associated_fn"), | ||
"method_visibility": String("public"), | ||
"name": String("Foo"), | ||
"path": List([ | ||
String("inherent_method_now_doc_hidden"), | ||
String("union_inherent_method_now_doc_hidden"), | ||
String("Foo"), | ||
]), | ||
"span_begin_line": Uint64(7), | ||
"span_filename": String("src/union_inherent_method_now_doc_hidden.rs"), | ||
"visibility_limit": String("public"), | ||
}, | ||
{ | ||
"method_name": String("method"), | ||
"method_visibility": String("public"), | ||
"name": String("Foo"), | ||
"path": List([ | ||
String("inherent_method_now_doc_hidden"), | ||
String("union_inherent_method_now_doc_hidden"), | ||
String("Foo"), | ||
]), | ||
"span_begin_line": Uint64(11), | ||
"span_filename": String("src/union_inherent_method_now_doc_hidden.rs"), | ||
"visibility_limit": String("public"), | ||
}, | ||
], | ||
} |
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