From 4ab75de934935f59f243ab64a641e28aa89e6fcd Mon Sep 17 00:00:00 2001 From: clubby789 Date: Mon, 30 Jan 2023 23:47:10 +0000 Subject: Improve diagnostic for missing space in range pattern --- compiler/rustc_parse/src/parser/expr.rs | 8 ++++++++ compiler/rustc_parse/src/parser/pat.rs | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) (limited to 'compiler/rustc_parse/src/parser') diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index b7a023868fc..3d42a9dcbbe 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -2717,6 +2717,14 @@ impl<'a> Parser<'a> { ); err.emit(); this.bump(); + } else if matches!( + (&this.prev_token.kind, &this.token.kind), + (token::DotDotEq, token::Gt) + ) { + // `error_inclusive_range_match_arrow` handles cases like `0..=> {}`, + // so we supress the error here + err.delay_as_bug(); + this.bump(); } else { return Err(err); } diff --git a/compiler/rustc_parse/src/parser/pat.rs b/compiler/rustc_parse/src/parser/pat.rs index 88c75fd81e7..4a2bd3fc530 100644 --- a/compiler/rustc_parse/src/parser/pat.rs +++ b/compiler/rustc_parse/src/parser/pat.rs @@ -744,7 +744,7 @@ impl<'a> Parser<'a> { } token::Gt if no_space => { let after_pat = span.with_hi(span.hi() - rustc_span::BytePos(1)).shrink_to_hi(); - self.sess.emit_err(InclusiveRangeMatchArrow { span, after_pat }); + self.sess.emit_err(InclusiveRangeMatchArrow { span, arrow: tok.span, after_pat }); } _ => { self.sess.emit_err(InclusiveRangeNoEnd { span }); -- cgit 1.4.1-3-g733a5