aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/ty
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/ty')
-rw-r--r--crates/ra_hir/src/ty/method_resolution.rs53
-rw-r--r--crates/ra_hir/src/ty/primitive.rs50
-rw-r--r--crates/ra_hir/src/ty/tests.rs69
-rw-r--r--crates/ra_hir/src/ty/tests/data/basics.txt8
-rw-r--r--crates/ra_hir/src/ty/tests/data/binary_op.txt86
-rw-r--r--crates/ra_hir/src/ty/tests/data/let.txt4
-rw-r--r--crates/ra_hir/src/ty/tests/data/literals.txt12
-rw-r--r--crates/ra_hir/src/ty/tests/data/struct.txt4
-rw-r--r--crates/ra_hir/src/ty/tests/data/tuple.txt18
-rw-r--r--crates/ra_hir/src/ty/tests/data/unary_op.txt28
10 files changed, 231 insertions, 101 deletions
diff --git a/crates/ra_hir/src/ty/method_resolution.rs b/crates/ra_hir/src/ty/method_resolution.rs
index 7c3839388..b221bd142 100644
--- a/crates/ra_hir/src/ty/method_resolution.rs
+++ b/crates/ra_hir/src/ty/method_resolution.rs
@@ -6,7 +6,7 @@ use std::sync::Arc;
6 6
7use rustc_hash::FxHashMap; 7use rustc_hash::FxHashMap;
8 8
9use ra_db::{Cancelable, SourceRootId}; 9use ra_db::SourceRootId;
10 10
11use crate::{HirDatabase, DefId, module_tree::ModuleId, Module, Crate, Name, Function, impl_block::{ImplId, ImplBlock, ImplItem}}; 11use crate::{HirDatabase, DefId, module_tree::ModuleId, Module, Crate, Name, Function, impl_block::{ImplId, ImplBlock, ImplItem}};
12use super::Ty; 12use super::Ty;
@@ -42,21 +42,21 @@ impl CrateImplBlocks {
42 &'a self, 42 &'a self,
43 db: &'a impl HirDatabase, 43 db: &'a impl HirDatabase,
44 ty: &Ty, 44 ty: &Ty,
45 ) -> impl Iterator<Item = Cancelable<ImplBlock>> + 'a { 45 ) -> impl Iterator<Item = ImplBlock> + 'a {
46 let fingerprint = TyFingerprint::for_impl(ty); 46 let fingerprint = TyFingerprint::for_impl(ty);
47 fingerprint 47 fingerprint
48 .and_then(|f| self.impls.get(&f)) 48 .and_then(|f| self.impls.get(&f))
49 .into_iter() 49 .into_iter()
50 .flat_map(|i| i.iter()) 50 .flat_map(|i| i.iter())
51 .map(move |(module_id, impl_id)| { 51 .map(move |(module_id, impl_id)| {
52 let module_impl_blocks = db.impls_in_module(self.source_root_id, *module_id)?; 52 let module_impl_blocks = db.impls_in_module(self.source_root_id, *module_id);
53 Ok(ImplBlock::from_id(module_impl_blocks, *impl_id)) 53 ImplBlock::from_id(module_impl_blocks, *impl_id)
54 }) 54 })
55 } 55 }
56 56
57 fn collect_recursive(&mut self, db: &impl HirDatabase, module: Module) -> Cancelable<()> { 57 fn collect_recursive(&mut self, db: &impl HirDatabase, module: Module) {
58 let module_id = module.def_id.loc(db).module_id; 58 let module_id = module.def_id.loc(db).module_id;
59 let module_impl_blocks = db.impls_in_module(self.source_root_id, module_id)?; 59 let module_impl_blocks = db.impls_in_module(self.source_root_id, module_id);
60 60
61 for (impl_id, impl_data) in module_impl_blocks.impls.iter() { 61 for (impl_id, impl_data) in module_impl_blocks.impls.iter() {
62 let impl_block = ImplBlock::from_id(Arc::clone(&module_impl_blocks), impl_id); 62 let impl_block = ImplBlock::from_id(Arc::clone(&module_impl_blocks), impl_id);
@@ -65,7 +65,7 @@ impl CrateImplBlocks {
65 // ignore for now 65 // ignore for now
66 } else { 66 } else {
67 let target_ty = 67 let target_ty =
68 Ty::from_hir(db, &module, Some(&impl_block), impl_data.target_type())?; 68 Ty::from_hir(db, &module, Some(&impl_block), impl_data.target_type());
69 if let Some(target_ty_fp) = TyFingerprint::for_impl(&target_ty) { 69 if let Some(target_ty_fp) = TyFingerprint::for_impl(&target_ty) {
70 self.impls 70 self.impls
71 .entry(target_ty_fp) 71 .entry(target_ty_fp)
@@ -75,17 +75,15 @@ impl CrateImplBlocks {
75 } 75 }
76 } 76 }
77 77
78 for child in module.children(db)? { 78 for child in module.children(db) {
79 self.collect_recursive(db, child)?; 79 self.collect_recursive(db, child);
80 } 80 }
81
82 Ok(())
83 } 81 }
84 82
85 pub(crate) fn impls_in_crate_query( 83 pub(crate) fn impls_in_crate_query(
86 db: &impl HirDatabase, 84 db: &impl HirDatabase,
87 krate: Crate, 85 krate: Crate,
88 ) -> Cancelable<Arc<CrateImplBlocks>> { 86 ) -> Arc<CrateImplBlocks> {
89 let crate_graph = db.crate_graph(); 87 let crate_graph = db.crate_graph();
90 let file_id = crate_graph.crate_root(krate.crate_id); 88 let file_id = crate_graph.crate_root(krate.crate_id);
91 let source_root_id = db.file_source_root(file_id); 89 let source_root_id = db.file_source_root(file_id);
@@ -93,17 +91,17 @@ impl CrateImplBlocks {
93 source_root_id, 91 source_root_id,
94 impls: FxHashMap::default(), 92 impls: FxHashMap::default(),
95 }; 93 };
96 if let Some(module) = krate.root_module(db)? { 94 if let Some(module) = krate.root_module(db) {
97 crate_impl_blocks.collect_recursive(db, module)?; 95 crate_impl_blocks.collect_recursive(db, module);
98 } 96 }
99 Ok(Arc::new(crate_impl_blocks)) 97 Arc::new(crate_impl_blocks)
100 } 98 }
101} 99}
102 100
103fn def_crate(db: &impl HirDatabase, ty: &Ty) -> Cancelable<Option<Crate>> { 101fn def_crate(db: &impl HirDatabase, ty: &Ty) -> Option<Crate> {
104 match ty { 102 match ty {
105 Ty::Adt { def_id, .. } => def_id.krate(db), 103 Ty::Adt { def_id, .. } => def_id.krate(db),
106 _ => Ok(None), 104 _ => None,
107 } 105 }
108} 106}
109 107
@@ -111,13 +109,13 @@ impl Ty {
111 // TODO: cache this as a query? 109 // TODO: cache this as a query?
112 // - if so, what signature? (TyFingerprint, Name)? 110 // - if so, what signature? (TyFingerprint, Name)?
113 // - or maybe cache all names and def_ids of methods per fingerprint? 111 // - or maybe cache all names and def_ids of methods per fingerprint?
114 pub fn lookup_method(self, db: &impl HirDatabase, name: &Name) -> Cancelable<Option<DefId>> { 112 pub fn lookup_method(self, db: &impl HirDatabase, name: &Name) -> Option<DefId> {
115 self.iterate_methods(db, |f| { 113 self.iterate_methods(db, |f| {
116 let sig = f.signature(db); 114 let sig = f.signature(db);
117 if sig.name() == name && sig.has_self_param() { 115 if sig.name() == name && sig.has_self_param() {
118 Ok(Some(f.def_id())) 116 Some(f.def_id())
119 } else { 117 } else {
120 Ok(None) 118 None
121 } 119 }
122 }) 120 })
123 } 121 }
@@ -127,8 +125,8 @@ impl Ty {
127 pub fn iterate_methods<T>( 125 pub fn iterate_methods<T>(
128 self, 126 self,
129 db: &impl HirDatabase, 127 db: &impl HirDatabase,
130 mut callback: impl FnMut(Function) -> Cancelable<Option<T>>, 128 mut callback: impl FnMut(Function) -> Option<T>,
131 ) -> Cancelable<Option<T>> { 129 ) -> Option<T> {
132 // For method calls, rust first does any number of autoderef, and then one 130 // For method calls, rust first does any number of autoderef, and then one
133 // autoref (i.e. when the method takes &self or &mut self). We just ignore 131 // autoref (i.e. when the method takes &self or &mut self). We just ignore
134 // the autoref currently -- when we find a method matching the given name, 132 // the autoref currently -- when we find a method matching the given name,
@@ -139,19 +137,18 @@ impl Ty {
139 // rustc does an autoderef and then autoref again). 137 // rustc does an autoderef and then autoref again).
140 138
141 for derefed_ty in self.autoderef(db) { 139 for derefed_ty in self.autoderef(db) {
142 let krate = match def_crate(db, &derefed_ty)? { 140 let krate = match def_crate(db, &derefed_ty) {
143 Some(krate) => krate, 141 Some(krate) => krate,
144 None => continue, 142 None => continue,
145 }; 143 };
146 let impls = db.impls_in_crate(krate)?; 144 let impls = db.impls_in_crate(krate);
147 145
148 for impl_block in impls.lookup_impl_blocks(db, &derefed_ty) { 146 for impl_block in impls.lookup_impl_blocks(db, &derefed_ty) {
149 let impl_block = impl_block?;
150 for item in impl_block.items() { 147 for item in impl_block.items() {
151 match item { 148 match item {
152 ImplItem::Method(f) => { 149 ImplItem::Method(f) => {
153 if let Some(result) = callback(f.clone())? { 150 if let Some(result) = callback(f.clone()) {
154 return Ok(Some(result)); 151 return Some(result);
155 } 152 }
156 } 153 }
157 _ => {} 154 _ => {}
@@ -159,6 +156,6 @@ impl Ty {
159 } 156 }
160 } 157 }
161 } 158 }
162 Ok(None) 159 None
163 } 160 }
164} 161}
diff --git a/crates/ra_hir/src/ty/primitive.rs b/crates/ra_hir/src/ty/primitive.rs
index 498d42d52..5741ca90d 100644
--- a/crates/ra_hir/src/ty/primitive.rs
+++ b/crates/ra_hir/src/ty/primitive.rs
@@ -2,6 +2,56 @@ use std::fmt;
2 2
3use crate::{Name, KnownName}; 3use crate::{Name, KnownName};
4 4
5#[derive(Debug, Clone, Eq, PartialEq, Hash, Copy)]
6pub enum UncertainIntTy {
7 Unknown,
8 Unsigned(UintTy),
9 Signed(IntTy),
10}
11
12impl UncertainIntTy {
13 pub fn ty_to_string(&self) -> &'static str {
14 match *self {
15 UncertainIntTy::Unknown => "{integer}",
16 UncertainIntTy::Signed(ty) => ty.ty_to_string(),
17 UncertainIntTy::Unsigned(ty) => ty.ty_to_string(),
18 }
19 }
20
21 pub fn from_name(name: &Name) -> Option<UncertainIntTy> {
22 if let Some(ty) = IntTy::from_name(name) {
23 Some(UncertainIntTy::Signed(ty))
24 } else if let Some(ty) = UintTy::from_name(name) {
25 Some(UncertainIntTy::Unsigned(ty))
26 } else {
27 None
28 }
29 }
30}
31
32#[derive(Debug, Clone, Eq, PartialEq, Hash, Copy)]
33pub enum UncertainFloatTy {
34 Unknown,
35 Known(FloatTy),
36}
37
38impl UncertainFloatTy {
39 pub fn ty_to_string(&self) -> &'static str {
40 match *self {
41 UncertainFloatTy::Unknown => "{float}",
42 UncertainFloatTy::Known(ty) => ty.ty_to_string(),
43 }
44 }
45
46 pub fn from_name(name: &Name) -> Option<UncertainFloatTy> {
47 if let Some(ty) = FloatTy::from_name(name) {
48 Some(UncertainFloatTy::Known(ty))
49 } else {
50 None
51 }
52 }
53}
54
5#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Copy)] 55#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Copy)]
6pub enum IntTy { 56pub enum IntTy {
7 Isize, 57 Isize,
diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs
index 920188fc9..5d7bc25cc 100644
--- a/crates/ra_hir/src/ty/tests.rs
+++ b/crates/ra_hir/src/ty/tests.rs
@@ -133,6 +133,55 @@ fn test(a: &u32, b: &mut u32, c: *const u32, d: *mut u32) {
133} 133}
134 134
135#[test] 135#[test]
136fn infer_literals() {
137 check_inference(
138 r##"
139fn test() {
140 5i32;
141 "hello";
142 b"bytes";
143 'c';
144 b'b';
145 3.14;
146 5000;
147 false;
148 true;
149 r#"
150 //! doc
151 // non-doc
152 mod foo {}
153 "#;
154 br#"yolo"#;
155}
156"##,
157 "literals.txt",
158 );
159}
160
161#[test]
162fn infer_unary_op() {
163 check_inference(
164 r#"
165enum SomeType {}
166
167fn test(x: SomeType) {
168 let b = false;
169 let c = !b;
170 let a = 100;
171 let d: i128 = -a;
172 let e = -100;
173 let f = !!!true;
174 -3.14;
175 -x;
176 !x;
177 -"hello";
178}
179"#,
180 "unary_op.txt",
181 );
182}
183
184#[test]
136fn infer_backwards() { 185fn infer_backwards() {
137 check_inference( 186 check_inference(
138 r#" 187 r#"
@@ -180,7 +229,7 @@ fn f(x: bool) -> i32 {
180 0i32 229 0i32
181} 230}
182 231
183fn test() { 232fn test() -> bool {
184 let x = a && b; 233 let x = a && b;
185 let y = true || false; 234 let y = true || false;
186 let z = x == y; 235 let z = x == y;
@@ -277,8 +326,6 @@ fn test(x: &str, y: isize) {
277 let b = (a, x); 326 let b = (a, x);
278 let c = (y, x); 327 let c = (y, x);
279 let d = (c, x); 328 let d = (c, x);
280
281 // we have not infered these case yet.
282 let e = (1, "e"); 329 let e = (1, "e");
283 let f = (e, "d"); 330 let f = (e, "d");
284} 331}
@@ -296,11 +343,9 @@ fn infer(content: &str) -> String {
296 .descendants() 343 .descendants()
297 .filter_map(ast::FnDef::cast) 344 .filter_map(ast::FnDef::cast)
298 { 345 {
299 let func = source_binder::function_from_source(&db, file_id, fn_def) 346 let func = source_binder::function_from_source(&db, file_id, fn_def).unwrap();
300 .unwrap() 347 let inference_result = func.infer(&db);
301 .unwrap(); 348 let body_syntax_mapping = func.body_syntax_mapping(&db);
302 let inference_result = func.infer(&db).unwrap();
303 let body_syntax_mapping = func.body_syntax_mapping(&db).unwrap();
304 let mut types = Vec::new(); 349 let mut types = Vec::new();
305 for (pat, ty) in inference_result.type_of_pat.iter() { 350 for (pat, ty) in inference_result.type_of_pat.iter() {
306 let syntax_ptr = match body_syntax_mapping.pat_syntax(pat) { 351 let syntax_ptr = match body_syntax_mapping.pat_syntax(pat) {
@@ -380,12 +425,10 @@ fn typing_whitespace_inside_a_function_should_not_invalidate_types() {
380 } 425 }
381 ", 426 ",
382 ); 427 );
383 let func = source_binder::function_from_position(&db, pos) 428 let func = source_binder::function_from_position(&db, pos).unwrap();
384 .unwrap()
385 .unwrap();
386 { 429 {
387 let events = db.log_executed(|| { 430 let events = db.log_executed(|| {
388 func.infer(&db).unwrap(); 431 func.infer(&db);
389 }); 432 });
390 assert!(format!("{:?}", events).contains("infer")) 433 assert!(format!("{:?}", events).contains("infer"))
391 } 434 }
@@ -404,7 +447,7 @@ fn typing_whitespace_inside_a_function_should_not_invalidate_types() {
404 447
405 { 448 {
406 let events = db.log_executed(|| { 449 let events = db.log_executed(|| {
407 func.infer(&db).unwrap(); 450 func.infer(&db);
408 }); 451 });
409 assert!(!format!("{:?}", events).contains("infer"), "{:#?}", events) 452 assert!(!format!("{:?}", events).contains("infer"), "{:#?}", events)
410 } 453 }
diff --git a/crates/ra_hir/src/ty/tests/data/basics.txt b/crates/ra_hir/src/ty/tests/data/basics.txt
index ac7faae0a..e65fe07aa 100644
--- a/crates/ra_hir/src/ty/tests/data/basics.txt
+++ b/crates/ra_hir/src/ty/tests/data/basics.txt
@@ -7,7 +7,7 @@
7[55; 56) 'b': isize 7[55; 56) 'b': isize
8[62; 63) 'c': ! 8[62; 63) 'c': !
9[69; 70) 'd': &str 9[69; 70) 'd': &str
10[76; 82) '1usize': [unknown] 10[76; 82) '1usize': usize
11[88; 94) '1isize': [unknown] 11[88; 94) '1isize': isize
12[100; 106) '"test"': [unknown] 12[100; 106) '"test"': &str
13[112; 118) '1.0f32': [unknown] 13[112; 118) '1.0f32': f32
diff --git a/crates/ra_hir/src/ty/tests/data/binary_op.txt b/crates/ra_hir/src/ty/tests/data/binary_op.txt
index 8a515ac5e..58a727691 100644
--- a/crates/ra_hir/src/ty/tests/data/binary_op.txt
+++ b/crates/ra_hir/src/ty/tests/data/binary_op.txt
@@ -1,46 +1,46 @@
1[6; 7) 'x': bool 1[6; 7) 'x': bool
2[22; 34) '{ 0i32 }': i32 2[22; 34) '{ 0i32 }': i32
3[28; 32) '0i32': i32 3[28; 32) '0i32': i32
4[46; 342) '{ ... < 3 }': bool 4[54; 350) '{ ... < 3 }': bool
5[56; 57) 'x': bool 5[64; 65) 'x': bool
6[60; 61) 'a': bool 6[68; 69) 'a': bool
7[60; 66) 'a && b': bool 7[68; 74) 'a && b': bool
8[65; 66) 'b': bool 8[73; 74) 'b': bool
9[76; 77) 'y': bool 9[84; 85) 'y': bool
10[80; 84) 'true': bool 10[88; 92) 'true': bool
11[80; 93) 'true || false': bool 11[88; 101) 'true || false': bool
12[88; 93) 'false': bool 12[96; 101) 'false': bool
13[103; 104) 'z': bool 13[111; 112) 'z': bool
14[107; 108) 'x': bool 14[115; 116) 'x': bool
15[107; 113) 'x == y': bool 15[115; 121) 'x == y': bool
16[112; 113) 'y': bool 16[120; 121) 'y': bool
17[123; 134) 'minus_forty': isize 17[131; 142) 'minus_forty': isize
18[144; 152) '-40isize': isize 18[152; 160) '-40isize': isize
19[145; 152) '40isize': [unknown] 19[153; 160) '40isize': isize
20[162; 163) 'h': bool 20[170; 171) 'h': bool
21[166; 177) 'minus_forty': isize 21[174; 185) 'minus_forty': isize
22[166; 188) 'minus_...ONST_2': bool 22[174; 196) 'minus_...ONST_2': bool
23[181; 188) 'CONST_2': isize 23[189; 196) 'CONST_2': isize
24[198; 199) 'c': i32 24[206; 207) 'c': i32
25[202; 203) 'f': fn(bool) -> i32 25[210; 211) 'f': fn(bool) -> i32
26[202; 211) 'f(z || y)': i32 26[210; 219) 'f(z || y)': i32
27[202; 215) 'f(z || y) + 5': i32 27[210; 223) 'f(z || y) + 5': i32
28[204; 205) 'z': bool 28[212; 213) 'z': bool
29[204; 210) 'z || y': bool 29[212; 218) 'z || y': bool
30[209; 210) 'y': bool 30[217; 218) 'y': bool
31[214; 215) '5': i32 31[222; 223) '5': i32
32[225; 226) 'd': [unknown] 32[233; 234) 'd': [unknown]
33[229; 230) 'b': [unknown] 33[237; 238) 'b': [unknown]
34[240; 241) 'g': () 34[248; 249) 'g': ()
35[244; 255) 'minus_forty': isize 35[252; 263) 'minus_forty': isize
36[244; 260) 'minus_...y ^= i': () 36[252; 268) 'minus_...y ^= i': ()
37[259; 260) 'i': isize 37[267; 268) 'i': isize
38[270; 273) 'ten': usize 38[278; 281) 'ten': usize
39[283; 285) '10': usize 39[291; 293) '10': usize
40[295; 308) 'ten_is_eleven': bool 40[303; 316) 'ten_is_eleven': bool
41[311; 314) 'ten': usize 41[319; 322) 'ten': usize
42[311; 326) 'ten == some_num': bool 42[319; 334) 'ten == some_num': bool
43[318; 326) 'some_num': usize 43[326; 334) 'some_num': usize
44[333; 336) 'ten': usize 44[341; 344) 'ten': usize
45[333; 340) 'ten < 3': bool 45[341; 348) 'ten < 3': bool
46[339; 340) '3': usize 46[347; 348) '3': usize
diff --git a/crates/ra_hir/src/ty/tests/data/let.txt b/crates/ra_hir/src/ty/tests/data/let.txt
index 30f4a2cf5..8815dba41 100644
--- a/crates/ra_hir/src/ty/tests/data/let.txt
+++ b/crates/ra_hir/src/ty/tests/data/let.txt
@@ -1,6 +1,6 @@
1[11; 71) '{ ...= b; }': () 1[11; 71) '{ ...= b; }': ()
2[21; 22) 'a': [unknown] 2[21; 22) 'a': isize
3[25; 31) '1isize': [unknown] 3[25; 31) '1isize': isize
4[41; 42) 'b': usize 4[41; 42) 'b': usize
5[52; 53) '1': usize 5[52; 53) '1': usize
6[63; 64) 'c': usize 6[63; 64) 'c': usize
diff --git a/crates/ra_hir/src/ty/tests/data/literals.txt b/crates/ra_hir/src/ty/tests/data/literals.txt
new file mode 100644
index 000000000..84ee2c11b
--- /dev/null
+++ b/crates/ra_hir/src/ty/tests/data/literals.txt
@@ -0,0 +1,12 @@
1[11; 201) '{ ...o"#; }': ()
2[17; 21) '5i32': i32
3[27; 34) '"hello"': &str
4[40; 48) 'b"bytes"': &[u8]
5[54; 57) ''c'': char
6[63; 67) 'b'b'': u8
7[73; 77) '3.14': f64
8[83; 87) '5000': i32
9[93; 98) 'false': bool
10[104; 108) 'true': bool
11[114; 182) 'r#" ... "#': &str
12[188; 198) 'br#"yolo"#': &[u8]
diff --git a/crates/ra_hir/src/ty/tests/data/struct.txt b/crates/ra_hir/src/ty/tests/data/struct.txt
index 7b324c82f..be9e12d02 100644
--- a/crates/ra_hir/src/ty/tests/data/struct.txt
+++ b/crates/ra_hir/src/ty/tests/data/struct.txt
@@ -2,14 +2,14 @@
2[82; 83) 'c': [unknown] 2[82; 83) 'c': [unknown]
3[86; 87) 'C': [unknown] 3[86; 87) 'C': [unknown]
4[86; 90) 'C(1)': [unknown] 4[86; 90) 'C(1)': [unknown]
5[88; 89) '1': [unknown] 5[88; 89) '1': i32
6[96; 97) 'B': [unknown] 6[96; 97) 'B': [unknown]
7[107; 108) 'a': A 7[107; 108) 'a': A
8[114; 133) 'A { b:...C(1) }': A 8[114; 133) 'A { b:...C(1) }': A
9[121; 122) 'B': B 9[121; 122) 'B': B
10[127; 128) 'C': [unknown] 10[127; 128) 'C': [unknown]
11[127; 131) 'C(1)': C 11[127; 131) 'C(1)': C
12[129; 130) '1': [unknown] 12[129; 130) '1': i32
13[139; 140) 'a': A 13[139; 140) 'a': A
14[139; 142) 'a.b': B 14[139; 142) 'a.b': B
15[148; 149) 'a': A 15[148; 149) 'a': A
diff --git a/crates/ra_hir/src/ty/tests/data/tuple.txt b/crates/ra_hir/src/ty/tests/data/tuple.txt
index 96169180d..a95d3c286 100644
--- a/crates/ra_hir/src/ty/tests/data/tuple.txt
+++ b/crates/ra_hir/src/ty/tests/data/tuple.txt
@@ -1,6 +1,6 @@
1[9; 10) 'x': &str 1[9; 10) 'x': &str
2[18; 19) 'y': isize 2[18; 19) 'y': isize
3[28; 214) '{ ...d"); }': () 3[28; 170) '{ ...d"); }': ()
4[38; 39) 'a': (u32, &str) 4[38; 39) 'a': (u32, &str)
5[55; 63) '(1, "a")': (u32, &str) 5[55; 63) '(1, "a")': (u32, &str)
6[56; 57) '1': u32 6[56; 57) '1': u32
@@ -17,11 +17,11 @@
17[117; 123) '(c, x)': ((isize, &str), &str) 17[117; 123) '(c, x)': ((isize, &str), &str)
18[118; 119) 'c': (isize, &str) 18[118; 119) 'c': (isize, &str)
19[121; 122) 'x': &str 19[121; 122) 'x': &str
20[177; 178) 'e': ([unknown], [unknown]) 20[133; 134) 'e': (i32, &str)
21[181; 189) '(1, "e")': ([unknown], [unknown]) 21[137; 145) '(1, "e")': (i32, &str)
22[182; 183) '1': [unknown] 22[138; 139) '1': i32
23[185; 188) '"e"': [unknown] 23[141; 144) '"e"': &str
24[199; 200) 'f': (([unknown], [unknown]), [unknown]) 24[155; 156) 'f': ((i32, &str), &str)
25[203; 211) '(e, "d")': (([unknown], [unknown]), [unknown]) 25[159; 167) '(e, "d")': ((i32, &str), &str)
26[204; 205) 'e': ([unknown], [unknown]) 26[160; 161) 'e': (i32, &str)
27[207; 210) '"d"': [unknown] 27[163; 166) '"d"': &str
diff --git a/crates/ra_hir/src/ty/tests/data/unary_op.txt b/crates/ra_hir/src/ty/tests/data/unary_op.txt
new file mode 100644
index 000000000..203022e82
--- /dev/null
+++ b/crates/ra_hir/src/ty/tests/data/unary_op.txt
@@ -0,0 +1,28 @@
1[27; 28) 'x': SomeType
2[40; 197) '{ ...lo"; }': ()
3[50; 51) 'b': bool
4[54; 59) 'false': bool
5[69; 70) 'c': bool
6[73; 75) '!b': bool
7[74; 75) 'b': bool
8[85; 86) 'a': i128
9[89; 92) '100': i128
10[102; 103) 'd': i128
11[112; 114) '-a': i128
12[113; 114) 'a': i128
13[124; 125) 'e': i32
14[128; 132) '-100': i32
15[129; 132) '100': i32
16[142; 143) 'f': bool
17[146; 153) '!!!true': bool
18[147; 153) '!!true': bool
19[148; 153) '!true': bool
20[149; 153) 'true': bool
21[159; 164) '-3.14': f64
22[160; 164) '3.14': f64
23[170; 172) '-x': [unknown]
24[171; 172) 'x': SomeType
25[178; 180) '!x': [unknown]
26[179; 180) 'x': SomeType
27[186; 194) '-"hello"': [unknown]
28[187; 194) '"hello"': &str