Skip to content

Commit

Permalink
Rename ParseSess::span_diagnostic as ParseSess::dcx.
Browse files Browse the repository at this point in the history
  • Loading branch information
nnethercote committed Dec 18, 2023
1 parent 9b1f87c commit 9df1576
Show file tree
Hide file tree
Showing 26 changed files with 89 additions and 98 deletions.
9 changes: 4 additions & 5 deletions compiler/rustc_builtin_macros/src/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub fn parse_asm_args<'a>(
sp: Span,
is_global_asm: bool,
) -> PResult<'a, AsmArgs> {
let diag = &sess.span_diagnostic;
let diag = &sess.dcx;

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

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

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

let mut new_abis = Vec::new();
Expand All @@ -381,8 +381,7 @@ fn parse_clobber_abi<'a>(p: &mut Parser<'a>, args: &mut AsmArgs) -> PResult<'a,
}
Err(opt_lit) => {
let span = opt_lit.map_or(p.token.span, |lit| lit.span);
let mut err =
p.sess.span_diagnostic.struct_span_err(span, "expected string literal");
let mut err = p.sess.dcx.struct_span_err(span, "expected string literal");
err.span_label(span, "not a string literal");
return Err(err);
}
Expand Down
4 changes: 1 addition & 3 deletions compiler/rustc_builtin_macros/src/cmdline_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ pub fn inject(krate: &mut ast::Crate, parse_sess: &ParseSess, attrs: &[String])
};
let end_span = parser.token.span;
if parser.token != token::Eof {
parse_sess
.span_diagnostic
.emit_err(errors::InvalidCrateAttr { span: start_span.to(end_span) });
parse_sess.dcx.emit_err(errors::InvalidCrateAttr { span: start_span.to(end_span) });
continue;
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_expand/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1208,7 +1208,7 @@ pub fn resolve_path(
span,
path: parse_sess.source_map().filename_for_diagnostics(&other).to_string(),
}
.into_diagnostic(&parse_sess.span_diagnostic));
.into_diagnostic(&parse_sess.dcx));
}
};
result.pop();
Expand Down
11 changes: 5 additions & 6 deletions compiler/rustc_expand/src/mbe/macro_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ pub(super) fn check_meta_variables(
rhses: &[TokenTree],
) -> bool {
if lhses.len() != rhses.len() {
sess.span_diagnostic.span_bug(span, "length mismatch between LHSes and RHSes")
sess.dcx.span_bug(span, "length mismatch between LHSes and RHSes")
}
let mut valid = true;
for (lhs, rhs) in iter::zip(lhses, rhses) {
Expand Down Expand Up @@ -244,7 +244,7 @@ fn check_binders(
// MetaVar(fragment) and not as MetaVarDecl(y, fragment).
TokenTree::MetaVar(span, name) => {
if macros.is_empty() {
sess.span_diagnostic.span_bug(span, "unexpected MetaVar in lhs");
sess.dcx.span_bug(span, "unexpected MetaVar in lhs");
}
let name = MacroRulesNormalizedIdent::new(name);
// There are 3 possibilities:
Expand Down Expand Up @@ -275,14 +275,13 @@ fn check_binders(
);
}
if !macros.is_empty() {
sess.span_diagnostic.span_bug(span, "unexpected MetaVarDecl in nested lhs");
sess.dcx.span_bug(span, "unexpected MetaVarDecl in nested lhs");
}
let name = MacroRulesNormalizedIdent::new(name);
if let Some(prev_info) = get_binder_info(macros, binders, name) {
// Duplicate binders at the top-level macro definition are errors. The lint is only
// for nested macro definitions.
sess.span_diagnostic
.emit_err(errors::DuplicateMatcherBinding { span, prev: prev_info.span });
sess.dcx.emit_err(errors::DuplicateMatcherBinding { span, prev: prev_info.span });
*valid = false;
} else {
binders.insert(name, BinderInfo { span, ops: ops.into() });
Expand Down Expand Up @@ -341,7 +340,7 @@ fn check_occurrences(
match *rhs {
TokenTree::Token(..) => {}
TokenTree::MetaVarDecl(span, _name, _kind) => {
sess.span_diagnostic.span_bug(span, "unexpected MetaVarDecl in rhs")
sess.dcx.span_bug(span, "unexpected MetaVarDecl in rhs")
}
TokenTree::MetaVar(span, name) => {
let name = MacroRulesNormalizedIdent::new(name);
Expand Down
17 changes: 8 additions & 9 deletions compiler/rustc_expand/src/mbe/macro_rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ pub fn compile_declarative_macro(
};
let dummy_syn_ext = || (mk_syn_ext(Box::new(macro_rules_dummy_expander)), Vec::new());

let diag = &sess.parse_sess.span_diagnostic;
let diag = &sess.parse_sess.dcx;
let lhs_nm = Ident::new(sym::lhs, def.span);
let rhs_nm = Ident::new(sym::rhs, def.span);
let tt_spec = Some(NonterminalKind::TT);
Expand Down Expand Up @@ -626,7 +626,7 @@ fn check_lhs_nt_follows(sess: &ParseSess, def: &ast::Item, lhs: &mbe::TokenTree)
check_matcher(sess, def, &delimited.tts)
} else {
let msg = "invalid macro matcher; matchers must be contained in balanced delimiters";
sess.span_diagnostic.span_err(lhs.span(), msg);
sess.dcx.span_err(lhs.span(), msg);
false
}
// we don't abort on errors on rejection, the driver will do that for us
Expand All @@ -652,8 +652,7 @@ fn is_empty_token_tree(sess: &ParseSess, seq: &mbe::SequenceRepetition) -> bool
iter.next();
}
let span = t.span.to(now.span);
sess.span_diagnostic
.span_note(span, "doc comments are ignored in matcher position");
sess.dcx.span_note(span, "doc comments are ignored in matcher position");
}
mbe::TokenTree::Sequence(_, sub_seq)
if (sub_seq.kleene.op == mbe::KleeneOp::ZeroOrMore
Expand Down Expand Up @@ -683,7 +682,7 @@ fn check_lhs_no_empty_seq(sess: &ParseSess, tts: &[mbe::TokenTree]) -> bool {
TokenTree::Sequence(span, seq) => {
if is_empty_token_tree(sess, seq) {
let sp = span.entire();
sess.span_diagnostic.span_err(sp, "repetition matches empty token tree");
sess.dcx.span_err(sp, "repetition matches empty token tree");
return false;
}
if !check_lhs_no_empty_seq(sess, &seq.tts) {
Expand All @@ -700,7 +699,7 @@ fn check_rhs(sess: &ParseSess, rhs: &mbe::TokenTree) -> bool {
match *rhs {
mbe::TokenTree::Delimited(..) => return true,
_ => {
sess.span_diagnostic.span_err(rhs.span(), "macro rhs must be delimited");
sess.dcx.span_err(rhs.span(), "macro rhs must be delimited");
}
}
false
Expand All @@ -709,9 +708,9 @@ fn check_rhs(sess: &ParseSess, rhs: &mbe::TokenTree) -> bool {
fn check_matcher(sess: &ParseSess, def: &ast::Item, matcher: &[mbe::TokenTree]) -> bool {
let first_sets = FirstSets::new(matcher);
let empty_suffix = TokenSet::empty();
let err = sess.span_diagnostic.err_count();
let err = sess.dcx.err_count();
check_matcher_core(sess, def, &first_sets, matcher, &empty_suffix);
err == sess.span_diagnostic.err_count()
err == sess.dcx.err_count()
}

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

let sp = next_token.span();
let mut err = sess.span_diagnostic.struct_span_err(
let mut err = sess.dcx.struct_span_err(
sp,
format!(
"`${name}:{frag}` {may_be} followed by `{next}`, which \
Expand Down
21 changes: 10 additions & 11 deletions compiler/rustc_expand/src/mbe/metavar_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl MetaVarExpr {
let ident = parse_ident(&mut tts, sess, outer_span)?;
let Some(TokenTree::Delimited(.., Delimiter::Parenthesis, args)) = tts.next() else {
let msg = "meta-variable expression parameter must be wrapped in parentheses";
return Err(sess.span_diagnostic.struct_span_err(ident.span, msg));
return Err(sess.dcx.struct_span_err(ident.span, msg));
};
check_trailing_token(&mut tts, sess)?;
let mut iter = args.trees();
Expand All @@ -50,7 +50,7 @@ impl MetaVarExpr {
"length" => MetaVarExpr::Length(parse_depth(&mut iter, sess, ident.span)?),
_ => {
let err_msg = "unrecognized meta-variable expression";
let mut err = sess.span_diagnostic.struct_span_err(ident.span, err_msg);
let mut err = sess.dcx.struct_span_err(ident.span, err_msg);
err.span_suggestion(
ident.span,
"supported expressions are count, ignore, index and length",
Expand Down Expand Up @@ -79,7 +79,7 @@ fn check_trailing_token<'sess>(
) -> PResult<'sess, ()> {
if let Some(tt) = iter.next() {
let mut diag = sess
.span_diagnostic
.dcx
.struct_span_err(tt.span(), format!("unexpected token: {}", pprust::tt_to_string(tt)));
diag.span_note(tt.span(), "meta-variable expression must not have trailing tokens");
Err(diag)
Expand All @@ -98,7 +98,7 @@ fn parse_count<'sess>(
let ident = parse_ident(iter, sess, span)?;
let depth = if try_eat_comma(iter) {
if iter.look_ahead(0).is_none() {
return Err(sess.span_diagnostic.struct_span_err(
return Err(sess.dcx.struct_span_err(
span,
"`count` followed by a comma must have an associated index indicating its depth",
));
Expand All @@ -119,7 +119,7 @@ fn parse_depth<'sess>(
let Some(tt) = iter.next() else { return Ok(0) };
let TokenTree::Token(token::Token { kind: token::TokenKind::Literal(lit), .. }, _) = tt else {
return Err(sess
.span_diagnostic
.dcx
.struct_span_err(span, "meta-variable expression depth must be a literal"));
};
if let Ok(lit_kind) = LitKind::from_token_lit(*lit)
Expand All @@ -129,7 +129,7 @@ fn parse_depth<'sess>(
Ok(n_usize)
} else {
let msg = "only unsuffixes integer literals are supported in meta-variable expressions";
Err(sess.span_diagnostic.struct_span_err(span, msg))
Err(sess.dcx.struct_span_err(span, msg))
}
}

Expand All @@ -146,9 +146,8 @@ fn parse_ident<'sess>(
return Ok(elem);
}
let token_str = pprust::token_to_string(token);
let mut err = sess
.span_diagnostic
.struct_span_err(span, format!("expected identifier, found `{}`", &token_str));
let mut err =
sess.dcx.struct_span_err(span, format!("expected identifier, found `{}`", &token_str));
err.span_suggestion(
token.span,
format!("try removing `{}`", &token_str),
Expand All @@ -157,7 +156,7 @@ fn parse_ident<'sess>(
);
return Err(err);
}
Err(sess.span_diagnostic.struct_span_err(span, "expected identifier"))
Err(sess.dcx.struct_span_err(span, "expected identifier"))
}

/// Tries to move the iterator forward returning `true` if there is a comma. If not, then the
Expand All @@ -181,7 +180,7 @@ fn eat_dollar<'sess>(
let _ = iter.next();
return Ok(());
}
Err(sess.span_diagnostic.struct_span_err(
Err(sess.dcx.struct_span_err(
span,
"meta-variables within meta-variable expressions must be referenced using a dollar sign",
))
Expand Down
15 changes: 7 additions & 8 deletions compiler/rustc_expand/src/mbe/quoted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ pub(super) fn parse(
"invalid fragment specifier `{}`",
frag.name
);
sess.span_diagnostic
sess.dcx
.struct_span_err(span, msg)
.help(VALID_FRAGMENT_NAMES_MSG)
.emit();
Expand Down Expand Up @@ -195,7 +195,7 @@ fn parse_tree<'a>(
_ => {
let tok = pprust::token_kind_to_string(&token::OpenDelim(delim));
let msg = format!("expected `(` or `{{`, found `{tok}`");
sess.span_diagnostic.span_err(delim_span.entire(), msg);
sess.dcx.span_err(delim_span.entire(), msg);
}
}
}
Expand Down Expand Up @@ -244,7 +244,7 @@ fn parse_tree<'a>(
Some(tokenstream::TokenTree::Token(token, _)) => {
let msg =
format!("expected identifier, found `{}`", pprust::token_to_string(token),);
sess.span_diagnostic.span_err(token.span, msg);
sess.dcx.span_err(token.span, msg);
TokenTree::MetaVar(token.span, Ident::empty())
}

Expand Down Expand Up @@ -325,7 +325,7 @@ fn parse_sep_and_kleene_op<'a>(
// #2 is the `?` Kleene op, which does not take a separator (error)
Ok(Ok((KleeneOp::ZeroOrOne, span))) => {
// Error!
sess.span_diagnostic.span_err(
sess.dcx.span_err(
token.span,
"the `?` macro repetition operator does not take a separator",
);
Expand All @@ -346,7 +346,7 @@ fn parse_sep_and_kleene_op<'a>(
};

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

// Return a dummy
(None, KleeneToken::new(KleeneOp::ZeroOrMore, span))
Expand All @@ -356,9 +356,8 @@ fn parse_sep_and_kleene_op<'a>(
//
// For example, `macro_rules! foo { ( ${length()} ) => {} }`
fn span_dollar_dollar_or_metavar_in_the_lhs_err(sess: &ParseSess, token: &Token) {
sess.span_diagnostic
.span_err(token.span, format!("unexpected token: {}", pprust::token_to_string(token)));
sess.span_diagnostic.span_note(
sess.dcx.span_err(token.span, format!("unexpected token: {}", pprust::token_to_string(token)));
sess.dcx.span_note(
token.span,
"`$$` and meta-variable expressions are not allowed inside macro parameter definitions",
);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_expand/src/proc_macro_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ impl server::FreeFunctions for Rustc<'_, '_> {
None,
);
}
self.sess().span_diagnostic.emit_diagnostic(diag);
self.sess().dcx.emit_diagnostic(diag);
}
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_expand/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ where
{
let mut p = string_to_parser(&ps, s);
let x = f(&mut p).unwrap();
p.sess.span_diagnostic.abort_if_errors();
p.sess.dcx.abort_if_errors();
x
}

Expand Down
Loading

0 comments on commit 9df1576

Please sign in to comment.