-
-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new lint:
trait_method_marked_deprecated
- Loading branch information
Showing
7 changed files
with
192 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,59 @@ | ||
SemverQuery( | ||
id: "trait_method_marked_deprecated", | ||
human_readable_name: "trait method #[deprecated] added", | ||
description: "A trait method has been newly marked with #[deprecated].", | ||
required_update: Minor, | ||
lint_level: Deny, | ||
reference_link: Some("https://doc.rust-lang.org/reference/attributes/diagnostics.html#the-deprecated-attribute"), | ||
query: r#" | ||
{ | ||
CrateDiff { | ||
current { | ||
item { | ||
... on Trait { | ||
visibility_limit @filter(op: "=", value: ["$public"]) | ||
name @output | ||
importable_path { | ||
path @tag @output | ||
public_api @filter(op: "=", value: ["$true"]) | ||
} | ||
method { | ||
method_name: name @output @tag | ||
deprecated @filter(op: "=", value: ["$true"]) | ||
} | ||
span_: span @optional { | ||
filename @output | ||
begin_line @output | ||
} | ||
} | ||
} | ||
} | ||
baseline { | ||
item { | ||
... on Trait { | ||
visibility_limit @filter(op: "=", value: ["$public"]) @output | ||
importable_path { | ||
path @filter(op: "=", value: ["%path"]) | ||
public_api @filter(op: "=", value: ["$true"]) | ||
} | ||
method { | ||
name @filter(op: "=", value: ["%method_name"]) | ||
deprecated @filter(op: "!=", value: ["$true"]) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}"#, | ||
arguments: { | ||
"public": "public", | ||
"true": true, | ||
}, | ||
error_message: "A trait method is now #[deprecated]. Downstream crates will get a compiler warning when using this method.", | ||
per_result_error_template: Some("method {{method_name}} in trait {{join \"::\" path}} 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
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_method_marked_deprecated" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] |
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,37 @@ | ||
pub trait TraitWithMethodToBeDeprecated { | ||
// These methods are now deprecated and should be reported | ||
#[deprecated] | ||
fn method_to_deprecated(&self) -> i32; | ||
|
||
#[deprecated = "This method is deprecated"] | ||
fn method_to_deprecated_message(&self, input: &str) -> String; | ||
|
||
// These methods should not trigger the lint | ||
fn method_stays_normal(&self); | ||
|
||
#[deprecated] | ||
fn method_already_deprecated(&self); | ||
|
||
#[deprecated = "New message"] | ||
fn method_message_changes(&self); | ||
} | ||
|
||
// Changes to private trait methods should not be reported | ||
trait PrivateTrait { | ||
#[deprecated] | ||
fn private_method_to_deprecated(&self); | ||
} | ||
|
||
#[deprecated] | ||
pub trait DeprecatedTrait { | ||
// Adding deprecated to a method in an already deprecated trait should not be reported | ||
#[deprecated] | ||
fn method_in_deprecated_trait(&self); | ||
} | ||
|
||
// This trait was added in the new version with deprecated methods. | ||
// It should NOT be reported by this rule to avoid duplicate lints. | ||
pub trait NewTraitWithDeprecatedMethod { | ||
#[deprecated] | ||
fn new_deprecated_method(&self); | ||
} |
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_method_marked_deprecated" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] |
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,27 @@ | ||
pub trait TraitWithMethodToBeDeprecated { | ||
// This method will be marked deprecated | ||
fn method_to_deprecated(&self) -> i32; | ||
|
||
// This method will be marked deprecated with a message | ||
fn method_to_deprecated_message(&self, input: &str) -> String; | ||
|
||
// These methods should not trigger the lint | ||
fn method_stays_normal(&self); | ||
|
||
#[deprecated] | ||
fn method_already_deprecated(&self); | ||
|
||
#[deprecated = "Old message"] | ||
fn method_message_changes(&self); | ||
} | ||
|
||
// Changes to private trait methods should not be reported | ||
trait PrivateTrait { | ||
fn private_method_to_deprecated(&self); | ||
} | ||
|
||
#[deprecated] | ||
pub trait DeprecatedTrait { | ||
// Adding deprecated to a method in an already deprecated trait should not be reported | ||
fn method_in_deprecated_trait(&self); | ||
} |
54 changes: 54 additions & 0 deletions
54
test_outputs/query_execution/trait_method_marked_deprecated.snap
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,54 @@ | ||
--- | ||
source: src/query.rs | ||
expression: "&query_execution_results" | ||
--- | ||
{ | ||
"./test_crates/trait_marked_deprecated/": [ | ||
{ | ||
"method_name": String("method"), | ||
"name": String("TraitToDeprecatedTrait"), | ||
"path": List([ | ||
String("trait_marked_deprecated"), | ||
String("TraitToDeprecatedTrait"), | ||
]), | ||
"span_begin_line": Uint64(5), | ||
"span_filename": String("src/lib.rs"), | ||
"visibility_limit": String("public"), | ||
}, | ||
{ | ||
"method_name": String("method"), | ||
"name": String("TraitToDeprecatedMessageTrait"), | ||
"path": List([ | ||
String("trait_marked_deprecated"), | ||
String("TraitToDeprecatedMessageTrait"), | ||
]), | ||
"span_begin_line": Uint64(10), | ||
"span_filename": String("src/lib.rs"), | ||
"visibility_limit": String("public"), | ||
}, | ||
], | ||
"./test_crates/trait_method_marked_deprecated/": [ | ||
{ | ||
"method_name": String("method_to_deprecated"), | ||
"name": String("TraitWithMethodToBeDeprecated"), | ||
"path": List([ | ||
String("trait_method_marked_deprecated"), | ||
String("TraitWithMethodToBeDeprecated"), | ||
]), | ||
"span_begin_line": Uint64(1), | ||
"span_filename": String("src/lib.rs"), | ||
"visibility_limit": String("public"), | ||
}, | ||
{ | ||
"method_name": String("method_to_deprecated_message"), | ||
"name": String("TraitWithMethodToBeDeprecated"), | ||
"path": List([ | ||
String("trait_method_marked_deprecated"), | ||
String("TraitWithMethodToBeDeprecated"), | ||
]), | ||
"span_begin_line": Uint64(1), | ||
"span_filename": String("src/lib.rs"), | ||
"visibility_limit": String("public"), | ||
}, | ||
], | ||
} |