Skip to content

Commit ff40ad4

Browse files
committed
Shorten some error invocations.
- `struct_foo` + `emit` -> `foo` - `create_foo` + `emit` -> `emit_foo` I have made recent commits in other PRs that have removed some of these shortcuts for combinations with few uses, e.g. `struct_span_err_with_code`. But for the remaining combinations that have high levels of use, we might as well use them wherever possible.
1 parent 4864cb8 commit ff40ad4

File tree

13 files changed

+30
-34
lines changed

13 files changed

+30
-34
lines changed

compiler/rustc_builtin_macros/src/source_util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ pub fn expand_include<'cx>(
155155
if self.p.token != token::Eof {
156156
let token = pprust::token_to_string(&self.p.token);
157157
let msg = format!("expected item, found `{token}`");
158-
self.p.dcx().struct_span_err(self.p.token.span, msg).emit();
158+
self.p.dcx().span_err(self.p.token.span, msg);
159159
}
160160

161161
break;

compiler/rustc_expand/src/mbe/diagnostics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ impl<'a, 'cx, 'matcher> Tracker<'matcher> for CollectTrackerAndEmitter<'a, 'cx,
180180
}
181181
Error(err_sp, msg) => {
182182
let span = err_sp.substitute_dummy(self.root_span);
183-
self.cx.dcx().struct_span_err(span, msg.clone()).emit();
183+
self.cx.dcx().span_err(span, msg.clone());
184184
self.result = Some(DummyResult::any(span));
185185
}
186186
ErrorReported(_) => self.result = Some(DummyResult::any(self.root_span)),

compiler/rustc_expand/src/mbe/macro_rules.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ pub fn compile_declarative_macro(
458458
return dummy_syn_ext();
459459
}
460460
Error(sp, msg) => {
461-
sess.dcx().struct_span_err(sp.substitute_dummy(def.span), msg).emit();
461+
sess.dcx().span_err(sp.substitute_dummy(def.span), msg);
462462
return dummy_syn_ext();
463463
}
464464
ErrorReported(_) => {

compiler/rustc_hir_analysis/src/check/intrinsic.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ pub fn check_platform_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>)
552552
sym::simd_shuffle_generic => (2, 1, vec![param(0), param(0)], param(1)),
553553
_ => {
554554
let msg = format!("unrecognized platform-specific intrinsic function: `{name}`");
555-
tcx.dcx().struct_span_err(it.span, msg).emit();
555+
tcx.dcx().span_err(it.span, msg);
556556
return;
557557
}
558558
};

compiler/rustc_hir_analysis/src/check/intrinsicck.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
325325
op.is_clobber(),
326326
) {
327327
let msg = format!("cannot use register `{}`: {}", reg.name(), msg);
328-
self.tcx.dcx().struct_span_err(*op_sp, msg).emit();
328+
self.tcx.dcx().span_err(*op_sp, msg);
329329
continue;
330330
}
331331
}
@@ -364,7 +364,7 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
364364
reg_class.name(),
365365
feature
366366
);
367-
self.tcx.dcx().struct_span_err(*op_sp, msg).emit();
367+
self.tcx.dcx().span_err(*op_sp, msg);
368368
// register isn't enabled, don't do more checks
369369
continue;
370370
}
@@ -378,7 +378,7 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
378378
.intersperse(", ")
379379
.collect::<String>(),
380380
);
381-
self.tcx.dcx().struct_span_err(*op_sp, msg).emit();
381+
self.tcx.dcx().span_err(*op_sp, msg);
382382
// register isn't enabled, don't do more checks
383383
continue;
384384
}

compiler/rustc_resolve/src/imports.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1371,12 +1371,12 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
13711371
let ImportKind::Glob { id, is_prelude, .. } = import.kind else { unreachable!() };
13721372

13731373
let ModuleOrUniformRoot::Module(module) = import.imported_module.get().unwrap() else {
1374-
self.dcx().create_err(CannotGlobImportAllCrates { span: import.span }).emit();
1374+
self.dcx().emit_err(CannotGlobImportAllCrates { span: import.span });
13751375
return;
13761376
};
13771377

13781378
if module.is_trait() {
1379-
self.dcx().create_err(ItemsInTraitsAreNotImportable { span: import.span }).emit();
1379+
self.dcx().emit_err(ItemsInTraitsAreNotImportable { span: import.span });
13801380
return;
13811381
} else if module == import.parent_scope.module {
13821382
return;

compiler/rustc_resolve/src/late.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2301,7 +2301,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
23012301
let report_error = |this: &Self, ns| {
23022302
if this.should_report_errs() {
23032303
let what = if ns == TypeNS { "type parameters" } else { "local variables" };
2304-
this.r.dcx().create_err(ImportsCannotReferTo { span: ident.span, what }).emit();
2304+
this.r.dcx().emit_err(ImportsCannotReferTo { span: ident.span, what });
23052305
}
23062306
};
23072307

compiler/rustc_session/src/session.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1447,7 +1447,7 @@ impl EarlyDiagCtxt {
14471447
#[allow(rustc::untranslatable_diagnostic)]
14481448
#[allow(rustc::diagnostic_outside_of_impl)]
14491449
pub fn early_note(&self, msg: impl Into<DiagnosticMessage>) {
1450-
self.dcx.struct_note(msg).emit()
1450+
self.dcx.note(msg)
14511451
}
14521452

14531453
#[allow(rustc::untranslatable_diagnostic)]
@@ -1460,13 +1460,13 @@ impl EarlyDiagCtxt {
14601460
#[allow(rustc::diagnostic_outside_of_impl)]
14611461
#[must_use = "ErrorGuaranteed must be returned from `run_compiler` in order to exit with a non-zero status code"]
14621462
pub fn early_err(&self, msg: impl Into<DiagnosticMessage>) -> ErrorGuaranteed {
1463-
self.dcx.struct_err(msg).emit()
1463+
self.dcx.err(msg)
14641464
}
14651465

14661466
#[allow(rustc::untranslatable_diagnostic)]
14671467
#[allow(rustc::diagnostic_outside_of_impl)]
14681468
pub fn early_fatal(&self, msg: impl Into<DiagnosticMessage>) -> ! {
1469-
self.dcx.struct_fatal(msg).emit()
1469+
self.dcx.fatal(msg)
14701470
}
14711471

14721472
#[allow(rustc::untranslatable_diagnostic)]
@@ -1481,7 +1481,7 @@ impl EarlyDiagCtxt {
14811481
#[allow(rustc::untranslatable_diagnostic)]
14821482
#[allow(rustc::diagnostic_outside_of_impl)]
14831483
pub fn early_warn(&self, msg: impl Into<DiagnosticMessage>) {
1484-
self.dcx.struct_warn(msg).emit()
1484+
self.dcx.warn(msg)
14851485
}
14861486

14871487
pub fn initialize_checked_jobserver(&self) {

src/librustdoc/config.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ impl Options {
421421
let paths = match theme::load_css_paths(content) {
422422
Ok(p) => p,
423423
Err(e) => {
424-
dcx.struct_err(e).emit();
424+
dcx.err(e);
425425
return Err(1);
426426
}
427427
};
@@ -452,10 +452,10 @@ impl Options {
452452
let input = PathBuf::from(if describe_lints {
453453
"" // dummy, this won't be used
454454
} else if matches.free.is_empty() {
455-
dcx.struct_err("missing file operand").emit();
455+
dcx.err("missing file operand");
456456
return Err(1);
457457
} else if matches.free.len() > 1 {
458-
dcx.struct_err("too many file operands").emit();
458+
dcx.err("too many file operands");
459459
return Err(1);
460460
} else {
461461
&matches.free[0]
@@ -467,7 +467,7 @@ impl Options {
467467
let extern_html_root_urls = match parse_extern_html_roots(matches) {
468468
Ok(ex) => ex,
469469
Err(err) => {
470-
dcx.struct_err(err).emit();
470+
dcx.err(err);
471471
return Err(1);
472472
}
473473
};
@@ -534,7 +534,7 @@ impl Options {
534534
let output = matches.opt_str("output").map(|s| PathBuf::from(&s));
535535
let output = match (out_dir, output) {
536536
(Some(_), Some(_)) => {
537-
dcx.struct_err("cannot use both 'out-dir' and 'output' at once").emit();
537+
dcx.err("cannot use both 'out-dir' and 'output' at once");
538538
return Err(1);
539539
}
540540
(Some(out_dir), None) => out_dir,
@@ -549,7 +549,7 @@ impl Options {
549549

550550
if let Some(ref p) = extension_css {
551551
if !p.is_file() {
552-
dcx.struct_err("option --extend-css argument must be a file").emit();
552+
dcx.err("option --extend-css argument must be a file");
553553
return Err(1);
554554
}
555555
}
@@ -567,7 +567,7 @@ impl Options {
567567
let paths = match theme::load_css_paths(content) {
568568
Ok(p) => p,
569569
Err(e) => {
570-
dcx.struct_err(e).emit();
570+
dcx.err(e);
571571
return Err(1);
572572
}
573573
};
@@ -589,7 +589,7 @@ impl Options {
589589
}
590590
let (success, ret) = theme::test_theme_against(&theme_file, &paths, &dcx);
591591
if !success {
592-
dcx.struct_err(format!("error loading theme file: \"{theme_s}\"")).emit();
592+
dcx.err(format!("error loading theme file: \"{theme_s}\""));
593593
return Err(1);
594594
} else if !ret.is_empty() {
595595
dcx.struct_warn(format!(
@@ -626,15 +626,15 @@ impl Options {
626626
match matches.opt_str("r").as_deref() {
627627
Some("rust") | None => {}
628628
Some(s) => {
629-
dcx.struct_err(format!("unknown input format: {s}")).emit();
629+
dcx.err(format!("unknown input format: {s}"));
630630
return Err(1);
631631
}
632632
}
633633

634634
let index_page = matches.opt_str("index-page").map(|s| PathBuf::from(&s));
635635
if let Some(ref index_page) = index_page {
636636
if !index_page.is_file() {
637-
dcx.struct_err("option `--index-page` argument must be a file").emit();
637+
dcx.err("option `--index-page` argument must be a file");
638638
return Err(1);
639639
}
640640
}
@@ -646,7 +646,7 @@ impl Options {
646646
let crate_types = match parse_crate_types_from_list(matches.opt_strs("crate-type")) {
647647
Ok(types) => types,
648648
Err(e) => {
649-
dcx.struct_err(format!("unknown crate type: {e}")).emit();
649+
dcx.err(format!("unknown crate type: {e}"));
650650
return Err(1);
651651
}
652652
};
@@ -664,7 +664,7 @@ impl Options {
664664
out_fmt
665665
}
666666
Err(e) => {
667-
dcx.struct_err(e).emit();
667+
dcx.err(e);
668668
return Err(1);
669669
}
670670
},

src/librustdoc/externalfiles.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ pub(crate) fn load_string<P: AsRef<Path>>(
9696
match str::from_utf8(&contents) {
9797
Ok(s) => Ok(s.to_string()),
9898
Err(_) => {
99-
dcx.struct_err(format!("error reading `{}`: not UTF-8", file_path.display())).emit();
99+
dcx.err(format!("error reading `{}`: not UTF-8", file_path.display()));
100100
Err(LoadStringError::BadUtf8)
101101
}
102102
}

src/librustdoc/html/render/context.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -757,8 +757,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
757757

758758
// Flush pending errors.
759759
Rc::get_mut(&mut self.shared).unwrap().fs.close();
760-
let nb_errors =
761-
self.shared.errors.iter().map(|err| self.tcx().dcx().struct_err(err).emit()).count();
760+
let nb_errors = self.shared.errors.iter().map(|err| self.tcx().dcx().err(err)).count();
762761
if nb_errors > 0 {
763762
Err(Error::new(io::Error::new(io::ErrorKind::Other, "I/O error"), ""))
764763
} else {

src/librustdoc/lib.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -676,10 +676,7 @@ type MainResult = Result<(), ErrorGuaranteed>;
676676
fn wrap_return(dcx: &rustc_errors::DiagCtxt, res: Result<(), String>) -> MainResult {
677677
match res {
678678
Ok(()) => dcx.has_errors().map_or(Ok(()), Err),
679-
Err(err) => {
680-
let reported = dcx.struct_err(err).emit();
681-
Err(reported)
682-
}
679+
Err(err) => Err(dcx.err(err)),
683680
}
684681
}
685682

src/librustdoc/theme.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ pub(crate) fn test_theme_against<P: AsRef<Path>>(
244244
{
245245
Ok(c) => c,
246246
Err(e) => {
247-
dcx.struct_err(e).emit();
247+
dcx.err(e);
248248
return (false, vec![]);
249249
}
250250
};

0 commit comments

Comments
 (0)