]> git.lizzy.rs Git - rust.git/commitdiff
Improve readability in inlay_hints.rs
authorIgor Aleksanov <popzxc@yandex.ru>
Sat, 3 Oct 2020 10:44:43 +0000 (13:44 +0300)
committerIgor Aleksanov <popzxc@yandex.ru>
Sat, 3 Oct 2020 10:44:43 +0000 (13:44 +0300)
crates/ide/src/inlay_hints.rs

index 29f3b6828c11e3845199c7135acd4a0f30dca40e..1d7e8de565903e44fd438955e550f34a71bef722 100644 (file)
@@ -254,10 +254,11 @@ fn should_not_display_type_hint(
                 ast::ForExpr(it) => {
                     // We *should* display hint only if user provided "in {expr}" and we know the type of expr (and it's not unit).
                     // Type of expr should be iterable.
-                    let type_is_known = |ty: Option<hir::Type>| ty.map(|ty| !ty.is_unit() && !ty.is_unknown()).unwrap_or(false);
-                    let should_display = it.in_token().is_some()
-                        && it.iterable().map(|expr| type_is_known(sema.type_of_expr(&expr))).unwrap_or(false);
-                    return !should_display;
+                    return it.in_token().is_none() ||
+                        it.iterable()
+                            .and_then(|iterable_expr|sema.type_of_expr(&iterable_expr))
+                            .map(|iterable_ty| iterable_ty.is_unknown() || iterable_ty.is_unit())
+                            .unwrap_or(true)
                 },
                 _ => (),
             }