Skip to content

Commit 466a634

Browse files
authored
Rollup merge of rust-lang#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 6e95b6d + c1538f0 commit 466a634

File tree

7 files changed

+24
-30
lines changed

7 files changed

+24
-30
lines changed

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

Lines changed: 7 additions & 14 deletions
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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -688,10 +688,10 @@ impl Diagnostic {
688688
&mut self,
689689
sp: Span,
690690
msg: impl Into<SubdiagnosticMessage>,
691-
suggestions: impl Iterator<Item = String>,
691+
suggestions: impl IntoIterator<Item = String>,
692692
applicability: Applicability,
693693
) -> &mut Self {
694-
let mut suggestions: Vec<_> = suggestions.collect();
694+
let mut suggestions: Vec<_> = suggestions.into_iter().collect();
695695
suggestions.sort();
696696

697697
debug_assert!(
@@ -717,7 +717,7 @@ impl Diagnostic {
717717
pub fn multipart_suggestions(
718718
&mut self,
719719
msg: impl Into<SubdiagnosticMessage>,
720-
suggestions: impl Iterator<Item = Vec<(Span, String)>>,
720+
suggestions: impl IntoIterator<Item = Vec<(Span, String)>>,
721721
applicability: Applicability,
722722
) -> &mut Self {
723723
let suggestions: Vec<_> = suggestions.collect();

compiler/rustc_errors/src/diagnostic_builder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -594,13 +594,13 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
594594
&mut self,
595595
sp: Span,
596596
msg: impl Into<SubdiagnosticMessage>,
597-
suggestions: impl Iterator<Item = String>,
597+
suggestions: impl IntoIterator<Item = String>,
598598
applicability: Applicability,
599599
) -> &mut Self);
600600
forward!(pub fn multipart_suggestions(
601601
&mut self,
602602
msg: impl Into<SubdiagnosticMessage>,
603-
suggestions: impl Iterator<Item = Vec<(Span, String)>>,
603+
suggestions: impl IntoIterator<Item = Vec<(Span, String)>>,
604604
applicability: Applicability,
605605
) -> &mut Self);
606606
forward!(pub fn span_suggestion_short(

compiler/rustc_parse/src/parser/ty.rs

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
422422

423423
fn try_lookup_name_relaxed(
424424
&mut self,
425-
err: &mut DiagnosticBuilder<'_, ErrorGuaranteed>,
425+
err: &mut Diagnostic,
426426
source: PathSource<'_>,
427427
path: &[Segment],
428428
span: Span,
@@ -482,7 +482,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
482482
.contains(span)
483483
{
484484
// Already reported this issue on the lhs of the type ascription.
485-
err.delay_as_bug();
485+
err.downgrade_to_delayed_bug();
486486
return (true, candidates);
487487
}
488488
}
@@ -594,7 +594,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
594594

595595
fn suggest_trait_and_bounds(
596596
&mut self,
597-
err: &mut DiagnosticBuilder<'_, ErrorGuaranteed>,
597+
err: &mut Diagnostic,
598598
source: PathSource<'_>,
599599
res: Option<Res>,
600600
span: Span,
@@ -669,7 +669,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
669669

670670
fn suggest_typo(
671671
&mut self,
672-
err: &mut DiagnosticBuilder<'_, ErrorGuaranteed>,
672+
err: &mut Diagnostic,
673673
source: PathSource<'_>,
674674
path: &[Segment],
675675
span: Span,
@@ -715,7 +715,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
715715

716716
fn err_code_special_cases(
717717
&mut self,
718-
err: &mut DiagnosticBuilder<'_, ErrorGuaranteed>,
718+
err: &mut Diagnostic,
719719
source: PathSource<'_>,
720720
path: &[Segment],
721721
span: Span,
@@ -1921,7 +1921,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
19211921
err.span_suggestions(
19221922
span,
19231923
&msg,
1924-
suggestable_variants.into_iter(),
1924+
suggestable_variants,
19251925
Applicability::MaybeIncorrect,
19261926
);
19271927
}
@@ -1975,7 +1975,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
19751975
err.span_suggestions(
19761976
span,
19771977
msg,
1978-
suggestable_variants.into_iter(),
1978+
suggestable_variants,
19791979
Applicability::MaybeIncorrect,
19801980
);
19811981
}
@@ -2005,7 +2005,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
20052005
err.span_suggestions(
20062006
span,
20072007
msg,
2008-
suggestable_variants_with_placeholders.into_iter(),
2008+
suggestable_variants_with_placeholders,
20092009
Applicability::HasPlaceholders,
20102010
);
20112011
}

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

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

0 commit comments

Comments
 (0)