Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RangeLimits variant naming #1373

Open
dtolnay opened this issue Feb 6, 2023 · 0 comments
Open

RangeLimits variant naming #1373

dtolnay opened this issue Feb 6, 2023 · 0 comments

Comments

@dtolnay
Copy link
Owner

dtolnay commented Feb 6, 2023

Here is syn's current RangeLimits enum:

syn/src/expr.rs

Lines 904 to 909 in 391c9c6

pub enum RangeLimits {
/// Inclusive at the beginning, exclusive at the end.
HalfOpen(Token![..]),
/// Inclusive at the beginning and end.
Closed(Token![..=]),
}

Rustc has the exact same thing: https://github.com/rust-lang/rust/blob/1.67.0/compiler/rustc_ast/src/ast.rs#L1323-L1328

pub enum RangeLimits {
    /// Inclusive at the beginning, exclusive at the end
    HalfOpen,
    /// Inclusive at the beginning and end
    Closed,
}

However it's ambiguous whether "half open" means "exclusive of upper bound" vs "bounded only on one side".

The opposite approach is taken by the current Rust Reference: https://doc.rust-lang.org/1.67.0/reference/patterns.html#range-patterns

RangePattern :
    InclusiveRangePattern | HalfOpenRangePattern

InclusiveRangePattern :
    RangePatternBound `..=` RangePatternBound

HalfOpenRangePattern :
    RangePatternBound `..` | `..=` RangePatternBound

Notice how it has a ..= pattern which it refers to as half open, even though ..= is never considered half open in syn or rustc.

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

No branches or pull requests

1 participant