-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Restriction lint for function pointer casts #7705
Conversation
r? @camsteffen (rust-highfive has picked a reviewer for you, use r? to override) |
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.
Could we generalize the lint even more, ban a cast to any type, and name it fn_cast
? That makes the lint name situation a little better.
cbf3ef8
to
6078a36
Compare
Thanks for the feedback @camsteffen! I've addressed all but one of your suggestions and I'm liking the new |
☔ The latest upstream changes (presumably #7673) made this pull request unmergeable. Please resolve the merge conflicts. |
6078a36
to
2a85d5f
Compare
Sorry, I'm second guessing what to do for the lint name. I didn't realize that this lint still allows I feel that we need to rename For this new lint, I suggest That leaves In sum:
@rust-lang/clippy thoughts? |
Alternatively we could keep the fn prop(xs: Vec<isize>) -> TestResult {
if xs.len() != 1 {
return TestResult::discard()
}
TestResult::from_bool(xs == reverse(&xs))
}
quickcheck(prop as fn(Vec<isize>) -> TestResult); Maybe this pattern is rare enough that hitting it with a restriction lint is considered acceptable. I'm not familiar with the process for removing a lint entirely... is it painful? |
I wouldn't rename it, because I think it makes sense to keep the name close to the I don't see a problem with keeping the old names and introduce a new |
Yeah I agree... Then it makes less sense to use "integer" for the new lint because it sounds more specific when it is actually less specific. So now I've come full circle and think the new lint should be |
We should decide what behavior we want for the lint, and name it accordingly. Not the other way around |
By now you're my go-to person for lint names 😄 So I'd be fine with that. Agreed on not linting fn -> fn_ptr. |
2a85d5f
to
c4cfd40
Compare
Ok, updated back to |
One minor thing and then ready to merge! |
c9ef27e
to
fbd0fb9
Compare
I squashed the commits. Thanks! @bors r+ |
📌 Commit fbd0fb9 has been approved by |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
The existing lints for function pointer casts cover the cases where a cast is non-portable or would result in truncation, however there's currently no way to forbid numeric function pointer casts entirely.
I've added a new lint
fn_to_numeric_cast_any
, which allows one to ban all numeric function pointer casts, including tousize
. This is useful if you're writing high-level Rust and want to opt-out of potentially surprising behaviour, avoiding silent bugs from forgotten parentheses, e.g.I'm open to suggestions for the naming of the lint, because. We've stuck withfn_to_numeric_cast_any
is a bit clunky. Ideally I'd call this lintfn_to_numeric_cast
, but that name is already taken for the more specific lintfn_to_numeric_cast_any
to avoid renaming the existing lint, or choosing a different name that's too generic (likefn_cast
).I'm also open to changing the suggestion behaviour, as adding parentheses is only one of many possible ways to fix the lint.
changelog: add
[`fn_to_numeric_cast_any`]
restriction lint