From 6203e9c4faee288f16d93dbb7dd0f1f8df487d83 Mon Sep 17 00:00:00 2001 From: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com> Date: Thu, 7 May 2020 11:23:38 +0200 Subject: add if let and while let postfix for Option and Result #4348 Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com> --- crates/ra_hir/src/code_model.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'crates/ra_hir/src') diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 5f480c304..7e840add5 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs @@ -1083,6 +1083,28 @@ impl Type { matches!(self.ty.value, Ty::Apply(ApplicationTy { ctor: TypeCtor::Bool, .. })) } + pub fn is_option(&self, db: &dyn HirDatabase) -> bool { + if let Some(adt_ty) = self.as_adt() { + if let Adt::Enum(_) = adt_ty { + if self.display(db).to_string().starts_with("Option<") { + return true; + } + } + } + false + } + + pub fn is_result(&self, db: &dyn HirDatabase) -> bool { + if let Some(adt_ty) = self.as_adt() { + if let Adt::Enum(_) = adt_ty { + if self.display(db).to_string().starts_with("Result<") { + return true; + } + } + } + false + } + pub fn is_mutable_reference(&self) -> bool { matches!( self.ty.value, -- cgit v1.2.3