Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new lint: global_value_marked_deprecated #1101

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions src/lints/global_value_marked_deprecated.ron
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
SemverQuery(
id: "global_value_marked_deprecated",
human_readable_name: "global value #[deprecated] added",
description: "A constant or static 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 GlobalValue {
visibility_limit @filter(op: "=", value: ["$public"])
kind: __typename @output
name @output
deprecated @filter(op: "=", value: ["$true"])

importable_path {
path @tag @output
public_api @filter(op: "=", value: ["$true"])
}

span_: span @optional {
filename @output
begin_line @output
}
}
}
}
baseline {
item {
... on GlobalValue {
visibility_limit @filter(op: "=", value: ["$public"]) @output
deprecated @filter(op: "!=", value: ["$true"])

importable_path {
path @filter(op: "=", value: ["%path"])
public_api @filter(op: "=", value: ["$true"])
}
}
}
}
}
}"#,
arguments: {
"public": "public",
"true": true,
},
error_message: "A global value (constant or static) is now #[deprecated]. Downstream crates will get a compiler warning when using this value.",
per_result_error_template: Some("{{lowercase kind}} {{name}} in {{span_filename}}:{{span_begin_line}}"),
)
6 changes: 3 additions & 3 deletions src/lints/pub_module_level_const_missing.ron
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
SemverQuery(
id: "pub_module_level_const_missing",
human_readable_name: "pub module-level const is missing",
description: "A pub const is missing, renamed, or changed to static.",
description: "A pub const is missing or renamed.",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch!

required_update: Major,
lint_level: Deny,
reference_link: Some("https://doc.rust-lang.org/cargo/reference/semver.html#item-remove"),
Expand All @@ -28,7 +28,7 @@ SemverQuery(
}
current {
item @fold @transform(op: "count") @filter(op: "=", value: ["$zero"]) {
... on Constant {
... on GlobalValue {
visibility_limit @filter(op: "=", value: ["$public"])

importable_path {
Expand All @@ -44,6 +44,6 @@ SemverQuery(
"zero": 0,
"true": true,
},
error_message: "A public const is missing, renamed, or changed from const to static.",
error_message: "A public const is missing or renamed",
per_result_error_template: Some("{{name}} in file {{span_filename}}:{{span_begin_line}}"),
)
1 change: 1 addition & 0 deletions src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1174,6 +1174,7 @@ add_lints!(
function_requires_different_const_generic_params,
function_requires_different_generic_type_params,
function_unsafe_added,
global_value_marked_deprecated,
inherent_associated_const_now_doc_hidden,
inherent_associated_pub_const_missing,
inherent_method_const_removed,
Expand Down
7 changes: 7 additions & 0 deletions test_crates/global_value_marked_deprecated/new/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
publish = false
name = "global_value_marked_deprecated"
version = "0.1.0"
edition = "2021"

[dependencies]
49 changes: 49 additions & 0 deletions test_crates/global_value_marked_deprecated/new/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// These values are now deprecated and should be reported
#[deprecated]
pub const VALUE_TO_DEPRECATED: i32 = 42;

#[deprecated]
pub static STATIC_TO_DEPRECATED: &str = "hello";

// Changed from const to static and deprecated - should be reported
#[deprecated]
pub static CONST_BECOMING_STATIC: u32 = 123;

// Changed from static to const and deprecated - should be reported
#[deprecated]
pub const STATIC_BECOMING_CONST: i32 = 456;

#[deprecated = "This value is deprecated"]
pub const VALUE_TO_DEPRECATED_MESSAGE: bool = true;

#[deprecated = "This static is deprecated"]
pub static STATIC_TO_DEPRECATED_MESSAGE: char = 'x';

// These values should not trigger the lint
pub const VALUE_STAYS_NORMAL: u32 = 100;
pub static STATIC_STAYS_NORMAL: i64 = 200;

#[deprecated]
pub const VALUE_ALREADY_DEPRECATED: f64 = 3.14;

#[deprecated]
pub static STATIC_ALREADY_DEPRECATED: u8 = 255;

#[deprecated = "New message"]
pub const VALUE_MESSAGE_CHANGES: &str = "old";

// Private values should not be reported
#[deprecated]
const PRIVATE_VALUE_TO_DEPRECATED: i32 = 0;

#[deprecated]
static PRIVATE_STATIC_TO_DEPRECATED: i32 = 1;

// Hidden values should not be reported
#[doc(hidden)]
#[deprecated]
pub const HIDDEN_VALUE_TO_DEPRECATED: i32 = 2;

#[doc(hidden)]
#[deprecated]
pub static HIDDEN_STATIC_TO_DEPRECATED: i32 = 3;
7 changes: 7 additions & 0 deletions test_crates/global_value_marked_deprecated/old/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
publish = false
name = "global_value_marked_deprecated"
version = "0.1.0"
edition = "2021"

[dependencies]
36 changes: 36 additions & 0 deletions test_crates/global_value_marked_deprecated/old/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// These values will be marked deprecated
pub const VALUE_TO_DEPRECATED: i32 = 42;
pub static STATIC_TO_DEPRECATED: &str = "hello";

// This const will become a static and be deprecated
pub const CONST_BECOMING_STATIC: u32 = 123;

// This static will become a const and be deprecated
pub static STATIC_BECOMING_CONST: i32 = 456;

pub const VALUE_TO_DEPRECATED_MESSAGE: bool = true;
pub static STATIC_TO_DEPRECATED_MESSAGE: char = 'x';

// These values should not trigger the lint
pub const VALUE_STAYS_NORMAL: u32 = 100;
pub static STATIC_STAYS_NORMAL: i64 = 200;

#[deprecated]
pub const VALUE_ALREADY_DEPRECATED: f64 = 3.14;

#[deprecated]
pub static STATIC_ALREADY_DEPRECATED: u8 = 255;

#[deprecated = "Old message"]
pub const VALUE_MESSAGE_CHANGES: &str = "old";

// Private values should not be reported
const PRIVATE_VALUE_TO_DEPRECATED: i32 = 0;
static PRIVATE_STATIC_TO_DEPRECATED: i32 = 1;

// Hidden values should not be reported
#[doc(hidden)]
pub const HIDDEN_VALUE_TO_DEPRECATED: i32 = 2;

#[doc(hidden)]
pub static HIDDEN_STATIC_TO_DEPRECATED: i32 = 3;
74 changes: 74 additions & 0 deletions test_outputs/query_execution/global_value_marked_deprecated.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
---
source: src/query.rs
expression: "&query_execution_results"
---
{
"./test_crates/global_value_marked_deprecated/": [
{
"kind": String("Constant"),
"name": String("VALUE_TO_DEPRECATED"),
"path": List([
String("global_value_marked_deprecated"),
String("VALUE_TO_DEPRECATED"),
]),
"span_begin_line": Uint64(3),
"span_filename": String("src/lib.rs"),
"visibility_limit": String("public"),
},
{
"kind": String("Static"),
"name": String("STATIC_TO_DEPRECATED"),
"path": List([
String("global_value_marked_deprecated"),
String("STATIC_TO_DEPRECATED"),
]),
"span_begin_line": Uint64(6),
"span_filename": String("src/lib.rs"),
"visibility_limit": String("public"),
},
{
"kind": String("Static"),
"name": String("CONST_BECOMING_STATIC"),
"path": List([
String("global_value_marked_deprecated"),
String("CONST_BECOMING_STATIC"),
]),
"span_begin_line": Uint64(10),
"span_filename": String("src/lib.rs"),
"visibility_limit": String("public"),
},
{
"kind": String("Constant"),
"name": String("STATIC_BECOMING_CONST"),
"path": List([
String("global_value_marked_deprecated"),
String("STATIC_BECOMING_CONST"),
]),
"span_begin_line": Uint64(14),
"span_filename": String("src/lib.rs"),
"visibility_limit": String("public"),
},
{
"kind": String("Constant"),
"name": String("VALUE_TO_DEPRECATED_MESSAGE"),
"path": List([
String("global_value_marked_deprecated"),
String("VALUE_TO_DEPRECATED_MESSAGE"),
]),
"span_begin_line": Uint64(17),
"span_filename": String("src/lib.rs"),
"visibility_limit": String("public"),
},
{
"kind": String("Static"),
"name": String("STATIC_TO_DEPRECATED_MESSAGE"),
"path": List([
String("global_value_marked_deprecated"),
String("STATIC_TO_DEPRECATED_MESSAGE"),
]),
"span_begin_line": Uint64(20),
"span_filename": String("src/lib.rs"),
"visibility_limit": String("public"),
},
],
}
56 changes: 0 additions & 56 deletions test_outputs/query_execution/pub_module_level_const_missing.snap
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,6 @@ expression: "&query_execution_results"
"span_filename": String("src/lib.rs"),
"visibility_limit": String("public"),
},
{
"name": String("PUB_CONST_IN_GLOBAL_WILL_BE_STATIC"),
"path": List([
String("pub_module_level_const_missing"),
String("PUB_CONST_IN_GLOBAL_WILL_BE_STATIC"),
]),
"span_begin_line": Uint64(4),
"span_filename": String("src/lib.rs"),
"visibility_limit": String("public"),
},
{
"name": String("PUB_CONST_IN_GLOBAL_WILL_BE_PRIVATE_CONST"),
"path": List([
Expand Down Expand Up @@ -76,17 +66,6 @@ expression: "&query_execution_results"
"span_filename": String("src/lib.rs"),
"visibility_limit": String("public"),
},
{
"name": String("PUB_CONST_IN_MODULE_WILL_BE_STATIC"),
"path": List([
String("pub_module_level_const_missing"),
String("my_module"),
String("PUB_CONST_IN_MODULE_WILL_BE_STATIC"),
]),
"span_begin_line": Uint64(12),
"span_filename": String("src/lib.rs"),
"visibility_limit": String("public"),
},
{
"name": String("PUB_CONST_IN_MODULE_WILL_BE_PRIVATE_CONST"),
"path": List([
Expand All @@ -109,17 +88,6 @@ expression: "&query_execution_results"
"span_filename": String("src/lib.rs"),
"visibility_limit": String("public"),
},
{
"name": String("PUB_CONST_IN_MODULE_WILL_RE_EXPORT_STATIC"),
"path": List([
String("pub_module_level_const_missing"),
String("my_module"),
String("PUB_CONST_IN_MODULE_WILL_RE_EXPORT_STATIC"),
]),
"span_begin_line": Uint64(16),
"span_filename": String("src/lib.rs"),
"visibility_limit": String("public"),
},
{
"name": String("PUB_CONST_IN_NESTED_MODULE_WILL_REMOVE"),
"path": List([
Expand All @@ -144,18 +112,6 @@ expression: "&query_execution_results"
"span_filename": String("src/lib.rs"),
"visibility_limit": String("public"),
},
{
"name": String("PUB_CONST_IN_NESTED_MODULE_WILL_BE_STATIC"),
"path": List([
String("pub_module_level_const_missing"),
String("my_module"),
String("my_module_nested"),
String("PUB_CONST_IN_NESTED_MODULE_WILL_BE_STATIC"),
]),
"span_begin_line": Uint64(22),
"span_filename": String("src/lib.rs"),
"visibility_limit": String("public"),
},
{
"name": String("PUB_CONST_IN_NESTED_MODULE_WILL_BE_PRIVATE_CONST"),
"path": List([
Expand All @@ -180,17 +136,5 @@ expression: "&query_execution_results"
"span_filename": String("src/lib.rs"),
"visibility_limit": String("public"),
},
{
"name": String("PUB_CONST_IN_NESTED_MODULE_WILL_RE_EXPORT_STATIC"),
"path": List([
String("pub_module_level_const_missing"),
String("my_module"),
String("my_module_nested"),
String("PUB_CONST_IN_NESTED_MODULE_WILL_RE_EXPORT_STATIC"),
]),
"span_begin_line": Uint64(26),
"span_filename": String("src/lib.rs"),
"visibility_limit": String("public"),
},
],
}
Loading