mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-23 15:23:46 +00:00
structured suggestion and rewording for ...
expression syntax error
Now that `..=` inclusive ranges are stabilized, people probably shouldn't be using `...` even in patterns, even if it's still legal there (see #51043). To avoid drawing attention to `...` being a real thing, let's reword this message to just say "unexpected token" rather "cannot be used in expressions".
This commit is contained in:
parent
4650361fb6
commit
a417518173
@ -4800,12 +4800,14 @@ impl<'a> Parser<'a> {
|
||||
|
||||
fn err_dotdotdot_syntax(&self, span: Span) {
|
||||
self.diagnostic().struct_span_err(span, {
|
||||
"`...` syntax cannot be used in expressions"
|
||||
}).help({
|
||||
"Use `..` if you need an exclusive range (a < b)"
|
||||
}).help({
|
||||
"or `..=` if you need an inclusive range (a <= b)"
|
||||
}).emit();
|
||||
"unexpected token: `...`"
|
||||
}).span_suggestion_with_applicability(
|
||||
span, "use `..` for an exclusive range", "..".to_owned(),
|
||||
Applicability::MaybeIncorrect
|
||||
).span_suggestion_with_applicability(
|
||||
span, "or `..=` for an inclusive range", "..=".to_owned(),
|
||||
Applicability::MaybeIncorrect
|
||||
).emit();
|
||||
}
|
||||
|
||||
// Parse bounds of a type parameter `BOUND + BOUND + BOUND`, possibly with trailing `+`.
|
||||
|
@ -15,22 +15,21 @@
|
||||
use std::ops::RangeToInclusive;
|
||||
|
||||
fn return_range_to() -> RangeToInclusive<i32> {
|
||||
return ...1; //~ERROR `...` syntax cannot be used in expressions
|
||||
//~^HELP Use `..` if you need an exclusive range (a < b)
|
||||
//~^^HELP or `..=` if you need an inclusive range (a <= b)
|
||||
return ...1; //~ERROR unexpected token: `...`
|
||||
//~^HELP use `..` for an exclusive range
|
||||
//~^^HELP or `..=` for an inclusive range
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
let x = ...0; //~ERROR `...` syntax cannot be used in expressions
|
||||
//~^HELP Use `..` if you need an exclusive range (a < b)
|
||||
//~^^HELP or `..=` if you need an inclusive range (a <= b)
|
||||
let x = ...0; //~ERROR unexpected token: `...`
|
||||
//~^HELP use `..` for an exclusive range
|
||||
//~^^HELP or `..=` for an inclusive range
|
||||
|
||||
let x = 5...5; //~ERROR `...` syntax cannot be used in expressions
|
||||
//~^HELP Use `..` if you need an exclusive range (a < b)
|
||||
//~^^HELP or `..=` if you need an inclusive range (a <= b)
|
||||
let x = 5...5; //~ERROR unexpected token: `...`
|
||||
//~^HELP use `..` for an exclusive range
|
||||
//~^^HELP or `..=` for an inclusive range
|
||||
|
||||
for _ in 0...1 {} //~ERROR `...` syntax cannot be used in expressions
|
||||
//~^HELP Use `..` if you need an exclusive range (a < b)
|
||||
//~^^HELP or `..=` if you need an inclusive range (a <= b)
|
||||
for _ in 0...1 {} //~ERROR unexpected token: `...`
|
||||
//~^HELP use `..` for an exclusive range
|
||||
//~^^HELP or `..=` for an inclusive range
|
||||
}
|
||||
|
||||
|
14
src/test/ui/suggestions/dotdotdot-expr.rs
Normal file
14
src/test/ui/suggestions/dotdotdot-expr.rs
Normal file
@ -0,0 +1,14 @@
|
||||
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
fn main() {
|
||||
let _redemptive = 1...21;
|
||||
//~^ ERROR unexpected token
|
||||
}
|
16
src/test/ui/suggestions/dotdotdot-expr.stderr
Normal file
16
src/test/ui/suggestions/dotdotdot-expr.stderr
Normal file
@ -0,0 +1,16 @@
|
||||
error: unexpected token: `...`
|
||||
--> $DIR/dotdotdot-expr.rs:12:24
|
||||
|
|
||||
LL | let _redemptive = 1...21;
|
||||
| ^^^
|
||||
help: use `..` for an exclusive range
|
||||
|
|
||||
LL | let _redemptive = 1..21;
|
||||
| ^^
|
||||
help: or `..=` for an inclusive range
|
||||
|
|
||||
LL | let _redemptive = 1..=21;
|
||||
| ^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
Loading…
Reference in New Issue
Block a user