diff options
| author | bors <bors@rust-lang.org> | 2021-07-18 05:58:16 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-07-18 05:58:16 +0000 |
| commit | 3ab6b60337edeb49339d173853fee1f8569421e0 (patch) | |
| tree | 56d696f33ba36371e0eda73e4c29172bf7a01fd4 /compiler/rustc_parse/src/parser/expr.rs | |
| parent | 77d155973c6c22a0e1af49a4a9bac024f697851d (diff) | |
| parent | b56079ec5466af5bff7d7d174ed6ae248aaa92c4 (diff) | |
| download | rust-3ab6b60337edeb49339d173853fee1f8569421e0.tar.gz rust-3ab6b60337edeb49339d173853fee1f8569421e0.zip | |
Auto merge of #87071 - inquisitivecrystal:inclusive-range, r=estebank
Add diagnostics for mistyped inclusive range Inclusive ranges are correctly typed as `..=`. However, it's quite easy to think of it as being like `==`, and type `..==` instead. This PR adds helpful diagnostics for this case. Resolves #86395 (there are some other cases there, but I think those should probably have separate issues). r? `@estebank`
Diffstat (limited to 'compiler/rustc_parse/src/parser/expr.rs')
| -rw-r--r-- | compiler/rustc_parse/src/parser/expr.rs | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index 47fdd852d90..ef05f64da94 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -431,7 +431,8 @@ impl<'a> Parser<'a> { let span = self.mk_expr_sp(&lhs, lhs.span, rhs_span); let limits = if op == AssocOp::DotDot { RangeLimits::HalfOpen } else { RangeLimits::Closed }; - Ok(self.mk_expr(span, self.mk_range(Some(lhs), rhs, limits), AttrVec::new())) + let range = self.mk_range(Some(lhs), rhs, limits); + Ok(self.mk_expr(span, range, AttrVec::new())) } fn is_at_start_of_range_notation_rhs(&self) -> bool { @@ -479,7 +480,8 @@ impl<'a> Parser<'a> { } else { (lo, None) }; - Ok(this.mk_expr(span, this.mk_range(None, opt_end, limits), attrs.into())) + let range = this.mk_range(None, opt_end, limits); + Ok(this.mk_expr(span, range, attrs.into())) }) } @@ -2517,13 +2519,13 @@ impl<'a> Parser<'a> { } fn mk_range( - &self, + &mut self, start: Option<P<Expr>>, end: Option<P<Expr>>, limits: RangeLimits, ) -> ExprKind { if end.is_none() && limits == RangeLimits::Closed { - self.error_inclusive_range_with_no_end(self.prev_token.span); + self.inclusive_range_with_incorrect_end(self.prev_token.span); ExprKind::Err } else { ExprKind::Range(start, end, limits) |
