Skip to content

Commit 1940310

Browse files
committed
Update comments
1 parent ed25cb9 commit 1940310

File tree

1 file changed

+16
-17
lines changed
  • compiler/rustc_parse/src/parser

1 file changed

+16
-17
lines changed

compiler/rustc_parse/src/parser/pat.rs

+16-17
Original file line numberDiff line numberDiff line change
@@ -357,26 +357,23 @@ impl<'a> Parser<'a> {
357357
return None;
358358
}
359359

360-
// Returns `true` iff `token` is `x.y` float
360+
// Returns `true` iff `token` is a `x.y` float
361361
let is_float_literal = |that: &Self, token: &Token| -> bool {
362362
use token::{Lit, LitKind};
363363

364-
if let token::Literal(Lit { kind: LitKind::Float, symbol, suffix: None }) = token.kind {
365-
if let DestructuredFloat::MiddleDot(..) = that.break_up_float(symbol, token.span) {
366-
return true;
367-
}
368-
}
364+
let token::Literal(Lit { kind: LitKind::Float, symbol, suffix: None }) = token.kind else {
365+
return false;
366+
};
369367

370-
false
368+
matches!(that.break_up_float(symbol, token.span), DestructuredFloat::MiddleDot(..))
371369
};
372370

373-
// Check for `.hello` or `.0`
374-
let has_dot_expr = self.check_noexpect(&token::Dot)
371+
// Check for `.hello` or `.0`.
372+
let has_dot_expr = self.check_noexpect(&token::Dot) // `.`
375373
&& self.look_ahead(1, |tok| {
376-
tok.is_ident()
377-
|| tok.is_integer_lit()
378-
// `0.0` get lexed as a float literal
379-
|| is_float_literal(&self, &tok)
374+
tok.is_ident() // `hello`
375+
|| tok.is_integer_lit() // `0`
376+
|| is_float_literal(&self, &tok) // `0.0`
380377
});
381378

382379
// Check for operators.
@@ -388,7 +385,7 @@ impl<'a> Parser<'a> {
388385
let has_trailing_operator = matches!(self.token.kind, token::BinOp(op) if op != BinOpToken::Or)
389386
|| self.token.kind == token::Question
390387
|| (self.token.kind == token::OpenDelim(Delimiter::Bracket)
391-
&& self.look_ahead(1, |tok| tok.kind != token::CloseDelim(Delimiter::Bracket)))
388+
&& self.look_ahead(1, |tok| tok.kind != token::CloseDelim(Delimiter::Bracket))) // excludes `[]`
392389
|| self.token.is_keyword(kw::As);
393390

394391
if !has_dot_expr && !has_trailing_operator {
@@ -431,13 +428,15 @@ impl<'a> Parser<'a> {
431428

432429
let span = expr.span;
433430

434-
let mut diag = self.dcx().create_err(UnexpectedExpressionInPattern {
431+
let mut err = self.dcx().create_err(UnexpectedExpressionInPattern {
435432
span,
436433
is_bound,
437434
is_method_call,
438435
});
436+
437+
// FIXME(inline_const): once stabilized, remove this check and remove the `(requires #[feature(inline_const])` note from the message
439438
if self.psess.unstable_features.is_nightly_build() {
440-
diag.subdiagnostic(
439+
err.subdiagnostic(
441440
&self.dcx(),
442441
UnexpectedExpressionInPatternConstPatSugg {
443442
start_span: span.shrink_to_lo(),
@@ -446,7 +445,7 @@ impl<'a> Parser<'a> {
446445
);
447446
}
448447

449-
return Some((diag.stash(span, StashKey::ExprInPat).unwrap(), span));
448+
return Some((err.stash(span, StashKey::ExprInPat).unwrap(), span));
450449
}
451450
}
452451

0 commit comments

Comments
 (0)