Skip to content

Commit 31ac4ef

Browse files
committed
Use Session::diagnostic in more places.
1 parent a179a53 commit 31ac4ef

File tree

7 files changed

+33
-40
lines changed

7 files changed

+33
-40
lines changed

compiler/rustc_parse/src/parser/attr.rs

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 2 deletions
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

Lines changed: 9 additions & 10 deletions
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
}
@@ -2522,8 +2522,7 @@ impl<'a> Parser<'a> {
25222522
Ok(Some(GenericArg::Const(self.parse_const_arg()?)))
25232523
} else {
25242524
let after_kw_const = self.token.span;
2525-
self.recover_const_arg(after_kw_const, err.into_diagnostic(&self.sess.span_diagnostic))
2526-
.map(Some)
2525+
self.recover_const_arg(after_kw_const, err.into_diagnostic(self.diagnostic())).map(Some)
25272526
}
25282527
}
25292528

@@ -2886,7 +2885,7 @@ impl<'a> Parser<'a> {
28862885
span: path.span.shrink_to_hi(),
28872886
between: between_span,
28882887
}
2889-
.into_diagnostic(&self.sess.span_diagnostic));
2888+
.into_diagnostic(self.diagnostic()));
28902889
}
28912890
}
28922891
}

compiler/rustc_parse/src/parser/expr.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1269,7 +1269,7 @@ impl<'a> Parser<'a> {
12691269
.collect(),
12701270
},
12711271
}
1272-
.into_diagnostic(&self.sess.span_diagnostic);
1272+
.into_diagnostic(self.diagnostic());
12731273
replacement_err.emit();
12741274

12751275
let old_err = mem::replace(err, replacement_err);
@@ -1691,7 +1691,7 @@ impl<'a> Parser<'a> {
16911691
err: impl FnOnce(&Self) -> DiagnosticBuilder<'a, ErrorGuaranteed>,
16921692
) -> L {
16931693
if let Some(mut diag) =
1694-
self.sess.span_diagnostic.steal_diagnostic(lifetime.span, StashKey::LifetimeIsChar)
1694+
self.diagnostic().steal_diagnostic(lifetime.span, StashKey::LifetimeIsChar)
16951695
{
16961696
diag.span_suggestion_verbose(
16971697
lifetime.span.shrink_to_hi(),
@@ -1882,7 +1882,7 @@ impl<'a> Parser<'a> {
18821882

18831883
let Some((ident, false)) = self.token.ident() else {
18841884
let err = errors::ExpectedBuiltinIdent { span: self.token.span }
1885-
.into_diagnostic(&self.sess.span_diagnostic);
1885+
.into_diagnostic(self.diagnostic());
18861886
return Err(err);
18871887
};
18881888
self.sess.gated_spans.gate(sym::builtin_syntax, ident.span);
@@ -1893,7 +1893,7 @@ impl<'a> Parser<'a> {
18931893
Ok(res)
18941894
} else {
18951895
let err = errors::UnknownBuiltinConstruct { span: lo.to(ident.span), name: ident.name }
1896-
.into_diagnostic(&self.sess.span_diagnostic);
1896+
.into_diagnostic(self.diagnostic());
18971897
return Err(err);
18981898
};
18991899
self.expect(&TokenKind::CloseDelim(Delimiter::Parenthesis))?;
@@ -1957,7 +1957,7 @@ impl<'a> Parser<'a> {
19571957
&& matches!(e.kind, ExprKind::Err)
19581958
{
19591959
let mut err = errors::InvalidInterpolatedExpression { span: self.token.span }
1960-
.into_diagnostic(&self.sess.span_diagnostic);
1960+
.into_diagnostic(self.diagnostic());
19611961
err.downgrade_to_delayed_bug();
19621962
return Err(err);
19631963
}
@@ -2169,7 +2169,7 @@ impl<'a> Parser<'a> {
21692169
return Err(errors::MissingSemicolonBeforeArray {
21702170
open_delim: open_delim_span,
21712171
semicolon: prev_span.shrink_to_hi(),
2172-
}.into_diagnostic(&self.sess.span_diagnostic));
2172+
}.into_diagnostic(self.diagnostic()));
21732173
}
21742174
Ok(_) => (),
21752175
Err(err) => err.cancel(),
@@ -2309,7 +2309,7 @@ impl<'a> Parser<'a> {
23092309
if self.check_keyword(kw::Async) {
23102310
let move_async_span = self.token.span.with_lo(self.prev_token.span.data().lo);
23112311
Err(errors::AsyncMoveOrderIncorrect { span: move_async_span }
2312-
.into_diagnostic(&self.sess.span_diagnostic))
2312+
.into_diagnostic(self.diagnostic()))
23132313
} else {
23142314
Ok(CaptureBy::Value { move_kw: move_kw_span })
23152315
}
@@ -2499,7 +2499,7 @@ impl<'a> Parser<'a> {
24992499
};
25002500
if self.prev_token.kind == token::BinOp(token::Or) {
25012501
// This was part of a closure, the that part of the parser recover.
2502-
return Err(err.into_diagnostic(&self.sess.span_diagnostic));
2502+
return Err(err.into_diagnostic(self.diagnostic()));
25032503
} else {
25042504
Some(self.sess.emit_err(err))
25052505
}
@@ -3148,7 +3148,7 @@ impl<'a> Parser<'a> {
31483148
let (attrs, body) = self.parse_inner_attrs_and_block()?;
31493149
if self.eat_keyword(kw::Catch) {
31503150
Err(errors::CatchAfterTry { span: self.prev_token.span }
3151-
.into_diagnostic(&self.sess.span_diagnostic))
3151+
.into_diagnostic(self.diagnostic()))
31523152
} else {
31533153
let span = span_lo.to(body.span);
31543154
self.sess.gated_spans.gate(sym::try_blocks, span);

compiler/rustc_parse/src/parser/item.rs

Lines changed: 6 additions & 11 deletions
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

@@ -1600,7 +1595,7 @@ impl<'a> Parser<'a> {
16001595
} else {
16011596
let err =
16021597
errors::UnexpectedTokenAfterStructName::new(self.token.span, self.token.clone());
1603-
return Err(err.into_diagnostic(&self.sess.span_diagnostic));
1598+
return Err(err.into_diagnostic(self.diagnostic()));
16041599
};
16051600

16061601
Ok((class_name, ItemKind::Struct(vdata, generics)))
@@ -1796,7 +1791,7 @@ impl<'a> Parser<'a> {
17961791
let sp = previous_span.shrink_to_hi();
17971792
err.missing_comma = Some(sp);
17981793
}
1799-
return Err(err.into_diagnostic(&self.sess.span_diagnostic));
1794+
return Err(err.into_diagnostic(self.diagnostic()));
18001795
}
18011796
}
18021797
_ => {
@@ -1846,7 +1841,7 @@ impl<'a> Parser<'a> {
18461841
// Make sure an error was emitted (either by recovering an angle bracket,
18471842
// or by finding an identifier as the next token), since we're
18481843
// going to continue parsing
1849-
assert!(self.sess.span_diagnostic.has_errors().is_some());
1844+
assert!(self.diagnostic().has_errors().is_some());
18501845
} else {
18511846
return Err(err);
18521847
}

compiler/rustc_parse/src/parser/nonterminal.rs

Lines changed: 4 additions & 4 deletions
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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -877,7 +877,7 @@ impl<'a> Parser<'a> {
877877
// will direct us over to `parse_enum_variant()`.
878878
if self.token == token::OpenDelim(Delimiter::Parenthesis) {
879879
return Err(EnumPatternInsteadOfIdentifier { span: self.prev_token.span }
880-
.into_diagnostic(&self.sess.span_diagnostic));
880+
.into_diagnostic(self.diagnostic()));
881881
}
882882

883883
Ok(PatKind::Ident(binding_annotation, ident, sub))
@@ -991,7 +991,7 @@ impl<'a> Parser<'a> {
991991
// check that a comma comes after every field
992992
if !ate_comma {
993993
let mut err = ExpectedCommaAfterPatternField { span: self.token.span }
994-
.into_diagnostic(&self.sess.span_diagnostic);
994+
.into_diagnostic(self.diagnostic());
995995
if let Some(mut delayed) = delayed_err {
996996
delayed.emit();
997997
}

0 commit comments

Comments
 (0)