Skip to content

Commit 3c57347

Browse files
Add more tests
1 parent a00fa0c commit 3c57347

File tree

2 files changed

+84
-8
lines changed

2 files changed

+84
-8
lines changed

crates/hir_ty/src/tests/simple.rs

+33-8
Original file line numberDiff line numberDiff line change
@@ -2427,13 +2427,38 @@ fn infer_inner_type() {
24272427
}
24282428
"#,
24292429
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-
"#]],
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]
2442+
fn 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+
"#]],
24382463
);
24392464
}

crates/hir_ty/src/tests/traits.rs

+51
Original file line numberDiff line numberDiff line change
@@ -3151,3 +3151,54 @@ fn test() {
31513151
"#,
31523152
);
31533153
}
3154+
3155+
#[test]
3156+
fn inner_use() {
3157+
check_types(
3158+
r#"
3159+
mod m {
3160+
pub trait Tr {
3161+
fn method(&self) -> u8 { 0 }
3162+
}
3163+
3164+
impl Tr for () {}
3165+
}
3166+
3167+
fn f() {
3168+
use m::Tr;
3169+
3170+
().method();
3171+
//^^^^^^^^^^^ u8
3172+
}
3173+
"#,
3174+
);
3175+
}
3176+
3177+
#[test]
3178+
fn inner_use_in_block() {
3179+
check_types(
3180+
r#"
3181+
mod m {
3182+
pub trait Tr {
3183+
fn method(&self) -> u8 { 0 }
3184+
}
3185+
3186+
impl Tr for () {}
3187+
}
3188+
3189+
fn f() {
3190+
{
3191+
use m::Tr;
3192+
3193+
().method();
3194+
//^^^^^^^^^^^ u8
3195+
}
3196+
3197+
{
3198+
().method();
3199+
//^^^^^^^^^^^ {unknown}
3200+
}
3201+
}
3202+
"#,
3203+
);
3204+
}

0 commit comments

Comments
 (0)