Skip to content

Commit 698e4a0

Browse files
committed
Use Session::diagnostic in more places.
1 parent a9baa4a commit 698e4a0

File tree

7 files changed

+33
-40
lines changed

7 files changed

+33
-40
lines changed

compiler/rustc_parse/src/parser/attr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ impl<'a> Parser<'a> {
5656
} else if let token::DocComment(comment_kind, attr_style, data) = self.token.kind {
5757
if attr_style != ast::AttrStyle::Outer {
5858
let span = self.token.span;
59-
let mut err = self.sess.span_diagnostic.struct_span_err_with_code(
59+
let mut err = self.diagnostic().struct_span_err_with_code(
6060
span,
6161
fluent::parse_inner_doc_comment_not_permitted,
6262
error_code!(E0753),
@@ -418,7 +418,7 @@ impl<'a> Parser<'a> {
418418
}
419419

420420
Err(InvalidMetaItem { span: self.token.span, token: self.token.clone() }
421-
.into_diagnostic(&self.sess.span_diagnostic))
421+
.into_diagnostic(self.diagnostic()))
422422
}
423423
}
424424

compiler/rustc_parse/src/parser/attr_wrapper.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,7 @@ impl<'a> Parser<'a> {
266266
if let Some(attr_range) = self.capture_state.inner_attr_ranges.remove(&inner_attr.id) {
267267
inner_attr_replace_ranges.push(attr_range);
268268
} else {
269-
self.sess
270-
.span_diagnostic
269+
self.diagnostic()
271270
.span_delayed_bug(inner_attr.span, "Missing token range for attribute");
272271
}
273272
}

compiler/rustc_parse/src/parser/diagnostics.rs

+9-10
Original file line numberDiff line numberDiff line change
@@ -247,11 +247,11 @@ impl<'a> Parser<'a> {
247247
sp: S,
248248
m: impl Into<DiagnosticMessage>,
249249
) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
250-
self.sess.span_diagnostic.struct_span_err(sp, m)
250+
self.diagnostic().struct_span_err(sp, m)
251251
}
252252

253253
pub fn span_bug<S: Into<MultiSpan>>(&self, sp: S, m: impl Into<String>) -> ! {
254-
self.sess.span_diagnostic.span_bug(sp, m)
254+
self.diagnostic().span_bug(sp, m)
255255
}
256256

257257
pub(super) fn diagnostic(&self) -> &'a Handler {
@@ -285,7 +285,7 @@ impl<'a> Parser<'a> {
285285
span: self.prev_token.span,
286286
missing_comma: None,
287287
}
288-
.into_diagnostic(&self.sess.span_diagnostic));
288+
.into_diagnostic(self.diagnostic()));
289289
}
290290

291291
let valid_follow = &[
@@ -348,7 +348,7 @@ impl<'a> Parser<'a> {
348348
suggest_remove_comma,
349349
help_cannot_start_number,
350350
};
351-
let mut err = err.into_diagnostic(&self.sess.span_diagnostic);
351+
let mut err = err.into_diagnostic(self.diagnostic());
352352

353353
// if the token we have is a `<`
354354
// it *might* be a misplaced generic
@@ -1426,7 +1426,7 @@ impl<'a> Parser<'a> {
14261426
// Not entirely sure now, but we bubble the error up with the
14271427
// suggestion.
14281428
self.restore_snapshot(snapshot);
1429-
Err(err.into_diagnostic(&self.sess.span_diagnostic))
1429+
Err(err.into_diagnostic(self.diagnostic()))
14301430
}
14311431
}
14321432
} else if token::OpenDelim(Delimiter::Parenthesis) == self.token.kind {
@@ -1441,7 +1441,7 @@ impl<'a> Parser<'a> {
14411441
}
14421442
// Consume the fn call arguments.
14431443
match self.consume_fn_args() {
1444-
Err(()) => Err(err.into_diagnostic(&self.sess.span_diagnostic)),
1444+
Err(()) => Err(err.into_diagnostic(self.diagnostic())),
14451445
Ok(()) => {
14461446
self.sess.emit_err(err);
14471447
// FIXME: actually check that the two expressions in the binop are
@@ -1467,7 +1467,7 @@ impl<'a> Parser<'a> {
14671467
mk_err_expr(self, inner_op.span.to(self.prev_token.span))
14681468
} else {
14691469
// These cases cause too many knock-down errors, bail out (#61329).
1470-
Err(err.into_diagnostic(&self.sess.span_diagnostic))
1470+
Err(err.into_diagnostic(self.diagnostic()))
14711471
}
14721472
};
14731473
}
@@ -2572,8 +2572,7 @@ impl<'a> Parser<'a> {
25722572
Ok(Some(GenericArg::Const(self.parse_const_arg()?)))
25732573
} else {
25742574
let after_kw_const = self.token.span;
2575-
self.recover_const_arg(after_kw_const, err.into_diagnostic(&self.sess.span_diagnostic))
2576-
.map(Some)
2575+
self.recover_const_arg(after_kw_const, err.into_diagnostic(self.diagnostic())).map(Some)
25772576
}
25782577
}
25792578

@@ -2936,7 +2935,7 @@ impl<'a> Parser<'a> {
29362935
span: path.span.shrink_to_hi(),
29372936
between: between_span,
29382937
}
2939-
.into_diagnostic(&self.sess.span_diagnostic));
2938+
.into_diagnostic(self.diagnostic()));
29402939
}
29412940
}
29422941
}

compiler/rustc_parse/src/parser/expr.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -1268,7 +1268,7 @@ impl<'a> Parser<'a> {
12681268
.collect(),
12691269
},
12701270
}
1271-
.into_diagnostic(&self.sess.span_diagnostic);
1271+
.into_diagnostic(self.diagnostic());
12721272
replacement_err.emit();
12731273

12741274
let old_err = mem::replace(err, replacement_err);
@@ -1690,7 +1690,7 @@ impl<'a> Parser<'a> {
16901690
err: impl FnOnce(&Self) -> DiagnosticBuilder<'a, ErrorGuaranteed>,
16911691
) -> L {
16921692
if let Some(mut diag) =
1693-
self.sess.span_diagnostic.steal_diagnostic(lifetime.span, StashKey::LifetimeIsChar)
1693+
self.diagnostic().steal_diagnostic(lifetime.span, StashKey::LifetimeIsChar)
16941694
{
16951695
diag.span_suggestion_verbose(
16961696
lifetime.span.shrink_to_hi(),
@@ -1881,7 +1881,7 @@ impl<'a> Parser<'a> {
18811881

18821882
let Some((ident, false)) = self.token.ident() else {
18831883
let err = errors::ExpectedBuiltinIdent { span: self.token.span }
1884-
.into_diagnostic(&self.sess.span_diagnostic);
1884+
.into_diagnostic(self.diagnostic());
18851885
return Err(err);
18861886
};
18871887
self.sess.gated_spans.gate(sym::builtin_syntax, ident.span);
@@ -1892,7 +1892,7 @@ impl<'a> Parser<'a> {
18921892
Ok(res)
18931893
} else {
18941894
let err = errors::UnknownBuiltinConstruct { span: lo.to(ident.span), name: ident.name }
1895-
.into_diagnostic(&self.sess.span_diagnostic);
1895+
.into_diagnostic(self.diagnostic());
18961896
return Err(err);
18971897
};
18981898
self.expect(&TokenKind::CloseDelim(Delimiter::Parenthesis))?;
@@ -1956,7 +1956,7 @@ impl<'a> Parser<'a> {
19561956
&& matches!(e.kind, ExprKind::Err)
19571957
{
19581958
let mut err = errors::InvalidInterpolatedExpression { span: self.token.span }
1959-
.into_diagnostic(&self.sess.span_diagnostic);
1959+
.into_diagnostic(self.diagnostic());
19601960
err.downgrade_to_delayed_bug();
19611961
return Err(err);
19621962
}
@@ -2168,7 +2168,7 @@ impl<'a> Parser<'a> {
21682168
return Err(errors::MissingSemicolonBeforeArray {
21692169
open_delim: open_delim_span,
21702170
semicolon: prev_span.shrink_to_hi(),
2171-
}.into_diagnostic(&self.sess.span_diagnostic));
2171+
}.into_diagnostic(self.diagnostic()));
21722172
}
21732173
Ok(_) => (),
21742174
Err(err) => err.cancel(),
@@ -2308,7 +2308,7 @@ impl<'a> Parser<'a> {
23082308
if self.check_keyword(kw::Async) {
23092309
let move_async_span = self.token.span.with_lo(self.prev_token.span.data().lo);
23102310
Err(errors::AsyncMoveOrderIncorrect { span: move_async_span }
2311-
.into_diagnostic(&self.sess.span_diagnostic))
2311+
.into_diagnostic(self.diagnostic()))
23122312
} else {
23132313
Ok(CaptureBy::Value { move_kw: move_kw_span })
23142314
}
@@ -2496,7 +2496,7 @@ impl<'a> Parser<'a> {
24962496
};
24972497
if self.prev_token.kind == token::BinOp(token::Or) {
24982498
// This was part of a closure, the that part of the parser recover.
2499-
return Err(err.into_diagnostic(&self.sess.span_diagnostic));
2499+
return Err(err.into_diagnostic(self.diagnostic()));
25002500
} else {
25012501
Some(self.sess.emit_err(err))
25022502
}
@@ -3056,7 +3056,7 @@ impl<'a> Parser<'a> {
30563056
let (attrs, body) = self.parse_inner_attrs_and_block()?;
30573057
if self.eat_keyword(kw::Catch) {
30583058
Err(errors::CatchAfterTry { span: self.prev_token.span }
3059-
.into_diagnostic(&self.sess.span_diagnostic))
3059+
.into_diagnostic(self.diagnostic()))
30603060
} else {
30613061
let span = span_lo.to(body.span);
30623062
self.sess.gated_spans.gate(sym::try_blocks, span);

compiler/rustc_parse/src/parser/item.rs

+6-11
Original file line numberDiff line numberDiff line change
@@ -444,11 +444,7 @@ impl<'a> Parser<'a> {
444444
None
445445
};
446446

447-
if let Some(err) = err {
448-
Err(err.into_diagnostic(&self.sess.span_diagnostic))
449-
} else {
450-
Ok(())
451-
}
447+
if let Some(err) = err { Err(err.into_diagnostic(self.diagnostic())) } else { Ok(()) }
452448
}
453449

454450
fn parse_item_builtin(&mut self) -> PResult<'a, Option<ItemInfo>> {
@@ -1382,8 +1378,7 @@ impl<'a> Parser<'a> {
13821378

13831379
let span = self.prev_token.span.shrink_to_hi();
13841380
let err: DiagnosticBuilder<'_, ErrorGuaranteed> =
1385-
errors::MissingConstType { span, colon, kind }
1386-
.into_diagnostic(&self.sess.span_diagnostic);
1381+
errors::MissingConstType { span, colon, kind }.into_diagnostic(self.diagnostic());
13871382
err.stash(span, StashKey::ItemNoType);
13881383

13891384
// The user intended that the type be inferred,
@@ -1400,7 +1395,7 @@ impl<'a> Parser<'a> {
14001395
self.bump();
14011396
self.sess.emit_err(err);
14021397
} else {
1403-
return Err(err.into_diagnostic(&self.sess.span_diagnostic));
1398+
return Err(err.into_diagnostic(self.diagnostic()));
14041399
}
14051400
}
14061401

@@ -1568,7 +1563,7 @@ impl<'a> Parser<'a> {
15681563
} else {
15691564
let err =
15701565
errors::UnexpectedTokenAfterStructName::new(self.token.span, self.token.clone());
1571-
return Err(err.into_diagnostic(&self.sess.span_diagnostic));
1566+
return Err(err.into_diagnostic(self.diagnostic()));
15721567
};
15731568

15741569
Ok((class_name, ItemKind::Struct(vdata, generics)))
@@ -1764,7 +1759,7 @@ impl<'a> Parser<'a> {
17641759
let sp = previous_span.shrink_to_hi();
17651760
err.missing_comma = Some(sp);
17661761
}
1767-
return Err(err.into_diagnostic(&self.sess.span_diagnostic));
1762+
return Err(err.into_diagnostic(self.diagnostic()));
17681763
}
17691764
}
17701765
_ => {
@@ -1814,7 +1809,7 @@ impl<'a> Parser<'a> {
18141809
// Make sure an error was emitted (either by recovering an angle bracket,
18151810
// or by finding an identifier as the next token), since we're
18161811
// going to continue parsing
1817-
assert!(self.sess.span_diagnostic.has_errors().is_some());
1812+
assert!(self.diagnostic().has_errors().is_some());
18181813
} else {
18191814
return Err(err);
18201815
}

compiler/rustc_parse/src/parser/nonterminal.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ impl<'a> Parser<'a> {
115115
Some(item) => NtItem(item),
116116
None => {
117117
return Err(UnexpectedNonterminal::Item(self.token.span)
118-
.into_diagnostic(&self.sess.span_diagnostic));
118+
.into_diagnostic(self.diagnostic()));
119119
}
120120
},
121121
NonterminalKind::Block => {
@@ -127,7 +127,7 @@ impl<'a> Parser<'a> {
127127
Some(s) => NtStmt(P(s)),
128128
None => {
129129
return Err(UnexpectedNonterminal::Statement(self.token.span)
130-
.into_diagnostic(&self.sess.span_diagnostic));
130+
.into_diagnostic(self.diagnostic()));
131131
}
132132
},
133133
NonterminalKind::PatParam { .. } | NonterminalKind::PatWithOr => {
@@ -163,7 +163,7 @@ impl<'a> Parser<'a> {
163163
span: self.token.span,
164164
token: self.token.clone(),
165165
}
166-
.into_diagnostic(&self.sess.span_diagnostic));
166+
.into_diagnostic(self.diagnostic()));
167167
}
168168
NonterminalKind::Path => {
169169
NtPath(P(self.collect_tokens_no_attrs(|this| this.parse_path(PathStyle::Type))?))
@@ -181,7 +181,7 @@ impl<'a> Parser<'a> {
181181
span: self.token.span,
182182
token: self.token.clone(),
183183
}
184-
.into_diagnostic(&self.sess.span_diagnostic));
184+
.into_diagnostic(self.diagnostic()));
185185
}
186186
}
187187
};

compiler/rustc_parse/src/parser/pat.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -855,7 +855,7 @@ impl<'a> Parser<'a> {
855855
// will direct us over to `parse_enum_variant()`.
856856
if self.token == token::OpenDelim(Delimiter::Parenthesis) {
857857
return Err(EnumPatternInsteadOfIdentifier { span: self.prev_token.span }
858-
.into_diagnostic(&self.sess.span_diagnostic));
858+
.into_diagnostic(self.diagnostic()));
859859
}
860860

861861
Ok(PatKind::Ident(binding_annotation, ident, sub))
@@ -969,7 +969,7 @@ impl<'a> Parser<'a> {
969969
// check that a comma comes after every field
970970
if !ate_comma {
971971
let mut err = ExpectedCommaAfterPatternField { span: self.token.span }
972-
.into_diagnostic(&self.sess.span_diagnostic);
972+
.into_diagnostic(self.diagnostic());
973973
if let Some(mut delayed) = delayed_err {
974974
delayed.emit();
975975
}

0 commit comments

Comments
 (0)