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

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

Closed
comex opened this issue Jun 3, 2023 · 1 comment · Fixed by #119342
Closed

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

comex opened this issue Jun 3, 2023 · 1 comment · Fixed by #119342
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@comex
Copy link
Contributor

comex commented Jun 3, 2023

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.

@comex comex added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 3, 2023
@compiler-errors
Copy link
Member

note: implementors of a recovery for this need to be careful not to break valid code like ..<[i32; 0]>::default()

@bors bors closed this as completed in 7f19365 Jan 27, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Jan 27, 2024
Rollup merge of rust-lang#119342 - sjwang05:issue-112254, r=wesleywiser

Emit suggestion when trying to write exclusive ranges as `..<`

Closes rust-lang#112254
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants
@comex @compiler-errors and others