Skip to content

Commit 83e4f77

Browse files
committed
Shorten some error invocations.
- `struct_foo` + `emit` -> `foo` - `create_foo` + `emit` -> `emit_foo` Previous commits in this PR have removed some of these shortcuts for combinations with few uses. But for the remaining combinations that have high levels of use, we might as well use them wherever possible.
1 parent a1789b4 commit 83e4f77

File tree

13 files changed

+30
-34
lines changed

13 files changed

+30
-34
lines changed

compiler/rustc_builtin_macros/src/source_util.rs

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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ pub fn compile_declarative_macro(
489489
return dummy_syn_ext();
490490
}
491491
Error(sp, msg) => {
492-
sess.dcx().struct_span_err(sp.substitute_dummy(def.span), msg).emit();
492+
sess.dcx().span_err(sp.substitute_dummy(def.span), msg);
493493
return dummy_syn_ext();
494494
}
495495
ErrorReported(_) => {

compiler/rustc_hir_analysis/src/check/intrinsic.rs

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

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

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

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1446,7 +1446,7 @@ impl EarlyDiagCtxt {
14461446
#[allow(rustc::untranslatable_diagnostic)]
14471447
#[allow(rustc::diagnostic_outside_of_impl)]
14481448
pub fn early_note(&self, msg: impl Into<DiagnosticMessage>) {
1449-
self.dcx.struct_note(msg).emit()
1449+
self.dcx.note(msg)
14501450
}
14511451

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

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

14711471
#[allow(rustc::untranslatable_diagnostic)]
@@ -1480,7 +1480,7 @@ impl EarlyDiagCtxt {
14801480
#[allow(rustc::untranslatable_diagnostic)]
14811481
#[allow(rustc::diagnostic_outside_of_impl)]
14821482
pub fn early_warn(&self, msg: impl Into<DiagnosticMessage>) {
1483-
self.dcx.struct_warn(msg).emit()
1483+
self.dcx.warn(msg)
14841484
}
14851485

14861486
pub fn initialize_checked_jobserver(&self) {

src/librustdoc/config.rs

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

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

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

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

Lines changed: 1 addition & 1 deletion
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)