aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurenČ›iu Nicola <[email protected]>2020-07-20 20:01:09 +0100
committerLaurenČ›iu Nicola <[email protected]>2020-07-20 20:01:09 +0100
commitb8e09b7f4e2ae868a5877c39216a2eadb1b42824 (patch)
treefa97381d2f01da2f7923026562e0f3c772be6528
parent3b6979be77dcce37edd5f29607c5fd41252e312d (diff)
Inline lang items in coercion tests
-rw-r--r--crates/ra_hir_ty/src/tests.rs16
-rw-r--r--crates/ra_hir_ty/src/tests/coercion.rs76
2 files changed, 65 insertions, 27 deletions
diff --git a/crates/ra_hir_ty/src/tests.rs b/crates/ra_hir_ty/src/tests.rs
index 5eaf25a77..59a21092e 100644
--- a/crates/ra_hir_ty/src/tests.rs
+++ b/crates/ra_hir_ty/src/tests.rs
@@ -346,22 +346,8 @@ fn typing_whitespace_inside_a_function_should_not_invalidate_types() {
346 } 346 }
347} 347}
348 348
349// Infer with some common definitions and impls.
350fn check_infer(ra_fixture: &str, expect: Expect) { 349fn check_infer(ra_fixture: &str, expect: Expect) {
351 let defs = r#" 350 let mut actual = infer(ra_fixture);
352 #[lang = "sized"]
353 pub trait Sized {}
354 #[lang = "unsize"]
355 pub trait Unsize<T: ?Sized> {}
356 #[lang = "coerce_unsized"]
357 pub trait CoerceUnsized<T> {}
358
359 impl<'a, 'b: 'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<&'a U> for &'b T {}
360 impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*mut U> for *mut T {}
361 "#;
362
363 // Append to the end to keep positions unchanged.
364 let mut actual = infer(&format!("{}{}", ra_fixture, defs));
365 actual.push('\n'); 351 actual.push('\n');
366 expect.assert_eq(&actual); 352 expect.assert_eq(&actual);
367} 353}
diff --git a/crates/ra_hir_ty/src/tests/coercion.rs b/crates/ra_hir_ty/src/tests/coercion.rs
index 823abddc6..17efd75cb 100644
--- a/crates/ra_hir_ty/src/tests/coercion.rs
+++ b/crates/ra_hir_ty/src/tests/coercion.rs
@@ -23,7 +23,7 @@ fn infer_block_expr_type_mismatch() {
23#[test] 23#[test]
24fn coerce_places() { 24fn coerce_places() {
25 check_infer( 25 check_infer(
26 r" 26 r#"
27 struct S<T> { a: T } 27 struct S<T> { a: T }
28 28
29 fn f<T>(_: &[T]) -> T { loop {} } 29 fn f<T>(_: &[T]) -> T { loop {} }
@@ -45,7 +45,17 @@ fn coerce_places() {
45 let f: [&[_]; 2] = [arr; 2]; 45 let f: [&[_]; 2] = [arr; 2];
46 let g: (&[_], &[_]) = (arr, arr); 46 let g: (&[_], &[_]) = (arr, arr);
47 } 47 }
48 ", 48
49 #[lang = "sized"]
50 pub trait Sized {}
51 #[lang = "unsize"]
52 pub trait Unsize<T: ?Sized> {}
53 #[lang = "coerce_unsized"]
54 pub trait CoerceUnsized<T> {}
55
56 impl<'a, 'b: 'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<&'a U> for &'b T {}
57 impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*mut U> for *mut T {}
58 "#,
49 expect![[r" 59 expect![[r"
50 30..31 '_': &[T] 60 30..31 '_': &[T]
51 44..55 '{ loop {} }': T 61 44..55 '{ loop {} }': T
@@ -121,7 +131,7 @@ fn infer_let_stmt_coerce() {
121#[test] 131#[test]
122fn infer_custom_coerce_unsized() { 132fn infer_custom_coerce_unsized() {
123 check_infer( 133 check_infer(
124 r" 134 r#"
125 struct A<T: ?Sized>(*const T); 135 struct A<T: ?Sized>(*const T);
126 struct B<T: ?Sized>(*const T); 136 struct B<T: ?Sized>(*const T);
127 struct C<T: ?Sized> { inner: *const T } 137 struct C<T: ?Sized> { inner: *const T }
@@ -138,7 +148,18 @@ fn infer_custom_coerce_unsized() {
138 let e = foo2(b); 148 let e = foo2(b);
139 let f = foo3(c); 149 let f = foo3(c);
140 } 150 }
141 ", 151
152
153 #[lang = "sized"]
154 pub trait Sized {}
155 #[lang = "unsize"]
156 pub trait Unsize<T: ?Sized> {}
157 #[lang = "coerce_unsized"]
158 pub trait CoerceUnsized<T> {}
159
160 impl<'a, 'b: 'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<&'a U> for &'b T {}
161 impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*mut U> for *mut T {}
162 "#,
142 expect![[r" 163 expect![[r"
143 257..258 'x': A<[T]> 164 257..258 'x': A<[T]>
144 278..283 '{ x }': A<[T]> 165 278..283 '{ x }': A<[T]>
@@ -172,7 +193,7 @@ fn infer_custom_coerce_unsized() {
172#[test] 193#[test]
173fn infer_if_coerce() { 194fn infer_if_coerce() {
174 check_infer( 195 check_infer(
175 r" 196 r#"
176 fn foo<T>(x: &[T]) -> &[T] { loop {} } 197 fn foo<T>(x: &[T]) -> &[T] { loop {} }
177 fn test() { 198 fn test() {
178 let x = if true { 199 let x = if true {
@@ -181,7 +202,13 @@ fn infer_if_coerce() {
181 &[1] 202 &[1]
182 }; 203 };
183 } 204 }
184 ", 205
206
207 #[lang = "sized"]
208 pub trait Sized {}
209 #[lang = "unsize"]
210 pub trait Unsize<T: ?Sized> {}
211 "#,
185 expect![[r" 212 expect![[r"
186 10..11 'x': &[T] 213 10..11 'x': &[T]
187 27..38 '{ loop {} }': &[T] 214 27..38 '{ loop {} }': &[T]
@@ -208,7 +235,7 @@ fn infer_if_coerce() {
208#[test] 235#[test]
209fn infer_if_else_coerce() { 236fn infer_if_else_coerce() {
210 check_infer( 237 check_infer(
211 r" 238 r#"
212 fn foo<T>(x: &[T]) -> &[T] { loop {} } 239 fn foo<T>(x: &[T]) -> &[T] { loop {} }
213 fn test() { 240 fn test() {
214 let x = if true { 241 let x = if true {
@@ -217,7 +244,17 @@ fn infer_if_else_coerce() {
217 foo(&[1]) 244 foo(&[1])
218 }; 245 };
219 } 246 }
220 ", 247
248 #[lang = "sized"]
249 pub trait Sized {}
250 #[lang = "unsize"]
251 pub trait Unsize<T: ?Sized> {}
252 #[lang = "coerce_unsized"]
253 pub trait CoerceUnsized<T> {}
254
255 impl<'a, 'b: 'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<&'a U> for &'b T {}
256 impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*mut U> for *mut T {}
257 "#,
221 expect![[r" 258 expect![[r"
222 10..11 'x': &[T] 259 10..11 'x': &[T]
223 27..38 '{ loop {} }': &[T] 260 27..38 '{ loop {} }': &[T]
@@ -244,7 +281,7 @@ fn infer_if_else_coerce() {
244#[test] 281#[test]
245fn infer_match_first_coerce() { 282fn infer_match_first_coerce() {
246 check_infer( 283 check_infer(
247 r" 284 r#"
248 fn foo<T>(x: &[T]) -> &[T] { loop {} } 285 fn foo<T>(x: &[T]) -> &[T] { loop {} }
249 fn test(i: i32) { 286 fn test(i: i32) {
250 let x = match i { 287 let x = match i {
@@ -253,7 +290,12 @@ fn infer_match_first_coerce() {
253 _ => &[3], 290 _ => &[3],
254 }; 291 };
255 } 292 }
256 ", 293
294 #[lang = "sized"]
295 pub trait Sized {}
296 #[lang = "unsize"]
297 pub trait Unsize<T: ?Sized> {}
298 "#,
257 expect![[r" 299 expect![[r"
258 10..11 'x': &[T] 300 10..11 'x': &[T]
259 27..38 '{ loop {} }': &[T] 301 27..38 '{ loop {} }': &[T]
@@ -287,7 +329,7 @@ fn infer_match_first_coerce() {
287#[test] 329#[test]
288fn infer_match_second_coerce() { 330fn infer_match_second_coerce() {
289 check_infer( 331 check_infer(
290 r" 332 r#"
291 fn foo<T>(x: &[T]) -> &[T] { loop {} } 333 fn foo<T>(x: &[T]) -> &[T] { loop {} }
292 fn test(i: i32) { 334 fn test(i: i32) {
293 let x = match i { 335 let x = match i {
@@ -296,7 +338,17 @@ fn infer_match_second_coerce() {
296 _ => &[3], 338 _ => &[3],
297 }; 339 };
298 } 340 }
299 ", 341
342 #[lang = "sized"]
343 pub trait Sized {}
344 #[lang = "unsize"]
345 pub trait Unsize<T: ?Sized> {}
346 #[lang = "coerce_unsized"]
347 pub trait CoerceUnsized<T> {}
348
349 impl<'a, 'b: 'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<&'a U> for &'b T {}
350 impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*mut U> for *mut T {}
351 "#,
300 expect![[r" 352 expect![[r"
301 10..11 'x': &[T] 353 10..11 'x': &[T]
302 27..38 '{ loop {} }': &[T] 354 27..38 '{ loop {} }': &[T]