aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/ty/tests.rs
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-01-14 20:58:20 +0000
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-01-14 20:58:20 +0000
commite8e82ce032f8678929b015e6f70ac060bb2cf94c (patch)
tree9fb158e9f7115bb70cf2b8623b70710c55497ed4 /crates/ra_hir/src/ty/tests.rs
parent784ff638e549a27503b719e5c2f0009b40d25364 (diff)
parent37ba237e6686d94783d1f025d23823ad7c0cb0c8 (diff)
Merge #485
485: Add type inference for a bunch of primitives r=flodiebold a=marcusklaas This PR adds inference for `&str`, `&[u8]`, `char`, `bool`, floats and integers. For floats and integers it uses type variables to infer the exact type, i.e. `u32`, from context when it's not annotated explicitly. I'm not quite happy with the implementation yet, but I think it mostly works now. Co-authored-by: Marcus Klaas de Vries <[email protected]>
Diffstat (limited to 'crates/ra_hir/src/ty/tests.rs')
-rw-r--r--crates/ra_hir/src/ty/tests.rs30
1 files changed, 27 insertions, 3 deletions
diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs
index 920188fc9..8aacb1a7f 100644
--- a/crates/ra_hir/src/ty/tests.rs
+++ b/crates/ra_hir/src/ty/tests.rs
@@ -133,6 +133,32 @@ 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]
136fn infer_backwards() { 162fn infer_backwards() {
137 check_inference( 163 check_inference(
138 r#" 164 r#"
@@ -180,7 +206,7 @@ fn f(x: bool) -> i32 {
180 0i32 206 0i32
181} 207}
182 208
183fn test() { 209fn test() -> bool {
184 let x = a && b; 210 let x = a && b;
185 let y = true || false; 211 let y = true || false;
186 let z = x == y; 212 let z = x == y;
@@ -277,8 +303,6 @@ fn test(x: &str, y: isize) {
277 let b = (a, x); 303 let b = (a, x);
278 let c = (y, x); 304 let c = (y, x);
279 let d = (c, x); 305 let d = (c, x);
280
281 // we have not infered these case yet.
282 let e = (1, "e"); 306 let e = (1, "e");
283 let f = (e, "d"); 307 let f = (e, "d");
284} 308}