Skip to content

Commit fefe560

Browse files
committed
Remove all uses of DiagnosticBuilder::forget_guarantee().
There are only three. It's simpler to make the type `DiagnosticBuilder<'_, ()>` from the start, no matter the level, than to change the guarantee later.
1 parent 2179fbf commit fefe560

File tree

3 files changed

+20
-19
lines changed

3 files changed

+20
-19
lines changed

compiler/rustc_builtin_macros/src/test.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::util::{check_builtin_macro_attribute, warn_on_duplicate_attribute};
55
use rustc_ast::ptr::P;
66
use rustc_ast::{self as ast, attr, GenericParamKind};
77
use rustc_ast_pretty::pprust;
8-
use rustc_errors::Applicability;
8+
use rustc_errors::{Applicability, DiagnosticBuilder, Level};
99
use rustc_expand::base::*;
1010
use rustc_span::symbol::{sym, Ident, Symbol};
1111
use rustc_span::{ErrorGuaranteed, FileNameDisplayPreference, Span};
@@ -391,15 +391,14 @@ pub fn expand_test_or_bench(
391391
fn not_testable_error(cx: &ExtCtxt<'_>, attr_sp: Span, item: Option<&ast::Item>) {
392392
let dcx = cx.sess.dcx();
393393
let msg = "the `#[test]` attribute may only be used on a non-associated function";
394-
let mut err = match item.map(|i| &i.kind) {
394+
let level = match item.map(|i| &i.kind) {
395395
// These were a warning before #92959 and need to continue being that to avoid breaking
396396
// stable user code (#94508).
397-
Some(ast::ItemKind::MacCall(_)) => dcx.struct_span_warn(attr_sp, msg),
398-
// `.forget_guarantee()` needed to get these two arms to match types. Because of how
399-
// locally close the `.emit()` call is I'm comfortable with it, but if it can be
400-
// reworked in the future to not need it, it'd be nice.
401-
_ => dcx.struct_span_err(attr_sp, msg).forget_guarantee(),
397+
Some(ast::ItemKind::MacCall(_)) => Level::Warning(None),
398+
_ => Level::Error { lint: false },
402399
};
400+
let mut err = DiagnosticBuilder::<()>::new(dcx, level, msg);
401+
err.set_span(attr_sp);
403402
if let Some(item) = item {
404403
err.span_label(
405404
item.span,

compiler/rustc_codegen_ssa/src/back/write.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use rustc_data_structures::profiling::{SelfProfilerRef, VerboseTimingGuard};
1515
use rustc_data_structures::sync::Lrc;
1616
use rustc_errors::emitter::Emitter;
1717
use rustc_errors::{translation::Translate, DiagCtxt, DiagnosticId, FatalError, Level};
18-
use rustc_errors::{DiagnosticMessage, Style};
18+
use rustc_errors::{DiagnosticBuilder, DiagnosticMessage, Style};
1919
use rustc_fs_util::link_or_copy;
2020
use rustc_hir::def_id::{CrateNum, LOCAL_CRATE};
2121
use rustc_incremental::{
@@ -1846,14 +1846,14 @@ impl SharedEmitterMain {
18461846
dcx.emit_diagnostic(d);
18471847
}
18481848
Ok(SharedEmitterMessage::InlineAsmError(cookie, msg, level, source)) => {
1849-
let msg = msg.strip_prefix("error: ").unwrap_or(&msg).to_string();
1850-
1851-
let mut err = match level {
1852-
Level::Error { lint: false } => sess.struct_err(msg).forget_guarantee(),
1853-
Level::Warning(_) => sess.struct_warn(msg),
1854-
Level::Note => sess.struct_note(msg),
1849+
let err_level = match level {
1850+
Level::Error { lint: false } => rustc_errors::Level::Error { lint: false },
1851+
Level::Warning(_) => rustc_errors::Level::Warning(None),
1852+
Level::Note => rustc_errors::Level::Note,
18551853
_ => bug!("Invalid inline asm diagnostic level"),
18561854
};
1855+
let msg = msg.strip_prefix("error: ").unwrap_or(&msg).to_string();
1856+
let mut err = DiagnosticBuilder::<()>::new(sess.dcx(), err_level, msg);
18571857

18581858
// If the cookie is 0 then we don't have span information.
18591859
if cookie != 0 {

src/tools/miri/src/diagnostics.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::num::NonZeroU64;
33

44
use log::trace;
55

6-
use rustc_errors::DiagnosticMessage;
6+
use rustc_errors::{DiagnosticBuilder, DiagnosticMessage, Level};
77
use rustc_span::{SpanData, Symbol, DUMMY_SP};
88
use rustc_target::abi::{Align, Size};
99

@@ -453,11 +453,13 @@ pub fn report_msg<'tcx>(
453453
) {
454454
let span = stacktrace.first().map_or(DUMMY_SP, |fi| fi.span);
455455
let sess = machine.tcx.sess;
456-
let mut err = match diag_level {
457-
DiagLevel::Error => sess.struct_span_err(span, title).forget_guarantee(),
458-
DiagLevel::Warning => sess.struct_span_warn(span, title),
459-
DiagLevel::Note => sess.dcx().struct_span_note(span, title),
456+
let level = match diag_level {
457+
DiagLevel::Error => Level::Error { lint: false },
458+
DiagLevel::Warning => Level::Warning(None),
459+
DiagLevel::Note => Level::Note,
460460
};
461+
let mut err = DiagnosticBuilder::<()>::new(sess.dcx(), level, title);
462+
err.set_span(span);
461463

462464
// Show main message.
463465
if span != DUMMY_SP {

0 commit comments

Comments
 (0)