Skip to content

Commit b5f5bdc

Browse files
authored
Rollup merge of rust-lang#100351 - compiler-errors:diagnostic-convention, r=fee1-dead
Use `&mut Diagnostic` instead of `&mut DiagnosticBuilder` unless needed This seems to be the established convention (02ff9e0) when `DiagnosticBuilder` was first added. I am guilty of introducing some of these.
2 parents a5b0f72 + a2b6744 commit b5f5bdc

File tree

15 files changed

+37
-59
lines changed

15 files changed

+37
-59
lines changed

compiler/rustc_ast_passes/src/ast_validation.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ use rustc_ast::walk_list;
1313
use rustc_ast::*;
1414
use rustc_ast_pretty::pprust::{self, State};
1515
use rustc_data_structures::fx::FxHashMap;
16-
use rustc_errors::{
17-
error_code, pluralize, struct_span_err, Applicability, DiagnosticBuilder, ErrorGuaranteed,
18-
};
16+
use rustc_errors::{error_code, pluralize, struct_span_err, Applicability, Diagnostic};
1917
use rustc_parse::validate_attr;
2018
use rustc_session::lint::builtin::{
2119
DEPRECATED_WHERE_CLAUSE_LOCATION, MISSING_ABI, PATTERNS_IN_FNS_WITHOUT_BODY,
@@ -477,7 +475,7 @@ impl<'a> AstValidator<'a> {
477475
ctx: &str,
478476
msg: &str,
479477
sugg: &str,
480-
help: impl FnOnce(&mut DiagnosticBuilder<'_, ErrorGuaranteed>),
478+
help: impl FnOnce(&mut Diagnostic),
481479
) {
482480
let source_map = self.session.source_map();
483481
let end = source_map.end_point(sp);
@@ -1196,7 +1194,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
11961194
let msg = "free function without a body";
11971195
let ext = sig.header.ext;
11981196

1199-
let f = |e: &mut DiagnosticBuilder<'_, _>| {
1197+
let f = |e: &mut Diagnostic| {
12001198
if let Extern::Implicit(start_span) | Extern::Explicit(_, start_span) = &ext
12011199
{
12021200
let start_suggestion = if let Extern::Explicit(abi, _) = ext {

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
451451

452452
fn suggest_borrow_fn_like(
453453
&self,
454-
err: &mut DiagnosticBuilder<'tcx, ErrorGuaranteed>,
454+
err: &mut Diagnostic,
455455
ty: Ty<'tcx>,
456456
move_sites: &[MoveSite],
457457
value_name: &str,
@@ -526,12 +526,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
526526
true
527527
}
528528

529-
fn suggest_adding_copy_bounds(
530-
&self,
531-
err: &mut DiagnosticBuilder<'tcx, ErrorGuaranteed>,
532-
ty: Ty<'tcx>,
533-
span: Span,
534-
) {
529+
fn suggest_adding_copy_bounds(&self, err: &mut Diagnostic, ty: Ty<'tcx>, span: Span) {
535530
let tcx = self.infcx.tcx;
536531
let generics = tcx.generics_of(self.mir_def_id());
537532

compiler/rustc_borrowck/src/diagnostics/region_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
783783

784784
fn maybe_suggest_constrain_dyn_trait_impl(
785785
&self,
786-
diag: &mut DiagnosticBuilder<'tcx, ErrorGuaranteed>,
786+
diag: &mut Diagnostic,
787787
f: Region<'tcx>,
788788
o: Region<'tcx>,
789789
category: &ConstraintCategory<'tcx>,

compiler/rustc_expand/src/mbe/macro_rules.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use rustc_ast::{NodeId, DUMMY_NODE_ID};
1414
use rustc_ast_pretty::pprust;
1515
use rustc_attr::{self as attr, TransparencyError};
1616
use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
17-
use rustc_errors::{Applicability, Diagnostic, DiagnosticBuilder, ErrorGuaranteed};
17+
use rustc_errors::{Applicability, Diagnostic, DiagnosticBuilder};
1818
use rustc_feature::Features;
1919
use rustc_lint_defs::builtin::{
2020
RUST_2021_INCOMPATIBLE_OR_PATTERNS, SEMICOLON_IN_EXPRESSIONS_FROM_MACROS,
@@ -608,11 +608,7 @@ enum ExplainDocComment {
608608
},
609609
}
610610

611-
fn annotate_doc_comment(
612-
err: &mut DiagnosticBuilder<'_, ErrorGuaranteed>,
613-
sm: &SourceMap,
614-
span: Span,
615-
) {
611+
fn annotate_doc_comment(err: &mut Diagnostic, sm: &SourceMap, span: Span) {
616612
if let Ok(src) = sm.span_to_snippet(span) {
617613
if src.starts_with("///") || src.starts_with("/**") {
618614
err.subdiagnostic(ExplainDocComment::Outer { span });

compiler/rustc_parse/src/parser/diagnostics.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use rustc_data_structures::fx::FxHashSet;
1919
use rustc_errors::{
2020
fluent, Applicability, DiagnosticBuilder, DiagnosticMessage, Handler, MultiSpan, PResult,
2121
};
22-
use rustc_errors::{pluralize, struct_span_err, Diagnostic, EmissionGuarantee, ErrorGuaranteed};
22+
use rustc_errors::{pluralize, struct_span_err, Diagnostic, ErrorGuaranteed};
2323
use rustc_macros::{SessionDiagnostic, SessionSubdiagnostic};
2424
use rustc_span::source_map::Spanned;
2525
use rustc_span::symbol::{kw, Ident};
@@ -228,13 +228,13 @@ struct MultiSugg {
228228
}
229229

230230
impl MultiSugg {
231-
fn emit<G: EmissionGuarantee>(self, err: &mut DiagnosticBuilder<'_, G>) {
231+
fn emit(self, err: &mut Diagnostic) {
232232
err.multipart_suggestion(&self.msg, self.patches, self.applicability);
233233
}
234234

235235
/// Overrides individual messages and applicabilities.
236-
fn emit_many<G: EmissionGuarantee>(
237-
err: &mut DiagnosticBuilder<'_, G>,
236+
fn emit_many(
237+
err: &mut Diagnostic,
238238
msg: &str,
239239
applicability: Applicability,
240240
suggestions: impl Iterator<Item = Self>,

compiler/rustc_parse/src/parser/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,7 @@ impl<'a> Parser<'a> {
859859
);
860860
let mut err = self.struct_span_err(span, &msg);
861861

862-
let suggest_parens = |err: &mut DiagnosticBuilder<'_, _>| {
862+
let suggest_parens = |err: &mut Diagnostic| {
863863
let suggestions = vec![
864864
(span.shrink_to_lo(), "(".to_string()),
865865
(span.shrink_to_hi(), ")".to_string()),

compiler/rustc_resolve/src/late/diagnostics.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2021,9 +2021,9 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
20212021

20222022
fn suggest_introducing_lifetime(
20232023
&self,
2024-
err: &mut DiagnosticBuilder<'_, ErrorGuaranteed>,
2024+
err: &mut Diagnostic,
20252025
name: Option<&str>,
2026-
suggest: impl Fn(&mut DiagnosticBuilder<'_, ErrorGuaranteed>, bool, Span, &str, String) -> bool,
2026+
suggest: impl Fn(&mut Diagnostic, bool, Span, &str, String) -> bool,
20272027
) {
20282028
let mut suggest_note = true;
20292029
for rib in self.lifetime_ribs.iter().rev() {
@@ -2149,7 +2149,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
21492149

21502150
pub(crate) fn add_missing_lifetime_specifiers_label(
21512151
&mut self,
2152-
err: &mut DiagnosticBuilder<'_, ErrorGuaranteed>,
2152+
err: &mut Diagnostic,
21532153
lifetime_refs: Vec<MissingLifetime>,
21542154
function_param_lifetimes: Option<(Vec<MissingLifetime>, Vec<ElisionFnParameter>)>,
21552155
) {

compiler/rustc_typeck/src/astconv/mod.rs

+5-8
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ use crate::require_c_abi_if_c_variadic;
1616
use rustc_ast::TraitObjectSyntax;
1717
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1818
use rustc_errors::{
19-
struct_span_err, Applicability, DiagnosticBuilder, ErrorGuaranteed, FatalError, MultiSpan,
19+
struct_span_err, Applicability, Diagnostic, DiagnosticBuilder, ErrorGuaranteed, FatalError,
20+
MultiSpan,
2021
};
2122
use rustc_hir as hir;
2223
use rustc_hir::def::{CtorOf, DefKind, Namespace, Res};
@@ -2106,7 +2107,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
21062107
pub fn prohibit_generics<'a>(
21072108
&self,
21082109
segments: impl Iterator<Item = &'a hir::PathSegment<'a>> + Clone,
2109-
extend: impl Fn(&mut DiagnosticBuilder<'tcx, ErrorGuaranteed>),
2110+
extend: impl Fn(&mut Diagnostic),
21102111
) -> bool {
21112112
let args = segments.clone().flat_map(|segment| segment.args().args);
21122113

@@ -2984,11 +2985,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
29842985
}
29852986

29862987
/// Make sure that we are in the condition to suggest the blanket implementation.
2987-
fn maybe_lint_blanket_trait_impl<T: rustc_errors::EmissionGuarantee>(
2988-
&self,
2989-
self_ty: &hir::Ty<'_>,
2990-
diag: &mut DiagnosticBuilder<'_, T>,
2991-
) {
2988+
fn maybe_lint_blanket_trait_impl(&self, self_ty: &hir::Ty<'_>, diag: &mut Diagnostic) {
29922989
let tcx = self.tcx();
29932990
let parent_id = tcx.hir().get_parent_item(self_ty.hir_id);
29942991
if let hir::Node::Item(hir::Item {
@@ -3081,7 +3078,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
30813078
sugg,
30823079
Applicability::MachineApplicable,
30833080
);
3084-
self.maybe_lint_blanket_trait_impl::<()>(&self_ty, &mut diag);
3081+
self.maybe_lint_blanket_trait_impl(&self_ty, &mut diag);
30853082
diag.emit();
30863083
},
30873084
);

compiler/rustc_typeck/src/check/check.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1525,9 +1525,7 @@ fn detect_discriminant_duplicate<'tcx>(
15251525
) {
15261526
// Helper closure to reduce duplicate code. This gets called everytime we detect a duplicate.
15271527
// Here `idx` refers to the order of which the discriminant appears, and its index in `vs`
1528-
let report = |dis: Discr<'tcx>,
1529-
idx: usize,
1530-
err: &mut DiagnosticBuilder<'_, ErrorGuaranteed>| {
1528+
let report = |dis: Discr<'tcx>, idx: usize, err: &mut Diagnostic| {
15311529
let var = &vs[idx]; // HIR for the duplicate discriminant
15321530
let (span, display_discr) = match var.disr_expr {
15331531
Some(ref expr) => {

compiler/rustc_typeck/src/check/coercion.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1585,9 +1585,9 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
15851585
}
15861586
}
15871587
}
1588-
fn note_unreachable_loop_return<'a>(
1588+
fn note_unreachable_loop_return(
15891589
&self,
1590-
err: &mut DiagnosticBuilder<'a, ErrorGuaranteed>,
1590+
err: &mut Diagnostic,
15911591
expr: &hir::Expr<'tcx>,
15921592
ret_exprs: &Vec<&'tcx hir::Expr<'tcx>>,
15931593
) {

compiler/rustc_typeck/src/check/expr.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use rustc_data_structures::fx::FxHashMap;
2828
use rustc_data_structures::stack::ensure_sufficient_stack;
2929
use rustc_errors::{
3030
pluralize, struct_span_err, Applicability, Diagnostic, DiagnosticBuilder, DiagnosticId,
31-
EmissionGuarantee, ErrorGuaranteed,
31+
ErrorGuaranteed,
3232
};
3333
use rustc_hir as hir;
3434
use rustc_hir::def::{CtorKind, DefKind, Res};
@@ -879,7 +879,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
879879
lhs: &'tcx hir::Expr<'tcx>,
880880
err_code: &'static str,
881881
op_span: Span,
882-
adjust_err: impl FnOnce(&mut DiagnosticBuilder<'tcx, ErrorGuaranteed>),
882+
adjust_err: impl FnOnce(&mut Diagnostic),
883883
) {
884884
if lhs.is_syntactic_place_expr() {
885885
return;
@@ -1089,8 +1089,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10891089

10901090
let lhs_ty = self.check_expr_with_needs(&lhs, Needs::MutPlace);
10911091

1092-
let suggest_deref_binop = |err: &mut DiagnosticBuilder<'tcx, ErrorGuaranteed>,
1093-
rhs_ty: Ty<'tcx>| {
1092+
let suggest_deref_binop = |err: &mut Diagnostic, rhs_ty: Ty<'tcx>| {
10941093
if let Some(lhs_deref_ty) = self.deref_once_mutably_for_diagnostic(lhs_ty) {
10951094
// Can only assign if the type is sized, so if `DerefMut` yields a type that is
10961095
// unsized, do not suggest dereferencing it.
@@ -2205,9 +2204,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
22052204
self.tcx().ty_error()
22062205
}
22072206

2208-
fn check_call_constructor<G: EmissionGuarantee>(
2207+
fn check_call_constructor(
22092208
&self,
2210-
err: &mut DiagnosticBuilder<'_, G>,
2209+
err: &mut Diagnostic,
22112210
base: &'tcx hir::Expr<'tcx>,
22122211
def_id: DefId,
22132212
) {

compiler/rustc_typeck/src/check/fn_ctxt/checks.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1778,7 +1778,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
17781778

17791779
fn label_fn_like(
17801780
&self,
1781-
err: &mut rustc_errors::DiagnosticBuilder<'tcx, rustc_errors::ErrorGuaranteed>,
1781+
err: &mut Diagnostic,
17821782
callable_def_id: Option<DefId>,
17831783
callee_ty: Option<Ty<'tcx>>,
17841784
) {

compiler/rustc_typeck/src/check/method/suggest.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -904,7 +904,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
904904
}
905905
}
906906

907-
let label_span_not_found = |err: &mut DiagnosticBuilder<'_, _>| {
907+
let label_span_not_found = |err: &mut Diagnostic| {
908908
if unsatisfied_predicates.is_empty() {
909909
err.span_label(span, format!("{item_kind} not found in `{ty_str}`"));
910910
let is_string_or_ref_str = match actual.kind() {
@@ -1154,7 +1154,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11541154
rcvr_ty: Ty<'tcx>,
11551155
expr: &hir::Expr<'_>,
11561156
item_name: Ident,
1157-
err: &mut DiagnosticBuilder<'tcx, ErrorGuaranteed>,
1157+
err: &mut Diagnostic,
11581158
) -> bool {
11591159
let tcx = self.tcx;
11601160
let field_receiver = self.autoderef(span, rcvr_ty).find_map(|(ty, _)| match ty.kind() {
@@ -1331,7 +1331,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
13311331

13321332
fn check_for_field_method(
13331333
&self,
1334-
err: &mut DiagnosticBuilder<'tcx, ErrorGuaranteed>,
1334+
err: &mut Diagnostic,
13351335
source: SelfSource<'tcx>,
13361336
span: Span,
13371337
actual: Ty<'tcx>,
@@ -1380,7 +1380,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
13801380

13811381
fn check_for_unwrap_self(
13821382
&self,
1383-
err: &mut DiagnosticBuilder<'tcx, ErrorGuaranteed>,
1383+
err: &mut Diagnostic,
13841384
source: SelfSource<'tcx>,
13851385
span: Span,
13861386
actual: Ty<'tcx>,

compiler/rustc_typeck/src/check/mod.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ use crate::astconv::AstConv;
104104
use crate::check::gather_locals::GatherLocalsVisitor;
105105
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
106106
use rustc_errors::{
107-
pluralize, struct_span_err, Applicability, DiagnosticBuilder, EmissionGuarantee, MultiSpan,
107+
pluralize, struct_span_err, Applicability, Diagnostic, DiagnosticBuilder, MultiSpan,
108108
};
109109
use rustc_hir as hir;
110110
use rustc_hir::def::Res;
@@ -973,12 +973,7 @@ fn has_expected_num_generic_args<'tcx>(
973973
/// * `span` - The span of the snippet
974974
/// * `params` - The number of parameters the constructor accepts
975975
/// * `err` - A mutable diagnostic builder to add the suggestion to
976-
fn suggest_call_constructor<G: EmissionGuarantee>(
977-
span: Span,
978-
kind: CtorOf,
979-
params: usize,
980-
err: &mut DiagnosticBuilder<'_, G>,
981-
) {
976+
fn suggest_call_constructor(span: Span, kind: CtorOf, params: usize, err: &mut Diagnostic) {
982977
// Note: tuple-structs don't have named fields, so just use placeholders
983978
let args = vec!["_"; params].join(", ");
984979
let applicable = if params > 0 {

compiler/rustc_typeck/src/check/op.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
5959
{
6060
// Suppress this error, since we already emitted
6161
// a deref suggestion in check_overloaded_binop
62-
err.delay_as_bug();
62+
err.downgrade_to_delayed_bug();
6363
}
6464
}
6565
});

0 commit comments

Comments
 (0)