-
-
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_associated_const_marked_deprecated
(#1100)
part of: #57
- Loading branch information
Showing
7 changed files
with
189 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,61 @@ | ||
SemverQuery( | ||
id: "trait_associated_const_marked_deprecated", | ||
human_readable_name: "trait associated constant #[deprecated] added", | ||
description: "A trait's associated constant 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"]) | ||
} | ||
associated_constant { | ||
associated_constant: name @output @tag | ||
public_api_eligible @filter(op: "=", value: ["$true"]) | ||
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"]) | ||
} | ||
associated_constant { | ||
name @filter(op: "=", value: ["%associated_constant"]) | ||
public_api_eligible @filter(op: "=", value: ["$true"]) | ||
deprecated @filter(op: "!=", value: ["$true"]) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}"#, | ||
arguments: { | ||
"public": "public", | ||
"true": true, | ||
}, | ||
error_message: "A trait associated constant is now #[deprecated]. Downstream crates will get a compiler warning when using it.", | ||
per_result_error_template: Some("associated constant {{associated_constant}} 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
7 changes: 7 additions & 0 deletions
7
test_crates/trait_associated_const_marked_deprecated/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_marked_deprecated" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] |
44 changes: 44 additions & 0 deletions
44
test_crates/trait_associated_const_marked_deprecated/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,44 @@ | ||
pub trait TraitWithConstToBeDeprecated { | ||
// These constants are now deprecated and should be reported | ||
#[deprecated] | ||
const CONST_TO_DEPRECATED: i32 = 42; | ||
|
||
#[deprecated = "This constant is deprecated"] | ||
const CONST_TO_DEPRECATED_MESSAGE: &'static str = "hello"; | ||
|
||
// These constants should not trigger the lint | ||
const CONST_STAYS_NORMAL: bool = true; | ||
|
||
#[deprecated] | ||
const CONST_ALREADY_DEPRECATED: u32 = 100; | ||
|
||
#[deprecated = "New message"] | ||
const CONST_MESSAGE_CHANGES: char = 'x'; | ||
} | ||
|
||
// Changes to private trait constants should not be reported | ||
trait PrivateTrait { | ||
#[deprecated] | ||
const PRIVATE_CONST_TO_DEPRECATED: i32 = 0; | ||
} | ||
|
||
#[deprecated] | ||
pub trait DeprecatedTrait { | ||
// Adding deprecated to a constant in an already deprecated trait should not be reported | ||
#[deprecated] | ||
const CONST_IN_DEPRECATED_TRAIT: i32 = 1; | ||
} | ||
|
||
// Hidden trait - changes to its constants should not be reported | ||
#[doc(hidden)] | ||
pub trait HiddenTrait { | ||
#[deprecated] | ||
const CONST_BECOMES_DEPRECATED: i32 = 2; | ||
} | ||
|
||
// Public trait with hidden constant should not be reported | ||
pub trait PublicTraitWithHiddenConst { | ||
#[doc(hidden)] | ||
#[deprecated] | ||
const HIDDEN_CONST_BECOMES_DEPRECATED: i32 = 3; | ||
} |
7 changes: 7 additions & 0 deletions
7
test_crates/trait_associated_const_marked_deprecated/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_marked_deprecated" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] |
39 changes: 39 additions & 0 deletions
39
test_crates/trait_associated_const_marked_deprecated/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,39 @@ | ||
pub trait TraitWithConstToBeDeprecated { | ||
// This associated constant will be marked deprecated | ||
const CONST_TO_DEPRECATED: i32 = 42; | ||
|
||
// This associated constant will be marked deprecated with a message | ||
const CONST_TO_DEPRECATED_MESSAGE: &'static str = "hello"; | ||
|
||
// These constants should not trigger the lint | ||
const CONST_STAYS_NORMAL: bool = true; | ||
|
||
#[deprecated] | ||
const CONST_ALREADY_DEPRECATED: u32 = 100; | ||
|
||
#[deprecated = "Old message"] | ||
const CONST_MESSAGE_CHANGES: char = 'x'; | ||
} | ||
|
||
// Changes to private trait constants should not be reported | ||
trait PrivateTrait { | ||
const PRIVATE_CONST_TO_DEPRECATED: i32 = 0; | ||
} | ||
|
||
#[deprecated] | ||
pub trait DeprecatedTrait { | ||
// Adding deprecated to a constant in an already deprecated trait should not be reported | ||
const CONST_IN_DEPRECATED_TRAIT: i32 = 1; | ||
} | ||
|
||
// Hidden trait - changes to its constants should not be reported | ||
#[doc(hidden)] | ||
pub trait HiddenTrait { | ||
const CONST_BECOMES_DEPRECATED: i32 = 2; | ||
} | ||
|
||
// Public trait with hidden constant should not be reported | ||
pub trait PublicTraitWithHiddenConst { | ||
#[doc(hidden)] | ||
const HIDDEN_CONST_BECOMES_DEPRECATED: i32 = 3; | ||
} |
30 changes: 30 additions & 0 deletions
30
test_outputs/query_execution/trait_associated_const_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,30 @@ | ||
--- | ||
source: src/query.rs | ||
expression: "&query_execution_results" | ||
--- | ||
{ | ||
"./test_crates/trait_associated_const_marked_deprecated/": [ | ||
{ | ||
"associated_constant": String("CONST_TO_DEPRECATED"), | ||
"name": String("TraitWithConstToBeDeprecated"), | ||
"path": List([ | ||
String("trait_associated_const_marked_deprecated"), | ||
String("TraitWithConstToBeDeprecated"), | ||
]), | ||
"span_begin_line": Uint64(4), | ||
"span_filename": String("src/lib.rs"), | ||
"visibility_limit": String("public"), | ||
}, | ||
{ | ||
"associated_constant": String("CONST_TO_DEPRECATED_MESSAGE"), | ||
"name": String("TraitWithConstToBeDeprecated"), | ||
"path": List([ | ||
String("trait_associated_const_marked_deprecated"), | ||
String("TraitWithConstToBeDeprecated"), | ||
]), | ||
"span_begin_line": Uint64(7), | ||
"span_filename": String("src/lib.rs"), | ||
"visibility_limit": String("public"), | ||
}, | ||
], | ||
} |