Skip to content

Commit 9a26e5a

Browse files
committed
Remove ExtCtxt methods that duplicate DiagCtxt methods.
1 parent 57ad505 commit 9a26e5a

33 files changed

+155
-180
lines changed

compiler/rustc_builtin_macros/src/alloc_error_handler.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub fn expand(
3131
{
3232
(item, true, ecx.with_def_site_ctxt(fn_kind.sig.span))
3333
} else {
34-
ecx.sess.dcx().emit_err(errors::AllocErrorMustBeFn { span: item.span() });
34+
ecx.dcx().emit_err(errors::AllocErrorMustBeFn { span: item.span() });
3535
return vec![orig_item];
3636
};
3737

compiler/rustc_builtin_macros/src/asm.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, args: AsmArgs) -> Option<ast::Inl
541541
let err = parser.errors.remove(0);
542542
let err_sp = template_span.from_inner(InnerSpan::new(err.span.start, err.span.end));
543543
let msg = format!("invalid asm template string: {}", err.description);
544-
let mut e = ecx.struct_span_err(err_sp, msg);
544+
let mut e = ecx.dcx().struct_span_err(err_sp, msg);
545545
e.span_label(err_sp, err.label + " in asm template string");
546546
if let Some(note) = err.note {
547547
e.note(note);
@@ -575,7 +575,7 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, args: AsmArgs) -> Option<ast::Inl
575575
|| args.reg_args.contains(idx)
576576
{
577577
let msg = format!("invalid reference to argument at index {idx}");
578-
let mut err = ecx.struct_span_err(span, msg);
578+
let mut err = ecx.dcx().struct_span_err(span, msg);
579579
err.span_label(span, "from here");
580580

581581
let positional_args = args.operands.len()
@@ -625,12 +625,13 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, args: AsmArgs) -> Option<ast::Inl
625625
None => {
626626
let msg = format!("there is no argument named `{name}`");
627627
let span = arg.position_span;
628-
ecx.struct_span_err(
629-
template_span
630-
.from_inner(InnerSpan::new(span.start, span.end)),
631-
msg,
632-
)
633-
.emit();
628+
ecx.dcx()
629+
.struct_span_err(
630+
template_span
631+
.from_inner(InnerSpan::new(span.start, span.end)),
632+
msg,
633+
)
634+
.emit();
634635
None
635636
}
636637
}
@@ -645,7 +646,7 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, args: AsmArgs) -> Option<ast::Inl
645646
.ty_span
646647
.map(|sp| template_sp.from_inner(InnerSpan::new(sp.start, sp.end)))
647648
.unwrap_or(template_sp);
648-
ecx.emit_err(errors::AsmModifierInvalid { span });
649+
ecx.dcx().emit_err(errors::AsmModifierInvalid { span });
649650
modifier = None;
650651
}
651652

@@ -692,7 +693,7 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, args: AsmArgs) -> Option<ast::Inl
692693
0 => {}
693694
1 => {
694695
let (sp, msg) = unused_operands.into_iter().next().unwrap();
695-
let mut err = ecx.struct_span_err(sp, msg);
696+
let mut err = ecx.dcx().struct_span_err(sp, msg);
696697
err.span_label(sp, msg);
697698
err.help(format!(
698699
"if this argument is intentionally unused, \
@@ -701,7 +702,7 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, args: AsmArgs) -> Option<ast::Inl
701702
err.emit();
702703
}
703704
_ => {
704-
let mut err = ecx.struct_span_err(
705+
let mut err = ecx.dcx().struct_span_err(
705706
unused_operands.iter().map(|&(sp, _)| sp).collect::<Vec<Span>>(),
706707
"multiple unused asm arguments",
707708
);

compiler/rustc_builtin_macros/src/assert.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ fn parse_assert<'a>(cx: &mut ExtCtxt<'a>, sp: Span, stream: TokenStream) -> PRes
115115
let mut parser = cx.new_parser_from_tts(stream);
116116

117117
if parser.token == token::Eof {
118-
return Err(cx.create_err(errors::AssertRequiresBoolean { span: sp }));
118+
return Err(cx.dcx().create_err(errors::AssertRequiresBoolean { span: sp }));
119119
}
120120

121121
let cond_expr = parser.parse_expr()?;
@@ -128,7 +128,7 @@ fn parse_assert<'a>(cx: &mut ExtCtxt<'a>, sp: Span, stream: TokenStream) -> PRes
128128
//
129129
// Emit an error about semicolon and suggest removing it.
130130
if parser.token == token::Semi {
131-
cx.emit_err(errors::AssertRequiresExpression { span: sp, token: parser.token.span });
131+
cx.dcx().emit_err(errors::AssertRequiresExpression { span: sp, token: parser.token.span });
132132
parser.bump();
133133
}
134134

@@ -141,7 +141,7 @@ fn parse_assert<'a>(cx: &mut ExtCtxt<'a>, sp: Span, stream: TokenStream) -> PRes
141141
let custom_message =
142142
if let token::Literal(token::Lit { kind: token::Str, .. }) = parser.token.kind {
143143
let comma = parser.prev_token.span.shrink_to_hi();
144-
cx.emit_err(errors::AssertMissingComma { span: parser.token.span, comma });
144+
cx.dcx().emit_err(errors::AssertMissingComma { span: parser.token.span, comma });
145145

146146
parse_custom_message(&mut parser)
147147
} else if parser.eat(&token::Comma) {

compiler/rustc_builtin_macros/src/cfg.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@ fn parse_cfg<'a>(cx: &mut ExtCtxt<'a>, span: Span, tts: TokenStream) -> PResult<
3939
let mut p = cx.new_parser_from_tts(tts);
4040

4141
if p.token == token::Eof {
42-
return Err(cx.create_err(errors::RequiresCfgPattern { span }));
42+
return Err(cx.dcx().create_err(errors::RequiresCfgPattern { span }));
4343
}
4444

4545
let cfg = p.parse_meta_item()?;
4646

4747
let _ = p.eat(&token::Comma);
4848

4949
if !p.eat(&token::Eof) {
50-
return Err(cx.create_err(errors::OneCfgPattern { span }));
50+
return Err(cx.dcx().create_err(errors::OneCfgPattern { span }));
5151
}
5252

5353
Ok(cfg)

compiler/rustc_builtin_macros/src/cfg_accessible.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,18 @@ fn validate_input<'a>(ecx: &mut ExtCtxt<'_>, mi: &'a ast::MetaItem) -> Option<&'
1515
match mi.meta_item_list() {
1616
None => {}
1717
Some([]) => {
18-
ecx.emit_err(UnspecifiedPath(mi.span));
18+
ecx.dcx().emit_err(UnspecifiedPath(mi.span));
1919
}
2020
Some([_, .., l]) => {
21-
ecx.emit_err(MultiplePaths(l.span()));
21+
ecx.dcx().emit_err(MultiplePaths(l.span()));
2222
}
2323
Some([nmi]) => match nmi.meta_item() {
2424
None => {
25-
ecx.emit_err(LiteralPath(nmi.span()));
25+
ecx.dcx().emit_err(LiteralPath(nmi.span()));
2626
}
2727
Some(mi) => {
2828
if !mi.is_word() {
29-
ecx.emit_err(HasArguments(mi.span));
29+
ecx.dcx().emit_err(HasArguments(mi.span));
3030
}
3131
return Some(&mi.path);
3232
}
@@ -61,7 +61,7 @@ impl MultiItemModifier for Expander {
6161
Ok(true) => ExpandResult::Ready(vec![item]),
6262
Ok(false) => ExpandResult::Ready(Vec::new()),
6363
Err(Indeterminate) if ecx.force_mode => {
64-
ecx.emit_err(errors::CfgAccessibleIndeterminate { span });
64+
ecx.dcx().emit_err(errors::CfgAccessibleIndeterminate { span });
6565
ExpandResult::Ready(vec![item])
6666
}
6767
Err(Indeterminate) => ExpandResult::Retry(item),

compiler/rustc_builtin_macros/src/compile_error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub fn expand_compile_error<'cx>(
1818
reason = "diagnostic message is specified by user"
1919
)]
2020
#[expect(rustc::untranslatable_diagnostic, reason = "diagnostic message is specified by user")]
21-
cx.span_err(sp, var.to_string());
21+
cx.dcx().span_err(sp, var.to_string());
2222

2323
DummyResult::any(sp)
2424
}

compiler/rustc_builtin_macros/src/concat.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ pub fn expand_concat(
3333
accumulator.push_str(&b.to_string());
3434
}
3535
Ok(ast::LitKind::CStr(..)) => {
36-
cx.emit_err(errors::ConcatCStrLit { span: e.span });
36+
cx.dcx().emit_err(errors::ConcatCStrLit { span: e.span });
3737
has_errors = true;
3838
}
3939
Ok(ast::LitKind::Byte(..) | ast::LitKind::ByteStr(..)) => {
40-
cx.emit_err(errors::ConcatBytestr { span: e.span });
40+
cx.dcx().emit_err(errors::ConcatBytestr { span: e.span });
4141
has_errors = true;
4242
}
4343
Ok(ast::LitKind::Err) => {
@@ -63,7 +63,7 @@ pub fn expand_concat(
6363
}
6464
}
6565
ast::ExprKind::IncludedBytes(..) => {
66-
cx.emit_err(errors::ConcatBytestr { span: e.span });
66+
cx.dcx().emit_err(errors::ConcatBytestr { span: e.span });
6767
}
6868
ast::ExprKind::Err => {
6969
has_errors = true;
@@ -75,7 +75,7 @@ pub fn expand_concat(
7575
}
7676

7777
if !missing_literal.is_empty() {
78-
cx.emit_err(errors::ConcatMissingLiteral { spans: missing_literal });
78+
cx.dcx().emit_err(errors::ConcatMissingLiteral { spans: missing_literal });
7979
return DummyResult::any(sp);
8080
} else if has_errors {
8181
return DummyResult::any(sp);

compiler/rustc_builtin_macros/src/concat_bytes.rs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,17 @@ fn invalid_type_err(
1717
ConcatBytesInvalid, ConcatBytesInvalidSuggestion, ConcatBytesNonU8, ConcatBytesOob,
1818
};
1919
let snippet = cx.sess.source_map().span_to_snippet(span).ok();
20+
let dcx = cx.dcx();
2021
match ast::LitKind::from_token_lit(token_lit) {
2122
Ok(ast::LitKind::CStr(_, _)) => {
2223
// Avoid ambiguity in handling of terminal `NUL` by refusing to
2324
// concatenate C string literals as bytes.
24-
cx.emit_err(errors::ConcatCStrLit { span: span });
25+
dcx.emit_err(errors::ConcatCStrLit { span: span });
2526
}
2627
Ok(ast::LitKind::Char(_)) => {
2728
let sugg =
2829
snippet.map(|snippet| ConcatBytesInvalidSuggestion::CharLit { span, snippet });
29-
cx.sess.emit_err(ConcatBytesInvalid { span, lit_kind: "character", sugg });
30+
dcx.emit_err(ConcatBytesInvalid { span, lit_kind: "character", sugg });
3031
}
3132
Ok(ast::LitKind::Str(_, _)) => {
3233
// suggestion would be invalid if we are nested
@@ -35,29 +36,29 @@ fn invalid_type_err(
3536
} else {
3637
None
3738
};
38-
cx.emit_err(ConcatBytesInvalid { span, lit_kind: "string", sugg });
39+
dcx.emit_err(ConcatBytesInvalid { span, lit_kind: "string", sugg });
3940
}
4041
Ok(ast::LitKind::Float(_, _)) => {
41-
cx.emit_err(ConcatBytesInvalid { span, lit_kind: "float", sugg: None });
42+
dcx.emit_err(ConcatBytesInvalid { span, lit_kind: "float", sugg: None });
4243
}
4344
Ok(ast::LitKind::Bool(_)) => {
44-
cx.emit_err(ConcatBytesInvalid { span, lit_kind: "boolean", sugg: None });
45+
dcx.emit_err(ConcatBytesInvalid { span, lit_kind: "boolean", sugg: None });
4546
}
4647
Ok(ast::LitKind::Err) => {}
4748
Ok(ast::LitKind::Int(_, _)) if !is_nested => {
4849
let sugg =
4950
snippet.map(|snippet| ConcatBytesInvalidSuggestion::IntLit { span: span, snippet });
50-
cx.emit_err(ConcatBytesInvalid { span, lit_kind: "numeric", sugg });
51+
dcx.emit_err(ConcatBytesInvalid { span, lit_kind: "numeric", sugg });
5152
}
5253
Ok(ast::LitKind::Int(
5354
val,
5455
ast::LitIntType::Unsuffixed | ast::LitIntType::Unsigned(ast::UintTy::U8),
5556
)) => {
5657
assert!(val > u8::MAX.into()); // must be an error
57-
cx.emit_err(ConcatBytesOob { span });
58+
dcx.emit_err(ConcatBytesOob { span });
5859
}
5960
Ok(ast::LitKind::Int(_, _)) => {
60-
cx.emit_err(ConcatBytesNonU8 { span });
61+
dcx.emit_err(ConcatBytesNonU8 { span });
6162
}
6263
Ok(ast::LitKind::ByteStr(..) | ast::LitKind::Byte(_)) => unreachable!(),
6364
Err(err) => {
@@ -72,10 +73,11 @@ fn handle_array_element(
7273
missing_literals: &mut Vec<rustc_span::Span>,
7374
expr: &P<rustc_ast::Expr>,
7475
) -> Option<u8> {
76+
let dcx = cx.dcx();
7577
match expr.kind {
7678
ast::ExprKind::Array(_) | ast::ExprKind::Repeat(_, _) => {
7779
if !*has_errors {
78-
cx.emit_err(errors::ConcatBytesArray { span: expr.span, bytestr: false });
80+
dcx.emit_err(errors::ConcatBytesArray { span: expr.span, bytestr: false });
7981
}
8082
*has_errors = true;
8183
None
@@ -89,7 +91,7 @@ fn handle_array_element(
8991
Ok(ast::LitKind::Byte(val)) => Some(val),
9092
Ok(ast::LitKind::ByteStr(..)) => {
9193
if !*has_errors {
92-
cx.emit_err(errors::ConcatBytesArray { span: expr.span, bytestr: true });
94+
dcx.emit_err(errors::ConcatBytesArray { span: expr.span, bytestr: true });
9395
}
9496
*has_errors = true;
9597
None
@@ -104,7 +106,7 @@ fn handle_array_element(
104106
},
105107
ast::ExprKind::IncludedBytes(..) => {
106108
if !*has_errors {
107-
cx.emit_err(errors::ConcatBytesArray { span: expr.span, bytestr: false });
109+
dcx.emit_err(errors::ConcatBytesArray { span: expr.span, bytestr: false });
108110
}
109111
*has_errors = true;
110112
None
@@ -151,7 +153,7 @@ pub fn expand_concat_bytes(
151153
}
152154
}
153155
} else {
154-
cx.emit_err(errors::ConcatBytesBadRepeat { span: count.value.span });
156+
cx.dcx().emit_err(errors::ConcatBytesBadRepeat { span: count.value.span });
155157
}
156158
}
157159
&ast::ExprKind::Lit(token_lit) => match ast::LitKind::from_token_lit(token_lit) {
@@ -180,7 +182,7 @@ pub fn expand_concat_bytes(
180182
}
181183
}
182184
if !missing_literals.is_empty() {
183-
cx.emit_err(errors::ConcatBytesMissingLiteral { spans: missing_literals });
185+
cx.dcx().emit_err(errors::ConcatBytesMissingLiteral { spans: missing_literals });
184186
return base::MacEager::expr(DummyResult::raw_expr(sp, true));
185187
} else if has_errors {
186188
return base::MacEager::expr(DummyResult::raw_expr(sp, true));

compiler/rustc_builtin_macros/src/concat_idents.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub fn expand_concat_idents<'cx>(
1414
tts: TokenStream,
1515
) -> Box<dyn base::MacResult + 'cx> {
1616
if tts.is_empty() {
17-
cx.emit_err(errors::ConcatIdentsMissingArgs { span: sp });
17+
cx.dcx().emit_err(errors::ConcatIdentsMissingArgs { span: sp });
1818
return DummyResult::any(sp);
1919
}
2020

@@ -24,7 +24,7 @@ pub fn expand_concat_idents<'cx>(
2424
match e {
2525
TokenTree::Token(Token { kind: token::Comma, .. }, _) => {}
2626
_ => {
27-
cx.emit_err(errors::ConcatIdentsMissingComma { span: sp });
27+
cx.dcx().emit_err(errors::ConcatIdentsMissingComma { span: sp });
2828
return DummyResult::any(sp);
2929
}
3030
}
@@ -36,7 +36,7 @@ pub fn expand_concat_idents<'cx>(
3636
}
3737
}
3838

39-
cx.emit_err(errors::ConcatIdentsIdentArgs { span: sp });
39+
cx.dcx().emit_err(errors::ConcatIdentsIdentArgs { span: sp });
4040
return DummyResult::any(sp);
4141
}
4242
}

compiler/rustc_builtin_macros/src/deriving/clone.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ pub fn expand_deriving_clone(
6262
cs_clone_simple("Clone", c, s, sub, true)
6363
}));
6464
}
65-
_ => cx.span_bug(span, "`#[derive(Clone)]` on wrong item kind"),
65+
_ => cx.dcx().span_bug(span, "`#[derive(Clone)]` on wrong item kind"),
6666
},
6767

68-
_ => cx.span_bug(span, "`#[derive(Clone)]` on trait item or impl item"),
68+
_ => cx.dcx().span_bug(span, "`#[derive(Clone)]` on trait item or impl item"),
6969
}
7070

7171
let trait_def = TraitDef {
@@ -144,7 +144,7 @@ fn cs_clone_simple(
144144
process_variant(&variant.data);
145145
}
146146
}
147-
_ => cx.span_bug(
147+
_ => cx.dcx().span_bug(
148148
trait_span,
149149
format!("unexpected substructure in simple `derive({name})`"),
150150
),
@@ -180,10 +180,10 @@ fn cs_clone(
180180
vdata = &variant.data;
181181
}
182182
EnumTag(..) | AllFieldlessEnum(..) => {
183-
cx.span_bug(trait_span, format!("enum tags in `derive({name})`",))
183+
cx.dcx().span_bug(trait_span, format!("enum tags in `derive({name})`",))
184184
}
185185
StaticEnum(..) | StaticStruct(..) => {
186-
cx.span_bug(trait_span, format!("associated function in `derive({name})`"))
186+
cx.dcx().span_bug(trait_span, format!("associated function in `derive({name})`"))
187187
}
188188
}
189189

@@ -193,7 +193,7 @@ fn cs_clone(
193193
.iter()
194194
.map(|field| {
195195
let Some(ident) = field.name else {
196-
cx.span_bug(
196+
cx.dcx().span_bug(
197197
trait_span,
198198
format!("unnamed field in normal struct in `derive({name})`",),
199199
);

compiler/rustc_builtin_macros/src/deriving/cmp/eq.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ fn cs_total_eq_assert(
9999
process_variant(&variant.data);
100100
}
101101
}
102-
_ => cx.span_bug(trait_span, "unexpected substructure in `derive(Eq)`"),
102+
_ => cx.dcx().span_bug(trait_span, "unexpected substructure in `derive(Eq)`"),
103103
}
104104
BlockOrExpr::new_stmts(stmts)
105105
}

compiler/rustc_builtin_macros/src/deriving/cmp/ord.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ pub fn cs_cmp(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_>) -> Bl
6161
|cx, fold| match fold {
6262
CsFold::Single(field) => {
6363
let [other_expr] = &field.other_selflike_exprs[..] else {
64-
cx.span_bug(field.span, "not exactly 2 arguments in `derive(Ord)`");
64+
cx.dcx().span_bug(field.span, "not exactly 2 arguments in `derive(Ord)`");
6565
};
6666
let args = thin_vec![field.self_expr.clone(), other_expr.clone()];
6767
cx.expr_call_global(field.span, cmp_path.clone(), args)

compiler/rustc_builtin_macros/src/deriving/cmp/partial_eq.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ pub fn expand_deriving_partial_eq(
2626
|cx, fold| match fold {
2727
CsFold::Single(field) => {
2828
let [other_expr] = &field.other_selflike_exprs[..] else {
29-
cx.span_bug(field.span, "not exactly 2 arguments in `derive(PartialEq)`");
29+
cx.dcx()
30+
.span_bug(field.span, "not exactly 2 arguments in `derive(PartialEq)`");
3031
};
3132

3233
// We received arguments of type `&T`. Convert them to type `T` by stripping

0 commit comments

Comments
 (0)