Format all the let chains in compiler
This commit is contained in:
parent
2763ca50da
commit
b2d2184ede
206 changed files with 3120 additions and 2228 deletions
|
@ -111,9 +111,10 @@ pub fn report_suspicious_mismatch_block(
|
|||
// If there is no suspicious span, give the last properly closed block may help
|
||||
if let Some(parent) = diag_info.matching_block_spans.last()
|
||||
&& diag_info.open_braces.last().is_none()
|
||||
&& diag_info.empty_block_spans.iter().all(|&sp| sp != parent.0.to(parent.1)) {
|
||||
err.span_label(parent.0, "this opening brace...");
|
||||
err.span_label(parent.1, "...matches this closing brace");
|
||||
&& diag_info.empty_block_spans.iter().all(|&sp| sp != parent.0.to(parent.1))
|
||||
{
|
||||
err.span_label(parent.0, "this opening brace...");
|
||||
err.span_label(parent.1, "...matches this closing brace");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -314,11 +314,10 @@ impl<'a> Parser<'a> {
|
|||
// which uses `Symbol::to_ident_string()` and "helpfully" adds an implicit `r#`
|
||||
let ident_name = ident.name.to_string();
|
||||
|
||||
Some(SuggEscapeIdentifier {
|
||||
span: ident.span.shrink_to_lo(),
|
||||
ident_name
|
||||
})
|
||||
} else { None };
|
||||
Some(SuggEscapeIdentifier { span: ident.span.shrink_to_lo(), ident_name })
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
let suggest_remove_comma =
|
||||
if self.token == token::Comma && self.look_ahead(1, |t| t.is_ident()) {
|
||||
|
@ -375,9 +374,11 @@ impl<'a> Parser<'a> {
|
|||
// and current token should be Ident with the item name (i.e. the function name)
|
||||
// if there is a `<` after the fn name, then don't show a suggestion, show help
|
||||
|
||||
if !self.look_ahead(1, |t| *t == token::Lt) &&
|
||||
let Ok(snippet) = self.sess.source_map().span_to_snippet(generic.span) {
|
||||
err.multipart_suggestion_verbose(
|
||||
if !self.look_ahead(1, |t| *t == token::Lt)
|
||||
&& let Ok(snippet) =
|
||||
self.sess.source_map().span_to_snippet(generic.span)
|
||||
{
|
||||
err.multipart_suggestion_verbose(
|
||||
format!("place the generic parameter name after the {ident_name} name"),
|
||||
vec![
|
||||
(self.token.span.shrink_to_hi(), snippet),
|
||||
|
@ -385,11 +386,11 @@ impl<'a> Parser<'a> {
|
|||
],
|
||||
Applicability::MaybeIncorrect,
|
||||
);
|
||||
} else {
|
||||
err.help(format!(
|
||||
"place the generic parameter name after the {ident_name} name"
|
||||
));
|
||||
}
|
||||
} else {
|
||||
err.help(format!(
|
||||
"place the generic parameter name after the {ident_name} name"
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(err) => {
|
||||
|
@ -402,7 +403,9 @@ impl<'a> Parser<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
if let Some(recovered_ident) = recovered_ident && recover {
|
||||
if let Some(recovered_ident) = recovered_ident
|
||||
&& recover
|
||||
{
|
||||
err.emit();
|
||||
Ok(recovered_ident)
|
||||
} else {
|
||||
|
@ -617,19 +620,19 @@ impl<'a> Parser<'a> {
|
|||
}
|
||||
|
||||
if let TokenKind::Ident(prev, _) = &self.prev_token.kind
|
||||
&& let TokenKind::Ident(cur, _) = &self.token.kind
|
||||
&& let TokenKind::Ident(cur, _) = &self.token.kind
|
||||
{
|
||||
let concat = Symbol::intern(&format!("{prev}{cur}"));
|
||||
let ident = Ident::new(concat, DUMMY_SP);
|
||||
if ident.is_used_keyword() || ident.is_reserved() || ident.is_raw_guess() {
|
||||
let span = self.prev_token.span.to(self.token.span);
|
||||
err.span_suggestion_verbose(
|
||||
span,
|
||||
format!("consider removing the space to spell keyword `{concat}`"),
|
||||
concat,
|
||||
Applicability::MachineApplicable,
|
||||
);
|
||||
}
|
||||
let concat = Symbol::intern(&format!("{prev}{cur}"));
|
||||
let ident = Ident::new(concat, DUMMY_SP);
|
||||
if ident.is_used_keyword() || ident.is_reserved() || ident.is_raw_guess() {
|
||||
let span = self.prev_token.span.to(self.token.span);
|
||||
err.span_suggestion_verbose(
|
||||
span,
|
||||
format!("consider removing the space to spell keyword `{concat}`"),
|
||||
concat,
|
||||
Applicability::MachineApplicable,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// `pub` may be used for an item or `pub(crate)`
|
||||
|
@ -1025,8 +1028,7 @@ impl<'a> Parser<'a> {
|
|||
.emit();
|
||||
match self.parse_expr() {
|
||||
Ok(_) => {
|
||||
*expr =
|
||||
self.mk_expr_err(expr.span.to(self.prev_token.span));
|
||||
*expr = self.mk_expr_err(expr.span.to(self.prev_token.span));
|
||||
return Ok(());
|
||||
}
|
||||
Err(err) => {
|
||||
|
@ -1218,7 +1220,9 @@ impl<'a> Parser<'a> {
|
|||
return if token::ModSep == self.token.kind {
|
||||
// We have some certainty that this was a bad turbofish at this point.
|
||||
// `foo< bar >::`
|
||||
if let ExprKind::Binary(o, ..) = inner_op.kind && o.node == BinOpKind::Lt {
|
||||
if let ExprKind::Binary(o, ..) = inner_op.kind
|
||||
&& o.node == BinOpKind::Lt
|
||||
{
|
||||
err.suggest_turbofish = Some(op.span.shrink_to_lo());
|
||||
} else {
|
||||
err.help_turbofish = Some(());
|
||||
|
@ -1248,7 +1252,9 @@ impl<'a> Parser<'a> {
|
|||
} else if token::OpenDelim(Delimiter::Parenthesis) == self.token.kind {
|
||||
// We have high certainty that this was a bad turbofish at this point.
|
||||
// `foo< bar >(`
|
||||
if let ExprKind::Binary(o, ..) = inner_op.kind && o.node == BinOpKind::Lt {
|
||||
if let ExprKind::Binary(o, ..) = inner_op.kind
|
||||
&& o.node == BinOpKind::Lt
|
||||
{
|
||||
err.suggest_turbofish = Some(op.span.shrink_to_lo());
|
||||
} else {
|
||||
err.help_turbofish = Some(());
|
||||
|
@ -1826,19 +1832,21 @@ impl<'a> Parser<'a> {
|
|||
let sm = self.sess.source_map();
|
||||
let left = begin_par_sp;
|
||||
let right = self.prev_token.span;
|
||||
let left_snippet = if let Ok(snip) = sm.span_to_prev_source(left) &&
|
||||
!snip.ends_with(' ') {
|
||||
" ".to_string()
|
||||
} else {
|
||||
"".to_string()
|
||||
};
|
||||
let left_snippet = if let Ok(snip) = sm.span_to_prev_source(left)
|
||||
&& !snip.ends_with(' ')
|
||||
{
|
||||
" ".to_string()
|
||||
} else {
|
||||
"".to_string()
|
||||
};
|
||||
|
||||
let right_snippet = if let Ok(snip) = sm.span_to_next_source(right) &&
|
||||
!snip.starts_with(' ') {
|
||||
" ".to_string()
|
||||
} else {
|
||||
"".to_string()
|
||||
};
|
||||
let right_snippet = if let Ok(snip) = sm.span_to_next_source(right)
|
||||
&& !snip.starts_with(' ')
|
||||
{
|
||||
" ".to_string()
|
||||
} else {
|
||||
"".to_string()
|
||||
};
|
||||
|
||||
self.sess.emit_err(ParenthesesInForHead {
|
||||
span: vec![left, right],
|
||||
|
|
|
@ -1007,8 +1007,9 @@ impl<'a> Parser<'a> {
|
|||
let span = self.token.span;
|
||||
let sm = self.sess.source_map();
|
||||
let (span, actual) = match (&self.token.kind, self.subparser_name) {
|
||||
(token::Eof, Some(_)) if let Ok(actual) = sm.span_to_snippet(sm.next_point(span)) =>
|
||||
(span.shrink_to_hi(), actual.into()),
|
||||
(token::Eof, Some(_)) if let Ok(actual) = sm.span_to_snippet(sm.next_point(span)) => {
|
||||
(span.shrink_to_hi(), actual.into())
|
||||
}
|
||||
_ => (span, actual),
|
||||
};
|
||||
self.sess.emit_err(errors::UnexpectedTokenAfterDot { span, actual });
|
||||
|
@ -1550,10 +1551,7 @@ impl<'a> Parser<'a> {
|
|||
self.sess.emit_err(errors::MacroInvocationWithQualifiedPath(path.span));
|
||||
}
|
||||
let lo = path.span;
|
||||
let mac = P(MacCall {
|
||||
path,
|
||||
args: self.parse_delim_args()?,
|
||||
});
|
||||
let mac = P(MacCall { path, args: self.parse_delim_args()? });
|
||||
(lo.to(self.prev_token.span), ExprKind::MacCall(mac))
|
||||
} else if self.check(&token::OpenDelim(Delimiter::Brace))
|
||||
&& let Some(expr) = self.maybe_parse_struct_expr(&qself, &path)
|
||||
|
@ -1771,7 +1769,9 @@ impl<'a> Parser<'a> {
|
|||
fn parse_expr_break(&mut self) -> PResult<'a, P<Expr>> {
|
||||
let lo = self.prev_token.span;
|
||||
let mut label = self.eat_label();
|
||||
let kind = if self.token == token::Colon && let Some(label) = label.take() {
|
||||
let kind = if self.token == token::Colon
|
||||
&& let Some(label) = label.take()
|
||||
{
|
||||
// The value expression can be a labeled loop, see issue #86948, e.g.:
|
||||
// `loop { break 'label: loop { break 'label 42; }; }`
|
||||
let lexpr = self.parse_expr_labeled(label, true)?;
|
||||
|
@ -2371,16 +2371,18 @@ impl<'a> Parser<'a> {
|
|||
let mut recover_block_from_condition = |this: &mut Self| {
|
||||
let block = match &mut cond.kind {
|
||||
ExprKind::Binary(Spanned { span: binop_span, .. }, _, right)
|
||||
if let ExprKind::Block(_, None) = right.kind => {
|
||||
self.sess.emit_err(errors::IfExpressionMissingThenBlock {
|
||||
if_span: lo,
|
||||
missing_then_block_sub:
|
||||
errors::IfExpressionMissingThenBlockSub::UnfinishedCondition(cond_span.shrink_to_lo().to(*binop_span)),
|
||||
let_else_sub: None,
|
||||
|
||||
});
|
||||
std::mem::replace(right, this.mk_expr_err(binop_span.shrink_to_hi()))
|
||||
},
|
||||
if let ExprKind::Block(_, None) = right.kind =>
|
||||
{
|
||||
self.sess.emit_err(errors::IfExpressionMissingThenBlock {
|
||||
if_span: lo,
|
||||
missing_then_block_sub:
|
||||
errors::IfExpressionMissingThenBlockSub::UnfinishedCondition(
|
||||
cond_span.shrink_to_lo().to(*binop_span),
|
||||
),
|
||||
let_else_sub: None,
|
||||
});
|
||||
std::mem::replace(right, this.mk_expr_err(binop_span.shrink_to_hi()))
|
||||
}
|
||||
ExprKind::Block(_, None) => {
|
||||
self.sess.emit_err(errors::IfExpressionMissingCondition {
|
||||
if_span: lo.shrink_to_hi(),
|
||||
|
@ -2557,13 +2559,16 @@ impl<'a> Parser<'a> {
|
|||
}
|
||||
|
||||
fn error_on_extra_if(&mut self, cond: &P<Expr>) -> PResult<'a, ()> {
|
||||
if let ExprKind::Binary(Spanned { span: binop_span, node: binop}, _, right) = &cond.kind &&
|
||||
let BinOpKind::And = binop &&
|
||||
let ExprKind::If(cond, ..) = &right.kind {
|
||||
Err(self.sess.create_err(errors::UnexpectedIfWithIf(binop_span.shrink_to_hi().to(cond.span.shrink_to_lo()))))
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
if let ExprKind::Binary(Spanned { span: binop_span, node: binop }, _, right) = &cond.kind
|
||||
&& let BinOpKind::And = binop
|
||||
&& let ExprKind::If(cond, ..) = &right.kind
|
||||
{
|
||||
Err(self.sess.create_err(errors::UnexpectedIfWithIf(
|
||||
binop_span.shrink_to_hi().to(cond.span.shrink_to_lo()),
|
||||
)))
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
/// Parses `for <src_pat> in <src_expr> <src_loop_block>` (`for` token already eaten).
|
||||
|
@ -2911,9 +2916,9 @@ impl<'a> Parser<'a> {
|
|||
.or_else(|mut err| {
|
||||
if this.token == token::FatArrow {
|
||||
if let Ok(expr_lines) = sm.span_to_lines(expr.span)
|
||||
&& let Ok(arm_start_lines) = sm.span_to_lines(arm_start_span)
|
||||
&& arm_start_lines.lines[0].end_col == expr_lines.lines[0].end_col
|
||||
&& expr_lines.lines.len() == 2
|
||||
&& let Ok(arm_start_lines) = sm.span_to_lines(arm_start_span)
|
||||
&& arm_start_lines.lines[0].end_col == expr_lines.lines[0].end_col
|
||||
&& expr_lines.lines.len() == 2
|
||||
{
|
||||
// We check whether there's any trailing code in the parse span,
|
||||
// if there isn't, we very likely have the following:
|
||||
|
@ -3169,7 +3174,7 @@ impl<'a> Parser<'a> {
|
|||
e.span_suggestion_verbose(
|
||||
self.token.span.shrink_to_lo(),
|
||||
"try naming a field",
|
||||
&format!("{ident}: ", ),
|
||||
&format!("{ident}: ",),
|
||||
Applicability::MaybeIncorrect,
|
||||
);
|
||||
}
|
||||
|
@ -3562,8 +3567,7 @@ impl MutVisitor for CondChecker<'_> {
|
|||
noop_visit_expr(e, self);
|
||||
self.forbid_let_reason = forbid_let_reason;
|
||||
}
|
||||
ExprKind::Cast(ref mut op, _)
|
||||
| ExprKind::Type(ref mut op, _) => {
|
||||
ExprKind::Cast(ref mut op, _) | ExprKind::Type(ref mut op, _) => {
|
||||
let forbid_let_reason = self.forbid_let_reason;
|
||||
self.forbid_let_reason = Some(OtherForbidden);
|
||||
self.visit_expr(op);
|
||||
|
|
|
@ -122,7 +122,9 @@ impl<'a> Parser<'a> {
|
|||
) -> PResult<'a, Option<Item>> {
|
||||
// Don't use `maybe_whole` so that we have precise control
|
||||
// over when we bump the parser
|
||||
if let token::Interpolated(nt) = &self.token.kind && let token::NtItem(item) = &**nt {
|
||||
if let token::Interpolated(nt) = &self.token.kind
|
||||
&& let token::NtItem(item) = &**nt
|
||||
{
|
||||
let mut item = item.clone();
|
||||
self.bump();
|
||||
|
||||
|
@ -623,11 +625,10 @@ impl<'a> Parser<'a> {
|
|||
// `impl<T: Default> impl Default for Wrapper<T>`
|
||||
// ^^^^^
|
||||
let extra_impl_kw = ty_first.span.until(bound.span());
|
||||
self.sess
|
||||
.emit_err(errors::ExtraImplKeywordInTraitImpl {
|
||||
extra_impl_kw,
|
||||
impl_trait_span: ty_first.span
|
||||
});
|
||||
self.sess.emit_err(errors::ExtraImplKeywordInTraitImpl {
|
||||
extra_impl_kw,
|
||||
impl_trait_span: ty_first.span,
|
||||
});
|
||||
} else {
|
||||
self.sess.emit_err(errors::ExpectedTraitInTraitImplFoundType {
|
||||
span: ty_first.span,
|
||||
|
@ -1306,7 +1307,9 @@ impl<'a> Parser<'a> {
|
|||
// Provide a nice error message if the user placed a where-clause before the item body.
|
||||
// Users may be tempted to write such code if they are still used to the deprecated
|
||||
// where-clause location on type aliases and associated types. See also #89122.
|
||||
if before_where_clause.has_where_token && let Some(expr) = &expr {
|
||||
if before_where_clause.has_where_token
|
||||
&& let Some(expr) = &expr
|
||||
{
|
||||
self.sess.emit_err(errors::WhereClauseBeforeConstBody {
|
||||
span: before_where_clause.span,
|
||||
name: ident.span,
|
||||
|
@ -1949,7 +1952,8 @@ impl<'a> Parser<'a> {
|
|||
let mut err = self.expected_ident_found_err();
|
||||
if self.eat_keyword_noexpect(kw::Let)
|
||||
&& let removal_span = self.prev_token.span.until(self.token.span)
|
||||
&& let Ok(ident) = self.parse_ident_common(false)
|
||||
&& let Ok(ident) = self
|
||||
.parse_ident_common(false)
|
||||
// Cancel this error, we don't need it.
|
||||
.map_err(|err| err.cancel())
|
||||
&& self.token.kind == TokenKind::Colon
|
||||
|
|
|
@ -558,8 +558,9 @@ impl<'a> Parser<'a> {
|
|||
}
|
||||
|
||||
if case == Case::Insensitive
|
||||
&& let Some((ident, /* is_raw */ false)) = self.token.ident()
|
||||
&& ident.as_str().to_lowercase() == kw.as_str().to_lowercase() {
|
||||
&& let Some((ident, /* is_raw */ false)) = self.token.ident()
|
||||
&& ident.as_str().to_lowercase() == kw.as_str().to_lowercase()
|
||||
{
|
||||
true
|
||||
} else {
|
||||
false
|
||||
|
@ -587,12 +588,10 @@ impl<'a> Parser<'a> {
|
|||
}
|
||||
|
||||
if case == Case::Insensitive
|
||||
&& let Some((ident, /* is_raw */ false)) = self.token.ident()
|
||||
&& ident.as_str().to_lowercase() == kw.as_str().to_lowercase() {
|
||||
self.sess.emit_err(errors::KwBadCase {
|
||||
span: ident.span,
|
||||
kw: kw.as_str()
|
||||
});
|
||||
&& let Some((ident, /* is_raw */ false)) = self.token.ident()
|
||||
&& ident.as_str().to_lowercase() == kw.as_str().to_lowercase()
|
||||
{
|
||||
self.sess.emit_err(errors::KwBadCase { span: ident.span, kw: kw.as_str() });
|
||||
self.bump();
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -115,7 +115,7 @@ impl<'a> Parser<'a> {
|
|||
Some(item) => NtItem(item),
|
||||
None => {
|
||||
return Err(UnexpectedNonterminal::Item(self.token.span)
|
||||
.into_diagnostic(&self.sess.span_diagnostic));
|
||||
.into_diagnostic(&self.sess.span_diagnostic));
|
||||
}
|
||||
},
|
||||
NonterminalKind::Block => {
|
||||
|
@ -127,7 +127,7 @@ impl<'a> Parser<'a> {
|
|||
Some(s) => NtStmt(P(s)),
|
||||
None => {
|
||||
return Err(UnexpectedNonterminal::Statement(self.token.span)
|
||||
.into_diagnostic(&self.sess.span_diagnostic));
|
||||
.into_diagnostic(&self.sess.span_diagnostic));
|
||||
}
|
||||
},
|
||||
NonterminalKind::PatParam { .. } | NonterminalKind::PatWithOr => {
|
||||
|
@ -146,19 +146,15 @@ impl<'a> Parser<'a> {
|
|||
NonterminalKind::Expr => NtExpr(self.parse_expr_force_collect()?),
|
||||
NonterminalKind::Literal => {
|
||||
// The `:literal` matcher does not support attributes
|
||||
NtLiteral(
|
||||
self.collect_tokens_no_attrs(|this| this.parse_literal_maybe_minus())?,
|
||||
)
|
||||
NtLiteral(self.collect_tokens_no_attrs(|this| this.parse_literal_maybe_minus())?)
|
||||
}
|
||||
|
||||
NonterminalKind::Ty => NtTy(
|
||||
self.collect_tokens_no_attrs(|this| this.parse_ty_no_question_mark_recover())?,
|
||||
),
|
||||
NonterminalKind::Ty => {
|
||||
NtTy(self.collect_tokens_no_attrs(|this| this.parse_ty_no_question_mark_recover())?)
|
||||
}
|
||||
|
||||
// this could be handled like a token, since it is one
|
||||
NonterminalKind::Ident
|
||||
if let Some((ident, is_raw)) = get_macro_ident(&self.token) =>
|
||||
{
|
||||
NonterminalKind::Ident if let Some((ident, is_raw)) = get_macro_ident(&self.token) => {
|
||||
self.bump();
|
||||
NtIdent(ident, is_raw)
|
||||
}
|
||||
|
@ -166,15 +162,17 @@ impl<'a> Parser<'a> {
|
|||
return Err(UnexpectedNonterminal::Ident {
|
||||
span: self.token.span,
|
||||
token: self.token.clone(),
|
||||
}.into_diagnostic(&self.sess.span_diagnostic));
|
||||
}
|
||||
.into_diagnostic(&self.sess.span_diagnostic));
|
||||
}
|
||||
NonterminalKind::Path => {
|
||||
NtPath(P(self.collect_tokens_no_attrs(|this| this.parse_path(PathStyle::Type))?))
|
||||
}
|
||||
NonterminalKind::Path => NtPath(
|
||||
P(self.collect_tokens_no_attrs(|this| this.parse_path(PathStyle::Type))?),
|
||||
),
|
||||
NonterminalKind::Meta => NtMeta(P(self.parse_attr_item(true)?)),
|
||||
NonterminalKind::Vis => NtVis(
|
||||
P(self.collect_tokens_no_attrs(|this| this.parse_visibility(FollowedByType::Yes))?),
|
||||
),
|
||||
NonterminalKind::Vis => {
|
||||
NtVis(P(self
|
||||
.collect_tokens_no_attrs(|this| this.parse_visibility(FollowedByType::Yes))?))
|
||||
}
|
||||
NonterminalKind::Lifetime => {
|
||||
if self.check_lifetime() {
|
||||
NtLifetime(self.expect_lifetime().ident)
|
||||
|
@ -182,7 +180,8 @@ impl<'a> Parser<'a> {
|
|||
return Err(UnexpectedNonterminal::Lifetime {
|
||||
span: self.token.span,
|
||||
token: self.token.clone(),
|
||||
}.into_diagnostic(&self.sess.span_diagnostic));
|
||||
}
|
||||
.into_diagnostic(&self.sess.span_diagnostic));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -764,7 +764,8 @@ impl<'a> Parser<'a> {
|
|||
if let ast::TyKind::Slice(inner_ty) | ast::TyKind::Array(inner_ty, _) = &ty.kind
|
||||
&& let ast::TyKind::Err = inner_ty.kind
|
||||
&& let Some(snapshot) = snapshot
|
||||
&& let Some(expr) = self.recover_unbraced_const_arg_that_can_begin_ty(snapshot)
|
||||
&& let Some(expr) =
|
||||
self.recover_unbraced_const_arg_that_can_begin_ty(snapshot)
|
||||
{
|
||||
return Ok(Some(self.dummy_const_arg_needs_braces(
|
||||
self.struct_span_err(expr.span, "invalid const generic expression"),
|
||||
|
@ -776,12 +777,10 @@ impl<'a> Parser<'a> {
|
|||
}
|
||||
Err(err) => {
|
||||
if let Some(snapshot) = snapshot
|
||||
&& let Some(expr) = self.recover_unbraced_const_arg_that_can_begin_ty(snapshot)
|
||||
&& let Some(expr) =
|
||||
self.recover_unbraced_const_arg_that_can_begin_ty(snapshot)
|
||||
{
|
||||
return Ok(Some(self.dummy_const_arg_needs_braces(
|
||||
err,
|
||||
expr.span,
|
||||
)));
|
||||
return Ok(Some(self.dummy_const_arg_needs_braces(err, expr.span)));
|
||||
}
|
||||
// Try to recover from possible `const` arg without braces.
|
||||
return self.recover_const_arg(start, err).map(Some);
|
||||
|
|
|
@ -52,7 +52,9 @@ impl<'a> Parser<'a> {
|
|||
|
||||
// Don't use `maybe_whole` so that we have precise control
|
||||
// over when we bump the parser
|
||||
if let token::Interpolated(nt) = &self.token.kind && let token::NtStmt(stmt) = &**nt {
|
||||
if let token::Interpolated(nt) = &self.token.kind
|
||||
&& let token::NtStmt(stmt) = &**nt
|
||||
{
|
||||
let mut stmt = stmt.clone();
|
||||
self.bump();
|
||||
stmt.visit_attrs(|stmt_attrs| {
|
||||
|
@ -227,8 +229,9 @@ impl<'a> Parser<'a> {
|
|||
/// Also error if the previous token was a doc comment.
|
||||
fn error_outer_attrs(&self, attrs: AttrWrapper) {
|
||||
if !attrs.is_empty()
|
||||
&& let attrs = attrs.take_for_recovery(self.sess)
|
||||
&& let attrs @ [.., last] = &*attrs {
|
||||
&& let attrs = attrs.take_for_recovery(self.sess)
|
||||
&& let attrs @ [.., last] = &*attrs
|
||||
{
|
||||
if last.is_doc_comment() {
|
||||
self.sess.emit_err(errors::DocCommentDoesNotDocumentAnything {
|
||||
span: last.span,
|
||||
|
@ -616,15 +619,17 @@ impl<'a> Parser<'a> {
|
|||
match &mut stmt.kind {
|
||||
// Expression without semicolon.
|
||||
StmtKind::Expr(expr)
|
||||
if self.token != token::Eof && classify::expr_requires_semi_to_be_stmt(expr) => {
|
||||
if self.token != token::Eof && classify::expr_requires_semi_to_be_stmt(expr) =>
|
||||
{
|
||||
// Just check for errors and recover; do not eat semicolon yet.
|
||||
// `expect_one_of` returns PResult<'a, bool /* recovered */>
|
||||
|
||||
let expect_result = self.expect_one_of(&[], &[token::Semi, token::CloseDelim(Delimiter::Brace)]);
|
||||
let expect_result =
|
||||
self.expect_one_of(&[], &[token::Semi, token::CloseDelim(Delimiter::Brace)]);
|
||||
|
||||
let replace_with_err = 'break_recover: {
|
||||
match expect_result {
|
||||
// Recover from parser, skip type error to avoid extra errors.
|
||||
// Recover from parser, skip type error to avoid extra errors.
|
||||
Ok(true) => true,
|
||||
Err(mut e) => {
|
||||
if let TokenKind::DocComment(..) = self.token.kind
|
||||
|
@ -654,14 +659,19 @@ impl<'a> Parser<'a> {
|
|||
}
|
||||
|
||||
match &expr.kind {
|
||||
ExprKind::Path(None, ast::Path { segments, .. }) if segments.len() == 1 => {
|
||||
ExprKind::Path(None, ast::Path { segments, .. })
|
||||
if segments.len() == 1 =>
|
||||
{
|
||||
if self.token == token::Colon
|
||||
&& self.look_ahead(1, |token| {
|
||||
token.is_whole_block() || matches!(
|
||||
token.kind,
|
||||
token::Ident(kw::For | kw::Loop | kw::While, false)
|
||||
| token::OpenDelim(Delimiter::Brace)
|
||||
)
|
||||
token.is_whole_block()
|
||||
|| matches!(
|
||||
token.kind,
|
||||
token::Ident(
|
||||
kw::For | kw::Loop | kw::While,
|
||||
false
|
||||
) | token::OpenDelim(Delimiter::Brace)
|
||||
)
|
||||
})
|
||||
{
|
||||
let snapshot = self.create_snapshot_for_diagnostic();
|
||||
|
@ -702,9 +712,8 @@ impl<'a> Parser<'a> {
|
|||
}
|
||||
|
||||
true
|
||||
|
||||
}
|
||||
Ok(false) => false
|
||||
Ok(false) => false,
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -727,7 +736,9 @@ impl<'a> Parser<'a> {
|
|||
}
|
||||
eat_semi = false;
|
||||
}
|
||||
StmtKind::Empty | StmtKind::Item(_) | StmtKind::Local(_) | StmtKind::Semi(_) => eat_semi = false,
|
||||
StmtKind::Empty | StmtKind::Item(_) | StmtKind::Local(_) | StmtKind::Semi(_) => {
|
||||
eat_semi = false
|
||||
}
|
||||
}
|
||||
|
||||
if add_semi_to_stmt || (eat_semi && self.eat(&token::Semi)) {
|
||||
|
|
|
@ -893,13 +893,15 @@ impl<'a> Parser<'a> {
|
|||
// to recover from errors, not make more).
|
||||
let path = if self.may_recover() {
|
||||
let (span, message, sugg, path, applicability) = match &ty.kind {
|
||||
TyKind::Ptr(..) | TyKind::Ref(..) if let TyKind::Path(_, path) = &ty.peel_refs().kind => {
|
||||
TyKind::Ptr(..) | TyKind::Ref(..)
|
||||
if let TyKind::Path(_, path) = &ty.peel_refs().kind =>
|
||||
{
|
||||
(
|
||||
ty.span.until(path.span),
|
||||
"consider removing the indirection",
|
||||
"",
|
||||
path,
|
||||
Applicability::MaybeIncorrect
|
||||
Applicability::MaybeIncorrect,
|
||||
)
|
||||
}
|
||||
TyKind::ImplTrait(_, bounds)
|
||||
|
@ -910,10 +912,10 @@ impl<'a> Parser<'a> {
|
|||
"use the trait bounds directly",
|
||||
"",
|
||||
&tr.trait_ref.path,
|
||||
Applicability::MachineApplicable
|
||||
Applicability::MachineApplicable,
|
||||
)
|
||||
}
|
||||
_ => return Err(err)
|
||||
_ => return Err(err),
|
||||
};
|
||||
|
||||
err.span_suggestion_verbose(span, message, sugg, applicability);
|
||||
|
@ -1027,7 +1029,8 @@ impl<'a> Parser<'a> {
|
|||
args.into_iter()
|
||||
.filter_map(|arg| {
|
||||
if let ast::AngleBracketedArg::Arg(generic_arg) = arg
|
||||
&& let ast::GenericArg::Lifetime(lifetime) = generic_arg {
|
||||
&& let ast::GenericArg::Lifetime(lifetime) = generic_arg
|
||||
{
|
||||
Some(lifetime)
|
||||
} else {
|
||||
None
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue