Skip to content

Commit 9df1576

Browse files
committed
Rename ParseSess::span_diagnostic as ParseSess::dcx.
1 parent 9b1f87c commit 9df1576

File tree

26 files changed

+89
-98
lines changed

26 files changed

+89
-98
lines changed

compiler/rustc_builtin_macros/src/asm.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ pub fn parse_asm_args<'a>(
4747
sp: Span,
4848
is_global_asm: bool,
4949
) -> PResult<'a, AsmArgs> {
50-
let diag = &sess.span_diagnostic;
50+
let diag = &sess.dcx;
5151

5252
if p.token == token::Eof {
5353
return Err(diag.create_err(errors::AsmRequiresTemplate { span: sp }));
@@ -298,7 +298,7 @@ pub fn parse_asm_args<'a>(
298298
fn err_duplicate_option(p: &mut Parser<'_>, symbol: Symbol, span: Span) {
299299
// Tool-only output
300300
let full_span = if p.token.kind == token::Comma { span.to(p.token.span) } else { span };
301-
p.sess.span_diagnostic.emit_err(errors::AsmOptAlreadyprovided { span, symbol, full_span });
301+
p.sess.dcx.emit_err(errors::AsmOptAlreadyprovided { span, symbol, full_span });
302302
}
303303

304304
/// Try to set the provided option in the provided `AsmArgs`.
@@ -370,7 +370,7 @@ fn parse_clobber_abi<'a>(p: &mut Parser<'a>, args: &mut AsmArgs) -> PResult<'a,
370370
p.expect(&token::OpenDelim(Delimiter::Parenthesis))?;
371371

372372
if p.eat(&token::CloseDelim(Delimiter::Parenthesis)) {
373-
return Err(p.sess.span_diagnostic.create_err(errors::NonABI { span: p.token.span }));
373+
return Err(p.sess.dcx.create_err(errors::NonABI { span: p.token.span }));
374374
}
375375

376376
let mut new_abis = Vec::new();
@@ -381,8 +381,7 @@ fn parse_clobber_abi<'a>(p: &mut Parser<'a>, args: &mut AsmArgs) -> PResult<'a,
381381
}
382382
Err(opt_lit) => {
383383
let span = opt_lit.map_or(p.token.span, |lit| lit.span);
384-
let mut err =
385-
p.sess.span_diagnostic.struct_span_err(span, "expected string literal");
384+
let mut err = p.sess.dcx.struct_span_err(span, "expected string literal");
386385
err.span_label(span, "not a string literal");
387386
return Err(err);
388387
}

compiler/rustc_builtin_macros/src/cmdline_attrs.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ pub fn inject(krate: &mut ast::Crate, parse_sess: &ParseSess, attrs: &[String])
2525
};
2626
let end_span = parser.token.span;
2727
if parser.token != token::Eof {
28-
parse_sess
29-
.span_diagnostic
30-
.emit_err(errors::InvalidCrateAttr { span: start_span.to(end_span) });
28+
parse_sess.dcx.emit_err(errors::InvalidCrateAttr { span: start_span.to(end_span) });
3129
continue;
3230
}
3331

compiler/rustc_expand/src/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1208,7 +1208,7 @@ pub fn resolve_path(
12081208
span,
12091209
path: parse_sess.source_map().filename_for_diagnostics(&other).to_string(),
12101210
}
1211-
.into_diagnostic(&parse_sess.span_diagnostic));
1211+
.into_diagnostic(&parse_sess.dcx));
12121212
}
12131213
};
12141214
result.pop();

compiler/rustc_expand/src/mbe/macro_check.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ pub(super) fn check_meta_variables(
205205
rhses: &[TokenTree],
206206
) -> bool {
207207
if lhses.len() != rhses.len() {
208-
sess.span_diagnostic.span_bug(span, "length mismatch between LHSes and RHSes")
208+
sess.dcx.span_bug(span, "length mismatch between LHSes and RHSes")
209209
}
210210
let mut valid = true;
211211
for (lhs, rhs) in iter::zip(lhses, rhses) {
@@ -244,7 +244,7 @@ fn check_binders(
244244
// MetaVar(fragment) and not as MetaVarDecl(y, fragment).
245245
TokenTree::MetaVar(span, name) => {
246246
if macros.is_empty() {
247-
sess.span_diagnostic.span_bug(span, "unexpected MetaVar in lhs");
247+
sess.dcx.span_bug(span, "unexpected MetaVar in lhs");
248248
}
249249
let name = MacroRulesNormalizedIdent::new(name);
250250
// There are 3 possibilities:
@@ -275,14 +275,13 @@ fn check_binders(
275275
);
276276
}
277277
if !macros.is_empty() {
278-
sess.span_diagnostic.span_bug(span, "unexpected MetaVarDecl in nested lhs");
278+
sess.dcx.span_bug(span, "unexpected MetaVarDecl in nested lhs");
279279
}
280280
let name = MacroRulesNormalizedIdent::new(name);
281281
if let Some(prev_info) = get_binder_info(macros, binders, name) {
282282
// Duplicate binders at the top-level macro definition are errors. The lint is only
283283
// for nested macro definitions.
284-
sess.span_diagnostic
285-
.emit_err(errors::DuplicateMatcherBinding { span, prev: prev_info.span });
284+
sess.dcx.emit_err(errors::DuplicateMatcherBinding { span, prev: prev_info.span });
286285
*valid = false;
287286
} else {
288287
binders.insert(name, BinderInfo { span, ops: ops.into() });
@@ -341,7 +340,7 @@ fn check_occurrences(
341340
match *rhs {
342341
TokenTree::Token(..) => {}
343342
TokenTree::MetaVarDecl(span, _name, _kind) => {
344-
sess.span_diagnostic.span_bug(span, "unexpected MetaVarDecl in rhs")
343+
sess.dcx.span_bug(span, "unexpected MetaVarDecl in rhs")
345344
}
346345
TokenTree::MetaVar(span, name) => {
347346
let name = MacroRulesNormalizedIdent::new(name);

compiler/rustc_expand/src/mbe/macro_rules.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ pub fn compile_declarative_macro(
402402
};
403403
let dummy_syn_ext = || (mk_syn_ext(Box::new(macro_rules_dummy_expander)), Vec::new());
404404

405-
let diag = &sess.parse_sess.span_diagnostic;
405+
let diag = &sess.parse_sess.dcx;
406406
let lhs_nm = Ident::new(sym::lhs, def.span);
407407
let rhs_nm = Ident::new(sym::rhs, def.span);
408408
let tt_spec = Some(NonterminalKind::TT);
@@ -626,7 +626,7 @@ fn check_lhs_nt_follows(sess: &ParseSess, def: &ast::Item, lhs: &mbe::TokenTree)
626626
check_matcher(sess, def, &delimited.tts)
627627
} else {
628628
let msg = "invalid macro matcher; matchers must be contained in balanced delimiters";
629-
sess.span_diagnostic.span_err(lhs.span(), msg);
629+
sess.dcx.span_err(lhs.span(), msg);
630630
false
631631
}
632632
// we don't abort on errors on rejection, the driver will do that for us
@@ -652,8 +652,7 @@ fn is_empty_token_tree(sess: &ParseSess, seq: &mbe::SequenceRepetition) -> bool
652652
iter.next();
653653
}
654654
let span = t.span.to(now.span);
655-
sess.span_diagnostic
656-
.span_note(span, "doc comments are ignored in matcher position");
655+
sess.dcx.span_note(span, "doc comments are ignored in matcher position");
657656
}
658657
mbe::TokenTree::Sequence(_, sub_seq)
659658
if (sub_seq.kleene.op == mbe::KleeneOp::ZeroOrMore
@@ -683,7 +682,7 @@ fn check_lhs_no_empty_seq(sess: &ParseSess, tts: &[mbe::TokenTree]) -> bool {
683682
TokenTree::Sequence(span, seq) => {
684683
if is_empty_token_tree(sess, seq) {
685684
let sp = span.entire();
686-
sess.span_diagnostic.span_err(sp, "repetition matches empty token tree");
685+
sess.dcx.span_err(sp, "repetition matches empty token tree");
687686
return false;
688687
}
689688
if !check_lhs_no_empty_seq(sess, &seq.tts) {
@@ -700,7 +699,7 @@ fn check_rhs(sess: &ParseSess, rhs: &mbe::TokenTree) -> bool {
700699
match *rhs {
701700
mbe::TokenTree::Delimited(..) => return true,
702701
_ => {
703-
sess.span_diagnostic.span_err(rhs.span(), "macro rhs must be delimited");
702+
sess.dcx.span_err(rhs.span(), "macro rhs must be delimited");
704703
}
705704
}
706705
false
@@ -709,9 +708,9 @@ fn check_rhs(sess: &ParseSess, rhs: &mbe::TokenTree) -> bool {
709708
fn check_matcher(sess: &ParseSess, def: &ast::Item, matcher: &[mbe::TokenTree]) -> bool {
710709
let first_sets = FirstSets::new(matcher);
711710
let empty_suffix = TokenSet::empty();
712-
let err = sess.span_diagnostic.err_count();
711+
let err = sess.dcx.err_count();
713712
check_matcher_core(sess, def, &first_sets, matcher, &empty_suffix);
714-
err == sess.span_diagnostic.err_count()
713+
err == sess.dcx.err_count()
715714
}
716715

717716
fn has_compile_error_macro(rhs: &mbe::TokenTree) -> bool {
@@ -1190,7 +1189,7 @@ fn check_matcher_core<'tt>(
11901189
};
11911190

11921191
let sp = next_token.span();
1193-
let mut err = sess.span_diagnostic.struct_span_err(
1192+
let mut err = sess.dcx.struct_span_err(
11941193
sp,
11951194
format!(
11961195
"`${name}:{frag}` {may_be} followed by `{next}`, which \

compiler/rustc_expand/src/mbe/metavar_expr.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ impl MetaVarExpr {
3636
let ident = parse_ident(&mut tts, sess, outer_span)?;
3737
let Some(TokenTree::Delimited(.., Delimiter::Parenthesis, args)) = tts.next() else {
3838
let msg = "meta-variable expression parameter must be wrapped in parentheses";
39-
return Err(sess.span_diagnostic.struct_span_err(ident.span, msg));
39+
return Err(sess.dcx.struct_span_err(ident.span, msg));
4040
};
4141
check_trailing_token(&mut tts, sess)?;
4242
let mut iter = args.trees();
@@ -50,7 +50,7 @@ impl MetaVarExpr {
5050
"length" => MetaVarExpr::Length(parse_depth(&mut iter, sess, ident.span)?),
5151
_ => {
5252
let err_msg = "unrecognized meta-variable expression";
53-
let mut err = sess.span_diagnostic.struct_span_err(ident.span, err_msg);
53+
let mut err = sess.dcx.struct_span_err(ident.span, err_msg);
5454
err.span_suggestion(
5555
ident.span,
5656
"supported expressions are count, ignore, index and length",
@@ -79,7 +79,7 @@ fn check_trailing_token<'sess>(
7979
) -> PResult<'sess, ()> {
8080
if let Some(tt) = iter.next() {
8181
let mut diag = sess
82-
.span_diagnostic
82+
.dcx
8383
.struct_span_err(tt.span(), format!("unexpected token: {}", pprust::tt_to_string(tt)));
8484
diag.span_note(tt.span(), "meta-variable expression must not have trailing tokens");
8585
Err(diag)
@@ -98,7 +98,7 @@ fn parse_count<'sess>(
9898
let ident = parse_ident(iter, sess, span)?;
9999
let depth = if try_eat_comma(iter) {
100100
if iter.look_ahead(0).is_none() {
101-
return Err(sess.span_diagnostic.struct_span_err(
101+
return Err(sess.dcx.struct_span_err(
102102
span,
103103
"`count` followed by a comma must have an associated index indicating its depth",
104104
));
@@ -119,7 +119,7 @@ fn parse_depth<'sess>(
119119
let Some(tt) = iter.next() else { return Ok(0) };
120120
let TokenTree::Token(token::Token { kind: token::TokenKind::Literal(lit), .. }, _) = tt else {
121121
return Err(sess
122-
.span_diagnostic
122+
.dcx
123123
.struct_span_err(span, "meta-variable expression depth must be a literal"));
124124
};
125125
if let Ok(lit_kind) = LitKind::from_token_lit(*lit)
@@ -129,7 +129,7 @@ fn parse_depth<'sess>(
129129
Ok(n_usize)
130130
} else {
131131
let msg = "only unsuffixes integer literals are supported in meta-variable expressions";
132-
Err(sess.span_diagnostic.struct_span_err(span, msg))
132+
Err(sess.dcx.struct_span_err(span, msg))
133133
}
134134
}
135135

@@ -146,9 +146,8 @@ fn parse_ident<'sess>(
146146
return Ok(elem);
147147
}
148148
let token_str = pprust::token_to_string(token);
149-
let mut err = sess
150-
.span_diagnostic
151-
.struct_span_err(span, format!("expected identifier, found `{}`", &token_str));
149+
let mut err =
150+
sess.dcx.struct_span_err(span, format!("expected identifier, found `{}`", &token_str));
152151
err.span_suggestion(
153152
token.span,
154153
format!("try removing `{}`", &token_str),
@@ -157,7 +156,7 @@ fn parse_ident<'sess>(
157156
);
158157
return Err(err);
159158
}
160-
Err(sess.span_diagnostic.struct_span_err(span, "expected identifier"))
159+
Err(sess.dcx.struct_span_err(span, "expected identifier"))
161160
}
162161

163162
/// Tries to move the iterator forward returning `true` if there is a comma. If not, then the
@@ -181,7 +180,7 @@ fn eat_dollar<'sess>(
181180
let _ = iter.next();
182181
return Ok(());
183182
}
184-
Err(sess.span_diagnostic.struct_span_err(
183+
Err(sess.dcx.struct_span_err(
185184
span,
186185
"meta-variables within meta-variable expressions must be referenced using a dollar sign",
187186
))

compiler/rustc_expand/src/mbe/quoted.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ pub(super) fn parse(
8484
"invalid fragment specifier `{}`",
8585
frag.name
8686
);
87-
sess.span_diagnostic
87+
sess.dcx
8888
.struct_span_err(span, msg)
8989
.help(VALID_FRAGMENT_NAMES_MSG)
9090
.emit();
@@ -195,7 +195,7 @@ fn parse_tree<'a>(
195195
_ => {
196196
let tok = pprust::token_kind_to_string(&token::OpenDelim(delim));
197197
let msg = format!("expected `(` or `{{`, found `{tok}`");
198-
sess.span_diagnostic.span_err(delim_span.entire(), msg);
198+
sess.dcx.span_err(delim_span.entire(), msg);
199199
}
200200
}
201201
}
@@ -244,7 +244,7 @@ fn parse_tree<'a>(
244244
Some(tokenstream::TokenTree::Token(token, _)) => {
245245
let msg =
246246
format!("expected identifier, found `{}`", pprust::token_to_string(token),);
247-
sess.span_diagnostic.span_err(token.span, msg);
247+
sess.dcx.span_err(token.span, msg);
248248
TokenTree::MetaVar(token.span, Ident::empty())
249249
}
250250

@@ -325,7 +325,7 @@ fn parse_sep_and_kleene_op<'a>(
325325
// #2 is the `?` Kleene op, which does not take a separator (error)
326326
Ok(Ok((KleeneOp::ZeroOrOne, span))) => {
327327
// Error!
328-
sess.span_diagnostic.span_err(
328+
sess.dcx.span_err(
329329
token.span,
330330
"the `?` macro repetition operator does not take a separator",
331331
);
@@ -346,7 +346,7 @@ fn parse_sep_and_kleene_op<'a>(
346346
};
347347

348348
// If we ever get to this point, we have experienced an "unexpected token" error
349-
sess.span_diagnostic.span_err(span, "expected one of: `*`, `+`, or `?`");
349+
sess.dcx.span_err(span, "expected one of: `*`, `+`, or `?`");
350350

351351
// Return a dummy
352352
(None, KleeneToken::new(KleeneOp::ZeroOrMore, span))
@@ -356,9 +356,8 @@ fn parse_sep_and_kleene_op<'a>(
356356
//
357357
// For example, `macro_rules! foo { ( ${length()} ) => {} }`
358358
fn span_dollar_dollar_or_metavar_in_the_lhs_err(sess: &ParseSess, token: &Token) {
359-
sess.span_diagnostic
360-
.span_err(token.span, format!("unexpected token: {}", pprust::token_to_string(token)));
361-
sess.span_diagnostic.span_note(
359+
sess.dcx.span_err(token.span, format!("unexpected token: {}", pprust::token_to_string(token)));
360+
sess.dcx.span_note(
362361
token.span,
363362
"`$$` and meta-variable expressions are not allowed inside macro parameter definitions",
364363
);

compiler/rustc_expand/src/proc_macro_server.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ impl server::FreeFunctions for Rustc<'_, '_> {
506506
None,
507507
);
508508
}
509-
self.sess().span_diagnostic.emit_diagnostic(diag);
509+
self.sess().dcx.emit_diagnostic(diag);
510510
}
511511
}
512512

compiler/rustc_expand/src/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ where
4646
{
4747
let mut p = string_to_parser(&ps, s);
4848
let x = f(&mut p).unwrap();
49-
p.sess.span_diagnostic.abort_if_errors();
49+
p.sess.dcx.abort_if_errors();
5050
x
5151
}
5252

0 commit comments

Comments
 (0)