mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-26 20:09:19 +00:00
add unnecessary else diagnostic
This commit is contained in:
parent
1974e7490d
commit
62cc4f9c46
6 changed files with 380 additions and 4 deletions
|
@ -68,6 +68,7 @@ diagnostics![
|
|||
PrivateAssocItem,
|
||||
PrivateField,
|
||||
ReplaceFilterMapNextWithFindMap,
|
||||
RemoveUnnecessaryElse,
|
||||
TraitImplIncorrectSafety,
|
||||
TraitImplMissingAssocItems,
|
||||
TraitImplOrphan,
|
||||
|
@ -342,6 +343,11 @@ pub struct TraitImplRedundantAssocItems {
|
|||
pub assoc_item: (Name, AssocItem),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct RemoveUnnecessaryElse {
|
||||
pub if_expr: InFile<AstPtr<ast::IfExpr>>,
|
||||
}
|
||||
|
||||
impl AnyDiagnostic {
|
||||
pub(crate) fn body_validation_diagnostic(
|
||||
db: &dyn HirDatabase,
|
||||
|
@ -444,6 +450,16 @@ impl AnyDiagnostic {
|
|||
Err(SyntheticSyntax) => (),
|
||||
}
|
||||
}
|
||||
BodyValidationDiagnostic::RemoveUnnecessaryElse { if_expr } => {
|
||||
if let Ok(source_ptr) = source_map.expr_syntax(if_expr) {
|
||||
if let Some(ptr) = source_ptr.value.cast::<ast::IfExpr>() {
|
||||
return Some(
|
||||
RemoveUnnecessaryElse { if_expr: InFile::new(source_ptr.file_id, ptr) }
|
||||
.into(),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue