use subdiagnostic for sugesting add let
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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()});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user