1
Fork 0

use subdiagnostic for sugesting add let

This commit is contained in:
yukang 2022-11-08 16:04:14 +08:00
parent 667b15bb0e
commit 9e7d2287cd
5 changed files with 21 additions and 7 deletions

View file

@ -180,6 +180,18 @@ pub enum SourceKindMultiSuggestion<'a> {
},
}
#[derive(Subdiagnostic)]
#[suggestion(
infer_suggest_add_let_for_letchains,
style = "verbose",
applicability = "machine-applicable",
code = "let "
)]
pub(crate) struct SuggAddLetForLetChains {
#[primary_span]
pub span: Span,
}
impl<'a> SourceKindMultiSuggestion<'a> {
pub fn new_fully_qualified(
span: Span,

View file

@ -59,6 +59,7 @@ use crate::traits::{
StatementAsExpression,
};
use crate::errors::SuggAddLetForLetChains;
use hir::intravisit::{walk_expr, walk_stmt};
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
use rustc_errors::{pluralize, struct_span_err, Diagnostic, ErrorGuaranteed, IntoDiagnosticArg};
@ -2421,12 +2422,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
let mut visitor = IfVisitor { err_span: span, found_if: false, result: false };
visitor.visit_body(&body);
if visitor.result {
err.span_suggestion_verbose(
span.shrink_to_lo(),
"consider adding `let`",
"let ".to_string(),
Applicability::MachineApplicable,
);
err.subdiagnostic(SuggAddLetForLetChains{span: span.shrink_to_lo()});
}
}
}