compiler: factor out OVERFLOWING_LITERALS impl#130646
Merged
bors merged 2 commits intorust-lang:masterfrom Sep 21, 2024
Merged
Conversation
no functional changes should arise, just moves the lint impl details out of a very crowded file with lots of different lints in it.
no need for a weird macro when a self-explanatory `match` will do.
Collaborator
|
rustbot has assigned @michaelwoerister. Use |
Contributor
|
I confirmed that this is mostly just moving things around. Thanks! r? compiler-errors @bors r+ rollup |
Collaborator
workingjubilee
commented
Sep 21, 2024
Comment on lines
-384
to
-420
| use ty::IntTy::*; | ||
| use ty::UintTy::*; | ||
| macro_rules! find_fit { | ||
| ($ty:expr, $val:expr, $negative:expr, | ||
| $($type:ident => [$($utypes:expr),*] => [$($itypes:expr),*]),+) => { | ||
| { | ||
| let _neg = if negative { 1 } else { 0 }; | ||
| match $ty { | ||
| $($type => { | ||
| $(if !negative && val <= uint_ty_range($utypes).1 { | ||
| return Some($utypes.name_str()) | ||
| })* | ||
| $(if val <= int_ty_range($itypes).1 as u128 + _neg { | ||
| return Some($itypes.name_str()) | ||
| })* | ||
| None | ||
| },)+ | ||
| _ => None | ||
| } | ||
| } | ||
| } | ||
| } | ||
| match t.kind() { | ||
| ty::Int(i) => find_fit!(i, val, negative, | ||
| I8 => [U8] => [I16, I32, I64, I128], | ||
| I16 => [U16] => [I32, I64, I128], | ||
| I32 => [U32] => [I64, I128], | ||
| I64 => [U64] => [I128], | ||
| I128 => [U128] => []), | ||
| ty::Uint(u) => find_fit!(u, val, negative, | ||
| U8 => [U8, U16, U32, U64, U128] => [], | ||
| U16 => [U16, U32, U64, U128] => [], | ||
| U32 => [U32, U64, U128] => [], | ||
| U64 => [U64, U128] => [], | ||
| U128 => [U128] => []), | ||
| _ => None, | ||
| } |
Member
Author
There was a problem hiding this comment.
I at least find this kind of macro-heavy stuff extremely hard to read or understand. And I find "locating knotty bits of code in a 2000-line file" somewhat challenging, too.
bors
added a commit
to rust-lang-ci/rust
that referenced
this pull request
Sep 21, 2024
…iaskrgr Rollup of 6 pull requests Successful merges: - rust-lang#129718 (add guarantee about remove_dir and remove_file error kinds) - rust-lang#130598 (Add recursion limit to FFI safety lint) - rust-lang#130642 (Pass the current cargo to `run-make` tests) - rust-lang#130644 (Only expect valtree consts in codegen) - rust-lang#130645 (Normalize consts in writeback when GCE is enabled) - rust-lang#130646 (compiler: factor out `OVERFLOWING_LITERALS` impl) r? `@ghost` `@rustbot` modify labels: rollup
rust-timer
added a commit
to rust-lang-ci/rust
that referenced
this pull request
Sep 21, 2024
Rollup merge of rust-lang#130646 - workingjubilee:literally-factorize-int-lint, r=compiler-errors compiler: factor out `OVERFLOWING_LITERALS` impl This puts it into `rustc_lint/src/types/literal.rs`. It then uses the fact that it's easier to navigate the logic to identify something that can easily be factored out, as an instance of "why".
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This puts it into
rustc_lint/src/types/literal.rs. It then uses the fact that it's easier to navigate the logic to identify something that can easily be factored out, as an instance of "why".