Skip to content

Commit 8c87d07

Browse files
Remove eagerly_format from DiagCtxt
1 parent 43221b4 commit 8c87d07

4 files changed

Lines changed: 19 additions & 42 deletions

File tree

compiler/rustc_errors/src/lib.rs

Lines changed: 8 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ use rustc_span::{DUMMY_SP, Span};
6666
use tracing::debug;
6767

6868
use crate::emitter::TimingEvent;
69+
use crate::formatting::DiagMessageAddArg;
6970
pub use crate::formatting::format_diag_message;
7071
use crate::timings::TimingRecord;
7172

@@ -482,16 +483,6 @@ impl DiagCtxt {
482483
self.inner.borrow_mut().emitter = emitter;
483484
}
484485

485-
/// Format `message` eagerly with `args` to `DiagMessage::Eager`.
486-
pub fn eagerly_format<'a>(
487-
&self,
488-
message: DiagMessage,
489-
args: impl Iterator<Item = DiagArg<'a>>,
490-
) -> DiagMessage {
491-
let inner = self.inner.borrow();
492-
inner.eagerly_format(message, args)
493-
}
494-
495486
/// Format `message` eagerly with `args` to `String`.
496487
pub fn eagerly_format_to_string<'a>(
497488
&self,
@@ -1417,15 +1408,6 @@ impl DiagCtxtInner {
14171408
self.has_errors().or_else(|| self.delayed_bugs.get(0).map(|(_, guar)| guar).copied())
14181409
}
14191410

1420-
/// Format `message` eagerly with `args` to `DiagMessage::Eager`.
1421-
fn eagerly_format<'a>(
1422-
&self,
1423-
message: DiagMessage,
1424-
args: impl Iterator<Item = DiagArg<'a>>,
1425-
) -> DiagMessage {
1426-
DiagMessage::Str(Cow::from(self.eagerly_format_to_string(message, args)))
1427-
}
1428-
14291411
/// Format `message` eagerly with `args` to `String`.
14301412
fn eagerly_format_to_string<'a>(
14311413
&self,
@@ -1436,14 +1418,6 @@ impl DiagCtxtInner {
14361418
format_diag_message(&message, &args).to_string()
14371419
}
14381420

1439-
fn eagerly_format_for_subdiag(
1440-
&self,
1441-
diag: &DiagInner,
1442-
msg: impl Into<DiagMessage>,
1443-
) -> DiagMessage {
1444-
self.eagerly_format(msg.into(), diag.args.iter())
1445-
}
1446-
14471421
fn flush_delayed(&mut self) {
14481422
// Stashed diagnostics must be emitted before delayed bugs are flushed.
14491423
// Otherwise, we might ICE prematurely when errors would have
@@ -1493,7 +1467,7 @@ impl DiagCtxtInner {
14931467
);
14941468
}
14951469

1496-
let mut bug = if decorate { bug.decorate(self) } else { bug.inner };
1470+
let mut bug = if decorate { bug.decorate() } else { bug.inner };
14971471

14981472
// "Undelay" the delayed bugs into plain bugs.
14991473
if bug.level != DelayedBug {
@@ -1503,11 +1477,9 @@ impl DiagCtxtInner {
15031477
// We are at the `DiagInner`/`DiagCtxtInner` level rather than
15041478
// the usual `Diag`/`DiagCtxt` level, so we must augment `bug`
15051479
// in a lower-level fashion.
1506-
bug.arg("level", bug.level);
15071480
let msg = msg!(
15081481
"`flushed_delayed` got diagnostic with level {$level}, instead of the expected `DelayedBug`"
1509-
);
1510-
let msg = self.eagerly_format_for_subdiag(&bug, msg); // after the `arg` call
1482+
).arg("level", bug.level).format();
15111483
bug.sub(Note, msg, bug.span.primary_span().unwrap().into());
15121484
}
15131485
bug.level = Bug;
@@ -1542,7 +1514,7 @@ impl DelayedDiagInner {
15421514
DelayedDiagInner { inner: diagnostic, note: backtrace }
15431515
}
15441516

1545-
fn decorate(self, dcx: &DiagCtxtInner) -> DiagInner {
1517+
fn decorate(self) -> DiagInner {
15461518
// We are at the `DiagInner`/`DiagCtxtInner` level rather than the
15471519
// usual `Diag`/`DiagCtxt` level, so we must construct `diag` in a
15481520
// lower-level fashion.
@@ -1555,10 +1527,10 @@ impl DelayedDiagInner {
15551527
// Avoid the needless newline when no backtrace has been captured,
15561528
// the display impl should just be a single line.
15571529
_ => msg!("delayed at {$emitted_at} - {$note}"),
1558-
};
1559-
diag.arg("emitted_at", diag.emitted_at.clone());
1560-
diag.arg("note", self.note);
1561-
let msg = dcx.eagerly_format_for_subdiag(&diag, msg); // after the `arg` calls
1530+
}
1531+
.arg("emitted_at", diag.emitted_at.clone())
1532+
.arg("note", self.note)
1533+
.format();
15621534
diag.sub(Note, msg, diag.span.primary_span().unwrap_or(DUMMY_SP).into());
15631535
diag
15641536
}

compiler/rustc_hir_typeck/src/errors.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -989,11 +989,15 @@ impl rustc_errors::Subdiagnostic for CastUnknownPointerSub {
989989
CastUnknownPointerSub::To(span) => {
990990
let msg = msg!("needs more type information");
991991
diag.span_label(span, msg);
992-
let msg = msg!("the type information given here is insufficient to check whether the pointer cast is valid");
992+
let msg = msg!(
993+
"the type information given here is insufficient to check whether the pointer cast is valid"
994+
);
993995
diag.note(msg);
994996
}
995997
CastUnknownPointerSub::From(span) => {
996-
let msg = msg!("the type information given here is insufficient to check whether the pointer cast is valid");
998+
let msg = msg!(
999+
"the type information given here is insufficient to check whether the pointer cast is valid"
1000+
);
9971001
diag.span_label(span, msg);
9981002
}
9991003
}

compiler/rustc_lint/src/if_let_rescope.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -354,9 +354,8 @@ impl Subdiagnostic for IfLetRescopeRewrite {
354354
.chain(repeat_n('}', closing_brackets.count))
355355
.collect(),
356356
));
357-
let msg = msg!(
358-
"a `match` with a single arm can preserve the drop order up to Edition 2021"
359-
);
357+
let msg =
358+
msg!("a `match` with a single arm can preserve the drop order up to Edition 2021");
360359
diag.multipart_suggestion_with_style(
361360
msg,
362361
suggestions,

compiler/rustc_trait_selection/src/errors.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1169,7 +1169,9 @@ impl Subdiagnostic for ConsiderBorrowingParamHelp {
11691169
type_param_span
11701170
.push_span_label(span, msg!("consider borrowing this type parameter in the trait"));
11711171
}
1172-
let msg = msg!("the lifetime requirements from the `impl` do not correspond to the requirements in the `trait`");
1172+
let msg = msg!(
1173+
"the lifetime requirements from the `impl` do not correspond to the requirements in the `trait`"
1174+
);
11731175
diag.span_help(type_param_span, msg);
11741176
}
11751177
}

0 commit comments

Comments
 (0)