Skip to content

Diagnostic when trying to write exclusive ranges as ..< #112254

Closed
@comex

Description

@comex

Code

fn foo() {
    0..=10; // OK
    0..<10; // error (valid in Swift)
}

Current output

error: expected type, found `10`
 --> src/lib.rs:3:9
  |
3 |     0..<10; // error (valid in Swift)
  |         ^^ expected type

Desired output

Suggest 0..10.

Rationale and extra context

The syntax ..= for inclusive ranges seems to suggest ..< for exclusive ranges, especially since Swift uses ..< for exclusive ranges.

(Though, Swift doesn't use ..= for inclusive ranges, but rather .)

I initially thought this would be easy to diagnose since ..< is never legal syntax, but actually it can be legal as part of an exclusive range where the upper bound is an UFCS call:

0..<A>::b(); // OK

Oh well.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions