A pattern is something that can be used to test if a value is a certain shape. A literal is a piece of source code that creates a value. For discoverability purposes, some literals and patterns look similar to each other, to indicate how they are related.
Rust 1.0 allowed using ... in a pattern, so that syntax is still allowed today for backwards compatibility:
match 42 {
1...100 => println!("Just right"),
_ => println!("No good"),
}
However, Rust 1.0 did not stabilize using ... as a literal. After much bikeshedding, we decided that ..= was better syntax for an inclusive range. That syntax is what was stabilized in Rust 1.26 as the literal and it was also added as a pattern.
New code should prefer ..= for patterns. The compiler even suggests updating the usage of ... in patterns:
warning: `...` range patterns are deprecated
--> src/main.rs:3:10
|
3 | 1...100 => println!("Just right"),
| ^^^ help: use `..=` for an inclusive range
|
It is proposed that this warning will be an error in edition 2021.
The documentation could be updated to indicate that ..= may also be used in patterns and is the preferred syntax over ....
See also: