aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty/src/tests/simple.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_ty/src/tests/simple.rs')
-rw-r--r--crates/hir_ty/src/tests/simple.rs155
1 files changed, 155 insertions, 0 deletions
diff --git a/crates/hir_ty/src/tests/simple.rs b/crates/hir_ty/src/tests/simple.rs
index 8d431b920..2947857a5 100644
--- a/crates/hir_ty/src/tests/simple.rs
+++ b/crates/hir_ty/src/tests/simple.rs
@@ -29,6 +29,30 @@ mod boxed {
29} 29}
30 30
31#[test] 31#[test]
32fn infer_box_with_allocator() {
33 check_types(
34 r#"
35//- /main.rs crate:main deps:std
36fn test() {
37 let x = box 1;
38 let t = (x, box x, box &1, box [1]);
39 t;
40} //^ (Box<i32, {unknown}>, Box<Box<i32, {unknown}>, {unknown}>, Box<&i32, {unknown}>, Box<[i32; _], {unknown}>)
41
42//- /std.rs crate:std
43#[prelude_import] use prelude::*;
44mod boxed {
45 #[lang = "owned_box"]
46 pub struct Box<T: ?Sized, A: Allocator> {
47 inner: *mut T,
48 allocator: A,
49 }
50}
51"#,
52 );
53}
54
55#[test]
32fn infer_adt_self() { 56fn infer_adt_self() {
33 check_types( 57 check_types(
34 r#" 58 r#"
@@ -2391,3 +2415,134 @@ fn infer_const_params() {
2391 "#]], 2415 "#]],
2392 ); 2416 );
2393} 2417}
2418
2419#[test]
2420fn infer_inner_type() {
2421 check_infer(
2422 r#"
2423 fn foo() {
2424 struct S { field: u32 }
2425 let s = S { field: 0 };
2426 let f = s.field;
2427 }
2428 "#,
2429 expect![[r#"
2430 9..89 '{ ...eld; }': ()
2431 47..48 's': S
2432 51..65 'S { field: 0 }': S
2433 62..63 '0': u32
2434 75..76 'f': u32
2435 79..80 's': S
2436 79..86 's.field': u32
2437 "#]],
2438 );
2439}
2440
2441#[test]
2442fn infer_nested_inner_type() {
2443 check_infer(
2444 r#"
2445 fn foo() {
2446 {
2447 let s = S { field: 0 };
2448 let f = s.field;
2449 }
2450 struct S { field: u32 }
2451 }
2452 "#,
2453 expect![[r#"
2454 9..109 '{ ...32 } }': ()
2455 15..79 '{ ... }': ()
2456 29..30 's': S
2457 33..47 'S { field: 0 }': S
2458 44..45 '0': u32
2459 61..62 'f': u32
2460 65..66 's': S
2461 65..72 's.field': u32
2462 "#]],
2463 );
2464}
2465
2466#[test]
2467fn inner_use_enum_rename() {
2468 check_infer(
2469 r#"
2470 enum Request {
2471 Info
2472 }
2473
2474 fn f() {
2475 use Request as R;
2476
2477 let r = R::Info;
2478 match r {
2479 R::Info => {}
2480 }
2481 }
2482 "#,
2483 expect![[r#"
2484 34..123 '{ ... } }': ()
2485 67..68 'r': Request
2486 71..78 'R::Info': Request
2487 84..121 'match ... }': ()
2488 90..91 'r': Request
2489 102..109 'R::Info': Request
2490 113..115 '{}': ()
2491 "#]],
2492 )
2493}
2494
2495#[test]
2496fn box_into_vec() {
2497 check_infer(
2498 r#"
2499#[lang = "sized"]
2500pub trait Sized {}
2501
2502#[lang = "unsize"]
2503pub trait Unsize<T: ?Sized> {}
2504
2505#[lang = "coerce_unsized"]
2506pub trait CoerceUnsized<T> {}
2507
2508pub unsafe trait Allocator {}
2509
2510pub struct Global;
2511unsafe impl Allocator for Global {}
2512
2513#[lang = "owned_box"]
2514#[fundamental]
2515pub struct Box<T: ?Sized, A: Allocator = Global>;
2516
2517impl<T: ?Sized + Unsize<U>, U: ?Sized, A: Allocator> CoerceUnsized<Box<U, A>> for Box<T, A> {}
2518
2519pub struct Vec<T, A: Allocator = Global> {}
2520
2521#[lang = "slice"]
2522impl<T> [T] {}
2523
2524#[lang = "slice_alloc"]
2525impl<T> [T] {
2526 pub fn into_vec<A: Allocator>(self: Box<Self, A>) -> Vec<T, A> {
2527 unimplemented!()
2528 }
2529}
2530
2531fn test() {
2532 let vec = <[_]>::into_vec(box [1i32]);
2533}
2534"#,
2535 expect![[r#"
2536 569..573 'self': Box<[T], A>
2537 602..634 '{ ... }': Vec<T, A>
2538 612..628 'unimpl...ted!()': Vec<T, A>
2539 648..694 '{ ...2]); }': ()
2540 658..661 'vec': Vec<i32, Global>
2541 664..679 '<[_]>::into_vec': fn into_vec<i32, Global>(Box<[i32], Global>) -> Vec<i32, Global>
2542 664..691 '<[_]>:...1i32])': Vec<i32, Global>
2543 680..690 'box [1i32]': Box<[i32; _], Global>
2544 684..690 '[1i32]': [i32; _]
2545 685..689 '1i32': i32
2546 "#]],
2547 )
2548}