Skip to content

exclusive_range_pattern error is unhelpful #120047

Closed
@ilyvion

Description

@ilyvion

Code

match x {
    0..42 => {},
    _ => {},
}

Current output

error[E0658]: exclusive range pattern syntax is experimental
 --> src/lib.rs:3:9
  |
3 |         0..42 => {},
  |         ^^^^^
  |
  = note: see issue #37854 <https://github.com/rust-lang/rust/issues/37854> for more information

Desired output

error[E0658]: exclusive range pattern syntax is experimental
 --> src/lib.rs:3:9
  |
3 |         0..42 => {},
  |         ^^^^^
  |
  = note: see issue #37854 <https://github.com/rust-lang/rust/issues/37854> for more information
  = help: use an inclusive range pattern, like 0..=41

Rationale and extra context

Came across this when a beginner was very confused about what was wrong with their match; the words "is experimental" and the link to the issue was not sufficient for their discovering what the problem/solution was.

The suggested inclusive range pattern doesn't need to contain the actual matching value if producing it is hard or impossible, printing something like use an inclusive range pattern, like N..=M is still better than nothing.

This issue may of course be ignored/closed if this nightly feature is just about ready to be stabilized or something.

Other cases

No response

Rust Version

❯ rustc --version --verbose
rustc 1.75.0 (82e1608df 2023-12-21)
binary: rustc
commit-hash: 82e1608dfa6e0b5569232559e3d385fea5a93112
commit-date: 2023-12-21
host: x86_64-pc-windows-msvc
release: 1.75.0
LLVM version: 17.0.6

Anything else?

@rustbot label +D-terse +C-enhancement +F-exclusive_range_pattern

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.D-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.F-exclusive_range_pattern`#![feature(exclusive_range_pattern)]`T-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