Skip to content

Commit e5ecf62

Browse files
Rollup merge of #102763 - compiler-errors:nits, r=cjgillot
Some diagnostic-related nits 1. Use `&mut Diagnostic` instead of `&mut DiagnosticBuilder<'_, T>` 2. Make `diag.span_suggestions` take an `IntoIterator` instead of `Iterator`, just to remove some `.into_iter` calls on the caller. idk if I should add a lint to make sure people use `&mut Diagnostic` instead of `&mut DiagnosticBuilder<'_, T>` in cases where we're just, e.g., adding subdiagnostics to the diagnostic... maybe a followup.
2 parents 5eef9b2 + 9568138 commit e5ecf62

File tree

7 files changed

+26
-32
lines changed

7 files changed

+26
-32
lines changed

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

+7-14
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
use rustc_errors::{
2-
Applicability, Diagnostic, DiagnosticBuilder, EmissionGuarantee, ErrorGuaranteed,
3-
};
1+
use rustc_errors::{Applicability, Diagnostic};
42
use rustc_hir as hir;
53
use rustc_hir::intravisit::Visitor;
64
use rustc_hir::Node;
@@ -629,25 +627,20 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
629627
self.buffer_error(err);
630628
}
631629

632-
fn suggest_map_index_mut_alternatives(
633-
&self,
634-
ty: Ty<'_>,
635-
err: &mut DiagnosticBuilder<'_, ErrorGuaranteed>,
636-
span: Span,
637-
) {
630+
fn suggest_map_index_mut_alternatives(&self, ty: Ty<'tcx>, err: &mut Diagnostic, span: Span) {
638631
let Some(adt) = ty.ty_adt_def() else { return };
639632
let did = adt.did();
640633
if self.infcx.tcx.is_diagnostic_item(sym::HashMap, did)
641634
|| self.infcx.tcx.is_diagnostic_item(sym::BTreeMap, did)
642635
{
643-
struct V<'a, 'b, 'tcx, G: EmissionGuarantee> {
636+
struct V<'a, 'tcx> {
644637
assign_span: Span,
645-
err: &'a mut DiagnosticBuilder<'b, G>,
638+
err: &'a mut Diagnostic,
646639
ty: Ty<'tcx>,
647640
suggested: bool,
648641
}
649-
impl<'a, 'b: 'a, 'hir, 'tcx, G: EmissionGuarantee> Visitor<'hir> for V<'a, 'b, 'tcx, G> {
650-
fn visit_stmt(&mut self, stmt: &'hir hir::Stmt<'hir>) {
642+
impl<'a, 'tcx> Visitor<'tcx> for V<'a, 'tcx> {
643+
fn visit_stmt(&mut self, stmt: &'tcx hir::Stmt<'tcx>) {
651644
hir::intravisit::walk_stmt(self, stmt);
652645
let expr = match stmt.kind {
653646
hir::StmtKind::Semi(expr) | hir::StmtKind::Expr(expr) => expr,
@@ -705,7 +698,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
705698
),
706699
(rv.span.shrink_to_hi(), ")".to_string()),
707700
],
708-
].into_iter(),
701+
],
709702
Applicability::MachineApplicable,
710703
);
711704
self.suggested = true;

compiler/rustc_errors/src/diagnostic.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,7 @@ impl Diagnostic {
742742
&mut self,
743743
sp: Span,
744744
msg: impl Into<SubdiagnosticMessage>,
745-
suggestions: impl Iterator<Item = String>,
745+
suggestions: impl IntoIterator<Item = String>,
746746
applicability: Applicability,
747747
) -> &mut Self {
748748
self.span_suggestions_with_style(
@@ -759,11 +759,11 @@ impl Diagnostic {
759759
&mut self,
760760
sp: Span,
761761
msg: impl Into<SubdiagnosticMessage>,
762-
suggestions: impl Iterator<Item = String>,
762+
suggestions: impl IntoIterator<Item = String>,
763763
applicability: Applicability,
764764
style: SuggestionStyle,
765765
) -> &mut Self {
766-
let mut suggestions: Vec<_> = suggestions.collect();
766+
let mut suggestions: Vec<_> = suggestions.into_iter().collect();
767767
suggestions.sort();
768768

769769
debug_assert!(
@@ -790,10 +790,10 @@ impl Diagnostic {
790790
pub fn multipart_suggestions(
791791
&mut self,
792792
msg: impl Into<SubdiagnosticMessage>,
793-
suggestions: impl Iterator<Item = Vec<(Span, String)>>,
793+
suggestions: impl IntoIterator<Item = Vec<(Span, String)>>,
794794
applicability: Applicability,
795795
) -> &mut Self {
796-
let suggestions: Vec<_> = suggestions.collect();
796+
let suggestions: Vec<_> = suggestions.into_iter().collect();
797797
debug_assert!(
798798
!(suggestions
799799
.iter()

compiler/rustc_errors/src/diagnostic_builder.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -599,13 +599,13 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
599599
&mut self,
600600
sp: Span,
601601
msg: impl Into<SubdiagnosticMessage>,
602-
suggestions: impl Iterator<Item = String>,
602+
suggestions: impl IntoIterator<Item = String>,
603603
applicability: Applicability,
604604
) -> &mut Self);
605605
forward!(pub fn multipart_suggestions(
606606
&mut self,
607607
msg: impl Into<SubdiagnosticMessage>,
608-
suggestions: impl Iterator<Item = Vec<(Span, String)>>,
608+
suggestions: impl IntoIterator<Item = Vec<(Span, String)>>,
609609
applicability: Applicability,
610610
) -> &mut Self);
611611
forward!(pub fn span_suggestion_short(

compiler/rustc_parse/src/parser/ty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ impl<'a> Parser<'a> {
401401
.span_suggestions(
402402
span.shrink_to_hi(),
403403
"add `mut` or `const` here",
404-
["mut ".to_string(), "const ".to_string()].into_iter(),
404+
["mut ".to_string(), "const ".to_string()],
405405
Applicability::HasPlaceholders,
406406
)
407407
.emit();

compiler/rustc_passes/src/liveness.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ use self::VarKind::*;
8787
use rustc_ast::InlineAsmOptions;
8888
use rustc_data_structures::fx::FxIndexMap;
8989
use rustc_errors::Applicability;
90+
use rustc_errors::Diagnostic;
9091
use rustc_hir as hir;
9192
use rustc_hir::def::*;
9293
use rustc_hir::def_id::{DefId, LocalDefId};
@@ -1690,7 +1691,7 @@ impl<'tcx> Liveness<'_, 'tcx> {
16901691
&self,
16911692
name: &str,
16921693
opt_body: Option<&hir::Body<'_>>,
1693-
err: &mut rustc_errors::DiagnosticBuilder<'_, ()>,
1694+
err: &mut Diagnostic,
16941695
) -> bool {
16951696
let mut has_litstring = false;
16961697
let Some(opt_body) = opt_body else {return false;};

compiler/rustc_resolve/src/late/diagnostics.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
437437

438438
fn try_lookup_name_relaxed(
439439
&mut self,
440-
err: &mut DiagnosticBuilder<'_, ErrorGuaranteed>,
440+
err: &mut Diagnostic,
441441
source: PathSource<'_>,
442442
path: &[Segment],
443443
span: Span,
@@ -497,7 +497,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
497497
.contains(span)
498498
{
499499
// Already reported this issue on the lhs of the type ascription.
500-
err.delay_as_bug();
500+
err.downgrade_to_delayed_bug();
501501
return (true, candidates);
502502
}
503503
}
@@ -616,7 +616,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
616616

617617
fn suggest_trait_and_bounds(
618618
&mut self,
619-
err: &mut DiagnosticBuilder<'_, ErrorGuaranteed>,
619+
err: &mut Diagnostic,
620620
source: PathSource<'_>,
621621
res: Option<Res>,
622622
span: Span,
@@ -691,7 +691,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
691691

692692
fn suggest_typo(
693693
&mut self,
694-
err: &mut DiagnosticBuilder<'_, ErrorGuaranteed>,
694+
err: &mut Diagnostic,
695695
source: PathSource<'_>,
696696
path: &[Segment],
697697
span: Span,
@@ -750,7 +750,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
750750

751751
fn err_code_special_cases(
752752
&mut self,
753-
err: &mut DiagnosticBuilder<'_, ErrorGuaranteed>,
753+
err: &mut Diagnostic,
754754
source: PathSource<'_>,
755755
path: &[Segment],
756756
span: Span,
@@ -1941,7 +1941,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
19411941
err.span_suggestions(
19421942
span,
19431943
&msg,
1944-
suggestable_variants.into_iter(),
1944+
suggestable_variants,
19451945
Applicability::MaybeIncorrect,
19461946
);
19471947
}
@@ -1995,7 +1995,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
19951995
err.span_suggestions(
19961996
span,
19971997
msg,
1998-
suggestable_variants.into_iter(),
1998+
suggestable_variants,
19991999
Applicability::MaybeIncorrect,
20002000
);
20012001
}
@@ -2025,7 +2025,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
20252025
err.span_suggestions(
20262026
span,
20272027
msg,
2028-
suggestable_variants_with_placeholders.into_iter(),
2028+
suggestable_variants_with_placeholders,
20292029
Applicability::HasPlaceholders,
20302030
);
20312031
}

compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1116,7 +1116,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
11161116
err.span_suggestions(
11171117
span.shrink_to_lo(),
11181118
"consider borrowing here",
1119-
["&".to_string(), "&mut ".to_string()].into_iter(),
1119+
["&".to_string(), "&mut ".to_string()],
11201120
Applicability::MaybeIncorrect,
11211121
);
11221122
} else {

0 commit comments

Comments
 (0)