Skip to content

gccrs: add path statement lint - #4623

Closed
lucasly-ba wants to merge 1 commit into
Rust-GCC:masterfrom
lucasly-ba:path-statements
Closed

lucasly-ba wants to merge 1 commit into
Rust-GCC:masterfrom
lucasly-ba:path-statements

Conversation

@lucasly-ba

Copy link
Copy Markdown
Contributor

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:

* rust/compile/path-statements_0.rs: New test.

@lucasly-ba
lucasly-ba force-pushed the path-statements branch 2 times, most recently from 1d07cc0 to b43acd6 Compare June 29, 2026 21:35
@CohenArthur
CohenArthur added this pull request to the merge queue Jun 30, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Jun 30, 2026
@lucasly-ba
lucasly-ba force-pushed the path-statements branch 4 times, most recently from 0a0f62b to 38c8c64 Compare July 8, 2026 23:41
@powerboat9

Copy link
Copy Markdown
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
}

@lucasly-ba
lucasly-ba force-pushed the path-statements branch 3 times, most recently from d3a0712 to 7c84bc3 Compare July 9, 2026 18:38
@lucasly-ba

lucasly-ba commented Jul 9, 2026 •

Copy link
Copy Markdown
Contributor Author

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
}

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.

@lucasly-ba

Copy link
Copy Markdown
Contributor Author

@P-E-P

@philberty

Copy link
Copy Markdown
Member

merge conflicts but other wise looks good

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>
@lucasly-ba

Copy link
Copy Markdown
Contributor Author

should be good @philberty

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants