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.
This commit is contained in:
commit
e5ecf629dd
7 changed files with 26 additions and 32 deletions
|
@ -1,6 +1,4 @@
|
||||||
use rustc_errors::{
|
use rustc_errors::{Applicability, Diagnostic};
|
||||||
Applicability, Diagnostic, DiagnosticBuilder, EmissionGuarantee, ErrorGuaranteed,
|
|
||||||
};
|
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::intravisit::Visitor;
|
use rustc_hir::intravisit::Visitor;
|
||||||
use rustc_hir::Node;
|
use rustc_hir::Node;
|
||||||
|
@ -629,25 +627,20 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
||||||
self.buffer_error(err);
|
self.buffer_error(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn suggest_map_index_mut_alternatives(
|
fn suggest_map_index_mut_alternatives(&self, ty: Ty<'tcx>, err: &mut Diagnostic, span: Span) {
|
||||||
&self,
|
|
||||||
ty: Ty<'_>,
|
|
||||||
err: &mut DiagnosticBuilder<'_, ErrorGuaranteed>,
|
|
||||||
span: Span,
|
|
||||||
) {
|
|
||||||
let Some(adt) = ty.ty_adt_def() else { return };
|
let Some(adt) = ty.ty_adt_def() else { return };
|
||||||
let did = adt.did();
|
let did = adt.did();
|
||||||
if self.infcx.tcx.is_diagnostic_item(sym::HashMap, did)
|
if self.infcx.tcx.is_diagnostic_item(sym::HashMap, did)
|
||||||
|| self.infcx.tcx.is_diagnostic_item(sym::BTreeMap, did)
|
|| self.infcx.tcx.is_diagnostic_item(sym::BTreeMap, did)
|
||||||
{
|
{
|
||||||
struct V<'a, 'b, 'tcx, G: EmissionGuarantee> {
|
struct V<'a, 'tcx> {
|
||||||
assign_span: Span,
|
assign_span: Span,
|
||||||
err: &'a mut DiagnosticBuilder<'b, G>,
|
err: &'a mut Diagnostic,
|
||||||
ty: Ty<'tcx>,
|
ty: Ty<'tcx>,
|
||||||
suggested: bool,
|
suggested: bool,
|
||||||
}
|
}
|
||||||
impl<'a, 'b: 'a, 'hir, 'tcx, G: EmissionGuarantee> Visitor<'hir> for V<'a, 'b, 'tcx, G> {
|
impl<'a, 'tcx> Visitor<'tcx> for V<'a, 'tcx> {
|
||||||
fn visit_stmt(&mut self, stmt: &'hir hir::Stmt<'hir>) {
|
fn visit_stmt(&mut self, stmt: &'tcx hir::Stmt<'tcx>) {
|
||||||
hir::intravisit::walk_stmt(self, stmt);
|
hir::intravisit::walk_stmt(self, stmt);
|
||||||
let expr = match stmt.kind {
|
let expr = match stmt.kind {
|
||||||
hir::StmtKind::Semi(expr) | hir::StmtKind::Expr(expr) => expr,
|
hir::StmtKind::Semi(expr) | hir::StmtKind::Expr(expr) => expr,
|
||||||
|
@ -705,7 +698,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
||||||
),
|
),
|
||||||
(rv.span.shrink_to_hi(), ")".to_string()),
|
(rv.span.shrink_to_hi(), ")".to_string()),
|
||||||
],
|
],
|
||||||
].into_iter(),
|
],
|
||||||
Applicability::MachineApplicable,
|
Applicability::MachineApplicable,
|
||||||
);
|
);
|
||||||
self.suggested = true;
|
self.suggested = true;
|
||||||
|
|
|
@ -742,7 +742,7 @@ impl Diagnostic {
|
||||||
&mut self,
|
&mut self,
|
||||||
sp: Span,
|
sp: Span,
|
||||||
msg: impl Into<SubdiagnosticMessage>,
|
msg: impl Into<SubdiagnosticMessage>,
|
||||||
suggestions: impl Iterator<Item = String>,
|
suggestions: impl IntoIterator<Item = String>,
|
||||||
applicability: Applicability,
|
applicability: Applicability,
|
||||||
) -> &mut Self {
|
) -> &mut Self {
|
||||||
self.span_suggestions_with_style(
|
self.span_suggestions_with_style(
|
||||||
|
@ -759,11 +759,11 @@ impl Diagnostic {
|
||||||
&mut self,
|
&mut self,
|
||||||
sp: Span,
|
sp: Span,
|
||||||
msg: impl Into<SubdiagnosticMessage>,
|
msg: impl Into<SubdiagnosticMessage>,
|
||||||
suggestions: impl Iterator<Item = String>,
|
suggestions: impl IntoIterator<Item = String>,
|
||||||
applicability: Applicability,
|
applicability: Applicability,
|
||||||
style: SuggestionStyle,
|
style: SuggestionStyle,
|
||||||
) -> &mut Self {
|
) -> &mut Self {
|
||||||
let mut suggestions: Vec<_> = suggestions.collect();
|
let mut suggestions: Vec<_> = suggestions.into_iter().collect();
|
||||||
suggestions.sort();
|
suggestions.sort();
|
||||||
|
|
||||||
debug_assert!(
|
debug_assert!(
|
||||||
|
@ -790,10 +790,10 @@ impl Diagnostic {
|
||||||
pub fn multipart_suggestions(
|
pub fn multipart_suggestions(
|
||||||
&mut self,
|
&mut self,
|
||||||
msg: impl Into<SubdiagnosticMessage>,
|
msg: impl Into<SubdiagnosticMessage>,
|
||||||
suggestions: impl Iterator<Item = Vec<(Span, String)>>,
|
suggestions: impl IntoIterator<Item = Vec<(Span, String)>>,
|
||||||
applicability: Applicability,
|
applicability: Applicability,
|
||||||
) -> &mut Self {
|
) -> &mut Self {
|
||||||
let suggestions: Vec<_> = suggestions.collect();
|
let suggestions: Vec<_> = suggestions.into_iter().collect();
|
||||||
debug_assert!(
|
debug_assert!(
|
||||||
!(suggestions
|
!(suggestions
|
||||||
.iter()
|
.iter()
|
||||||
|
|
|
@ -599,13 +599,13 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
|
||||||
&mut self,
|
&mut self,
|
||||||
sp: Span,
|
sp: Span,
|
||||||
msg: impl Into<SubdiagnosticMessage>,
|
msg: impl Into<SubdiagnosticMessage>,
|
||||||
suggestions: impl Iterator<Item = String>,
|
suggestions: impl IntoIterator<Item = String>,
|
||||||
applicability: Applicability,
|
applicability: Applicability,
|
||||||
) -> &mut Self);
|
) -> &mut Self);
|
||||||
forward!(pub fn multipart_suggestions(
|
forward!(pub fn multipart_suggestions(
|
||||||
&mut self,
|
&mut self,
|
||||||
msg: impl Into<SubdiagnosticMessage>,
|
msg: impl Into<SubdiagnosticMessage>,
|
||||||
suggestions: impl Iterator<Item = Vec<(Span, String)>>,
|
suggestions: impl IntoIterator<Item = Vec<(Span, String)>>,
|
||||||
applicability: Applicability,
|
applicability: Applicability,
|
||||||
) -> &mut Self);
|
) -> &mut Self);
|
||||||
forward!(pub fn span_suggestion_short(
|
forward!(pub fn span_suggestion_short(
|
||||||
|
|
|
@ -401,7 +401,7 @@ impl<'a> Parser<'a> {
|
||||||
.span_suggestions(
|
.span_suggestions(
|
||||||
span.shrink_to_hi(),
|
span.shrink_to_hi(),
|
||||||
"add `mut` or `const` here",
|
"add `mut` or `const` here",
|
||||||
["mut ".to_string(), "const ".to_string()].into_iter(),
|
["mut ".to_string(), "const ".to_string()],
|
||||||
Applicability::HasPlaceholders,
|
Applicability::HasPlaceholders,
|
||||||
)
|
)
|
||||||
.emit();
|
.emit();
|
||||||
|
|
|
@ -87,6 +87,7 @@ use self::VarKind::*;
|
||||||
use rustc_ast::InlineAsmOptions;
|
use rustc_ast::InlineAsmOptions;
|
||||||
use rustc_data_structures::fx::FxIndexMap;
|
use rustc_data_structures::fx::FxIndexMap;
|
||||||
use rustc_errors::Applicability;
|
use rustc_errors::Applicability;
|
||||||
|
use rustc_errors::Diagnostic;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def::*;
|
use rustc_hir::def::*;
|
||||||
use rustc_hir::def_id::{DefId, LocalDefId};
|
use rustc_hir::def_id::{DefId, LocalDefId};
|
||||||
|
@ -1690,7 +1691,7 @@ impl<'tcx> Liveness<'_, 'tcx> {
|
||||||
&self,
|
&self,
|
||||||
name: &str,
|
name: &str,
|
||||||
opt_body: Option<&hir::Body<'_>>,
|
opt_body: Option<&hir::Body<'_>>,
|
||||||
err: &mut rustc_errors::DiagnosticBuilder<'_, ()>,
|
err: &mut Diagnostic,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
let mut has_litstring = false;
|
let mut has_litstring = false;
|
||||||
let Some(opt_body) = opt_body else {return false;};
|
let Some(opt_body) = opt_body else {return false;};
|
||||||
|
|
|
@ -437,7 +437,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
|
||||||
|
|
||||||
fn try_lookup_name_relaxed(
|
fn try_lookup_name_relaxed(
|
||||||
&mut self,
|
&mut self,
|
||||||
err: &mut DiagnosticBuilder<'_, ErrorGuaranteed>,
|
err: &mut Diagnostic,
|
||||||
source: PathSource<'_>,
|
source: PathSource<'_>,
|
||||||
path: &[Segment],
|
path: &[Segment],
|
||||||
span: Span,
|
span: Span,
|
||||||
|
@ -497,7 +497,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
|
||||||
.contains(span)
|
.contains(span)
|
||||||
{
|
{
|
||||||
// Already reported this issue on the lhs of the type ascription.
|
// Already reported this issue on the lhs of the type ascription.
|
||||||
err.delay_as_bug();
|
err.downgrade_to_delayed_bug();
|
||||||
return (true, candidates);
|
return (true, candidates);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -616,7 +616,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
|
||||||
|
|
||||||
fn suggest_trait_and_bounds(
|
fn suggest_trait_and_bounds(
|
||||||
&mut self,
|
&mut self,
|
||||||
err: &mut DiagnosticBuilder<'_, ErrorGuaranteed>,
|
err: &mut Diagnostic,
|
||||||
source: PathSource<'_>,
|
source: PathSource<'_>,
|
||||||
res: Option<Res>,
|
res: Option<Res>,
|
||||||
span: Span,
|
span: Span,
|
||||||
|
@ -691,7 +691,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
|
||||||
|
|
||||||
fn suggest_typo(
|
fn suggest_typo(
|
||||||
&mut self,
|
&mut self,
|
||||||
err: &mut DiagnosticBuilder<'_, ErrorGuaranteed>,
|
err: &mut Diagnostic,
|
||||||
source: PathSource<'_>,
|
source: PathSource<'_>,
|
||||||
path: &[Segment],
|
path: &[Segment],
|
||||||
span: Span,
|
span: Span,
|
||||||
|
@ -750,7 +750,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
|
||||||
|
|
||||||
fn err_code_special_cases(
|
fn err_code_special_cases(
|
||||||
&mut self,
|
&mut self,
|
||||||
err: &mut DiagnosticBuilder<'_, ErrorGuaranteed>,
|
err: &mut Diagnostic,
|
||||||
source: PathSource<'_>,
|
source: PathSource<'_>,
|
||||||
path: &[Segment],
|
path: &[Segment],
|
||||||
span: Span,
|
span: Span,
|
||||||
|
@ -1941,7 +1941,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
|
||||||
err.span_suggestions(
|
err.span_suggestions(
|
||||||
span,
|
span,
|
||||||
&msg,
|
&msg,
|
||||||
suggestable_variants.into_iter(),
|
suggestable_variants,
|
||||||
Applicability::MaybeIncorrect,
|
Applicability::MaybeIncorrect,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1995,7 +1995,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
|
||||||
err.span_suggestions(
|
err.span_suggestions(
|
||||||
span,
|
span,
|
||||||
msg,
|
msg,
|
||||||
suggestable_variants.into_iter(),
|
suggestable_variants,
|
||||||
Applicability::MaybeIncorrect,
|
Applicability::MaybeIncorrect,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -2025,7 +2025,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
|
||||||
err.span_suggestions(
|
err.span_suggestions(
|
||||||
span,
|
span,
|
||||||
msg,
|
msg,
|
||||||
suggestable_variants_with_placeholders.into_iter(),
|
suggestable_variants_with_placeholders,
|
||||||
Applicability::HasPlaceholders,
|
Applicability::HasPlaceholders,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1116,7 +1116,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
||||||
err.span_suggestions(
|
err.span_suggestions(
|
||||||
span.shrink_to_lo(),
|
span.shrink_to_lo(),
|
||||||
"consider borrowing here",
|
"consider borrowing here",
|
||||||
["&".to_string(), "&mut ".to_string()].into_iter(),
|
["&".to_string(), "&mut ".to_string()],
|
||||||
Applicability::MaybeIncorrect,
|
Applicability::MaybeIncorrect,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue