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.
This commit is contained in:
Nicholas Nethercote 2023-12-22 10:54:17 +11:00
parent 3db58e636f
commit 00e8485057
3 changed files with 20 additions and 19 deletions

View file

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