use format_args_capture
in some parts of rustc_parse
This commit is contained in:
parent
3ba1ebea12
commit
896b113ec3
4 changed files with 60 additions and 61 deletions
|
@ -139,7 +139,7 @@ impl<'a> Parser<'a> {
|
||||||
Ok(attr::mk_attr_from_item(item, None, style, attr_sp))
|
Ok(attr::mk_attr_from_item(item, None, style, attr_sp))
|
||||||
} else {
|
} else {
|
||||||
let token_str = pprust::token_to_string(&this.token);
|
let token_str = pprust::token_to_string(&this.token);
|
||||||
let msg = &format!("expected `#`, found `{}`", token_str);
|
let msg = &format!("expected `#`, found `{token_str}`");
|
||||||
Err(this.struct_span_err(this.token.span, msg))
|
Err(this.struct_span_err(this.token.span, msg))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -421,7 +421,7 @@ impl<'a> Parser<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
let found = pprust::token_to_string(&self.token);
|
let found = pprust::token_to_string(&self.token);
|
||||||
let msg = format!("expected unsuffixed literal or identifier, found `{}`", found);
|
let msg = format!("expected unsuffixed literal or identifier, found `{found}`");
|
||||||
Err(self.struct_span_err(self.token.span, &msg))
|
Err(self.struct_span_err(self.token.span, &msg))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -327,8 +327,8 @@ impl<'a> Parser<'a> {
|
||||||
expect.clone()
|
expect.clone()
|
||||||
};
|
};
|
||||||
(
|
(
|
||||||
format!("expected one of {}, found {}", expect, actual),
|
format!("expected one of {expect}, found {actual}"),
|
||||||
(self.prev_token.span.shrink_to_hi(), format!("expected one of {}", short_expect)),
|
(self.prev_token.span.shrink_to_hi(), format!("expected one of {short_expect}")),
|
||||||
)
|
)
|
||||||
} else if expected.is_empty() {
|
} else if expected.is_empty() {
|
||||||
(
|
(
|
||||||
|
@ -337,8 +337,8 @@ impl<'a> Parser<'a> {
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
(
|
(
|
||||||
format!("expected {}, found {}", expect, actual),
|
format!("expected {expect}, found {actual}"),
|
||||||
(self.prev_token.span.shrink_to_hi(), format!("expected {}", expect)),
|
(self.prev_token.span.shrink_to_hi(), format!("expected {expect}")),
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
self.last_unexpected_token_span = Some(self.token.span);
|
self.last_unexpected_token_span = Some(self.token.span);
|
||||||
|
@ -421,7 +421,7 @@ impl<'a> Parser<'a> {
|
||||||
String::new(),
|
String::new(),
|
||||||
Applicability::MachineApplicable,
|
Applicability::MachineApplicable,
|
||||||
);
|
);
|
||||||
err.note(&format!("the raw string started with {} `#`s", n_hashes));
|
err.note(&format!("the raw string started with {n_hashes} `#`s"));
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
_ => false,
|
_ => false,
|
||||||
|
@ -1191,7 +1191,7 @@ impl<'a> Parser<'a> {
|
||||||
_ => None,
|
_ => None,
|
||||||
};
|
};
|
||||||
if let Some(name) = previous_item_kind_name {
|
if let Some(name) = previous_item_kind_name {
|
||||||
err.help(&format!("{} declarations are not followed by a semicolon", name));
|
err.help(&format!("{name} declarations are not followed by a semicolon"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
err.emit();
|
err.emit();
|
||||||
|
@ -1226,12 +1226,12 @@ impl<'a> Parser<'a> {
|
||||||
"expected `{}`, found {}",
|
"expected `{}`, found {}",
|
||||||
token_str,
|
token_str,
|
||||||
match (&self.token.kind, self.subparser_name) {
|
match (&self.token.kind, self.subparser_name) {
|
||||||
(token::Eof, Some(origin)) => format!("end of {}", origin),
|
(token::Eof, Some(origin)) => format!("end of {origin}"),
|
||||||
_ => this_token_str,
|
_ => this_token_str,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
let mut err = self.struct_span_err(sp, &msg);
|
let mut err = self.struct_span_err(sp, &msg);
|
||||||
let label_exp = format!("expected `{}`", token_str);
|
let label_exp = format!("expected `{token_str}`");
|
||||||
match self.recover_closing_delimiter(&[t.clone()], err) {
|
match self.recover_closing_delimiter(&[t.clone()], err) {
|
||||||
Err(e) => err = e,
|
Err(e) => err = e,
|
||||||
Ok(recovered) => {
|
Ok(recovered) => {
|
||||||
|
@ -1368,7 +1368,7 @@ impl<'a> Parser<'a> {
|
||||||
Applicability::MachineApplicable,
|
Applicability::MachineApplicable,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
err.span_suggestion(lo.shrink_to_lo(), &format!("{}you can still access the deprecated `try!()` macro using the \"raw identifier\" syntax", prefix), "r#".to_string(), Applicability::MachineApplicable);
|
err.span_suggestion(lo.shrink_to_lo(), &format!("{prefix}you can still access the deprecated `try!()` macro using the \"raw identifier\" syntax"), "r#".to_string(), Applicability::MachineApplicable);
|
||||||
err.emit();
|
err.emit();
|
||||||
Ok(self.mk_expr_err(lo.to(hi)))
|
Ok(self.mk_expr_err(lo.to(hi)))
|
||||||
} else {
|
} else {
|
||||||
|
@ -1504,7 +1504,7 @@ impl<'a> Parser<'a> {
|
||||||
delim.retain(|c| c != '`');
|
delim.retain(|c| c != '`');
|
||||||
err.span_suggestion_short(
|
err.span_suggestion_short(
|
||||||
self.prev_token.span.shrink_to_hi(),
|
self.prev_token.span.shrink_to_hi(),
|
||||||
&format!("`{}` may belong here", delim),
|
&format!("`{delim}` may belong here"),
|
||||||
delim,
|
delim,
|
||||||
Applicability::MaybeIncorrect,
|
Applicability::MaybeIncorrect,
|
||||||
);
|
);
|
||||||
|
@ -1698,7 +1698,7 @@ impl<'a> Parser<'a> {
|
||||||
(
|
(
|
||||||
ident,
|
ident,
|
||||||
"self: ".to_string(),
|
"self: ".to_string(),
|
||||||
format!("{}: &{}TypeName", ident, mutab),
|
format!("{ident}: &{mutab}TypeName"),
|
||||||
"_: ".to_string(),
|
"_: ".to_string(),
|
||||||
pat.span.shrink_to_lo(),
|
pat.span.shrink_to_lo(),
|
||||||
pat.span,
|
pat.span,
|
||||||
|
@ -1826,7 +1826,7 @@ impl<'a> Parser<'a> {
|
||||||
let (span, msg) = match (&self.token.kind, self.subparser_name) {
|
let (span, msg) = match (&self.token.kind, self.subparser_name) {
|
||||||
(&token::Eof, Some(origin)) => {
|
(&token::Eof, Some(origin)) => {
|
||||||
let sp = self.sess.source_map().next_point(self.prev_token.span);
|
let sp = self.sess.source_map().next_point(self.prev_token.span);
|
||||||
(sp, format!("expected expression, found end of {}", origin))
|
(sp, format!("expected expression, found end of {origin}"))
|
||||||
}
|
}
|
||||||
_ => (
|
_ => (
|
||||||
self.token.span,
|
self.token.span,
|
||||||
|
@ -1975,8 +1975,8 @@ impl<'a> Parser<'a> {
|
||||||
(ty_generics, self.sess.source_map().span_to_snippet(param.span()))
|
(ty_generics, self.sess.source_map().span_to_snippet(param.span()))
|
||||||
{
|
{
|
||||||
let (span, sugg) = match &generics.params[..] {
|
let (span, sugg) = match &generics.params[..] {
|
||||||
[] => (generics.span, format!("<{}>", snippet)),
|
[] => (generics.span, format!("<{snippet}>")),
|
||||||
[.., generic] => (generic.span().shrink_to_hi(), format!(", {}", snippet)),
|
[.., generic] => (generic.span().shrink_to_hi(), format!(", {snippet}")),
|
||||||
};
|
};
|
||||||
err.multipart_suggestion(
|
err.multipart_suggestion(
|
||||||
"`const` parameters must be declared for the `impl`",
|
"`const` parameters must be declared for the `impl`",
|
||||||
|
|
|
@ -223,7 +223,7 @@ impl<'a> Parser<'a> {
|
||||||
AssocOp::NotEqual => "!=",
|
AssocOp::NotEqual => "!=",
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
};
|
};
|
||||||
self.struct_span_err(sp, &format!("invalid comparison operator `{}=`", sugg))
|
self.struct_span_err(sp, &format!("invalid comparison operator `{sugg}=`"))
|
||||||
.span_suggestion_short(
|
.span_suggestion_short(
|
||||||
sp,
|
sp,
|
||||||
&format!("`{s}=` is not a valid comparison operator, use `{s}`", s = sugg),
|
&format!("`{s}=` is not a valid comparison operator, use `{s}`", s = sugg),
|
||||||
|
@ -441,10 +441,10 @@ impl<'a> Parser<'a> {
|
||||||
|
|
||||||
/// Error on `and` and `or` suggesting `&&` and `||` respectively.
|
/// Error on `and` and `or` suggesting `&&` and `||` respectively.
|
||||||
fn error_bad_logical_op(&self, bad: &str, good: &str, english: &str) {
|
fn error_bad_logical_op(&self, bad: &str, good: &str, english: &str) {
|
||||||
self.struct_span_err(self.token.span, &format!("`{}` is not a logical operator", bad))
|
self.struct_span_err(self.token.span, &format!("`{bad}` is not a logical operator"))
|
||||||
.span_suggestion_short(
|
.span_suggestion_short(
|
||||||
self.token.span,
|
self.token.span,
|
||||||
&format!("use `{}` to perform logical {}", good, english),
|
&format!("use `{good}` to perform logical {english}"),
|
||||||
good.to_string(),
|
good.to_string(),
|
||||||
Applicability::MachineApplicable,
|
Applicability::MachineApplicable,
|
||||||
)
|
)
|
||||||
|
@ -766,9 +766,9 @@ impl<'a> Parser<'a> {
|
||||||
self.look_ahead(1, |t| t.span).to(span_after_type),
|
self.look_ahead(1, |t| t.span).to(span_after_type),
|
||||||
"interpreted as generic arguments",
|
"interpreted as generic arguments",
|
||||||
)
|
)
|
||||||
.span_label(self.token.span, format!("not interpreted as {}", op_noun))
|
.span_label(self.token.span, format!("not interpreted as {op_noun}"))
|
||||||
.multipart_suggestion(
|
.multipart_suggestion(
|
||||||
&format!("try {} the cast value", op_verb),
|
&format!("try {op_verb} the cast value"),
|
||||||
vec![
|
vec![
|
||||||
(expr.span.shrink_to_lo(), "(".to_string()),
|
(expr.span.shrink_to_lo(), "(".to_string()),
|
||||||
(expr.span.shrink_to_hi(), ")".to_string()),
|
(expr.span.shrink_to_hi(), ")".to_string()),
|
||||||
|
@ -970,7 +970,7 @@ impl<'a> Parser<'a> {
|
||||||
fn error_unexpected_after_dot(&self) {
|
fn error_unexpected_after_dot(&self) {
|
||||||
// FIXME Could factor this out into non_fatal_unexpected or something.
|
// FIXME Could factor this out into non_fatal_unexpected or something.
|
||||||
let actual = pprust::token_to_string(&self.token);
|
let actual = pprust::token_to_string(&self.token);
|
||||||
self.struct_span_err(self.token.span, &format!("unexpected token: `{}`", actual)).emit();
|
self.struct_span_err(self.token.span, &format!("unexpected token: `{actual}`")).emit();
|
||||||
}
|
}
|
||||||
|
|
||||||
// We need an identifier or integer, but the next token is a float.
|
// We need an identifier or integer, but the next token is a float.
|
||||||
|
@ -1151,7 +1151,7 @@ impl<'a> Parser<'a> {
|
||||||
mem::replace(err, replacement_err).cancel();
|
mem::replace(err, replacement_err).cancel();
|
||||||
|
|
||||||
err.multipart_suggestion(
|
err.multipart_suggestion(
|
||||||
&format!("if `{}` is a struct, use braces as delimiters", name),
|
&format!("if `{name}` is a struct, use braces as delimiters"),
|
||||||
vec![
|
vec![
|
||||||
(open_paren, " { ".to_string()),
|
(open_paren, " { ".to_string()),
|
||||||
(close_paren, " }".to_string()),
|
(close_paren, " }".to_string()),
|
||||||
|
@ -1159,7 +1159,7 @@ impl<'a> Parser<'a> {
|
||||||
Applicability::MaybeIncorrect,
|
Applicability::MaybeIncorrect,
|
||||||
);
|
);
|
||||||
err.multipart_suggestion(
|
err.multipart_suggestion(
|
||||||
&format!("if `{}` is a function, use the arguments directly", name),
|
&format!("if `{name}` is a function, use the arguments directly"),
|
||||||
fields
|
fields
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|field| (field.span.until(field.expr.span), String::new()))
|
.map(|field| (field.span.until(field.expr.span), String::new()))
|
||||||
|
@ -1776,9 +1776,9 @@ impl<'a> Parser<'a> {
|
||||||
)
|
)
|
||||||
.emit();
|
.emit();
|
||||||
} else {
|
} else {
|
||||||
let msg = format!("invalid suffix `{}` for number literal", suf);
|
let msg = format!("invalid suffix `{suf}` for number literal");
|
||||||
self.struct_span_err(span, &msg)
|
self.struct_span_err(span, &msg)
|
||||||
.span_label(span, format!("invalid suffix `{}`", suf))
|
.span_label(span, format!("invalid suffix `{suf}`"))
|
||||||
.help("the suffix must be one of the numeric types (`u32`, `isize`, `f32`, etc.)")
|
.help("the suffix must be one of the numeric types (`u32`, `isize`, `f32`, etc.)")
|
||||||
.emit();
|
.emit();
|
||||||
}
|
}
|
||||||
|
@ -1791,9 +1791,9 @@ impl<'a> Parser<'a> {
|
||||||
let msg = format!("invalid width `{}` for float literal", &suf[1..]);
|
let msg = format!("invalid width `{}` for float literal", &suf[1..]);
|
||||||
self.struct_span_err(span, &msg).help("valid widths are 32 and 64").emit();
|
self.struct_span_err(span, &msg).help("valid widths are 32 and 64").emit();
|
||||||
} else {
|
} else {
|
||||||
let msg = format!("invalid suffix `{}` for float literal", suf);
|
let msg = format!("invalid suffix `{suf}` for float literal");
|
||||||
self.struct_span_err(span, &msg)
|
self.struct_span_err(span, &msg)
|
||||||
.span_label(span, format!("invalid suffix `{}`", suf))
|
.span_label(span, format!("invalid suffix `{suf}`"))
|
||||||
.help("valid suffixes are `f32` and `f64`")
|
.help("valid suffixes are `f32` and `f64`")
|
||||||
.emit();
|
.emit();
|
||||||
}
|
}
|
||||||
|
@ -1805,7 +1805,7 @@ impl<'a> Parser<'a> {
|
||||||
2 => "binary",
|
2 => "binary",
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
};
|
};
|
||||||
self.struct_span_err(span, &format!("{} float literal is not supported", descr))
|
self.struct_span_err(span, &format!("{descr} float literal is not supported"))
|
||||||
.span_label(span, "not supported")
|
.span_label(span, "not supported")
|
||||||
.emit();
|
.emit();
|
||||||
}
|
}
|
||||||
|
@ -1825,7 +1825,7 @@ impl<'a> Parser<'a> {
|
||||||
let mut err = self
|
let mut err = self
|
||||||
.sess
|
.sess
|
||||||
.span_diagnostic
|
.span_diagnostic
|
||||||
.struct_span_warn(sp, &format!("suffixes on {} are invalid", kind));
|
.struct_span_warn(sp, &format!("suffixes on {kind} are invalid"));
|
||||||
err.note(&format!(
|
err.note(&format!(
|
||||||
"`{}` is *temporarily* accepted on tuple index fields as it was \
|
"`{}` is *temporarily* accepted on tuple index fields as it was \
|
||||||
incorrectly accepted on stable for a few releases",
|
incorrectly accepted on stable for a few releases",
|
||||||
|
@ -1842,10 +1842,10 @@ impl<'a> Parser<'a> {
|
||||||
);
|
);
|
||||||
err
|
err
|
||||||
} else {
|
} else {
|
||||||
self.struct_span_err(sp, &format!("suffixes on {} are invalid", kind))
|
self.struct_span_err(sp, &format!("suffixes on {kind} are invalid"))
|
||||||
.forget_guarantee()
|
.forget_guarantee()
|
||||||
};
|
};
|
||||||
err.span_label(sp, format!("invalid suffix `{}`", suf));
|
err.span_label(sp, format!("invalid suffix `{suf}`"));
|
||||||
err.emit();
|
err.emit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2211,7 +2211,7 @@ impl<'a> Parser<'a> {
|
||||||
let ctx = if is_ctx_else { "else" } else { "if" };
|
let ctx = if is_ctx_else { "else" } else { "if" };
|
||||||
self.struct_span_err(last, "outer attributes are not allowed on `if` and `else` branches")
|
self.struct_span_err(last, "outer attributes are not allowed on `if` and `else` branches")
|
||||||
.span_label(branch_span, "the attributes are attached to this branch")
|
.span_label(branch_span, "the attributes are attached to this branch")
|
||||||
.span_label(ctx_span, format!("the branch belongs to this `{}`", ctx))
|
.span_label(ctx_span, format!("the branch belongs to this `{ctx}`"))
|
||||||
.span_suggestion(
|
.span_suggestion(
|
||||||
span,
|
span,
|
||||||
"remove the attributes",
|
"remove the attributes",
|
||||||
|
@ -2391,7 +2391,7 @@ impl<'a> Parser<'a> {
|
||||||
err.span_label(arrow_span, "while parsing the `match` arm starting here");
|
err.span_label(arrow_span, "while parsing the `match` arm starting here");
|
||||||
if stmts.len() > 1 {
|
if stmts.len() > 1 {
|
||||||
err.multipart_suggestion(
|
err.multipart_suggestion(
|
||||||
&format!("surround the statement{} with a body", s),
|
&format!("surround the statement{s} with a body"),
|
||||||
vec![
|
vec![
|
||||||
(span.shrink_to_lo(), "{ ".to_string()),
|
(span.shrink_to_lo(), "{ ".to_string()),
|
||||||
(span.shrink_to_hi(), " }".to_string()),
|
(span.shrink_to_hi(), " }".to_string()),
|
||||||
|
|
|
@ -66,7 +66,7 @@ impl<'a> Parser<'a> {
|
||||||
if !self.eat(term) {
|
if !self.eat(term) {
|
||||||
let token_str = super::token_descr(&self.token);
|
let token_str = super::token_descr(&self.token);
|
||||||
if !self.maybe_consume_incorrect_semicolon(&items) {
|
if !self.maybe_consume_incorrect_semicolon(&items) {
|
||||||
let msg = &format!("expected item, found {}", token_str);
|
let msg = &format!("expected item, found {token_str}");
|
||||||
let mut err = self.struct_span_err(self.token.span, msg);
|
let mut err = self.struct_span_err(self.token.span, msg);
|
||||||
err.span_label(self.token.span, "expected item");
|
err.span_label(self.token.span, "expected item");
|
||||||
return Err(err);
|
return Err(err);
|
||||||
|
@ -163,9 +163,9 @@ impl<'a> Parser<'a> {
|
||||||
}
|
}
|
||||||
let vs = pprust::vis_to_string(&vis);
|
let vs = pprust::vis_to_string(&vis);
|
||||||
let vs = vs.trim_end();
|
let vs = vs.trim_end();
|
||||||
self.struct_span_err(vis.span, &format!("visibility `{}` is not followed by an item", vs))
|
self.struct_span_err(vis.span, &format!("visibility `{vs}` is not followed by an item"))
|
||||||
.span_label(vis.span, "the visibility")
|
.span_label(vis.span, "the visibility")
|
||||||
.help(&format!("you likely meant to define an item, e.g., `{} fn foo() {{}}`", vs))
|
.help(&format!("you likely meant to define an item, e.g., `{vs} fn foo() {{}}`"))
|
||||||
.emit();
|
.emit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -327,7 +327,7 @@ impl<'a> Parser<'a> {
|
||||||
if self.look_ahead(1, |t| *t == token::OpenDelim(token::Brace)) {
|
if self.look_ahead(1, |t| *t == token::OpenDelim(token::Brace)) {
|
||||||
// possible public struct definition where `struct` was forgotten
|
// possible public struct definition where `struct` was forgotten
|
||||||
let ident = self.parse_ident().unwrap();
|
let ident = self.parse_ident().unwrap();
|
||||||
let msg = format!("add `struct` here to parse `{}` as a public struct", ident);
|
let msg = format!("add `struct` here to parse `{ident}` as a public struct");
|
||||||
let mut err = self.struct_span_err(sp, "missing `struct` for struct definition");
|
let mut err = self.struct_span_err(sp, "missing `struct` for struct definition");
|
||||||
err.span_suggestion_short(
|
err.span_suggestion_short(
|
||||||
sp,
|
sp,
|
||||||
|
@ -355,16 +355,16 @@ impl<'a> Parser<'a> {
|
||||||
("fn` or `struct", "function or struct", true)
|
("fn` or `struct", "function or struct", true)
|
||||||
};
|
};
|
||||||
|
|
||||||
let msg = format!("missing `{}` for {} definition", kw, kw_name);
|
let msg = format!("missing `{kw}` for {kw_name} definition");
|
||||||
let mut err = self.struct_span_err(sp, &msg);
|
let mut err = self.struct_span_err(sp, &msg);
|
||||||
if !ambiguous {
|
if !ambiguous {
|
||||||
self.consume_block(token::Brace, ConsumeClosingDelim::Yes);
|
self.consume_block(token::Brace, ConsumeClosingDelim::Yes);
|
||||||
let suggestion =
|
let suggestion =
|
||||||
format!("add `{}` here to parse `{}` as a public {}", kw, ident, kw_name);
|
format!("add `{kw}` here to parse `{ident}` as a public {kw_name}");
|
||||||
err.span_suggestion_short(
|
err.span_suggestion_short(
|
||||||
sp,
|
sp,
|
||||||
&suggestion,
|
&suggestion,
|
||||||
format!(" {} ", kw),
|
format!(" {kw} "),
|
||||||
Applicability::MachineApplicable,
|
Applicability::MachineApplicable,
|
||||||
);
|
);
|
||||||
} else if let Ok(snippet) = self.span_to_snippet(ident_sp) {
|
} else if let Ok(snippet) = self.span_to_snippet(ident_sp) {
|
||||||
|
@ -393,12 +393,12 @@ impl<'a> Parser<'a> {
|
||||||
} else {
|
} else {
|
||||||
("fn` or `struct", "function or struct", true)
|
("fn` or `struct", "function or struct", true)
|
||||||
};
|
};
|
||||||
let msg = format!("missing `{}` for {} definition", kw, kw_name);
|
let msg = format!("missing `{kw}` for {kw_name} definition");
|
||||||
let mut err = self.struct_span_err(sp, &msg);
|
let mut err = self.struct_span_err(sp, &msg);
|
||||||
if !ambiguous {
|
if !ambiguous {
|
||||||
err.span_suggestion_short(
|
err.span_suggestion_short(
|
||||||
sp,
|
sp,
|
||||||
&format!("add `{}` here to parse `{}` as a public {}", kw, ident, kw_name),
|
&format!("add `{kw}` here to parse `{ident}` as a public {kw_name}"),
|
||||||
format!(" {} ", kw),
|
format!(" {} ", kw),
|
||||||
Applicability::MachineApplicable,
|
Applicability::MachineApplicable,
|
||||||
);
|
);
|
||||||
|
@ -1031,8 +1031,8 @@ impl<'a> Parser<'a> {
|
||||||
fn error_bad_item_kind<T>(&self, span: Span, kind: &ItemKind, ctx: &str) -> Option<T> {
|
fn error_bad_item_kind<T>(&self, span: Span, kind: &ItemKind, ctx: &str) -> Option<T> {
|
||||||
let span = self.sess.source_map().guess_head_span(span);
|
let span = self.sess.source_map().guess_head_span(span);
|
||||||
let descr = kind.descr();
|
let descr = kind.descr();
|
||||||
self.struct_span_err(span, &format!("{} is not supported in {}", descr, ctx))
|
self.struct_span_err(span, &format!("{descr} is not supported in {ctx}"))
|
||||||
.help(&format!("consider moving the {} out to a nearby module scope", descr))
|
.help(&format!("consider moving the {descr} out to a nearby module scope"))
|
||||||
.emit();
|
.emit();
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
@ -1161,11 +1161,11 @@ impl<'a> Parser<'a> {
|
||||||
Some(Mutability::Not) => "static",
|
Some(Mutability::Not) => "static",
|
||||||
None => "const",
|
None => "const",
|
||||||
};
|
};
|
||||||
let mut err = self.struct_span_err(id.span, &format!("missing type for `{}` item", kind));
|
let mut err = self.struct_span_err(id.span, &format!("missing type for `{kind}` item"));
|
||||||
err.span_suggestion(
|
err.span_suggestion(
|
||||||
id.span,
|
id.span,
|
||||||
"provide a type for the item",
|
"provide a type for the item",
|
||||||
format!("{}: <type>", id),
|
format!("{id}: <type>"),
|
||||||
Applicability::HasPlaceholders,
|
Applicability::HasPlaceholders,
|
||||||
);
|
);
|
||||||
err.stash(id.span, StashKey::ItemNoType);
|
err.stash(id.span, StashKey::ItemNoType);
|
||||||
|
@ -1282,8 +1282,7 @@ impl<'a> Parser<'a> {
|
||||||
} else {
|
} else {
|
||||||
let token_str = super::token_descr(&self.token);
|
let token_str = super::token_descr(&self.token);
|
||||||
let msg = &format!(
|
let msg = &format!(
|
||||||
"expected `where`, `{{`, `(`, or `;` after struct name, found {}",
|
"expected `where`, `{{`, `(`, or `;` after struct name, found {token_str}"
|
||||||
token_str
|
|
||||||
);
|
);
|
||||||
let mut err = self.struct_span_err(self.token.span, msg);
|
let mut err = self.struct_span_err(self.token.span, msg);
|
||||||
err.span_label(self.token.span, "expected `where`, `{`, `(`, or `;` after struct name");
|
err.span_label(self.token.span, "expected `where`, `{`, `(`, or `;` after struct name");
|
||||||
|
@ -1310,7 +1309,7 @@ impl<'a> Parser<'a> {
|
||||||
VariantData::Struct(fields, recovered)
|
VariantData::Struct(fields, recovered)
|
||||||
} else {
|
} else {
|
||||||
let token_str = super::token_descr(&self.token);
|
let token_str = super::token_descr(&self.token);
|
||||||
let msg = &format!("expected `where` or `{{` after union name, found {}", token_str);
|
let msg = &format!("expected `where` or `{{` after union name, found {token_str}");
|
||||||
let mut err = self.struct_span_err(self.token.span, msg);
|
let mut err = self.struct_span_err(self.token.span, msg);
|
||||||
err.span_label(self.token.span, "expected `where` or `{` after union name");
|
err.span_label(self.token.span, "expected `where` or `{` after union name");
|
||||||
return Err(err);
|
return Err(err);
|
||||||
|
@ -1591,7 +1590,7 @@ impl<'a> Parser<'a> {
|
||||||
}
|
}
|
||||||
let mut err = self.struct_span_err(
|
let mut err = self.struct_span_err(
|
||||||
lo.to(self.prev_token.span),
|
lo.to(self.prev_token.span),
|
||||||
&format!("functions are not allowed in {} definitions", adt_ty),
|
&format!("functions are not allowed in {adt_ty} definitions"),
|
||||||
);
|
);
|
||||||
err.help("unlike in C++, Java, and C#, functions are declared in `impl` blocks");
|
err.help("unlike in C++, Java, and C#, functions are declared in `impl` blocks");
|
||||||
err.help("see https://doc.rust-lang.org/book/ch05-03-method-syntax.html for more information");
|
err.help("see https://doc.rust-lang.org/book/ch05-03-method-syntax.html for more information");
|
||||||
|
@ -1706,7 +1705,7 @@ impl<'a> Parser<'a> {
|
||||||
let vstr = pprust::vis_to_string(vis);
|
let vstr = pprust::vis_to_string(vis);
|
||||||
let vstr = vstr.trim_end();
|
let vstr = vstr.trim_end();
|
||||||
if macro_rules {
|
if macro_rules {
|
||||||
let msg = format!("can't qualify macro_rules invocation with `{}`", vstr);
|
let msg = format!("can't qualify macro_rules invocation with `{vstr}`");
|
||||||
self.struct_span_err(vis.span, &msg)
|
self.struct_span_err(vis.span, &msg)
|
||||||
.span_suggestion(
|
.span_suggestion(
|
||||||
vis.span,
|
vis.span,
|
||||||
|
@ -1723,7 +1722,7 @@ impl<'a> Parser<'a> {
|
||||||
String::new(),
|
String::new(),
|
||||||
Applicability::MachineApplicable,
|
Applicability::MachineApplicable,
|
||||||
)
|
)
|
||||||
.help(&format!("try adjusting the macro to put `{}` inside the invocation", vstr))
|
.help(&format!("try adjusting the macro to put `{vstr}` inside the invocation"))
|
||||||
.emit();
|
.emit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1781,11 +1780,11 @@ impl<'a> Parser<'a> {
|
||||||
|
|
||||||
self.struct_span_err(
|
self.struct_span_err(
|
||||||
kw_token.span,
|
kw_token.span,
|
||||||
&format!("`{}` definition cannot be nested inside `{}`", kw_str, keyword),
|
&format!("`{kw_str}` definition cannot be nested inside `{keyword}`"),
|
||||||
)
|
)
|
||||||
.span_suggestion(
|
.span_suggestion(
|
||||||
item.unwrap().span,
|
item.unwrap().span,
|
||||||
&format!("consider creating a new `{}` definition instead of nesting", kw_str),
|
&format!("consider creating a new `{kw_str}` definition instead of nesting"),
|
||||||
String::new(),
|
String::new(),
|
||||||
Applicability::MaybeIncorrect,
|
Applicability::MaybeIncorrect,
|
||||||
)
|
)
|
||||||
|
@ -2045,11 +2044,11 @@ impl<'a> Parser<'a> {
|
||||||
|
|
||||||
err.span_suggestion(
|
err.span_suggestion(
|
||||||
self.token.uninterpolated_span(),
|
self.token.uninterpolated_span(),
|
||||||
&format!("`{}` already used earlier, remove this one", original_kw),
|
&format!("`{original_kw}` already used earlier, remove this one"),
|
||||||
"".to_string(),
|
"".to_string(),
|
||||||
Applicability::MachineApplicable,
|
Applicability::MachineApplicable,
|
||||||
)
|
)
|
||||||
.span_note(original_sp, &format!("`{}` first seen here", original_kw));
|
.span_note(original_sp, &format!("`{original_kw}` first seen here"));
|
||||||
}
|
}
|
||||||
// The keyword has not been seen yet, suggest correct placement in the function front matter
|
// The keyword has not been seen yet, suggest correct placement in the function front matter
|
||||||
else if let Some(WrongKw::Misplaced(correct_pos_sp)) = wrong_kw {
|
else if let Some(WrongKw::Misplaced(correct_pos_sp)) = wrong_kw {
|
||||||
|
@ -2060,8 +2059,8 @@ impl<'a> Parser<'a> {
|
||||||
|
|
||||||
err.span_suggestion(
|
err.span_suggestion(
|
||||||
correct_pos_sp.to(misplaced_qual_sp),
|
correct_pos_sp.to(misplaced_qual_sp),
|
||||||
&format!("`{}` must come before `{}`", misplaced_qual, current_qual),
|
&format!("`{misplaced_qual}` must come before `{current_qual}`"),
|
||||||
format!("{} {}", misplaced_qual, current_qual),
|
format!("{misplaced_qual} {current_qual}"),
|
||||||
Applicability::MachineApplicable,
|
Applicability::MachineApplicable,
|
||||||
).note("keyword order for functions declaration is `default`, `pub`, `const`, `async`, `unsafe`, `extern`");
|
).note("keyword order for functions declaration is `default`, `pub`, `const`, `async`, `unsafe`, `extern`");
|
||||||
}
|
}
|
||||||
|
@ -2084,8 +2083,8 @@ impl<'a> Parser<'a> {
|
||||||
if matches!(orig_vis.kind, VisibilityKind::Inherited) {
|
if matches!(orig_vis.kind, VisibilityKind::Inherited) {
|
||||||
err.span_suggestion(
|
err.span_suggestion(
|
||||||
sp_start.to(self.prev_token.span),
|
sp_start.to(self.prev_token.span),
|
||||||
&format!("visibility `{}` must come before `{}`", vs, snippet),
|
&format!("visibility `{vs}` must come before `{snippet}`"),
|
||||||
format!("{} {}", vs, snippet),
|
format!("{vs} {snippet}"),
|
||||||
Applicability::MachineApplicable,
|
Applicability::MachineApplicable,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue