Rewrite EndianBytes lint pass#17363
Conversation
|
r? @llogiq rustbot has assigned @llogiq. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
Lintcheck changes for 445d8f6
This comment will be updated if you push new changes |
* Check the method name before type checking. * Don't use `get_def_path` for `format!` when linting. * Check that the `from_*_bytes` method used is defined on one of the primitives. * Add suggestions for the other endian conversions if applicable. * Lint in the context of the method name. * Lint all uses of the methods, not just calls.
|
The lintcheck results are a pain to read. The added emissions can be split in three cases:
The removals all come from the macro location change. |
| if let Some(ty) = cx.ty_based_def(e.hir_id).opt_parent(cx).opt_impl_ty(cx) | ||
| && let ty::Uint(_) | ty::Int(_) | ty::Float(_) = *ty.instantiate_identity().skip_normalization().kind() |
There was a problem hiding this comment.
Was going to suggest using a diagnostic item to be certain these are applicable methods, but there's probably too many methods to justify the added certainty (6 methods, 6 unsigned integers, 6 signed integers, 2+ floats, so at least 84 diagnostic items...)
There was a problem hiding this comment.
Any type dependent name lookup prefers resolving to inherent items over trait items. Since we know the implemented type has methods with the names we're matching on we don't have to actually confirm anything here.
| if !only_one { | ||
| help_str.push_str("either of "); | ||
| span_lint_and_then(cx, lint, sp, msg, |diag| { | ||
| if !ptr::addr_eq(lint, HOST_ENDIAN_BYTES) && is_lint_allowed(cx, HOST_ENDIAN_BYTES, e.hir_id) { |
There was a problem hiding this comment.
I'm assuming the is_lint_allowed(...) check prevents suggesting an alternative that's also being linted away? If so, might be worth keeping the tests that confirmed that behaviour?
| #[rustfmt::skip] | ||
| #[warn(clippy::host_endian_bytes)] | ||
| #[warn(clippy::big_endian_bytes)] | ||
| fn host_encourage_little() { fn_body_smol!(); } | ||
|
|
||
| #[rustfmt::skip] | ||
| #[warn(clippy::host_endian_bytes)] | ||
| #[warn(clippy::little_endian_bytes)] | ||
| fn host_encourage_big() { fn_body_smol!(); } | ||
|
|
||
| #[rustfmt::skip] | ||
| #[warn(clippy::host_endian_bytes)] | ||
| #[warn(clippy::little_endian_bytes)] | ||
| #[warn(clippy::big_endian_bytes)] | ||
| fn no_help() { fn_body_smol!(); } | ||
|
|
||
| #[rustfmt::skip] | ||
| #[warn(clippy::little_endian_bytes)] | ||
| #[warn(clippy::big_endian_bytes)] | ||
| fn little_encourage_host() { fn_body_smol!(); } | ||
|
|
||
| #[rustfmt::skip] | ||
| #[warn(clippy::host_endian_bytes)] | ||
| #[warn(clippy::little_endian_bytes)] | ||
| fn little_encourage_big() { fn_body_smol!(); } | ||
|
|
||
| #[rustfmt::skip] | ||
| #[warn(clippy::big_endian_bytes)] | ||
| #[warn(clippy::little_endian_bytes)] | ||
| fn big_encourage_host() { fn_body_smol!(); } | ||
|
|
||
| #[rustfmt::skip] | ||
| #[warn(clippy::host_endian_bytes)] | ||
| #[warn(clippy::big_endian_bytes)] | ||
| fn big_encourage_little() { fn_body_smol!(); } |
There was a problem hiding this comment.
These are the tests I think are worth keeping as mentioned above.
There was a problem hiding this comment.
An equivalent test exists in each of the new test files.
There was a problem hiding this comment.
Whoops, that's my bad then!
|
☔ The latest upstream changes (possibly #17389) made this pull request unmergeable. Please resolve the merge conflicts. |
Changes:
get_def_pathforformat!when linting.from_*_bytesmethod used is defined on one of the primitives.The old test file broke
ui_testso something had to be done. It was also hard to actually check if it was correct with all the repeated macro expansions.changelog: [
big_endian_bytes], [host_endian_bytes], [little_endian_bytes]: Lint any time the methods are named instead of just when called.changelog: [
big_endian_bytes], [host_endian_bytes], [little_endian_bytes]: Lint whento_*_bytesis called via UFCS.changelog: [
big_endian_bytes], [host_endian_bytes], [little_endian_bytes]: Always lint when the method name comes from the current crate.