Skip to content

Commit 464e02a

Browse files
authored
Rollup merge of #113884 - oli-obk:delay_span_bug_detrans_late, r=davidtwco
Don't translate compiler-internal bug messages These are not very useful to be translated, as * translators would get really weird and bad english versions to start out from, * compiler devs have to do some work for what is supposed to be dead code and just a sanity check, * the target audience is other compiler devs. r? `@davidtwco`
2 parents 8ac957a + d97ec97 commit 464e02a

File tree

6 files changed

+27
-45
lines changed

6 files changed

+27
-45
lines changed

Diff for: compiler/rustc_errors/src/lib.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -1003,7 +1003,7 @@ impl Handler {
10031003
self.emit_diag_at_span(Diagnostic::new_with_code(Warning(None), Some(code), msg), span);
10041004
}
10051005

1006-
pub fn span_bug(&self, span: impl Into<MultiSpan>, msg: impl Into<DiagnosticMessage>) -> ! {
1006+
pub fn span_bug(&self, span: impl Into<MultiSpan>, msg: impl Into<String>) -> ! {
10071007
self.inner.borrow_mut().span_bug(span, msg)
10081008
}
10091009

@@ -1012,7 +1012,7 @@ impl Handler {
10121012
pub fn delay_span_bug(
10131013
&self,
10141014
span: impl Into<MultiSpan>,
1015-
msg: impl Into<DiagnosticMessage>,
1015+
msg: impl Into<String>,
10161016
) -> ErrorGuaranteed {
10171017
self.inner.borrow_mut().delay_span_bug(span, msg)
10181018
}
@@ -1596,8 +1596,8 @@ impl HandlerInner {
15961596
}
15971597

15981598
#[track_caller]
1599-
fn span_bug(&mut self, sp: impl Into<MultiSpan>, msg: impl Into<DiagnosticMessage>) -> ! {
1600-
self.emit_diag_at_span(Diagnostic::new(Bug, msg), sp);
1599+
fn span_bug(&mut self, sp: impl Into<MultiSpan>, msg: impl Into<String>) -> ! {
1600+
self.emit_diag_at_span(Diagnostic::new(Bug, msg.into()), sp);
16011601
panic::panic_any(ExplicitBug);
16021602
}
16031603

@@ -1610,7 +1610,7 @@ impl HandlerInner {
16101610
fn delay_span_bug(
16111611
&mut self,
16121612
sp: impl Into<MultiSpan>,
1613-
msg: impl Into<DiagnosticMessage>,
1613+
msg: impl Into<String>,
16141614
) -> ErrorGuaranteed {
16151615
// This is technically `self.treat_err_as_bug()` but `delay_span_bug` is called before
16161616
// incrementing `err_count` by one, so we need to +1 the comparing.
@@ -1619,9 +1619,9 @@ impl HandlerInner {
16191619
self.err_count() + self.lint_err_count + self.delayed_bug_count() + 1 >= c.get()
16201620
}) {
16211621
// FIXME: don't abort here if report_delayed_bugs is off
1622-
self.span_bug(sp, msg);
1622+
self.span_bug(sp, msg.into());
16231623
}
1624-
let mut diagnostic = Diagnostic::new(Level::DelayedBug, msg);
1624+
let mut diagnostic = Diagnostic::new(Level::DelayedBug, msg.into());
16251625
diagnostic.set_span(sp.into());
16261626
self.emit_diagnostic(&mut diagnostic).unwrap()
16271627
}

Diff for: compiler/rustc_expand/src/base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1147,7 +1147,7 @@ impl<'a> ExtCtxt<'a> {
11471147
pub fn span_warn<S: Into<MultiSpan>>(&self, sp: S, msg: impl Into<DiagnosticMessage>) {
11481148
self.sess.parse_sess.span_diagnostic.span_warn(sp, msg);
11491149
}
1150-
pub fn span_bug<S: Into<MultiSpan>>(&self, sp: S, msg: impl Into<DiagnosticMessage>) -> ! {
1150+
pub fn span_bug<S: Into<MultiSpan>>(&self, sp: S, msg: impl Into<String>) -> ! {
11511151
self.sess.parse_sess.span_diagnostic.span_bug(sp, msg);
11521152
}
11531153
pub fn trace_macros_diag(&mut self) {

Diff for: compiler/rustc_middle/src/ty/sty.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use hir::def::DefKind;
1515
use polonius_engine::Atom;
1616
use rustc_data_structures::captures::Captures;
1717
use rustc_data_structures::intern::Interned;
18-
use rustc_error_messages::DiagnosticMessage;
1918
use rustc_errors::{DiagnosticArgValue, ErrorGuaranteed, IntoDiagnosticArg, MultiSpan};
2019
use rustc_hir as hir;
2120
use rustc_hir::def_id::DefId;
@@ -1991,7 +1990,7 @@ impl<'tcx> Ty<'tcx> {
19911990
pub fn new_error_with_message<S: Into<MultiSpan>>(
19921991
tcx: TyCtxt<'tcx>,
19931992
span: S,
1994-
msg: impl Into<DiagnosticMessage>,
1993+
msg: impl Into<String>,
19951994
) -> Ty<'tcx> {
19961995
let reported = tcx.sess.delay_span_bug(span, msg);
19971996
Ty::new(tcx, Error(reported))

Diff for: compiler/rustc_parse/src/parser/diagnostics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ impl<'a> Parser<'a> {
247247
self.sess.span_diagnostic.struct_span_err(sp, m)
248248
}
249249

250-
pub fn span_bug<S: Into<MultiSpan>>(&self, sp: S, m: impl Into<DiagnosticMessage>) -> ! {
250+
pub fn span_bug<S: Into<MultiSpan>>(&self, sp: S, m: impl Into<String>) -> ! {
251251
self.sess.span_diagnostic.span_bug(sp, m)
252252
}
253253

Diff for: compiler/rustc_parse/src/parser/pat.rs

+16-33
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use crate::errors::{
88
TrailingVertNotAllowed, UnexpectedLifetimeInPattern, UnexpectedVertVertBeforeFunctionParam,
99
UnexpectedVertVertInPattern,
1010
};
11-
use crate::fluent_generated as fluent;
1211
use crate::{maybe_recover_from_interpolated_ty_qpath, maybe_whole};
1312
use rustc_ast::mut_visit::{noop_visit_pat, MutVisitor};
1413
use rustc_ast::ptr::P;
@@ -214,41 +213,25 @@ impl<'a> Parser<'a> {
214213

215214
if let PatKind::Or(pats) = &pat.kind {
216215
let span = pat.span;
217-
218-
if trailing_vert {
219-
// We already emitted an error and suggestion to remove the trailing vert. Don't
220-
// emit again.
221-
222-
// FIXME(#100717): pass `TopLevelOrPatternNotAllowed::* { sub: None }` to
223-
// `delay_span_bug()` instead of fluent message
224-
self.sess.span_diagnostic.delay_span_bug(
225-
span,
226-
match syntax_loc {
227-
PatternLocation::LetBinding => {
228-
fluent::parse_or_pattern_not_allowed_in_let_binding
229-
}
230-
PatternLocation::FunctionParameter => {
231-
fluent::parse_or_pattern_not_allowed_in_fn_parameters
232-
}
233-
},
234-
);
216+
let pat = pprust::pat_to_string(&pat);
217+
let sub = if pats.len() == 1 {
218+
Some(TopLevelOrPatternNotAllowedSugg::RemoveLeadingVert { span, pat })
235219
} else {
236-
let pat = pprust::pat_to_string(&pat);
237-
let sub = if pats.len() == 1 {
238-
Some(TopLevelOrPatternNotAllowedSugg::RemoveLeadingVert { span, pat })
239-
} else {
240-
Some(TopLevelOrPatternNotAllowedSugg::WrapInParens { span, pat })
241-
};
220+
Some(TopLevelOrPatternNotAllowedSugg::WrapInParens { span, pat })
221+
};
242222

243-
self.sess.emit_err(match syntax_loc {
244-
PatternLocation::LetBinding => {
245-
TopLevelOrPatternNotAllowed::LetBinding { span, sub }
246-
}
247-
PatternLocation::FunctionParameter => {
248-
TopLevelOrPatternNotAllowed::FunctionParameter { span, sub }
249-
}
250-
});
223+
let mut err = self.sess.create_err(match syntax_loc {
224+
PatternLocation::LetBinding => {
225+
TopLevelOrPatternNotAllowed::LetBinding { span, sub }
226+
}
227+
PatternLocation::FunctionParameter => {
228+
TopLevelOrPatternNotAllowed::FunctionParameter { span, sub }
229+
}
230+
});
231+
if trailing_vert {
232+
err.delay_as_bug();
251233
}
234+
err.emit();
252235
}
253236

254237
Ok((pat, colon))

Diff for: compiler/rustc_session/src/session.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ impl Session {
677677
pub fn delay_span_bug<S: Into<MultiSpan>>(
678678
&self,
679679
sp: S,
680-
msg: impl Into<DiagnosticMessage>,
680+
msg: impl Into<String>,
681681
) -> ErrorGuaranteed {
682682
self.diagnostic().delay_span_bug(sp, msg)
683683
}

0 commit comments

Comments
 (0)