parser: call .struct_span_err directly
This commit is contained in:
parent
a9dd56ff9a
commit
2091062bf6
7 changed files with 56 additions and 68 deletions
|
@ -133,7 +133,7 @@ impl<'a> Parser<'a> {
|
|||
"previous outer attribute"
|
||||
};
|
||||
|
||||
let mut diagnostic = self.diagnostic().struct_span_err(attr_sp, reason);
|
||||
let mut diagnostic = self.struct_span_err(attr_sp, reason);
|
||||
|
||||
if let Some(prev_attr_sp) = prev_attr_sp {
|
||||
diagnostic
|
||||
|
@ -231,8 +231,7 @@ impl<'a> Parser<'a> {
|
|||
|
||||
if !lit.kind.is_unsuffixed() {
|
||||
let msg = "suffixed literals are not allowed in attributes";
|
||||
self.diagnostic()
|
||||
.struct_span_err(lit.span, msg)
|
||||
self.struct_span_err(lit.span, msg)
|
||||
.help(
|
||||
"instead of using a suffixed literal \
|
||||
(1u8, 1.0f32, etc.), use an unsuffixed version \
|
||||
|
@ -332,6 +331,6 @@ impl<'a> Parser<'a> {
|
|||
|
||||
let found = pprust::token_to_string(&self.token);
|
||||
let msg = format!("expected unsuffixed literal or identifier, found `{}`", found);
|
||||
Err(self.diagnostic().struct_span_err(self.token.span, &msg))
|
||||
Err(self.struct_span_err(self.token.span, &msg))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -502,8 +502,7 @@ impl<'a> Parser<'a> {
|
|||
let span = lo.until(self.token.span);
|
||||
|
||||
let total_num_of_gt = number_of_gt + number_of_shr * 2;
|
||||
self.diagnostic()
|
||||
.struct_span_err(
|
||||
self.struct_span_err(
|
||||
span,
|
||||
&format!("unmatched angle bracket{}", pluralize!(total_num_of_gt)),
|
||||
)
|
||||
|
@ -762,8 +761,7 @@ impl<'a> Parser<'a> {
|
|||
path.span = ty_span.to(self.prev_span);
|
||||
|
||||
let ty_str = self.span_to_snippet(ty_span).unwrap_or_else(|_| pprust::ty_to_string(&ty));
|
||||
self.diagnostic()
|
||||
.struct_span_err(path.span, "missing angle brackets in associated item path")
|
||||
self.struct_span_err(path.span, "missing angle brackets in associated item path")
|
||||
.span_suggestion(
|
||||
// This is a best-effort recovery.
|
||||
path.span,
|
||||
|
|
|
@ -1915,8 +1915,7 @@ impl<'a> Parser<'a> {
|
|||
return;
|
||||
}
|
||||
|
||||
self.diagnostic()
|
||||
.struct_span_err(self.token.span, "expected `:`, found `=`")
|
||||
self.struct_span_err(self.token.span, "expected `:`, found `=`")
|
||||
.span_suggestion(
|
||||
field_name.span.shrink_to_hi().to(self.token.span),
|
||||
"replace equals symbol with a colon",
|
||||
|
|
|
@ -306,8 +306,7 @@ impl<'a> Parser<'a> {
|
|||
// possible public struct definition where `struct` was forgotten
|
||||
let ident = self.parse_ident().unwrap();
|
||||
let msg = format!("add `struct` here to parse `{}` as a public struct", ident);
|
||||
let mut err =
|
||||
self.diagnostic().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(
|
||||
sp,
|
||||
&msg,
|
||||
|
@ -335,7 +334,7 @@ impl<'a> Parser<'a> {
|
|||
};
|
||||
|
||||
let msg = format!("missing `{}` for {} definition", kw, kw_name);
|
||||
let mut err = self.diagnostic().struct_span_err(sp, &msg);
|
||||
let mut err = self.struct_span_err(sp, &msg);
|
||||
if !ambiguous {
|
||||
self.consume_block(token::Brace, ConsumeClosingDelim::Yes);
|
||||
let suggestion =
|
||||
|
@ -375,7 +374,7 @@ impl<'a> Parser<'a> {
|
|||
("fn` or `struct", "function or struct", true)
|
||||
};
|
||||
let msg = format!("missing `{}` for {} definition", kw, kw_name);
|
||||
let mut err = self.diagnostic().struct_span_err(sp, &msg);
|
||||
let mut err = self.struct_span_err(sp, &msg);
|
||||
if !ambiguous {
|
||||
err.span_suggestion_short(
|
||||
sp,
|
||||
|
@ -466,7 +465,7 @@ impl<'a> Parser<'a> {
|
|||
_ => "expected item after attributes",
|
||||
};
|
||||
|
||||
let mut err = self.diagnostic().struct_span_err(self.prev_span, message);
|
||||
let mut err = self.struct_span_err(self.prev_span, message);
|
||||
if attrs.last().unwrap().is_doc_comment() {
|
||||
err.span_label(self.prev_span, "this doc comment doesn't document anything");
|
||||
}
|
||||
|
@ -536,7 +535,6 @@ impl<'a> Parser<'a> {
|
|||
// ^^ `sp` below will point to this
|
||||
let sp = prev_span.between(self.prev_span);
|
||||
let mut err = self
|
||||
.diagnostic()
|
||||
.struct_span_err(sp, &format!("{} for {}-item declaration", expected_kinds, item_type));
|
||||
err.span_label(sp, expected_kinds);
|
||||
err
|
||||
|
@ -1603,9 +1601,8 @@ impl<'a> Parser<'a> {
|
|||
VisibilityKind::Inherited => {}
|
||||
_ => {
|
||||
let mut err = if self.token.is_keyword(sym::macro_rules) {
|
||||
let mut err = self
|
||||
.diagnostic()
|
||||
.struct_span_err(sp, "can't qualify macro_rules invocation with `pub`");
|
||||
let mut err =
|
||||
self.struct_span_err(sp, "can't qualify macro_rules invocation with `pub`");
|
||||
err.span_suggestion(
|
||||
sp,
|
||||
"try exporting the macro",
|
||||
|
@ -1614,9 +1611,8 @@ impl<'a> Parser<'a> {
|
|||
);
|
||||
err
|
||||
} else {
|
||||
let mut err = self
|
||||
.diagnostic()
|
||||
.struct_span_err(sp, "can't qualify macro invocation with `pub`");
|
||||
let mut err =
|
||||
self.struct_span_err(sp, "can't qualify macro invocation with `pub`");
|
||||
err.help("try adjusting the macro to put `pub` inside the invocation");
|
||||
err
|
||||
};
|
||||
|
|
|
@ -129,7 +129,7 @@ impl<'a> Parser<'a> {
|
|||
DirectoryOwnership::UnownedViaBlock => {
|
||||
let msg = "Cannot declare a non-inline module inside a block \
|
||||
unless it has a path attribute";
|
||||
let mut err = self.diagnostic().struct_span_err(id_sp, msg);
|
||||
let mut err = self.struct_span_err(id_sp, msg);
|
||||
if paths.path_exists {
|
||||
let msg = format!(
|
||||
"Maybe `use` the module `{}` instead of redeclaring it",
|
||||
|
@ -140,9 +140,8 @@ impl<'a> Parser<'a> {
|
|||
Err(err)
|
||||
}
|
||||
DirectoryOwnership::UnownedViaMod => {
|
||||
let mut err = self
|
||||
.diagnostic()
|
||||
.struct_span_err(id_sp, "cannot declare a new module at this location");
|
||||
let mut err =
|
||||
self.struct_span_err(id_sp, "cannot declare a new module at this location");
|
||||
if !id_sp.is_dummy() {
|
||||
let src_path = self.sess.source_map().span_to_filename(id_sp);
|
||||
if let FileName::Real(src_path) = src_path {
|
||||
|
|
|
@ -699,8 +699,7 @@ impl<'a> Parser<'a> {
|
|||
let range_span = lo.to(end.span);
|
||||
let begin = self.mk_expr(range_span, ExprKind::Err, AttrVec::new());
|
||||
|
||||
self.diagnostic()
|
||||
.struct_span_err(range_span, &format!("`{}X` range patterns are not supported", form))
|
||||
self.struct_span_err(range_span, &format!("`{}X` range patterns are not supported", form))
|
||||
.span_suggestion(
|
||||
range_span,
|
||||
"try using the minimum value for the type",
|
||||
|
@ -722,8 +721,7 @@ impl<'a> Parser<'a> {
|
|||
// Parsing e.g. `X..`.
|
||||
let range_span = begin.span.to(self.prev_span);
|
||||
|
||||
self.diagnostic()
|
||||
.struct_span_err(
|
||||
self.struct_span_err(
|
||||
range_span,
|
||||
&format!("`X{}` range patterns are not supported", form),
|
||||
)
|
||||
|
|
|
@ -325,8 +325,7 @@ impl<'a> Parser<'a> {
|
|||
|
||||
// Make a span over ${unmatched angle bracket count} characters.
|
||||
let span = lo.with_hi(lo.lo() + BytePos(snapshot.unmatched_angle_bracket_count));
|
||||
self.diagnostic()
|
||||
.struct_span_err(
|
||||
self.struct_span_err(
|
||||
span,
|
||||
&format!(
|
||||
"unmatched angle bracket{}",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue