From b8e09b7f4e2ae868a5877c39216a2eadb1b42824 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauren=C8=9Biu=20Nicola?= Date: Mon, 20 Jul 2020 22:01:09 +0300 Subject: Inline lang items in coercion tests --- crates/ra_hir_ty/src/tests.rs | 16 +------ crates/ra_hir_ty/src/tests/coercion.rs | 76 ++++++++++++++++++++++++++++------ 2 files changed, 65 insertions(+), 27 deletions(-) (limited to 'crates') 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() { } } -// Infer with some common definitions and impls. fn check_infer(ra_fixture: &str, expect: Expect) { - let defs = r#" - #[lang = "sized"] - pub trait Sized {} - #[lang = "unsize"] - pub trait Unsize {} - #[lang = "coerce_unsized"] - pub trait CoerceUnsized {} - - impl<'a, 'b: 'a, T: ?Sized + Unsize, U: ?Sized> CoerceUnsized<&'a U> for &'b T {} - impl, U: ?Sized> CoerceUnsized<*mut U> for *mut T {} - "#; - - // Append to the end to keep positions unchanged. - let mut actual = infer(&format!("{}{}", ra_fixture, defs)); + let mut actual = infer(ra_fixture); actual.push('\n'); expect.assert_eq(&actual); } 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() { #[test] fn coerce_places() { check_infer( - r" + r#" struct S { a: T } fn f(_: &[T]) -> T { loop {} } @@ -45,7 +45,17 @@ fn coerce_places() { let f: [&[_]; 2] = [arr; 2]; let g: (&[_], &[_]) = (arr, arr); } - ", + + #[lang = "sized"] + pub trait Sized {} + #[lang = "unsize"] + pub trait Unsize {} + #[lang = "coerce_unsized"] + pub trait CoerceUnsized {} + + impl<'a, 'b: 'a, T: ?Sized + Unsize, U: ?Sized> CoerceUnsized<&'a U> for &'b T {} + impl, U: ?Sized> CoerceUnsized<*mut U> for *mut T {} + "#, expect![[r" 30..31 '_': &[T] 44..55 '{ loop {} }': T @@ -121,7 +131,7 @@ fn infer_let_stmt_coerce() { #[test] fn infer_custom_coerce_unsized() { check_infer( - r" + r#" struct A(*const T); struct B(*const T); struct C { inner: *const T } @@ -138,7 +148,18 @@ fn infer_custom_coerce_unsized() { let e = foo2(b); let f = foo3(c); } - ", + + + #[lang = "sized"] + pub trait Sized {} + #[lang = "unsize"] + pub trait Unsize {} + #[lang = "coerce_unsized"] + pub trait CoerceUnsized {} + + impl<'a, 'b: 'a, T: ?Sized + Unsize, U: ?Sized> CoerceUnsized<&'a U> for &'b T {} + impl, U: ?Sized> CoerceUnsized<*mut U> for *mut T {} + "#, expect![[r" 257..258 'x': A<[T]> 278..283 '{ x }': A<[T]> @@ -172,7 +193,7 @@ fn infer_custom_coerce_unsized() { #[test] fn infer_if_coerce() { check_infer( - r" + r#" fn foo(x: &[T]) -> &[T] { loop {} } fn test() { let x = if true { @@ -181,7 +202,13 @@ fn infer_if_coerce() { &[1] }; } - ", + + + #[lang = "sized"] + pub trait Sized {} + #[lang = "unsize"] + pub trait Unsize {} + "#, expect![[r" 10..11 'x': &[T] 27..38 '{ loop {} }': &[T] @@ -208,7 +235,7 @@ fn infer_if_coerce() { #[test] fn infer_if_else_coerce() { check_infer( - r" + r#" fn foo(x: &[T]) -> &[T] { loop {} } fn test() { let x = if true { @@ -217,7 +244,17 @@ fn infer_if_else_coerce() { foo(&[1]) }; } - ", + + #[lang = "sized"] + pub trait Sized {} + #[lang = "unsize"] + pub trait Unsize {} + #[lang = "coerce_unsized"] + pub trait CoerceUnsized {} + + impl<'a, 'b: 'a, T: ?Sized + Unsize, U: ?Sized> CoerceUnsized<&'a U> for &'b T {} + impl, U: ?Sized> CoerceUnsized<*mut U> for *mut T {} + "#, expect![[r" 10..11 'x': &[T] 27..38 '{ loop {} }': &[T] @@ -244,7 +281,7 @@ fn infer_if_else_coerce() { #[test] fn infer_match_first_coerce() { check_infer( - r" + r#" fn foo(x: &[T]) -> &[T] { loop {} } fn test(i: i32) { let x = match i { @@ -253,7 +290,12 @@ fn infer_match_first_coerce() { _ => &[3], }; } - ", + + #[lang = "sized"] + pub trait Sized {} + #[lang = "unsize"] + pub trait Unsize {} + "#, expect![[r" 10..11 'x': &[T] 27..38 '{ loop {} }': &[T] @@ -287,7 +329,7 @@ fn infer_match_first_coerce() { #[test] fn infer_match_second_coerce() { check_infer( - r" + r#" fn foo(x: &[T]) -> &[T] { loop {} } fn test(i: i32) { let x = match i { @@ -296,7 +338,17 @@ fn infer_match_second_coerce() { _ => &[3], }; } - ", + + #[lang = "sized"] + pub trait Sized {} + #[lang = "unsize"] + pub trait Unsize {} + #[lang = "coerce_unsized"] + pub trait CoerceUnsized {} + + impl<'a, 'b: 'a, T: ?Sized + Unsize, U: ?Sized> CoerceUnsized<&'a U> for &'b T {} + impl, U: ?Sized> CoerceUnsized<*mut U> for *mut T {} + "#, expect![[r" 10..11 'x': &[T] 27..38 '{ loop {} }': &[T] -- cgit v1.2.3