Skip to content

gccrs: add path statement lint#4623

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

gccrs: add path statement lint#4623
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 2 times, most recently from 4f1b704 to d3a0712 Compare July 9, 2026 15:43
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

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.

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.

3 participants