gccrs: add path statement lint#4623
Open
lucasly-ba wants to merge 1 commit into
Open
Conversation
1d07cc0 to
b43acd6
Compare
CohenArthur
approved these changes
Jun 30, 2026
0a0f62b to
38c8c64
Compare
Collaborator
|
Does this catch cases where a path statement is used, and has an effect? Say, mod a {
pub(crate) const B: bool = true;
}
pub fn foo_is_active () -> bool {
a::B
} |
4f1b704 to
d3a0712
Compare
gcc/rust/ChangeLog: * checks/lints/unused/rust-unused-checker.cc (UnusedChecker::visit): New. * checks/lints/unused/rust-unused-checker.h (UnusedChecker::visit): New. * rust-lang.cc (grs_langhook_init_options_struct): Enable warn_unused_value. gcc/testsuite/ChangeLog: * rust/compile/path-statements_0.rs: New test. Signed-off-by: Lucas Ly Ba <lucas.ly-ba@outlook.com>
d3a0712 to
7c84bc3
Compare
Contributor
Author
Yes. The lint only fires on a path in statement position, a path used as a tail/return expression like your a::B isn't an ExprStmt, so it's never flagged same as rustc's path_statements. I've added your example as a test to make that explicit. |
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 path statement lint, which warns on a statement made of a single path expression, as it has no effect.
gcc/testsuite/ChangeLog: