Skip to content

Commit 2091062

Browse files
committed
parser: call .struct_span_err directly
1 parent a9dd56f commit 2091062

File tree

7 files changed

+56
-68
lines changed

7 files changed

+56
-68
lines changed

src/librustc_parse/parser/attr.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ impl<'a> Parser<'a> {
133133
"previous outer attribute"
134134
};
135135

136-
let mut diagnostic = self.diagnostic().struct_span_err(attr_sp, reason);
136+
let mut diagnostic = self.struct_span_err(attr_sp, reason);
137137

138138
if let Some(prev_attr_sp) = prev_attr_sp {
139139
diagnostic
@@ -231,8 +231,7 @@ impl<'a> Parser<'a> {
231231

232232
if !lit.kind.is_unsuffixed() {
233233
let msg = "suffixed literals are not allowed in attributes";
234-
self.diagnostic()
235-
.struct_span_err(lit.span, msg)
234+
self.struct_span_err(lit.span, msg)
236235
.help(
237236
"instead of using a suffixed literal \
238237
(1u8, 1.0f32, etc.), use an unsuffixed version \
@@ -332,6 +331,6 @@ impl<'a> Parser<'a> {
332331

333332
let found = pprust::token_to_string(&self.token);
334333
let msg = format!("expected unsuffixed literal or identifier, found `{}`", found);
335-
Err(self.diagnostic().struct_span_err(self.token.span, &msg))
334+
Err(self.struct_span_err(self.token.span, &msg))
336335
}
337336
}

src/librustc_parse/parser/diagnostics.rs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -502,18 +502,17 @@ impl<'a> Parser<'a> {
502502
let span = lo.until(self.token.span);
503503

504504
let total_num_of_gt = number_of_gt + number_of_shr * 2;
505-
self.diagnostic()
506-
.struct_span_err(
507-
span,
508-
&format!("unmatched angle bracket{}", pluralize!(total_num_of_gt)),
509-
)
510-
.span_suggestion(
511-
span,
512-
&format!("remove extra angle bracket{}", pluralize!(total_num_of_gt)),
513-
String::new(),
514-
Applicability::MachineApplicable,
515-
)
516-
.emit();
505+
self.struct_span_err(
506+
span,
507+
&format!("unmatched angle bracket{}", pluralize!(total_num_of_gt)),
508+
)
509+
.span_suggestion(
510+
span,
511+
&format!("remove extra angle bracket{}", pluralize!(total_num_of_gt)),
512+
String::new(),
513+
Applicability::MachineApplicable,
514+
)
515+
.emit();
517516
}
518517
}
519518

@@ -762,8 +761,7 @@ impl<'a> Parser<'a> {
762761
path.span = ty_span.to(self.prev_span);
763762

764763
let ty_str = self.span_to_snippet(ty_span).unwrap_or_else(|_| pprust::ty_to_string(&ty));
765-
self.diagnostic()
766-
.struct_span_err(path.span, "missing angle brackets in associated item path")
764+
self.struct_span_err(path.span, "missing angle brackets in associated item path")
767765
.span_suggestion(
768766
// This is a best-effort recovery.
769767
path.span,

src/librustc_parse/parser/expr.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1915,8 +1915,7 @@ impl<'a> Parser<'a> {
19151915
return;
19161916
}
19171917

1918-
self.diagnostic()
1919-
.struct_span_err(self.token.span, "expected `:`, found `=`")
1918+
self.struct_span_err(self.token.span, "expected `:`, found `=`")
19201919
.span_suggestion(
19211920
field_name.span.shrink_to_hi().to(self.token.span),
19221921
"replace equals symbol with a colon",

src/librustc_parse/parser/item.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,7 @@ impl<'a> Parser<'a> {
306306
// possible public struct definition where `struct` was forgotten
307307
let ident = self.parse_ident().unwrap();
308308
let msg = format!("add `struct` here to parse `{}` as a public struct", ident);
309-
let mut err =
310-
self.diagnostic().struct_span_err(sp, "missing `struct` for struct definition");
309+
let mut err = self.struct_span_err(sp, "missing `struct` for struct definition");
311310
err.span_suggestion_short(
312311
sp,
313312
&msg,
@@ -335,7 +334,7 @@ impl<'a> Parser<'a> {
335334
};
336335

337336
let msg = format!("missing `{}` for {} definition", kw, kw_name);
338-
let mut err = self.diagnostic().struct_span_err(sp, &msg);
337+
let mut err = self.struct_span_err(sp, &msg);
339338
if !ambiguous {
340339
self.consume_block(token::Brace, ConsumeClosingDelim::Yes);
341340
let suggestion =
@@ -375,7 +374,7 @@ impl<'a> Parser<'a> {
375374
("fn` or `struct", "function or struct", true)
376375
};
377376
let msg = format!("missing `{}` for {} definition", kw, kw_name);
378-
let mut err = self.diagnostic().struct_span_err(sp, &msg);
377+
let mut err = self.struct_span_err(sp, &msg);
379378
if !ambiguous {
380379
err.span_suggestion_short(
381380
sp,
@@ -466,7 +465,7 @@ impl<'a> Parser<'a> {
466465
_ => "expected item after attributes",
467466
};
468467

469-
let mut err = self.diagnostic().struct_span_err(self.prev_span, message);
468+
let mut err = self.struct_span_err(self.prev_span, message);
470469
if attrs.last().unwrap().is_doc_comment() {
471470
err.span_label(self.prev_span, "this doc comment doesn't document anything");
472471
}
@@ -536,7 +535,6 @@ impl<'a> Parser<'a> {
536535
// ^^ `sp` below will point to this
537536
let sp = prev_span.between(self.prev_span);
538537
let mut err = self
539-
.diagnostic()
540538
.struct_span_err(sp, &format!("{} for {}-item declaration", expected_kinds, item_type));
541539
err.span_label(sp, expected_kinds);
542540
err
@@ -1603,9 +1601,8 @@ impl<'a> Parser<'a> {
16031601
VisibilityKind::Inherited => {}
16041602
_ => {
16051603
let mut err = if self.token.is_keyword(sym::macro_rules) {
1606-
let mut err = self
1607-
.diagnostic()
1608-
.struct_span_err(sp, "can't qualify macro_rules invocation with `pub`");
1604+
let mut err =
1605+
self.struct_span_err(sp, "can't qualify macro_rules invocation with `pub`");
16091606
err.span_suggestion(
16101607
sp,
16111608
"try exporting the macro",
@@ -1614,9 +1611,8 @@ impl<'a> Parser<'a> {
16141611
);
16151612
err
16161613
} else {
1617-
let mut err = self
1618-
.diagnostic()
1619-
.struct_span_err(sp, "can't qualify macro invocation with `pub`");
1614+
let mut err =
1615+
self.struct_span_err(sp, "can't qualify macro invocation with `pub`");
16201616
err.help("try adjusting the macro to put `pub` inside the invocation");
16211617
err
16221618
};

src/librustc_parse/parser/module.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ impl<'a> Parser<'a> {
129129
DirectoryOwnership::UnownedViaBlock => {
130130
let msg = "Cannot declare a non-inline module inside a block \
131131
unless it has a path attribute";
132-
let mut err = self.diagnostic().struct_span_err(id_sp, msg);
132+
let mut err = self.struct_span_err(id_sp, msg);
133133
if paths.path_exists {
134134
let msg = format!(
135135
"Maybe `use` the module `{}` instead of redeclaring it",
@@ -140,9 +140,8 @@ impl<'a> Parser<'a> {
140140
Err(err)
141141
}
142142
DirectoryOwnership::UnownedViaMod => {
143-
let mut err = self
144-
.diagnostic()
145-
.struct_span_err(id_sp, "cannot declare a new module at this location");
143+
let mut err =
144+
self.struct_span_err(id_sp, "cannot declare a new module at this location");
146145
if !id_sp.is_dummy() {
147146
let src_path = self.sess.source_map().span_to_filename(id_sp);
148147
if let FileName::Real(src_path) = src_path {

src/librustc_parse/parser/pat.rs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -699,8 +699,7 @@ impl<'a> Parser<'a> {
699699
let range_span = lo.to(end.span);
700700
let begin = self.mk_expr(range_span, ExprKind::Err, AttrVec::new());
701701

702-
self.diagnostic()
703-
.struct_span_err(range_span, &format!("`{}X` range patterns are not supported", form))
702+
self.struct_span_err(range_span, &format!("`{}X` range patterns are not supported", form))
704703
.span_suggestion(
705704
range_span,
706705
"try using the minimum value for the type",
@@ -722,18 +721,17 @@ impl<'a> Parser<'a> {
722721
// Parsing e.g. `X..`.
723722
let range_span = begin.span.to(self.prev_span);
724723

725-
self.diagnostic()
726-
.struct_span_err(
727-
range_span,
728-
&format!("`X{}` range patterns are not supported", form),
729-
)
730-
.span_suggestion(
731-
range_span,
732-
"try using the maximum value for the type",
733-
format!("{}{}MAX", pprust::expr_to_string(&begin), form),
734-
Applicability::HasPlaceholders,
735-
)
736-
.emit();
724+
self.struct_span_err(
725+
range_span,
726+
&format!("`X{}` range patterns are not supported", form),
727+
)
728+
.span_suggestion(
729+
range_span,
730+
"try using the maximum value for the type",
731+
format!("{}{}MAX", pprust::expr_to_string(&begin), form),
732+
Applicability::HasPlaceholders,
733+
)
734+
.emit();
737735

738736
Ok(self.mk_expr(range_span, ExprKind::Err, AttrVec::new()))
739737
}

src/librustc_parse/parser/path.rs

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -325,24 +325,23 @@ impl<'a> Parser<'a> {
325325

326326
// Make a span over ${unmatched angle bracket count} characters.
327327
let span = lo.with_hi(lo.lo() + BytePos(snapshot.unmatched_angle_bracket_count));
328-
self.diagnostic()
329-
.struct_span_err(
330-
span,
331-
&format!(
332-
"unmatched angle bracket{}",
333-
pluralize!(snapshot.unmatched_angle_bracket_count)
334-
),
335-
)
336-
.span_suggestion(
337-
span,
338-
&format!(
339-
"remove extra angle bracket{}",
340-
pluralize!(snapshot.unmatched_angle_bracket_count)
341-
),
342-
String::new(),
343-
Applicability::MachineApplicable,
344-
)
345-
.emit();
328+
self.struct_span_err(
329+
span,
330+
&format!(
331+
"unmatched angle bracket{}",
332+
pluralize!(snapshot.unmatched_angle_bracket_count)
333+
),
334+
)
335+
.span_suggestion(
336+
span,
337+
&format!(
338+
"remove extra angle bracket{}",
339+
pluralize!(snapshot.unmatched_angle_bracket_count)
340+
),
341+
String::new(),
342+
Applicability::MachineApplicable,
343+
)
344+
.emit();
346345

347346
// Try again without unmatched angle bracket characters.
348347
self.parse_generic_args()

0 commit comments

Comments
 (0)