From 603380ed39ef81d005e4ddf393ec951fbf5cf4ea Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 9 Sep 2026 13:39:59 +1000 Subject: [PATCH] Avoid some `struct_foo(..).emit()` chains These can be replaced with `foo(..)`. Also make the return type of `report_unterminated_block_comment` more precise. --- compiler/rustc_ast_lowering/src/item.rs | 4 +--- compiler/rustc_ast_lowering/src/lib.rs | 13 ++++++------- compiler/rustc_hir_analysis/src/check/check.rs | 2 +- .../src/outlives/implicit_infer.rs | 10 ++++------ compiler/rustc_hir_typeck/src/intrinsicck.rs | 2 +- compiler/rustc_parse/src/lexer/mod.rs | 2 +- 6 files changed, 14 insertions(+), 19 deletions(-) diff --git a/compiler/rustc_ast_lowering/src/item.rs b/compiler/rustc_ast_lowering/src/item.rs index b5e28d21a26..60bb6e62b64 100644 --- a/compiler/rustc_ast_lowering/src/item.rs +++ b/compiler/rustc_ast_lowering/src/item.rs @@ -800,9 +800,7 @@ impl<'hir> LoweringContext<'_, 'hir> { fn lower_variant(&mut self, item_kind: &ItemKind, v: &Variant) -> hir::Variant<'hir> { if v.ident.name == kw::Underscore && self.tcx.features().unnamed_enum_variants() { // FIXME(#156628): lower unnamed enum variants to HIR. - self.dcx() - .struct_span_fatal(v.span, "unnamed enum variants are not yet implemented") - .emit() + self.dcx().span_fatal(v.span, "unnamed enum variants are not yet implemented"); } let hir_id = self.lower_node_id(v.id); self.lower_attrs(hir_id, &v.attrs, v.span, Target::Variant); diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index a27dc47bf27..b196e1de8e8 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -1795,9 +1795,9 @@ impl<'hir> LoweringContext<'_, 'hir> { if expr::WillCreateDefIdsVisitor.visit_expr(expr).is_break() { // FIXME(mgca): make this non-fatal once we have a better way to handle // nested items in invalid `direct_const_arg!()` arguments. - self.dcx().struct_span_fatal(span, msg).emit() + self.dcx().span_fatal(span, msg) } else { - self.dcx().struct_span_err(span, msg).emit() + self.dcx().span_err(span, msg) } } @@ -2983,9 +2983,8 @@ impl<'hir> LoweringContext<'_, 'hir> { let literal = self.lower_lit(literal, span); let kind = if !matches!(literal.node, LitKind::Int(..)) { - let err = - self.dcx().struct_span_err(expr.span, "negated literal must be an integer"); - hir::ConstArgKind::Error(err.emit()) + let err = self.dcx().span_err(expr.span, "negated literal must be an integer"); + hir::ConstArgKind::Error(err) } else { hir::ConstArgKind::Literal { lit: literal.node, negated: true } }; @@ -3389,9 +3388,9 @@ impl UnrepresentableConstArgError { // FIXME(mgca): make this non-fatal once we have a better way to handle // nested items in const args // Issue: https://github.com/rust-lang/rust/issues/154539 - lowering_context.dcx().struct_span_fatal(self.span, msg).emit() + lowering_context.dcx().span_fatal(self.span, msg) } else { - lowering_context.dcx().struct_span_err(self.span, msg).emit() + lowering_context.dcx().span_err(self.span, msg) }; ConstArg { diff --git a/compiler/rustc_hir_analysis/src/check/check.rs b/compiler/rustc_hir_analysis/src/check/check.rs index d5bc834b831..9f8cde7892f 100644 --- a/compiler/rustc_hir_analysis/src/check/check.rs +++ b/compiler/rustc_hir_analysis/src/check/check.rs @@ -1554,7 +1554,7 @@ fn check_scalable_vector(tcx: TyCtxt<'_>, span: Span, def_id: LocalDefId, scalab return; } ScalableElt::ElementCount(..) if fields.len() >= 2 => { - tcx.dcx().struct_span_err(span, "scalable vectors cannot have multiple fields").emit(); + tcx.dcx().span_err(span, "scalable vectors cannot have multiple fields"); return; } ScalableElt::Container if fields.is_empty() => { diff --git a/compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs b/compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs index 131812a364e..ca7e246a9e0 100644 --- a/compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs +++ b/compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs @@ -97,12 +97,10 @@ pub(super) fn infer_clauses( } else { "overflow computing implied lifetime bounds".to_string() }; - tcx.dcx() - .struct_span_fatal( - clauses_added.iter().map(|id| tcx.def_span(*id)).collect::>(), - msg, - ) - .emit(); + tcx.dcx().span_fatal( + clauses_added.iter().map(|id| tcx.def_span(*id)).collect::>(), + msg, + ); } } diff --git a/compiler/rustc_hir_typeck/src/intrinsicck.rs b/compiler/rustc_hir_typeck/src/intrinsicck.rs index d63bffab882..989c63ac2f3 100644 --- a/compiler/rustc_hir_typeck/src/intrinsicck.rs +++ b/compiler/rustc_hir_typeck/src/intrinsicck.rs @@ -78,7 +78,7 @@ fn check_transmute<'tcx>( let normalize = |ty: Unnormalized<'tcx, Ty<'tcx>>| -> Result, ErrorGuaranteed> { tcx.try_normalize_erasing_regions(typing_env, ty).map_err(|err| { let err = LayoutError::NormalizationFailure(ty.skip_normalization(), err); - tcx.dcx().struct_span_err(span, err.to_string()).emit() + tcx.dcx().span_err(span, err.to_string()) }) }; diff --git a/compiler/rustc_parse/src/lexer/mod.rs b/compiler/rustc_parse/src/lexer/mod.rs index 6ed61a9f4e0..2afb55b02e2 100644 --- a/compiler/rustc_parse/src/lexer/mod.rs +++ b/compiler/rustc_parse/src/lexer/mod.rs @@ -1007,7 +1007,7 @@ impl<'psess, 'src> Lexer<'psess, 'src> { err.emit() } - fn report_unterminated_block_comment(&self, start: BytePos, doc_style: Option) { + fn report_unterminated_block_comment(&self, start: BytePos, doc_style: Option) -> ! { let msg = match doc_style { Some(_) => "unterminated block doc-comment", None => "unterminated block comment",