Skip to content

Commit 7c2ad1b

Browse files
authored
new lint: type_associated_const_deprecated (#1131)
part of: #57
1 parent 356dfad commit 7c2ad1b

File tree

14 files changed

+754
-0
lines changed

14 files changed

+754
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
SemverQuery(
2+
id: "type_associated_const_marked_deprecated",
3+
human_readable_name: "type's associated constant #[deprecated] added",
4+
description: "An inherent associated constant has been newly marked with #[deprecated].",
5+
required_update: Minor,
6+
lint_level: Deny,
7+
reference_link: Some("https://doc.rust-lang.org/reference/attributes/diagnostics.html#the-deprecated-attribute"),
8+
query: r#"
9+
{
10+
CrateDiff {
11+
current {
12+
item {
13+
... on ImplOwner {
14+
visibility_limit @filter(op: "=", value: ["$public"])
15+
name @output
16+
owner_type: __typename @tag @output
17+
18+
importable_path {
19+
path @tag @output
20+
public_api @filter(op: "=", value: ["$true"])
21+
}
22+
23+
inherent_impl {
24+
public_api_eligible @filter(op: "=", value: ["$true"])
25+
26+
associated_constant {
27+
associated_constant: name @output @tag
28+
public_api_eligible @filter(op: "=", value: ["$true"])
29+
deprecated @filter(op: "=", value: ["$true"])
30+
31+
span_: span @optional {
32+
filename @output
33+
begin_line @output
34+
end_line @output
35+
}
36+
}
37+
}
38+
}
39+
}
40+
}
41+
baseline {
42+
item {
43+
... on ImplOwner {
44+
visibility_limit @filter(op: "=", value: ["$public"])
45+
__typename @filter(op: "=", value: ["%owner_type"])
46+
47+
importable_path {
48+
path @filter(op: "=", value: ["%path"])
49+
public_api @filter(op: "=", value: ["$true"])
50+
}
51+
52+
inherent_impl {
53+
public_api_eligible @filter(op: "=", value: ["$true"])
54+
55+
associated_constant {
56+
name @filter(op: "=", value: ["%associated_constant"])
57+
public_api_eligible @filter(op: "=", value: ["$true"])
58+
deprecated @filter(op: "!=", value: ["$true"])
59+
}
60+
}
61+
}
62+
}
63+
}
64+
}
65+
}"#,
66+
arguments: {
67+
"public": "public",
68+
"true": true,
69+
},
70+
error_message: "A type's associated constant is now #[deprecated]. Downstream crates will get a compiler warning when using it.",
71+
per_result_error_template: Some("associated constant {{join \"::\" path}}::{{associated_constant}} in {{span_filename}}:{{span_begin_line}}"),
72+
)

src/query.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1251,6 +1251,7 @@ add_lints!(
12511251
tuple_struct_to_plain_struct,
12521252
type_allows_fewer_const_generic_params,
12531253
type_allows_fewer_generic_type_params,
1254+
type_associated_const_marked_deprecated,
12541255
type_marked_deprecated,
12551256
type_method_marked_deprecated,
12561257
type_mismatched_generic_lifetimes,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[package]
2+
publish = false
3+
name = "type_associated_const_marked_deprecated"
4+
version = "0.1.0"
5+
edition = "2021"
6+
7+
[dependencies]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
pub enum NormalEnum {
2+
A,
3+
B,
4+
}
5+
6+
impl NormalEnum {
7+
#[deprecated]
8+
pub const CONST_TO_DEPRECATED: i32 = 42;
9+
10+
#[deprecated = "Use new_const instead"]
11+
pub const CONST_WITH_MESSAGE: &'static str = "hello";
12+
13+
#[deprecated]
14+
pub const ALREADY_DEPRECATED: u32 = 100;
15+
16+
pub const STAYS_NORMAL: bool = true;
17+
}
18+
19+
#[doc(hidden)]
20+
pub enum HiddenEnum {
21+
A,
22+
}
23+
24+
impl HiddenEnum {
25+
#[deprecated]
26+
pub const CONST_TO_DEPRECATED: i32 = 0;
27+
}
28+
29+
pub enum EnumWithHiddenImpl {
30+
A,
31+
}
32+
33+
#[doc(hidden)]
34+
impl EnumWithHiddenImpl {
35+
#[deprecated]
36+
pub const CONST_TO_DEPRECATED: i32 = 1;
37+
}
38+
39+
pub enum EnumWithHiddenConst {
40+
A,
41+
}
42+
43+
impl EnumWithHiddenConst {
44+
#[doc(hidden)]
45+
#[deprecated]
46+
pub const CONST_TO_DEPRECATED: i32 = 2;
47+
}
48+
49+
#[deprecated]
50+
pub enum EnumBecomesDeprecated {
51+
A,
52+
}
53+
54+
impl EnumBecomesDeprecated {
55+
pub const CONST_REMAINS_NORMAL: i32 = 3;
56+
}
57+
58+
enum PrivateEnum {
59+
A,
60+
}
61+
62+
impl PrivateEnum {
63+
#[deprecated]
64+
pub const CONST_TO_DEPRECATED: i32 = 4;
65+
}
66+
67+
// Both enum and const are deprecated
68+
#[deprecated = "Use NewEnum instead"]
69+
pub enum BothBecomeDeprecated {
70+
A,
71+
B,
72+
}
73+
74+
impl BothBecomeDeprecated {
75+
#[deprecated]
76+
pub const CONST_BOTH_DEPRECATED: i32 = 5;
77+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pub mod enums;
2+
pub mod structs;
3+
pub mod unions;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
pub struct NormalStruct {
2+
value: i32,
3+
}
4+
5+
impl NormalStruct {
6+
#[deprecated]
7+
pub const CONST_TO_DEPRECATED: i32 = 42;
8+
9+
#[deprecated = "Use new_const instead"]
10+
pub const CONST_WITH_MESSAGE: &'static str = "hello";
11+
12+
#[deprecated]
13+
pub const ALREADY_DEPRECATED: u32 = 100;
14+
15+
pub const STAYS_NORMAL: bool = true;
16+
}
17+
18+
#[doc(hidden)]
19+
pub struct HiddenStruct {
20+
value: i32,
21+
}
22+
23+
impl HiddenStruct {
24+
#[deprecated]
25+
pub const CONST_TO_DEPRECATED: i32 = 0;
26+
}
27+
28+
pub struct StructWithHiddenImpl {
29+
value: i32,
30+
}
31+
32+
#[doc(hidden)]
33+
impl StructWithHiddenImpl {
34+
#[deprecated]
35+
pub const CONST_TO_DEPRECATED: i32 = 1;
36+
}
37+
38+
pub struct StructWithHiddenConst {
39+
value: i32,
40+
}
41+
42+
impl StructWithHiddenConst {
43+
#[doc(hidden)]
44+
#[deprecated]
45+
pub const CONST_TO_DEPRECATED: i32 = 2;
46+
}
47+
48+
#[deprecated]
49+
pub struct StructBecomesDeprecated {
50+
value: i32,
51+
}
52+
53+
impl StructBecomesDeprecated {
54+
pub const CONST_REMAINS_NORMAL: i32 = 3;
55+
}
56+
57+
struct PrivateStruct {
58+
value: i32,
59+
}
60+
61+
impl PrivateStruct {
62+
#[deprecated]
63+
pub const CONST_TO_DEPRECATED: i32 = 4;
64+
}
65+
66+
// Both struct and const are deprecated
67+
#[deprecated = "Use NewStruct instead"]
68+
pub struct BothBecomeDeprecated {
69+
value: i32,
70+
}
71+
72+
impl BothBecomeDeprecated {
73+
#[deprecated]
74+
pub const CONST_BOTH_DEPRECATED: i32 = 5;
75+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
pub union NormalUnion {
2+
a: i32,
3+
b: u32,
4+
}
5+
6+
impl NormalUnion {
7+
#[deprecated]
8+
pub const CONST_TO_DEPRECATED: i32 = 42;
9+
10+
#[deprecated = "Use new_const instead"]
11+
pub const CONST_WITH_MESSAGE: &'static str = "hello";
12+
13+
#[deprecated]
14+
pub const ALREADY_DEPRECATED: u32 = 100;
15+
16+
pub const STAYS_NORMAL: bool = true;
17+
}
18+
19+
#[doc(hidden)]
20+
pub union HiddenUnion {
21+
a: i32,
22+
}
23+
24+
impl HiddenUnion {
25+
#[deprecated]
26+
pub const CONST_TO_DEPRECATED: i32 = 0;
27+
}
28+
29+
pub union UnionWithHiddenImpl {
30+
a: i32,
31+
}
32+
33+
#[doc(hidden)]
34+
impl UnionWithHiddenImpl {
35+
#[deprecated]
36+
pub const CONST_TO_DEPRECATED: i32 = 1;
37+
}
38+
39+
pub union UnionWithHiddenConst {
40+
a: i32,
41+
}
42+
43+
impl UnionWithHiddenConst {
44+
#[doc(hidden)]
45+
#[deprecated]
46+
pub const CONST_TO_DEPRECATED: i32 = 2;
47+
}
48+
49+
#[deprecated]
50+
pub union UnionBecomesDeprecated {
51+
a: i32,
52+
}
53+
54+
impl UnionBecomesDeprecated {
55+
pub const CONST_REMAINS_NORMAL: i32 = 3;
56+
}
57+
58+
union PrivateUnion {
59+
a: i32,
60+
}
61+
62+
impl PrivateUnion {
63+
#[deprecated]
64+
pub const CONST_TO_DEPRECATED: i32 = 4;
65+
}
66+
67+
// Both union and const are deprecated
68+
#[deprecated = "Use NewUnion instead"]
69+
pub union BothBecomeDeprecated {
70+
a: i32,
71+
}
72+
73+
impl BothBecomeDeprecated {
74+
#[deprecated]
75+
pub const CONST_BOTH_DEPRECATED: i32 = 5;
76+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[package]
2+
publish = false
3+
name = "type_associated_const_marked_deprecated"
4+
version = "0.1.0"
5+
edition = "2021"
6+
7+
[dependencies]

0 commit comments

Comments
 (0)