gccrs: add trivial numeric casts lint - #4629
Open
lucasly-ba wants to merge 1 commit into
Open
Conversation
lucasly-ba
force-pushed
the
trivial-numeric-casts
branch
3 times, most recently
from
July 6, 2026 12:02
d516826 to
1a8bad4
Compare
lucasly-ba
force-pushed
the
trivial-numeric-casts
branch
3 times, most recently
from
July 9, 2026 13:35
1e07909 to
2ac20b3
Compare
Contributor
Author
philberty
requested changes
Aug 15, 2026
| { | ||
| TyTy::BaseType *from; | ||
| TyTy::BaseType *to; | ||
| if (context.lookup_type (expr.get_casted_expr ().get_mappings ().get_hirid (), |
Member
There was a problem hiding this comment.
You should split this if statement up...
bool found_from = lookup_expr;
bool found_expr = lookup
if (found_from && found_expr)
{
bool is_numeric = ...
bool type_names_match = ...
// you might be able to get away with using TypeCompatable to be more generic not sure maybe this is meant to only work on numeric values...
if (is_numeric && type_names_match)
... warrning
}
walk (expr)
This is jsut much easier to read down the line
lucasly-ba
force-pushed
the
trivial-numeric-casts
branch
from
August 15, 2026 21:20
2ac20b3 to
069b04f
Compare
gcc/rust/ChangeLog: * checks/lints/unused/rust-unused-checker.cc (is_numeric): New. (UnusedChecker::visit): New. * checks/lints/unused/rust-unused-checker.h (UnusedChecker::visit): New. * rust-lang.cc (grs_langhook_init_options_struct): Enable warn_unused. gcc/testsuite/ChangeLog: * rust/compile/trivial-numeric-casts_0.rs: New test. Signed-off-by: Lucas Ly Ba <lucas.ly-ba@outlook.com>
lucasly-ba
force-pushed
the
trivial-numeric-casts
branch
from
August 15, 2026 21:20
069b04f to
47f18b5
Compare
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 patch adds the trivial numeric casts lint, which warns on a numeric cast where the source and target types are the same, e.g.
x as i32whenxis already ani32.gcc/testsuite/ChangeLog: