Format all the let chains in compiler

This commit is contained in:
Michael Goulet 2023-10-13 08:58:33 +00:00
parent 2763ca50da
commit b2d2184ede
206 changed files with 3120 additions and 2228 deletions

View file

@ -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],