diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-12-13 19:49:01 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2019-12-13 19:49:01 +0000 |
commit | 9c9f4635b4eb7d987717b4064a7de789f7983e2a (patch) | |
tree | a90ec3dd748d8e4f9fcd6e808bf39c234a25c6d7 /crates/ra_hir_ty/src/tests | |
parent | ebc95af2b5b91239fc1d8a5fc8344ded6f6ef3e4 (diff) | |
parent | 77052090515c1bb2a00236b3a57cdd778e581c8c (diff) |
Merge #2550
2550: Infer - and ! using std::ops::{Neg, Not} r=flodiebold a=kiljacken
Found some low hanging fruit while taking a cursory look at index inferring.
Co-authored-by: Emil Lauridsen <[email protected]>
Diffstat (limited to 'crates/ra_hir_ty/src/tests')
-rw-r--r-- | crates/ra_hir_ty/src/tests/traits.rs | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/crates/ra_hir_ty/src/tests/traits.rs b/crates/ra_hir_ty/src/tests/traits.rs index 93c5f9a15..6139adb72 100644 --- a/crates/ra_hir_ty/src/tests/traits.rs +++ b/crates/ra_hir_ty/src/tests/traits.rs | |||
@@ -116,6 +116,70 @@ mod collections { | |||
116 | } | 116 | } |
117 | 117 | ||
118 | #[test] | 118 | #[test] |
119 | fn infer_ops_neg() { | ||
120 | let (db, pos) = TestDB::with_position( | ||
121 | r#" | ||
122 | //- /main.rs crate:main deps:std | ||
123 | |||
124 | struct Bar; | ||
125 | struct Foo; | ||
126 | |||
127 | impl std::ops::Neg for Bar { | ||
128 | type Output = Foo; | ||
129 | } | ||
130 | |||
131 | fn test() { | ||
132 | let a = Bar; | ||
133 | let b = -a; | ||
134 | b<|>; | ||
135 | } | ||
136 | |||
137 | //- /std.rs crate:std | ||
138 | |||
139 | #[prelude_import] use ops::*; | ||
140 | mod ops { | ||
141 | pub trait Neg { | ||
142 | type Output; | ||
143 | } | ||
144 | } | ||
145 | "#, | ||
146 | ); | ||
147 | assert_eq!("Foo", type_at_pos(&db, pos)); | ||
148 | } | ||
149 | |||
150 | #[test] | ||
151 | fn infer_ops_not() { | ||
152 | let (db, pos) = TestDB::with_position( | ||
153 | r#" | ||
154 | //- /main.rs crate:main deps:std | ||
155 | |||
156 | struct Bar; | ||
157 | struct Foo; | ||
158 | |||
159 | impl std::ops::Not for Bar { | ||
160 | type Output = Foo; | ||
161 | } | ||
162 | |||
163 | fn test() { | ||
164 | let a = Bar; | ||
165 | let b = !a; | ||
166 | b<|>; | ||
167 | } | ||
168 | |||
169 | //- /std.rs crate:std | ||
170 | |||
171 | #[prelude_import] use ops::*; | ||
172 | mod ops { | ||
173 | pub trait Not { | ||
174 | type Output; | ||
175 | } | ||
176 | } | ||
177 | "#, | ||
178 | ); | ||
179 | assert_eq!("Foo", type_at_pos(&db, pos)); | ||
180 | } | ||
181 | |||
182 | #[test] | ||
119 | fn infer_from_bound_1() { | 183 | fn infer_from_bound_1() { |
120 | assert_snapshot!( | 184 | assert_snapshot!( |
121 | infer(r#" | 185 | infer(r#" |