aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_assists/src/assists/add_explicit_type.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-11-26 11:05:05 +0000
committerGitHub <[email protected]>2019-11-26 11:05:05 +0000
commit500e022f7decbee29a693b0f0dd2f63789a99e5a (patch)
tree2f7839288ce5676a89c6d6062cbaf70544e0beed /crates/ra_assists/src/assists/add_explicit_type.rs
parent5901cc736074bbc4d780a8e45079d405ab2cec4b (diff)
parente5eadb339039e21718d382c0b3d02a4bf053b3f4 (diff)
Merge #2398
2398: WIP: introduce hir::Type r=matklad a=matklad This introduces `hir::Type` wrapper over `hir::Ty`, with two purposes: * bind `Ty` and it's corresponding environment * Am I correct that `Ty` without an env doesn't make much sense, because the meaning of type parameters is unclear * Am I correct that we can safely re-use the same environment for all types derived from the given type? * hide representation defails of `Ty`. Specifically, I want to change `Ty::Adt` to use `hir_def::AdtId` instead of `hir::Adt`, but IDE doesn't know about underlying IDs. More generally, I feel like IDE shouldn't know that `Ty` is enum. @flodiebold what do you think about this? Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_assists/src/assists/add_explicit_type.rs')
-rw-r--r--crates/ra_assists/src/assists/add_explicit_type.rs13
1 files changed, 2 insertions, 11 deletions
diff --git a/crates/ra_assists/src/assists/add_explicit_type.rs b/crates/ra_assists/src/assists/add_explicit_type.rs
index 562a09685..eeb4ff39f 100644
--- a/crates/ra_assists/src/assists/add_explicit_type.rs
+++ b/crates/ra_assists/src/assists/add_explicit_type.rs
@@ -1,4 +1,4 @@
1use hir::{db::HirDatabase, HirDisplay, Ty}; 1use hir::{db::HirDatabase, HirDisplay};
2use ra_syntax::{ 2use ra_syntax::{
3 ast::{self, AstNode, LetStmt, NameOwner}, 3 ast::{self, AstNode, LetStmt, NameOwner},
4 T, 4 T,
@@ -43,7 +43,7 @@ pub(crate) fn add_explicit_type(ctx: AssistCtx<impl HirDatabase>) -> Option<Assi
43 let analyzer = ctx.source_analyzer(stmt.syntax(), None); 43 let analyzer = ctx.source_analyzer(stmt.syntax(), None);
44 let ty = analyzer.type_of(db, &expr)?; 44 let ty = analyzer.type_of(db, &expr)?;
45 // Assist not applicable if the type is unknown 45 // Assist not applicable if the type is unknown
46 if is_unknown(&ty) { 46 if ty.contains_unknown() {
47 return None; 47 return None;
48 } 48 }
49 49
@@ -53,15 +53,6 @@ pub(crate) fn add_explicit_type(ctx: AssistCtx<impl HirDatabase>) -> Option<Assi
53 }) 53 })
54} 54}
55 55
56/// Returns true if any type parameter is unknown
57fn is_unknown(ty: &Ty) -> bool {
58 match ty {
59 Ty::Unknown => true,
60 Ty::Apply(a_ty) => a_ty.parameters.iter().any(is_unknown),
61 _ => false,
62 }
63}
64
65#[cfg(test)] 56#[cfg(test)]
66mod tests { 57mod tests {
67 use super::*; 58 use super::*;