Skip to content

gccrs: add overlapping range endpoints lint#4642

Open
lucasly-ba wants to merge 1 commit into
Rust-GCC:masterfrom
lucasly-ba:overlapping-range-endpoints
Open

gccrs: add overlapping range endpoints lint#4642
lucasly-ba wants to merge 1 commit into
Rust-GCC:masterfrom
lucasly-ba:overlapping-range-endpoints

Conversation

@lucasly-ba

Copy link
Copy Markdown
Contributor

This patch adds the overlapping range endpoints lint, which warns when two range patterns in a match overlap on a single endpoint, for example 0..=5 and 5..=10 (both match 5).

gcc/testsuite/ChangeLog:

* rust/compile/overlapping-range-endpoints_0.rs: New test.

@lucasly-ba lucasly-ba force-pushed the overlapping-range-endpoints branch 2 times, most recently from fe72bca to b8f244f Compare June 29, 2026 21:37
@powerboat9 powerboat9 added this pull request to the merge queue Jul 3, 2026
@powerboat9

Copy link
Copy Markdown
Collaborator

It looks like these range checks are O(n^2) despite there probably being O(nlogn) solutions, but it should be fine for now.

@powerboat9 powerboat9 removed this pull request from the merge queue due to a manual request Jul 3, 2026
@powerboat9

Copy link
Copy Markdown
Collaborator

Actually, it looks like your changelog needs some tweaks. It should only mention the test you added and your changes to (UnusedChecker::visit (MatchExpr))

@powerboat9 powerboat9 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changelog

@lucasly-ba lucasly-ba force-pushed the overlapping-range-endpoints branch 2 times, most recently from 4581dc1 to a18328d Compare July 8, 2026 14:42
Warn when two range patterns in a match overlap on a single endpoint,
for example `0..=5` and `5..=10` which both match `5`.

gcc/rust/ChangeLog:

	* checks/lints/unused/rust-unused-checker.cc
	(UnusedChecker::visit(HIR::MatchExpr)): Warn on overlapping range
	endpoints.
	* rust-lang.cc (grs_langhook_init_options_struct): Enable warn_unused.

gcc/testsuite/ChangeLog:

	* rust/compile/overlapping-range-endpoints_0.rs: New test.

Signed-off-by: Lucas Ly Ba <lucas.ly-ba@outlook.com>
@lucasly-ba lucasly-ba force-pushed the overlapping-range-endpoints branch from a18328d to 4f77d72 Compare July 9, 2026 13:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants