diff options
| author | bors <bors@rust-lang.org> | 2018-06-26 23:15:30 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2018-06-26 23:15:30 +0000 |
| commit | 0cf0691ea1879a84d09d53a19e0f0b06827cf95a (patch) | |
| tree | 8a72b059c5adc812cf4a73c7603c9b3ad6c49d2d /src/libsyntax/parse | |
| parent | 84804c3874a15f55a905c0b53d820372003b0c24 (diff) | |
| parent | 64365e46f2675403babb2669d60d418fae3e0a7c (diff) | |
| download | rust-0cf0691ea1879a84d09d53a19e0f0b06827cf95a.tar.gz rust-0cf0691ea1879a84d09d53a19e0f0b06827cf95a.zip | |
Auto merge of #51149 - zackmdavis:․․․_to_․․=, r=nikomatsakis
lint to favor `..=` over `...` range patterns; migrate to `..=` throughout codebase We probably need an RFC to actually deprecate the `...` syntax, but here's a candidate implementation for the lint considered in #51043. (My local build is super flaky, but hopefully I got all of the test revisions.)
Diffstat (limited to 'src/libsyntax/parse')
| -rw-r--r-- | src/libsyntax/parse/lexer/mod.rs | 4 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 33 |
2 files changed, 23 insertions, 14 deletions
diff --git a/src/libsyntax/parse/lexer/mod.rs b/src/libsyntax/parse/lexer/mod.rs index 5353ff9a1e1..c09cfd910d2 100644 --- a/src/libsyntax/parse/lexer/mod.rs +++ b/src/libsyntax/parse/lexer/mod.rs @@ -266,7 +266,7 @@ impl<'a> StringReader<'a> { /// Pushes a character to a message string for error reporting fn push_escaped_char_for_msg(m: &mut String, c: char) { match c { - '\u{20}'...'\u{7e}' => { + '\u{20}'..='\u{7e}' => { // Don't escape \, ' or " for user-facing messages m.push(c); } @@ -779,7 +779,7 @@ impl<'a> StringReader<'a> { base = 16; num_digits = self.scan_digits(16, 16); } - '0'...'9' | '_' | '.' | 'e' | 'E' => { + '0'..='9' | '_' | '.' | 'e' | 'E' => { num_digits = self.scan_digits(10, 10) + 1; } _ => { diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 955bdbdcf91..21bd6c08324 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -4024,12 +4024,14 @@ impl<'a> Parser<'a> { _ => panic!("can only parse `..`/`...`/`..=` for ranges \ (checked above)"), }; + let op_span = self.span; // Parse range let span = lo.to(self.prev_span); let begin = self.mk_expr(span, ExprKind::Path(qself, path), ThinVec::new()); self.bump(); let end = self.parse_pat_range_end()?; - pat = PatKind::Range(begin, end, end_kind); + let op = Spanned { span: op_span, node: end_kind }; + pat = PatKind::Range(begin, end, op); } token::OpenDelim(token::Brace) => { if qself.is_some() { @@ -4065,17 +4067,22 @@ impl<'a> Parser<'a> { // Try to parse everything else as literal with optional minus match self.parse_literal_maybe_minus() { Ok(begin) => { - if self.eat(&token::DotDotDot) { + let op_span = self.span; + if self.check(&token::DotDot) || self.check(&token::DotDotEq) || + self.check(&token::DotDotDot) { + let end_kind = if self.eat(&token::DotDotDot) { + RangeEnd::Included(RangeSyntax::DotDotDot) + } else if self.eat(&token::DotDotEq) { + RangeEnd::Included(RangeSyntax::DotDotEq) + } else if self.eat(&token::DotDot) { + RangeEnd::Excluded + } else { + panic!("impossible case: we already matched \ + on a range-operator token") + }; let end = self.parse_pat_range_end()?; - pat = PatKind::Range(begin, end, - RangeEnd::Included(RangeSyntax::DotDotDot)); - } else if self.eat(&token::DotDotEq) { - let end = self.parse_pat_range_end()?; - pat = PatKind::Range(begin, end, - RangeEnd::Included(RangeSyntax::DotDotEq)); - } else if self.eat(&token::DotDot) { - let end = self.parse_pat_range_end()?; - pat = PatKind::Range(begin, end, RangeEnd::Excluded); + let op = Spanned { span: op_span, node: end_kind }; + pat = PatKind::Range(begin, end, op); } else { pat = PatKind::Lit(begin); } @@ -4096,7 +4103,9 @@ impl<'a> Parser<'a> { if !allow_range_pat { match pat.node { - PatKind::Range(_, _, RangeEnd::Included(RangeSyntax::DotDotDot)) => {} + PatKind::Range( + _, _, Spanned { node: RangeEnd::Included(RangeSyntax::DotDotDot), .. } + ) => {}, PatKind::Range(..) => { let mut err = self.struct_span_err( pat.span, |
