diff --git a/compiler/rustc_builtin_macros/src/source_util.rs b/compiler/rustc_builtin_macros/src/source_util.rs index caebb12919f..e7d7b4a7012 100644 --- a/compiler/rustc_builtin_macros/src/source_util.rs +++ b/compiler/rustc_builtin_macros/src/source_util.rs @@ -155,7 +155,7 @@ pub fn expand_include<'cx>( if self.p.token != token::Eof { let token = pprust::token_to_string(&self.p.token); let msg = format!("expected item, found `{token}`"); - self.p.dcx().struct_span_err(self.p.token.span, msg).emit(); + self.p.dcx().span_err(self.p.token.span, msg); } break; diff --git a/compiler/rustc_expand/src/mbe/diagnostics.rs b/compiler/rustc_expand/src/mbe/diagnostics.rs index 2746e888b8d..eec86c36aed 100644 --- a/compiler/rustc_expand/src/mbe/diagnostics.rs +++ b/compiler/rustc_expand/src/mbe/diagnostics.rs @@ -180,7 +180,7 @@ impl<'a, 'cx, 'matcher> Tracker<'matcher> for CollectTrackerAndEmitter<'a, 'cx, } Error(err_sp, msg) => { let span = err_sp.substitute_dummy(self.root_span); - self.cx.dcx().struct_span_err(span, msg.clone()).emit(); + self.cx.dcx().span_err(span, msg.clone()); self.result = Some(DummyResult::any(span)); } ErrorReported(_) => self.result = Some(DummyResult::any(self.root_span)), diff --git a/compiler/rustc_expand/src/mbe/macro_rules.rs b/compiler/rustc_expand/src/mbe/macro_rules.rs index 68296700987..a56c980791a 100644 --- a/compiler/rustc_expand/src/mbe/macro_rules.rs +++ b/compiler/rustc_expand/src/mbe/macro_rules.rs @@ -458,7 +458,7 @@ pub fn compile_declarative_macro( return dummy_syn_ext(); } Error(sp, msg) => { - sess.dcx().struct_span_err(sp.substitute_dummy(def.span), msg).emit(); + sess.dcx().span_err(sp.substitute_dummy(def.span), msg); return dummy_syn_ext(); } ErrorReported(_) => { diff --git a/compiler/rustc_hir_analysis/src/check/intrinsic.rs b/compiler/rustc_hir_analysis/src/check/intrinsic.rs index 6cbb43d747f..14cac1418ee 100644 --- a/compiler/rustc_hir_analysis/src/check/intrinsic.rs +++ b/compiler/rustc_hir_analysis/src/check/intrinsic.rs @@ -552,7 +552,7 @@ pub fn check_platform_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) sym::simd_shuffle_generic => (2, 1, vec![param(0), param(0)], param(1)), _ => { let msg = format!("unrecognized platform-specific intrinsic function: `{name}`"); - tcx.dcx().struct_span_err(it.span, msg).emit(); + tcx.dcx().span_err(it.span, msg); return; } }; diff --git a/compiler/rustc_hir_analysis/src/check/intrinsicck.rs b/compiler/rustc_hir_analysis/src/check/intrinsicck.rs index 1979f52eda9..0835ae76b95 100644 --- a/compiler/rustc_hir_analysis/src/check/intrinsicck.rs +++ b/compiler/rustc_hir_analysis/src/check/intrinsicck.rs @@ -325,7 +325,7 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> { op.is_clobber(), ) { let msg = format!("cannot use register `{}`: {}", reg.name(), msg); - self.tcx.dcx().struct_span_err(*op_sp, msg).emit(); + self.tcx.dcx().span_err(*op_sp, msg); continue; } } @@ -364,7 +364,7 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> { reg_class.name(), feature ); - self.tcx.dcx().struct_span_err(*op_sp, msg).emit(); + self.tcx.dcx().span_err(*op_sp, msg); // register isn't enabled, don't do more checks continue; } @@ -378,7 +378,7 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> { .intersperse(", ") .collect::(), ); - self.tcx.dcx().struct_span_err(*op_sp, msg).emit(); + self.tcx.dcx().span_err(*op_sp, msg); // register isn't enabled, don't do more checks continue; } diff --git a/compiler/rustc_resolve/src/imports.rs b/compiler/rustc_resolve/src/imports.rs index 456a3bb1204..2ebf4c20562 100644 --- a/compiler/rustc_resolve/src/imports.rs +++ b/compiler/rustc_resolve/src/imports.rs @@ -1371,12 +1371,12 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { let ImportKind::Glob { id, is_prelude, .. } = import.kind else { unreachable!() }; let ModuleOrUniformRoot::Module(module) = import.imported_module.get().unwrap() else { - self.dcx().create_err(CannotGlobImportAllCrates { span: import.span }).emit(); + self.dcx().emit_err(CannotGlobImportAllCrates { span: import.span }); return; }; if module.is_trait() { - self.dcx().create_err(ItemsInTraitsAreNotImportable { span: import.span }).emit(); + self.dcx().emit_err(ItemsInTraitsAreNotImportable { span: import.span }); return; } else if module == import.parent_scope.module { return; diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index 27d92eb765a..0616cd5305b 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -2301,7 +2301,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> { let report_error = |this: &Self, ns| { if this.should_report_errs() { let what = if ns == TypeNS { "type parameters" } else { "local variables" }; - this.r.dcx().create_err(ImportsCannotReferTo { span: ident.span, what }).emit(); + this.r.dcx().emit_err(ImportsCannotReferTo { span: ident.span, what }); } }; diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index 720599f6095..bc6d6f7d56c 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -1447,7 +1447,7 @@ impl EarlyDiagCtxt { #[allow(rustc::untranslatable_diagnostic)] #[allow(rustc::diagnostic_outside_of_impl)] pub fn early_note(&self, msg: impl Into) { - self.dcx.struct_note(msg).emit() + self.dcx.note(msg) } #[allow(rustc::untranslatable_diagnostic)] @@ -1460,13 +1460,13 @@ impl EarlyDiagCtxt { #[allow(rustc::diagnostic_outside_of_impl)] #[must_use = "ErrorGuaranteed must be returned from `run_compiler` in order to exit with a non-zero status code"] pub fn early_err(&self, msg: impl Into) -> ErrorGuaranteed { - self.dcx.struct_err(msg).emit() + self.dcx.err(msg) } #[allow(rustc::untranslatable_diagnostic)] #[allow(rustc::diagnostic_outside_of_impl)] pub fn early_fatal(&self, msg: impl Into) -> ! { - self.dcx.struct_fatal(msg).emit() + self.dcx.fatal(msg) } #[allow(rustc::untranslatable_diagnostic)] @@ -1481,7 +1481,7 @@ impl EarlyDiagCtxt { #[allow(rustc::untranslatable_diagnostic)] #[allow(rustc::diagnostic_outside_of_impl)] pub fn early_warn(&self, msg: impl Into) { - self.dcx.struct_warn(msg).emit() + self.dcx.warn(msg) } pub fn initialize_checked_jobserver(&self) { diff --git a/src/librustdoc/config.rs b/src/librustdoc/config.rs index 614a64d4020..5a6001840e0 100644 --- a/src/librustdoc/config.rs +++ b/src/librustdoc/config.rs @@ -421,7 +421,7 @@ impl Options { let paths = match theme::load_css_paths(content) { Ok(p) => p, Err(e) => { - dcx.struct_err(e).emit(); + dcx.err(e); return Err(1); } }; @@ -452,10 +452,10 @@ impl Options { let input = PathBuf::from(if describe_lints { "" // dummy, this won't be used } else if matches.free.is_empty() { - dcx.struct_err("missing file operand").emit(); + dcx.err("missing file operand"); return Err(1); } else if matches.free.len() > 1 { - dcx.struct_err("too many file operands").emit(); + dcx.err("too many file operands"); return Err(1); } else { &matches.free[0] @@ -467,7 +467,7 @@ impl Options { let extern_html_root_urls = match parse_extern_html_roots(matches) { Ok(ex) => ex, Err(err) => { - dcx.struct_err(err).emit(); + dcx.err(err); return Err(1); } }; @@ -534,7 +534,7 @@ impl Options { let output = matches.opt_str("output").map(|s| PathBuf::from(&s)); let output = match (out_dir, output) { (Some(_), Some(_)) => { - dcx.struct_err("cannot use both 'out-dir' and 'output' at once").emit(); + dcx.err("cannot use both 'out-dir' and 'output' at once"); return Err(1); } (Some(out_dir), None) => out_dir, @@ -549,7 +549,7 @@ impl Options { if let Some(ref p) = extension_css { if !p.is_file() { - dcx.struct_err("option --extend-css argument must be a file").emit(); + dcx.err("option --extend-css argument must be a file"); return Err(1); } } @@ -567,7 +567,7 @@ impl Options { let paths = match theme::load_css_paths(content) { Ok(p) => p, Err(e) => { - dcx.struct_err(e).emit(); + dcx.err(e); return Err(1); } }; @@ -589,7 +589,7 @@ impl Options { } let (success, ret) = theme::test_theme_against(&theme_file, &paths, &dcx); if !success { - dcx.struct_err(format!("error loading theme file: \"{theme_s}\"")).emit(); + dcx.err(format!("error loading theme file: \"{theme_s}\"")); return Err(1); } else if !ret.is_empty() { dcx.struct_warn(format!( @@ -626,7 +626,7 @@ impl Options { match matches.opt_str("r").as_deref() { Some("rust") | None => {} Some(s) => { - dcx.struct_err(format!("unknown input format: {s}")).emit(); + dcx.err(format!("unknown input format: {s}")); return Err(1); } } @@ -634,7 +634,7 @@ impl Options { let index_page = matches.opt_str("index-page").map(|s| PathBuf::from(&s)); if let Some(ref index_page) = index_page { if !index_page.is_file() { - dcx.struct_err("option `--index-page` argument must be a file").emit(); + dcx.err("option `--index-page` argument must be a file"); return Err(1); } } @@ -646,7 +646,7 @@ impl Options { let crate_types = match parse_crate_types_from_list(matches.opt_strs("crate-type")) { Ok(types) => types, Err(e) => { - dcx.struct_err(format!("unknown crate type: {e}")).emit(); + dcx.err(format!("unknown crate type: {e}")); return Err(1); } }; @@ -664,7 +664,7 @@ impl Options { out_fmt } Err(e) => { - dcx.struct_err(e).emit(); + dcx.err(e); return Err(1); } }, diff --git a/src/librustdoc/externalfiles.rs b/src/librustdoc/externalfiles.rs index 8bc0cdf3a95..57e82b877bf 100644 --- a/src/librustdoc/externalfiles.rs +++ b/src/librustdoc/externalfiles.rs @@ -96,7 +96,7 @@ pub(crate) fn load_string>( match str::from_utf8(&contents) { Ok(s) => Ok(s.to_string()), Err(_) => { - dcx.struct_err(format!("error reading `{}`: not UTF-8", file_path.display())).emit(); + dcx.err(format!("error reading `{}`: not UTF-8", file_path.display())); Err(LoadStringError::BadUtf8) } } diff --git a/src/librustdoc/html/render/context.rs b/src/librustdoc/html/render/context.rs index aad63f8578a..fc6f51e8272 100644 --- a/src/librustdoc/html/render/context.rs +++ b/src/librustdoc/html/render/context.rs @@ -757,8 +757,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> { // Flush pending errors. Rc::get_mut(&mut self.shared).unwrap().fs.close(); - let nb_errors = - self.shared.errors.iter().map(|err| self.tcx().dcx().struct_err(err).emit()).count(); + let nb_errors = self.shared.errors.iter().map(|err| self.tcx().dcx().err(err)).count(); if nb_errors > 0 { Err(Error::new(io::Error::new(io::ErrorKind::Other, "I/O error"), "")) } else { diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index ad1838c53ad..d962beda4be 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -676,10 +676,7 @@ type MainResult = Result<(), ErrorGuaranteed>; fn wrap_return(dcx: &rustc_errors::DiagCtxt, res: Result<(), String>) -> MainResult { match res { Ok(()) => dcx.has_errors().map_or(Ok(()), Err), - Err(err) => { - let reported = dcx.struct_err(err).emit(); - Err(reported) - } + Err(err) => Err(dcx.err(err)), } } diff --git a/src/librustdoc/theme.rs b/src/librustdoc/theme.rs index 98010b056c9..31d32e23f8e 100644 --- a/src/librustdoc/theme.rs +++ b/src/librustdoc/theme.rs @@ -244,7 +244,7 @@ pub(crate) fn test_theme_against>( { Ok(c) => c, Err(e) => { - dcx.struct_err(e).emit(); + dcx.err(e); return (false, vec![]); } };