-
-
Notifications
You must be signed in to change notification settings - Fork 92
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
new lint: global_value_marked_deprecated
#1101
Conversation
This is a bit of nuance, yes:
Using #[doc(hidden)]
pub struct Example; Using mod private {
pub trait Sealed {}
} You'll recognize this as a trick common in trait-sealing, where So, concrete advice for queries:
|
"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("global value {{join \"::\" path}} in {{span_filename}}:{{span_begin_line}}"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be really nice if we could tell the user whether that specific value is a constant or static. "Global value" is a term we invented for purposes of making the schema make sense, not something well-established in Rust, so it might be confusing to users.
#[deprecated] | ||
pub const fn CONST_FN_TO_DEPRECATED(x: i32) -> i32 { | ||
x + 1 | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const fn
is not considered a const
item btw, it won't get picked up by this lint. It doesn't have a globally-available value per se. It's just a function that can be evaluated at compile-time, so it gets reported by the lint for deprecated functions. This is good! We don't want the same item to get flagged for the same issue by more than one lint — that'd just be frustrating.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I knew when I ran the test, I was worried about if it would trigger both! But should I keep it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bit of a judgment call that could go either way — I'd remove them because I think there's little risk of a future false-positive here (where const fn
is treated as a public constant item), and there's risk of confusion during future maintenance ("Why is const fn
being tested here? Surely there's a good reason I'm just missing?").
Thank you for the detailed explanation, learnt a lot again!
I see, very helpful advice on when to use which! I would apply this rule when I add new lints!
Yes, I would definitely want to work on deeper things after getting familiar with the whole project more! |
"./test_crates/global_value_marked_deprecated/": [ | ||
{ | ||
"name": String("CONST_BECOMING_STATIC"), | ||
"path": List([ | ||
String("global_value_marked_deprecated"), | ||
String("CONST_BECOMING_STATIC"), | ||
]), | ||
"span_begin_line": Uint64(9), | ||
"span_filename": String("src/lib.rs"), | ||
"visibility_limit": String("public"), | ||
}, | ||
], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is actually a false-positive in the pub_module_level_const_missing
lint, as of Rust 1.83 which relaxed the rules on when & how static
items may be used in const
items. Previously, assigning a static
to a const
item was always a hard error. As of 1.83, certain static
items can be assigned to const
items so we can't prove breakage merely by saying "this item used to be const
but now is static
."
Care to fix that lint? All you need to do is flip the baseline
type check from ... on Constant
to ... on GlobalValue
If you're also interested in writing new lints that flag the new breakage behavior made possible by Rust 1.83, I'd be happy to point you in the right direction there as well!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Care to fix that lint? All you need to do is flip the baseline type check from ... on Constant to ... on GlobalValue
Definitely
If you're also interested in writing new lints that flag the new breakage behavior made possible by Rust 1.83, I'd be happy to point you in the right direction there as well!
Would like to know more about this, would you write it down in a new issue or?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Care to fix that lint? All you need to do is flip the baseline type check from ... on Constant to ... on GlobalValue
I think we want to flip current
to be GlobalValue
since now a const
became static
should be allowed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, of course. Thanks for the catch!
@@ -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.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch!
part of #57
I am actually not very sure when I should use
public_api_eligible
orvisibility_limit
since we check that for trait method/type/const and enum, enum variant, but not for trait itself, impl_owner itself?