about summary refs log tree commit diff
path: root/compiler/rustc_lint/src
diff options
context:
space:
mode:
authorNicholas Nethercote <n.nethercote@gmail.com>2024-02-23 10:20:45 +1100
committerNicholas Nethercote <n.nethercote@gmail.com>2024-02-28 08:55:35 +1100
commit899cb40809a85eb9d89f6da3268713b83175360a (patch)
treee4c9a526f3eeb5d8563bfe254f1507648fddede2 /compiler/rustc_lint/src
parent4e1f9bd528aef7215bb3b446fcdf43368371da37 (diff)
downloadrust-899cb40809a85eb9d89f6da3268713b83175360a.tar.gz
rust-899cb40809a85eb9d89f6da3268713b83175360a.zip
Rename `DiagnosticBuilder` as `Diag`.
Much better!

Note that this involves renaming (and updating the value of)
`DIAGNOSTIC_BUILDER` in clippy.
Diffstat (limited to 'compiler/rustc_lint/src')
-rw-r--r--compiler/rustc_lint/src/context.rs16
-rw-r--r--compiler/rustc_lint/src/context/diagnostics.rs170
-rw-r--r--compiler/rustc_lint/src/errors.rs6
-rw-r--r--compiler/rustc_lint/src/levels.rs4
-rw-r--r--compiler/rustc_lint/src/lints.rs40
5 files changed, 117 insertions, 119 deletions
diff --git a/compiler/rustc_lint/src/context.rs b/compiler/rustc_lint/src/context.rs
index 5e27a0ed818..ab76da36ee3 100644
--- a/compiler/rustc_lint/src/context.rs
+++ b/compiler/rustc_lint/src/context.rs
@@ -21,7 +21,7 @@ use crate::passes::{EarlyLintPassObject, LateLintPassObject};
 use rustc_data_structures::fx::FxIndexMap;
 use rustc_data_structures::sync;
 use rustc_data_structures::unord::UnordMap;
-use rustc_errors::{DecorateLint, DiagnosticBuilder, DiagnosticMessage, MultiSpan};
+use rustc_errors::{DecorateLint, Diag, DiagnosticMessage, MultiSpan};
 use rustc_feature::Features;
 use rustc_hir as hir;
 use rustc_hir::def::Res;
@@ -338,7 +338,7 @@ impl LintStore {
     }
 
     /// Checks the name of a lint for its existence, and whether it was
-    /// renamed or removed. Generates a DiagnosticBuilder containing a
+    /// renamed or removed. Generates a `Diag` containing a
     /// warning for renamed and removed lints. This is over both lint
     /// names from attributes and those passed on the command line. Since
     /// it emits non-fatal warnings and there are *two* lint passes that
@@ -537,7 +537,7 @@ pub trait LintContext {
         lint: &'static Lint,
         span: Option<impl Into<MultiSpan>>,
         msg: impl Into<DiagnosticMessage>,
-        decorate: impl for<'a, 'b> FnOnce(&'b mut DiagnosticBuilder<'a, ()>),
+        decorate: impl for<'a, 'b> FnOnce(&'b mut Diag<'a, ()>),
         diagnostic: BuiltinLintDiagnostics,
     ) {
         // We first generate a blank diagnostic.
@@ -560,7 +560,7 @@ pub trait LintContext {
         lint: &'static Lint,
         span: Option<S>,
         msg: impl Into<DiagnosticMessage>,
-        decorate: impl for<'a, 'b> FnOnce(&'b mut DiagnosticBuilder<'a, ()>),
+        decorate: impl for<'a, 'b> FnOnce(&'b mut Diag<'a, ()>),
     );
 
     /// Emit a lint at `span` from a lint struct (some type that implements `DecorateLint`,
@@ -585,7 +585,7 @@ pub trait LintContext {
         lint: &'static Lint,
         span: S,
         msg: impl Into<DiagnosticMessage>,
-        decorate: impl for<'a, 'b> FnOnce(&'b mut DiagnosticBuilder<'a, ()>),
+        decorate: impl for<'a, 'b> FnOnce(&'b mut Diag<'a, ()>),
     ) {
         self.opt_span_lint(lint, Some(span), msg, decorate);
     }
@@ -606,7 +606,7 @@ pub trait LintContext {
         &self,
         lint: &'static Lint,
         msg: impl Into<DiagnosticMessage>,
-        decorate: impl for<'a, 'b> FnOnce(&'b mut DiagnosticBuilder<'a, ()>),
+        decorate: impl for<'a, 'b> FnOnce(&'b mut Diag<'a, ()>),
     ) {
         self.opt_span_lint(lint, None as Option<Span>, msg, decorate);
     }
@@ -671,7 +671,7 @@ impl<'tcx> LintContext for LateContext<'tcx> {
         lint: &'static Lint,
         span: Option<S>,
         msg: impl Into<DiagnosticMessage>,
-        decorate: impl for<'a, 'b> FnOnce(&'b mut DiagnosticBuilder<'a, ()>),
+        decorate: impl for<'a, 'b> FnOnce(&'b mut Diag<'a, ()>),
     ) {
         let hir_id = self.last_node_with_lint_attrs;
 
@@ -698,7 +698,7 @@ impl LintContext for EarlyContext<'_> {
         lint: &'static Lint,
         span: Option<S>,
         msg: impl Into<DiagnosticMessage>,
-        decorate: impl for<'a, 'b> FnOnce(&'b mut DiagnosticBuilder<'a, ()>),
+        decorate: impl for<'a, 'b> FnOnce(&'b mut Diag<'a, ()>),
     ) {
         self.builder.opt_span_lint(lint, span.map(|s| s.into()), msg, decorate)
     }
diff --git a/compiler/rustc_lint/src/context/diagnostics.rs b/compiler/rustc_lint/src/context/diagnostics.rs
index 86434002e2c..71aef50391d 100644
--- a/compiler/rustc_lint/src/context/diagnostics.rs
+++ b/compiler/rustc_lint/src/context/diagnostics.rs
@@ -2,7 +2,7 @@
 #![allow(rustc::untranslatable_diagnostic)]
 
 use rustc_ast::util::unicode::TEXT_FLOW_CONTROL_CHARS;
-use rustc_errors::{add_elided_lifetime_in_path_suggestion, DiagnosticBuilder};
+use rustc_errors::{add_elided_lifetime_in_path_suggestion, Diag};
 use rustc_errors::{Applicability, SuggestionStyle};
 use rustc_middle::middle::stability;
 use rustc_session::config::ExpectedValues;
@@ -12,11 +12,7 @@ use rustc_span::edit_distance::find_best_match_for_name;
 use rustc_span::symbol::{sym, Symbol};
 use rustc_span::BytePos;
 
-pub(super) fn builtin(
-    sess: &Session,
-    diagnostic: BuiltinLintDiagnostics,
-    db: &mut DiagnosticBuilder<'_, ()>,
-) {
+pub(super) fn builtin(sess: &Session, diagnostic: BuiltinLintDiagnostics, diag: &mut Diag<'_, ()>) {
     match diagnostic {
         BuiltinLintDiagnostics::UnicodeTextFlow(span, content) => {
             let spans: Vec<_> = content
@@ -32,22 +28,22 @@ pub(super) fn builtin(
                 1 => ("an ", ""),
                 _ => ("", "s"),
             };
-            db.span_label(
+            diag.span_label(
                 span,
                 format!(
                     "this comment contains {an}invisible unicode text flow control codepoint{s}",
                 ),
             );
             for (c, span) in &spans {
-                db.span_label(*span, format!("{c:?}"));
+                diag.span_label(*span, format!("{c:?}"));
             }
-            db.note(
+            diag.note(
                 "these kind of unicode codepoints change the way text flows on \
                          applications that support them, but can cause confusion because they \
                          change the order of characters on the screen",
             );
             if !spans.is_empty() {
-                db.multipart_suggestion_with_style(
+                diag.multipart_suggestion_with_style(
                     "if their presence wasn't intentional, you can remove them",
                     spans.into_iter().map(|(_, span)| (span, "".to_string())).collect(),
                     Applicability::MachineApplicable,
@@ -67,16 +63,16 @@ pub(super) fn builtin(
                 }
                 Err(_) => ("crate::<path>".to_string(), Applicability::HasPlaceholders),
             };
-            db.span_suggestion(span, "use `crate`", sugg, app);
+            diag.span_suggestion(span, "use `crate`", sugg, app);
         }
         BuiltinLintDiagnostics::ProcMacroDeriveResolutionFallback(span) => {
-            db.span_label(
+            diag.span_label(
                 span,
                 "names from parent modules are not accessible without an explicit import",
             );
         }
         BuiltinLintDiagnostics::MacroExpandedMacroExportsAccessedByAbsolutePaths(span_def) => {
-            db.span_note(span_def, "the macro is defined here");
+            diag.span_note(span_def, "the macro is defined here");
         }
         BuiltinLintDiagnostics::ElidedLifetimesInPaths(
             n,
@@ -86,7 +82,7 @@ pub(super) fn builtin(
         ) => {
             add_elided_lifetime_in_path_suggestion(
                 sess.source_map(),
-                db,
+                diag,
                 n,
                 path_span,
                 incl_angl_brckt,
@@ -94,11 +90,11 @@ pub(super) fn builtin(
             );
         }
         BuiltinLintDiagnostics::UnknownCrateTypes(span, note, sugg) => {
-            db.span_suggestion(span, note, sugg, Applicability::MaybeIncorrect);
+            diag.span_suggestion(span, note, sugg, Applicability::MaybeIncorrect);
         }
         BuiltinLintDiagnostics::UnusedImports(message, replaces, in_test_module) => {
             if !replaces.is_empty() {
-                db.tool_only_multipart_suggestion(
+                diag.tool_only_multipart_suggestion(
                     message,
                     replaces,
                     Applicability::MachineApplicable,
@@ -106,7 +102,7 @@ pub(super) fn builtin(
             }
 
             if let Some(span) = in_test_module {
-                db.span_help(
+                diag.span_help(
                     sess.source_map().guess_head_span(span),
                     "consider adding a `#[cfg(test)]` to the containing module",
                 );
@@ -115,19 +111,19 @@ pub(super) fn builtin(
         BuiltinLintDiagnostics::RedundantImport(spans, ident) => {
             for (span, is_imported) in spans {
                 let introduced = if is_imported { "imported" } else { "defined" };
-                db.span_label(span, format!("the item `{ident}` is already {introduced} here"));
+                diag.span_label(span, format!("the item `{ident}` is already {introduced} here"));
             }
         }
         BuiltinLintDiagnostics::DeprecatedMacro(suggestion, span) => {
-            stability::deprecation_suggestion(db, "macro", suggestion, span)
+            stability::deprecation_suggestion(diag, "macro", suggestion, span)
         }
         BuiltinLintDiagnostics::UnusedDocComment(span) => {
-            db.span_label(span, "rustdoc does not generate documentation for macro invocations");
-            db.help("to document an item produced by a macro, \
+            diag.span_label(span, "rustdoc does not generate documentation for macro invocations");
+            diag.help("to document an item produced by a macro, \
                                   the macro must produce the documentation as part of its expansion");
         }
         BuiltinLintDiagnostics::PatternsInFnsWithoutBody(span, ident) => {
-            db.span_suggestion(
+            diag.span_suggestion(
                 span,
                 "remove `mut` from the parameter",
                 ident,
@@ -135,17 +131,17 @@ pub(super) fn builtin(
             );
         }
         BuiltinLintDiagnostics::MissingAbi(span, default_abi) => {
-            db.span_label(span, "ABI should be specified here");
-            db.help(format!("the default ABI is {}", default_abi.name()));
+            diag.span_label(span, "ABI should be specified here");
+            diag.help(format!("the default ABI is {}", default_abi.name()));
         }
         BuiltinLintDiagnostics::LegacyDeriveHelpers(span) => {
-            db.span_label(span, "the attribute is introduced here");
+            diag.span_label(span, "the attribute is introduced here");
         }
         BuiltinLintDiagnostics::ProcMacroBackCompat(note) => {
-            db.note(note);
+            diag.note(note);
         }
         BuiltinLintDiagnostics::OrPatternsBackCompat(span, suggestion) => {
-            db.span_suggestion(
+            diag.span_suggestion(
                 span,
                 "use pat_param to preserve semantics",
                 suggestion,
@@ -153,8 +149,8 @@ pub(super) fn builtin(
             );
         }
         BuiltinLintDiagnostics::ReservedPrefix(span) => {
-            db.span_label(span, "unknown prefix");
-            db.span_suggestion_verbose(
+            diag.span_label(span, "unknown prefix");
+            diag.span_suggestion_verbose(
                 span.shrink_to_hi(),
                 "insert whitespace here to avoid this being parsed as a prefix in Rust 2021",
                 " ",
@@ -162,19 +158,19 @@ pub(super) fn builtin(
             );
         }
         BuiltinLintDiagnostics::UnusedBuiltinAttribute { attr_name, macro_name, invoc_span } => {
-            db.span_note(
+            diag.span_note(
                         invoc_span,
                         format!("the built-in attribute `{attr_name}` will be ignored, since it's applied to the macro invocation `{macro_name}`")
                     );
         }
         BuiltinLintDiagnostics::TrailingMacro(is_trailing, name) => {
             if is_trailing {
-                db.note("macro invocations at the end of a block are treated as expressions");
-                db.note(format!("to ignore the value produced by the macro, add a semicolon after the invocation of `{name}`"));
+                diag.note("macro invocations at the end of a block are treated as expressions");
+                diag.note(format!("to ignore the value produced by the macro, add a semicolon after the invocation of `{name}`"));
             }
         }
         BuiltinLintDiagnostics::BreakWithLabelAndLoop(span) => {
-            db.multipart_suggestion(
+            diag.multipart_suggestion(
                 "wrap this expression in parentheses",
                 vec![
                     (span.shrink_to_lo(), "(".to_string()),
@@ -184,8 +180,8 @@ pub(super) fn builtin(
             );
         }
         BuiltinLintDiagnostics::NamedAsmLabel(help) => {
-            db.help(help);
-            db.note("see the asm section of Rust By Example <https://doc.rust-lang.org/nightly/rust-by-example/unsafe/asm.html#labels> for more information");
+            diag.help(help);
+            diag.note("see the asm section of Rust By Example <https://doc.rust-lang.org/nightly/rust-by-example/unsafe/asm.html#labels> for more information");
         }
         BuiltinLintDiagnostics::UnexpectedCfgName((name, name_span), value) => {
             #[allow(rustc::potential_query_instability)]
@@ -212,7 +208,7 @@ pub(super) fn builtin(
             let mut is_feature_cfg = name == sym::feature;
 
             if is_feature_cfg && is_from_cargo {
-                db.help("consider defining some features in `Cargo.toml`");
+                diag.help("consider defining some features in `Cargo.toml`");
             // Suggest the most probable if we found one
             } else if let Some(best_match) = find_best_match_for_name(&possibilities, name, None) {
                 if let Some(ExpectedValues::Some(best_match_values)) =
@@ -227,7 +223,7 @@ pub(super) fn builtin(
                     let mut should_print_possibilities = true;
                     if let Some((value, value_span)) = value {
                         if best_match_values.contains(&Some(value)) {
-                            db.span_suggestion(
+                            diag.span_suggestion(
                                 name_span,
                                 "there is a config with a similar name and value",
                                 best_match,
@@ -235,7 +231,7 @@ pub(super) fn builtin(
                             );
                             should_print_possibilities = false;
                         } else if best_match_values.contains(&None) {
-                            db.span_suggestion(
+                            diag.span_suggestion(
                                 name_span.to(value_span),
                                 "there is a config with a similar name and no value",
                                 best_match,
@@ -243,14 +239,14 @@ pub(super) fn builtin(
                             );
                             should_print_possibilities = false;
                         } else if let Some(first_value) = possibilities.first() {
-                            db.span_suggestion(
+                            diag.span_suggestion(
                                 name_span.to(value_span),
                                 "there is a config with a similar name and different values",
                                 format!("{best_match} = \"{first_value}\""),
                                 Applicability::MaybeIncorrect,
                             );
                         } else {
-                            db.span_suggestion(
+                            diag.span_suggestion(
                                 name_span.to(value_span),
                                 "there is a config with a similar name and different values",
                                 best_match,
@@ -258,7 +254,7 @@ pub(super) fn builtin(
                             );
                         };
                     } else {
-                        db.span_suggestion(
+                        diag.span_suggestion(
                             name_span,
                             "there is a config with a similar name",
                             best_match,
@@ -268,12 +264,12 @@ pub(super) fn builtin(
 
                     if !possibilities.is_empty() && should_print_possibilities {
                         let possibilities = possibilities.join("`, `");
-                        db.help(format!(
+                        diag.help(format!(
                             "expected values for `{best_match}` are: `{possibilities}`"
                         ));
                     }
                 } else {
-                    db.span_suggestion(
+                    diag.span_suggestion(
                         name_span,
                         "there is a config with a similar name",
                         best_match,
@@ -286,7 +282,7 @@ pub(super) fn builtin(
                 if !names_possibilities.is_empty() && names_possibilities.len() <= 3 {
                     names_possibilities.sort();
                     for cfg_name in names_possibilities.iter() {
-                        db.span_suggestion(
+                        diag.span_suggestion(
                             name_span,
                             "found config with similar value",
                             format!("{cfg_name} = \"{name}\""),
@@ -304,7 +300,7 @@ pub(super) fn builtin(
                     // so the diagnostic produced can take a lot of space. To avoid
                     // cloging the user output we only want to print that diagnostic
                     // once.
-                    db.help_once(format!("expected names are: `{possibilities}`"));
+                    diag.help_once(format!("expected names are: `{possibilities}`"));
                 }
             }
 
@@ -317,12 +313,12 @@ pub(super) fn builtin(
 
             if is_from_cargo {
                 if !is_feature_cfg {
-                    db.help(format!("consider using a Cargo feature instead or adding `println!(\"cargo:rustc-check-cfg={inst}\");` to the top of a `build.rs`"));
+                    diag.help(format!("consider using a Cargo feature instead or adding `println!(\"cargo:rustc-check-cfg={inst}\");` to the top of a `build.rs`"));
                 }
-                db.note("see <https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#check-cfg> for more information about checking conditional configuration");
+                diag.note("see <https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#check-cfg> for more information about checking conditional configuration");
             } else {
-                db.help(format!("to expect this configuration use `--check-cfg={inst}`"));
-                db.note("see <https://doc.rust-lang.org/nightly/unstable-book/compiler-flags/check-cfg.html> for more information about checking conditional configuration");
+                diag.help(format!("to expect this configuration use `--check-cfg={inst}`"));
+                diag.note("see <https://doc.rust-lang.org/nightly/unstable-book/compiler-flags/check-cfg.html> for more information about checking conditional configuration");
             }
         }
         BuiltinLintDiagnostics::UnexpectedCfgValue((name, name_span), value) => {
@@ -356,14 +352,14 @@ pub(super) fn builtin(
                     let possibilities = possibilities.join("`, `");
                     let none = if have_none_possibility { "(none), " } else { "" };
 
-                    db.note(format!("expected values for `{name}` are: {none}`{possibilities}`"));
+                    diag.note(format!("expected values for `{name}` are: {none}`{possibilities}`"));
                 }
 
                 if let Some((value, value_span)) = value {
                     // Suggest the most probable if we found one
                     if let Some(best_match) = find_best_match_for_name(&possibilities, value, None)
                     {
-                        db.span_suggestion(
+                        diag.span_suggestion(
                             value_span,
                             "there is a expected value with a similar name",
                             format!("\"{best_match}\""),
@@ -371,7 +367,7 @@ pub(super) fn builtin(
                         );
                     }
                 } else if let &[first_possibility] = &possibilities[..] {
-                    db.span_suggestion(
+                    diag.span_suggestion(
                         name_span.shrink_to_hi(),
                         "specify a config value",
                         format!(" = \"{first_possibility}\""),
@@ -379,9 +375,9 @@ pub(super) fn builtin(
                     );
                 }
             } else if have_none_possibility {
-                db.note(format!("no expected value for `{name}`"));
+                diag.note(format!("no expected value for `{name}`"));
                 if let Some((_value, value_span)) = value {
-                    db.span_suggestion(
+                    diag.span_suggestion(
                         name_span.shrink_to_hi().to(value_span),
                         "remove the value",
                         "",
@@ -389,14 +385,14 @@ pub(super) fn builtin(
                     );
                 }
             } else {
-                db.note(format!("no expected values for `{name}`"));
+                diag.note(format!("no expected values for `{name}`"));
 
                 let sp = if let Some((_value, value_span)) = value {
                     name_span.to(value_span)
                 } else {
                     name_span
                 };
-                db.span_suggestion(sp, "remove the condition", "", Applicability::MaybeIncorrect);
+                diag.span_suggestion(sp, "remove the condition", "", Applicability::MaybeIncorrect);
             }
 
             // We don't want to suggest adding values to well known names
@@ -415,28 +411,30 @@ pub(super) fn builtin(
             if is_from_cargo {
                 if name == sym::feature {
                     if let Some((value, _value_span)) = value {
-                        db.help(format!("consider adding `{value}` as a feature in `Cargo.toml`"));
+                        diag.help(format!(
+                            "consider adding `{value}` as a feature in `Cargo.toml`"
+                        ));
                     } else {
-                        db.help("consider defining some features in `Cargo.toml`");
+                        diag.help("consider defining some features in `Cargo.toml`");
                     }
                 } else if !is_cfg_a_well_know_name {
-                    db.help(format!("consider using a Cargo feature instead or adding `println!(\"cargo:rustc-check-cfg={inst}\");` to the top of a `build.rs`"));
+                    diag.help(format!("consider using a Cargo feature instead or adding `println!(\"cargo:rustc-check-cfg={inst}\");` to the top of a `build.rs`"));
                 }
-                db.note("see <https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#check-cfg> for more information about checking conditional configuration");
+                diag.note("see <https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#check-cfg> for more information about checking conditional configuration");
             } else {
                 if !is_cfg_a_well_know_name {
-                    db.help(format!("to expect this configuration use `--check-cfg={inst}`"));
+                    diag.help(format!("to expect this configuration use `--check-cfg={inst}`"));
                 }
-                db.note("see <https://doc.rust-lang.org/nightly/unstable-book/compiler-flags/check-cfg.html> for more information about checking conditional configuration");
+                diag.note("see <https://doc.rust-lang.org/nightly/unstable-book/compiler-flags/check-cfg.html> for more information about checking conditional configuration");
             }
         }
         BuiltinLintDiagnostics::DeprecatedWhereclauseLocation(new_span, suggestion) => {
-            db.multipart_suggestion(
+            diag.multipart_suggestion(
                 "move it to the end of the type declaration",
-                vec![(db.span.primary_span().unwrap(), "".to_string()), (new_span, suggestion)],
+                vec![(diag.span.primary_span().unwrap(), "".to_string()), (new_span, suggestion)],
                 Applicability::MachineApplicable,
             );
-            db.note(
+            diag.note(
                         "see issue #89122 <https://github.com/rust-lang/rust/issues/89122> for more information",
                     );
         }
@@ -446,8 +444,8 @@ pub(super) fn builtin(
             deletion_span,
         } => {
             debug!(?param_span, ?use_span, ?deletion_span);
-            db.span_label(param_span, "this lifetime...");
-            db.span_label(use_span, "...is used only here");
+            diag.span_label(param_span, "this lifetime...");
+            diag.span_label(use_span, "...is used only here");
             if let Some(deletion_span) = deletion_span {
                 let msg = "elide the single-use lifetime";
                 let (use_span, replace_lt) = if elide {
@@ -468,7 +466,7 @@ pub(super) fn builtin(
                 } else {
                     vec![(deletion_span, String::new()), (use_span, replace_lt)]
                 };
-                db.multipart_suggestion(msg, suggestions, Applicability::MachineApplicable);
+                diag.multipart_suggestion(msg, suggestions, Applicability::MachineApplicable);
             }
         }
         BuiltinLintDiagnostics::SingleUseLifetime {
@@ -478,7 +476,7 @@ pub(super) fn builtin(
         } => {
             debug!(?deletion_span);
             if let Some(deletion_span) = deletion_span {
-                db.span_suggestion(
+                diag.span_suggestion(
                     deletion_span,
                     "elide the unused lifetime",
                     "",
@@ -493,7 +491,7 @@ pub(super) fn builtin(
             named_arg_name,
             is_formatting_arg,
         } => {
-            db.span_label(
+            diag.span_label(
                 named_arg_sp,
                 "this named argument is referred to by position in formatting string",
             );
@@ -501,7 +499,7 @@ pub(super) fn builtin(
                 let msg = format!(
                     "this formatting argument uses named argument `{named_arg_name}` by position"
                 );
-                db.span_label(positional_arg_for_msg, msg);
+                diag.span_label(positional_arg_for_msg, msg);
             }
 
             if let Some(positional_arg_to_replace) = position_sp_to_replace {
@@ -514,7 +512,7 @@ pub(super) fn builtin(
                 } else {
                     positional_arg_to_replace
                 };
-                db.span_suggestion_verbose(
+                diag.span_suggestion_verbose(
                     span_to_replace,
                     "use the named argument by name to avoid ambiguity",
                     name,
@@ -523,22 +521,22 @@ pub(super) fn builtin(
             }
         }
         BuiltinLintDiagnostics::ByteSliceInPackedStructWithDerive => {
-            db.help("consider implementing the trait by hand, or remove the `packed` attribute");
+            diag.help("consider implementing the trait by hand, or remove the `packed` attribute");
         }
         BuiltinLintDiagnostics::UnusedExternCrate { removal_span } => {
-            db.span_suggestion(removal_span, "remove it", "", Applicability::MachineApplicable);
+            diag.span_suggestion(removal_span, "remove it", "", Applicability::MachineApplicable);
         }
         BuiltinLintDiagnostics::ExternCrateNotIdiomatic { vis_span, ident_span } => {
             let suggestion_span = vis_span.between(ident_span);
-            db.span_suggestion_verbose(
+            diag.span_suggestion_verbose(
                 suggestion_span,
                 "convert it to a `use`",
                 if vis_span.is_empty() { "use " } else { " use " },
                 Applicability::MachineApplicable,
             );
         }
-        BuiltinLintDiagnostics::AmbiguousGlobImports { diag } => {
-            rustc_errors::report_ambiguity_error(db, diag);
+        BuiltinLintDiagnostics::AmbiguousGlobImports { diag: ambiguity } => {
+            rustc_errors::report_ambiguity_error(diag, ambiguity);
         }
         BuiltinLintDiagnostics::AmbiguousGlobReexports {
             name,
@@ -546,11 +544,11 @@ pub(super) fn builtin(
             first_reexport_span,
             duplicate_reexport_span,
         } => {
-            db.span_label(
+            diag.span_label(
                 first_reexport_span,
                 format!("the name `{name}` in the {namespace} namespace is first re-exported here"),
             );
-            db.span_label(
+            diag.span_label(
                 duplicate_reexport_span,
                 format!(
                     "but the name `{name}` in the {namespace} namespace is also re-exported here"
@@ -563,11 +561,11 @@ pub(super) fn builtin(
             glob_reexport_span,
             private_item_span,
         } => {
-            db.span_note(glob_reexport_span, format!("the name `{name}` in the {namespace} namespace is supposed to be publicly re-exported here"));
-            db.span_note(private_item_span, "but the private item here shadows it".to_owned());
+            diag.span_note(glob_reexport_span, format!("the name `{name}` in the {namespace} namespace is supposed to be publicly re-exported here"));
+            diag.span_note(private_item_span, "but the private item here shadows it".to_owned());
         }
         BuiltinLintDiagnostics::UnusedQualifications { removal_span } => {
-            db.span_suggestion_verbose(
+            diag.span_suggestion_verbose(
                 removal_span,
                 "remove the unnecessary path segments",
                 "",
@@ -575,7 +573,7 @@ pub(super) fn builtin(
             );
         }
         BuiltinLintDiagnostics::AssociatedConstElidedLifetime { elided, span } => {
-            db.span_suggestion_verbose(
+            diag.span_suggestion_verbose(
                 if elided { span.shrink_to_hi() } else { span },
                 "use the `'static` lifetime",
                 if elided { "'static " } else { "'static" },
@@ -583,8 +581,10 @@ pub(super) fn builtin(
             );
         }
         BuiltinLintDiagnostics::RedundantImportVisibility { max_vis, span } => {
-            db.span_note(span, format!("the most public imported item is `{max_vis}`"));
-            db.help("reduce the glob import's visibility or increase visibility of imported items");
+            diag.span_note(span, format!("the most public imported item is `{max_vis}`"));
+            diag.help(
+                "reduce the glob import's visibility or increase visibility of imported items",
+            );
         }
     }
 }
diff --git a/compiler/rustc_lint/src/errors.rs b/compiler/rustc_lint/src/errors.rs
index bcff20fc260..3be792a9e4f 100644
--- a/compiler/rustc_lint/src/errors.rs
+++ b/compiler/rustc_lint/src/errors.rs
@@ -1,7 +1,5 @@
 use crate::fluent_generated as fluent;
-use rustc_errors::{
-    codes::*, AddToDiagnostic, DiagnosticBuilder, EmissionGuarantee, SubdiagnosticMessageOp,
-};
+use rustc_errors::{codes::*, AddToDiagnostic, Diag, EmissionGuarantee, SubdiagnosticMessageOp};
 use rustc_macros::{Diagnostic, Subdiagnostic};
 use rustc_session::lint::Level;
 use rustc_span::{Span, Symbol};
@@ -28,7 +26,7 @@ pub enum OverruledAttributeSub {
 impl AddToDiagnostic for OverruledAttributeSub {
     fn add_to_diagnostic_with<G: EmissionGuarantee, F: SubdiagnosticMessageOp<G>>(
         self,
-        diag: &mut DiagnosticBuilder<'_, G>,
+        diag: &mut Diag<'_, G>,
         _f: F,
     ) {
         match self {
diff --git a/compiler/rustc_lint/src/levels.rs b/compiler/rustc_lint/src/levels.rs
index c1a083bde8d..ad4a0fc47db 100644
--- a/compiler/rustc_lint/src/levels.rs
+++ b/compiler/rustc_lint/src/levels.rs
@@ -16,7 +16,7 @@ use crate::{
 use rustc_ast as ast;
 use rustc_ast_pretty::pprust;
 use rustc_data_structures::fx::FxIndexMap;
-use rustc_errors::{DecorateLint, DiagnosticBuilder, DiagnosticMessage, MultiSpan};
+use rustc_errors::{DecorateLint, Diag, DiagnosticMessage, MultiSpan};
 use rustc_feature::{Features, GateIssue};
 use rustc_hir as hir;
 use rustc_hir::intravisit::{self, Visitor};
@@ -1107,7 +1107,7 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
         lint: &'static Lint,
         span: Option<MultiSpan>,
         msg: impl Into<DiagnosticMessage>,
-        decorate: impl for<'a, 'b> FnOnce(&'b mut DiagnosticBuilder<'a, ()>),
+        decorate: impl for<'a, 'b> FnOnce(&'b mut Diag<'a, ()>),
     ) {
         let (level, src) = self.lint_level(lint);
         lint_level(self.sess, lint, level, src, span, msg, decorate)
diff --git a/compiler/rustc_lint/src/lints.rs b/compiler/rustc_lint/src/lints.rs
index 80231d2e68a..8f6a175e7f9 100644
--- a/compiler/rustc_lint/src/lints.rs
+++ b/compiler/rustc_lint/src/lints.rs
@@ -5,7 +5,7 @@ use std::num::NonZero;
 use crate::errors::RequestedLevel;
 use crate::fluent_generated as fluent;
 use rustc_errors::{
-    codes::*, AddToDiagnostic, Applicability, DecorateLint, DiagnosticBuilder, DiagnosticMessage,
+    codes::*, AddToDiagnostic, Applicability, DecorateLint, Diag, DiagnosticMessage,
     DiagnosticStyledString, EmissionGuarantee, SubdiagnosticMessageOp, SuggestionStyle,
 };
 use rustc_hir::def_id::DefId;
@@ -137,7 +137,7 @@ pub struct BuiltinMissingDebugImpl<'a> {
 
 // Needed for def_path_str
 impl<'a> DecorateLint<'a, ()> for BuiltinMissingDebugImpl<'_> {
-    fn decorate_lint<'b>(self, diag: &'b mut rustc_errors::DiagnosticBuilder<'a, ()>) {
+    fn decorate_lint<'b>(self, diag: &'b mut rustc_errors::Diag<'a, ()>) {
         diag.arg("debug", self.tcx.def_path_str(self.def_id));
     }
 
@@ -242,7 +242,7 @@ pub struct BuiltinUngatedAsyncFnTrackCaller<'a> {
 }
 
 impl<'a> DecorateLint<'a, ()> for BuiltinUngatedAsyncFnTrackCaller<'_> {
-    fn decorate_lint<'b>(self, diag: &'b mut DiagnosticBuilder<'a, ()>) {
+    fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) {
         diag.span_label(self.label, fluent::lint_label);
         rustc_session::parse::add_feature_diagnostics(
             diag,
@@ -273,7 +273,7 @@ pub struct SuggestChangingAssocTypes<'a, 'b> {
 impl<'a, 'b> AddToDiagnostic for SuggestChangingAssocTypes<'a, 'b> {
     fn add_to_diagnostic_with<G: EmissionGuarantee, F: SubdiagnosticMessageOp<G>>(
         self,
-        diag: &mut DiagnosticBuilder<'_, G>,
+        diag: &mut Diag<'_, G>,
         _f: F,
     ) {
         // Access to associates types should use `<T as Bound>::Assoc`, which does not need a
@@ -282,7 +282,7 @@ impl<'a, 'b> AddToDiagnostic for SuggestChangingAssocTypes<'a, 'b> {
         // We use a HIR visitor to walk the type.
         use rustc_hir::intravisit::{self, Visitor};
         struct WalkAssocTypes<'a, 'b, G: EmissionGuarantee> {
-            err: &'a mut DiagnosticBuilder<'b, G>,
+            err: &'a mut Diag<'b, G>,
         }
         impl<'a, 'b, G: EmissionGuarantee> Visitor<'_> for WalkAssocTypes<'a, 'b, G> {
             fn visit_qpath(
@@ -329,7 +329,7 @@ pub struct BuiltinTypeAliasGenericBoundsSuggestion {
 impl AddToDiagnostic for BuiltinTypeAliasGenericBoundsSuggestion {
     fn add_to_diagnostic_with<G: EmissionGuarantee, F: SubdiagnosticMessageOp<G>>(
         self,
-        diag: &mut DiagnosticBuilder<'_, G>,
+        diag: &mut Diag<'_, G>,
         _f: F,
     ) {
         diag.multipart_suggestion(
@@ -424,7 +424,7 @@ pub struct BuiltinUnpermittedTypeInit<'a> {
 }
 
 impl<'a> DecorateLint<'a, ()> for BuiltinUnpermittedTypeInit<'_> {
-    fn decorate_lint<'b>(self, diag: &'b mut DiagnosticBuilder<'a, ()>) {
+    fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) {
         diag.arg("ty", self.ty);
         diag.span_label(self.label, fluent::lint_builtin_unpermitted_type_init_label);
         if let InhabitedPredicate::True = self.ty.inhabited_predicate(self.tcx) {
@@ -450,7 +450,7 @@ pub struct BuiltinUnpermittedTypeInitSub {
 impl AddToDiagnostic for BuiltinUnpermittedTypeInitSub {
     fn add_to_diagnostic_with<G: EmissionGuarantee, F: SubdiagnosticMessageOp<G>>(
         self,
-        diag: &mut DiagnosticBuilder<'_, G>,
+        diag: &mut Diag<'_, G>,
         _f: F,
     ) {
         let mut err = self.err;
@@ -505,7 +505,7 @@ pub struct BuiltinClashingExternSub<'a> {
 impl AddToDiagnostic for BuiltinClashingExternSub<'_> {
     fn add_to_diagnostic_with<G: EmissionGuarantee, F: SubdiagnosticMessageOp<G>>(
         self,
-        diag: &mut DiagnosticBuilder<'_, G>,
+        diag: &mut Diag<'_, G>,
         _f: F,
     ) {
         let mut expected_str = DiagnosticStyledString::new();
@@ -787,7 +787,7 @@ pub struct HiddenUnicodeCodepointsDiagLabels {
 impl AddToDiagnostic for HiddenUnicodeCodepointsDiagLabels {
     fn add_to_diagnostic_with<G: EmissionGuarantee, F: SubdiagnosticMessageOp<G>>(
         self,
-        diag: &mut DiagnosticBuilder<'_, G>,
+        diag: &mut Diag<'_, G>,
         _f: F,
     ) {
         for (c, span) in self.spans {
@@ -805,7 +805,7 @@ pub enum HiddenUnicodeCodepointsDiagSub {
 impl AddToDiagnostic for HiddenUnicodeCodepointsDiagSub {
     fn add_to_diagnostic_with<G: EmissionGuarantee, F: SubdiagnosticMessageOp<G>>(
         self,
-        diag: &mut DiagnosticBuilder<'_, G>,
+        diag: &mut Diag<'_, G>,
         _f: F,
     ) {
         match self {
@@ -957,7 +957,7 @@ pub struct NonBindingLetSub {
 impl AddToDiagnostic for NonBindingLetSub {
     fn add_to_diagnostic_with<G: EmissionGuarantee, F: SubdiagnosticMessageOp<G>>(
         self,
-        diag: &mut DiagnosticBuilder<'_, G>,
+        diag: &mut Diag<'_, G>,
         _f: F,
     ) {
         let can_suggest_binding = self.drop_fn_start_end.is_some() || !self.is_assign_desugar;
@@ -1164,7 +1164,7 @@ pub struct NonFmtPanicUnused {
 
 // Used because of two suggestions based on one Option<Span>
 impl<'a> DecorateLint<'a, ()> for NonFmtPanicUnused {
-    fn decorate_lint<'b>(self, diag: &'b mut DiagnosticBuilder<'a, ()>) {
+    fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) {
         diag.arg("count", self.count);
         diag.note(fluent::lint_note);
         if let Some(span) = self.suggestion {
@@ -1243,7 +1243,7 @@ pub enum NonSnakeCaseDiagSub {
 impl AddToDiagnostic for NonSnakeCaseDiagSub {
     fn add_to_diagnostic_with<G: EmissionGuarantee, F: SubdiagnosticMessageOp<G>>(
         self,
-        diag: &mut DiagnosticBuilder<'_, G>,
+        diag: &mut Diag<'_, G>,
         _f: F,
     ) {
         match self {
@@ -1402,7 +1402,7 @@ pub struct DropTraitConstraintsDiag<'a> {
 
 // Needed for def_path_str
 impl<'a> DecorateLint<'a, ()> for DropTraitConstraintsDiag<'_> {
-    fn decorate_lint<'b>(self, diag: &'b mut DiagnosticBuilder<'a, ()>) {
+    fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) {
         diag.arg("predicate", self.predicate);
         diag.arg("needs_drop", self.tcx.def_path_str(self.def_id));
     }
@@ -1419,7 +1419,7 @@ pub struct DropGlue<'a> {
 
 // Needed for def_path_str
 impl<'a> DecorateLint<'a, ()> for DropGlue<'_> {
-    fn decorate_lint<'b>(self, diag: &'b mut DiagnosticBuilder<'a, ()>) {
+    fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) {
         diag.arg("needs_drop", self.tcx.def_path_str(self.def_id));
     }
 
@@ -1485,7 +1485,7 @@ pub enum OverflowingBinHexSign {
 impl AddToDiagnostic for OverflowingBinHexSign {
     fn add_to_diagnostic_with<G: EmissionGuarantee, F: SubdiagnosticMessageOp<G>>(
         self,
-        diag: &mut DiagnosticBuilder<'_, G>,
+        diag: &mut Diag<'_, G>,
         _f: F,
     ) {
         match self {
@@ -1694,7 +1694,7 @@ pub struct ImproperCTypes<'a> {
 
 // Used because of the complexity of Option<DiagnosticMessage>, DiagnosticMessage, and Option<Span>
 impl<'a> DecorateLint<'a, ()> for ImproperCTypes<'_> {
-    fn decorate_lint<'b>(self, diag: &'b mut DiagnosticBuilder<'a, ()>) {
+    fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) {
         diag.arg("ty", self.ty);
         diag.arg("desc", self.desc);
         diag.span_label(self.label, fluent::lint_label);
@@ -1837,7 +1837,7 @@ pub enum UnusedDefSuggestion {
 
 // Needed because of def_path_str
 impl<'a> DecorateLint<'a, ()> for UnusedDef<'_, '_> {
-    fn decorate_lint<'b>(self, diag: &'b mut DiagnosticBuilder<'a, ()>) {
+    fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) {
         diag.arg("pre", self.pre);
         diag.arg("post", self.post);
         diag.arg("def", self.cx.tcx.def_path_str(self.def_id));
@@ -1920,7 +1920,7 @@ pub struct AsyncFnInTraitDiag {
 }
 
 impl<'a> DecorateLint<'a, ()> for AsyncFnInTraitDiag {
-    fn decorate_lint<'b>(self, diag: &'b mut DiagnosticBuilder<'a, ()>) {
+    fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) {
         diag.note(fluent::lint_note);
         if let Some(sugg) = self.sugg {
             diag.multipart_suggestion(fluent::lint_suggestion, sugg, Applicability::MaybeIncorrect);