Skip to content

Fix parse error described in #35#36

Open
sruggier wants to merge 4 commits intohelix-editor:masterfrom
sruggier:pr/fix-parse-error
Open

Fix parse error described in #35#36
sruggier wants to merge 4 commits intohelix-editor:masterfrom
sruggier:pr/fix-parse-error

Conversation

@sruggier
Copy link

Here's a minimal fix for the problem documented in #35.

It looks like there are other potential problems with intersect_range_impl, but addressing them fully is more complicated, and would be simpler if I could use let chains. That would require updating the edition to 2024, so I decided it would probably make sense to defer those changes into a separate PR or two.

This change adds a `new` fn, which uses debug assertions to validate
the arguments.

It also uses the non_exhaustive attribute to ensure callers have to
call new instead of initializing the struct directly, and updates all
affected code paths to use the new function.
After handling an excluded range, the start variable is bumped to the
end of the excluded range. This can cause it to be past the end of the
next parent range. Previously, the implementation would push an invalid
range when that happened. This change adds a condition to prevent that
from happening.
@sruggier
Copy link
Author

I've pushed the rest of the changes into the pr/edition-2024 and pr/rewrite-intersect_ranges_impl branches on my fork. Here's a permalinked comparison. It's best reviewed as separate commits, to avoid having to filter out noise from cargo fix and cargo fmt.

I can submit these in 3 separate PRs, merge them all into one, or something in between, as needed.

@the-mikedavis
Copy link
Member

Updating to edition 2024 would raise the MSRV significantly and libraries should avoid doing that unless there's something we really need in a higher Rust version.

@the-mikedavis the-mikedavis self-requested a review March 14, 2026 15:22
@sruggier
Copy link
Author

sruggier commented Mar 14, 2026

Updating to edition 2024 would raise the MSRV significantly and libraries should avoid doing that unless there's something we really need in a higher Rust version.

I really enjoyed being able to use let chains, but it sounds like it probably wouldn't fall into your definition of need, and it bumps the required Rust version up to 1.88.0.

Edit: I've backported my changes to the existing MSRV, and merged them into the branch for this PR.

This allows the compiler to instantiate a single instance of the generic
intersect_ranges_impl function, rather than monomorphizing a different
version for each arm of the match.
The previous implementation had at least one other bug in it, but
it was written in a way that was overly hard to reason about, and
less idiomatic than it could be. Rather than try to incrementally
fix bugs, it felt more efficient to rewrite it as a pair of iterator
transformations, one to handle exclusion, and a second one to calculate
the intersections.

This version should result in similar compiler output, but with more
readable source code, and a style of interface that's easier to compose
with other iterator functions.
@sruggier sruggier changed the title Minimal fix for parse error described in #35 Fix parse error described in #35 Mar 14, 2026
@sruggier
Copy link
Author

@the-mikedavis would you mind offering updated feedback about this, when you have time?

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