diff options
Diffstat (limited to 'crates/hir_ty/src/tests')
-rw-r--r-- | crates/hir_ty/src/tests/macros.rs | 23 | ||||
-rw-r--r-- | crates/hir_ty/src/tests/patterns.rs | 22 | ||||
-rw-r--r-- | crates/hir_ty/src/tests/regression.rs | 13 | ||||
-rw-r--r-- | crates/hir_ty/src/tests/traits.rs | 96 |
4 files changed, 154 insertions, 0 deletions
diff --git a/crates/hir_ty/src/tests/macros.rs b/crates/hir_ty/src/tests/macros.rs index 88ba9b118..7eda51866 100644 --- a/crates/hir_ty/src/tests/macros.rs +++ b/crates/hir_ty/src/tests/macros.rs | |||
@@ -607,6 +607,29 @@ fn bar() -> u32 {0} | |||
607 | } | 607 | } |
608 | 608 | ||
609 | #[test] | 609 | #[test] |
610 | fn infer_builtin_macros_include_child_mod() { | ||
611 | check_types( | ||
612 | r#" | ||
613 | //- /main.rs | ||
614 | #[rustc_builtin_macro] | ||
615 | macro_rules! include {() => {}} | ||
616 | |||
617 | include!("f/foo.rs"); | ||
618 | |||
619 | fn main() { | ||
620 | bar::bar(); | ||
621 | } //^ u32 | ||
622 | |||
623 | //- /f/foo.rs | ||
624 | pub mod bar; | ||
625 | |||
626 | //- /f/bar.rs | ||
627 | pub fn bar() -> u32 {0} | ||
628 | "#, | ||
629 | ); | ||
630 | } | ||
631 | |||
632 | #[test] | ||
610 | fn infer_builtin_macros_include_str() { | 633 | fn infer_builtin_macros_include_str() { |
611 | check_types( | 634 | check_types( |
612 | r#" | 635 | r#" |
diff --git a/crates/hir_ty/src/tests/patterns.rs b/crates/hir_ty/src/tests/patterns.rs index 5da19ba5f..85a28e76b 100644 --- a/crates/hir_ty/src/tests/patterns.rs +++ b/crates/hir_ty/src/tests/patterns.rs | |||
@@ -658,6 +658,28 @@ fn slice_tail_pattern() { | |||
658 | fn box_pattern() { | 658 | fn box_pattern() { |
659 | check_infer( | 659 | check_infer( |
660 | r#" | 660 | r#" |
661 | pub struct Global; | ||
662 | #[lang = "owned_box"] | ||
663 | pub struct Box<T, A = Global>(T); | ||
664 | |||
665 | fn foo(params: Box<i32>) { | ||
666 | match params { | ||
667 | box integer => {} | ||
668 | } | ||
669 | } | ||
670 | "#, | ||
671 | expect![[r#" | ||
672 | 83..89 'params': Box<i32, Global> | ||
673 | 101..155 '{ ... } }': () | ||
674 | 107..153 'match ... }': () | ||
675 | 113..119 'params': Box<i32, Global> | ||
676 | 130..141 'box integer': Box<i32, Global> | ||
677 | 134..141 'integer': i32 | ||
678 | 145..147 '{}': () | ||
679 | "#]], | ||
680 | ); | ||
681 | check_infer( | ||
682 | r#" | ||
661 | #[lang = "owned_box"] | 683 | #[lang = "owned_box"] |
662 | pub struct Box<T>(T); | 684 | pub struct Box<T>(T); |
663 | 685 | ||
diff --git a/crates/hir_ty/src/tests/regression.rs b/crates/hir_ty/src/tests/regression.rs index 69314e245..b69f86050 100644 --- a/crates/hir_ty/src/tests/regression.rs +++ b/crates/hir_ty/src/tests/regression.rs | |||
@@ -961,3 +961,16 @@ fn issue_6852() { | |||
961 | "#]], | 961 | "#]], |
962 | ); | 962 | ); |
963 | } | 963 | } |
964 | |||
965 | #[test] | ||
966 | fn param_overrides_fn() { | ||
967 | check_types( | ||
968 | r#" | ||
969 | fn example(example: i32) { | ||
970 | fn f() {} | ||
971 | example; | ||
972 | //^^^^^^^ i32 | ||
973 | } | ||
974 | "#, | ||
975 | ) | ||
976 | } | ||
diff --git a/crates/hir_ty/src/tests/traits.rs b/crates/hir_ty/src/tests/traits.rs index f7ee6def6..2ba97f814 100644 --- a/crates/hir_ty/src/tests/traits.rs +++ b/crates/hir_ty/src/tests/traits.rs | |||
@@ -2272,6 +2272,56 @@ fn test<T, U>() where T: Trait<U::Item>, U: Trait<T::Item> { | |||
2272 | } | 2272 | } |
2273 | 2273 | ||
2274 | #[test] | 2274 | #[test] |
2275 | fn unselected_projection_in_trait_env_cycle_3() { | ||
2276 | // this is a cycle for rustc; we currently accept it | ||
2277 | check_types( | ||
2278 | r#" | ||
2279 | //- /main.rs | ||
2280 | trait Trait { | ||
2281 | type Item; | ||
2282 | type OtherItem; | ||
2283 | } | ||
2284 | |||
2285 | fn test<T>() where T: Trait<OtherItem = T::Item> { | ||
2286 | let x: T::Item = no_matter; | ||
2287 | } //^ Trait::Item<T> | ||
2288 | "#, | ||
2289 | ); | ||
2290 | } | ||
2291 | |||
2292 | #[test] | ||
2293 | fn unselected_projection_in_trait_env_no_cycle() { | ||
2294 | // this is not a cycle | ||
2295 | check_types( | ||
2296 | r#" | ||
2297 | //- /main.rs | ||
2298 | trait Index { | ||
2299 | type Output; | ||
2300 | } | ||
2301 | |||
2302 | type Key<S: UnificationStoreBase> = <S as UnificationStoreBase>::Key; | ||
2303 | |||
2304 | pub trait UnificationStoreBase: Index<Output = Key<Self>> { | ||
2305 | type Key; | ||
2306 | |||
2307 | fn len(&self) -> usize; | ||
2308 | } | ||
2309 | |||
2310 | pub trait UnificationStoreMut: UnificationStoreBase { | ||
2311 | fn push(&mut self, value: Self::Key); | ||
2312 | } | ||
2313 | |||
2314 | fn test<T>(t: T) where T: UnificationStoreMut { | ||
2315 | let x; | ||
2316 | t.push(x); | ||
2317 | let y: Key<T>; | ||
2318 | (x, y); | ||
2319 | } //^ (UnificationStoreBase::Key<T>, UnificationStoreBase::Key<T>) | ||
2320 | "#, | ||
2321 | ); | ||
2322 | } | ||
2323 | |||
2324 | #[test] | ||
2275 | fn inline_assoc_type_bounds_1() { | 2325 | fn inline_assoc_type_bounds_1() { |
2276 | check_types( | 2326 | check_types( |
2277 | r#" | 2327 | r#" |
@@ -3274,3 +3324,49 @@ fn f() { | |||
3274 | "#]], | 3324 | "#]], |
3275 | ) | 3325 | ) |
3276 | } | 3326 | } |
3327 | |||
3328 | #[test] | ||
3329 | fn infer_default_trait_type_parameter() { | ||
3330 | check_infer( | ||
3331 | r#" | ||
3332 | struct A; | ||
3333 | |||
3334 | trait Op<RHS=Self> { | ||
3335 | type Output; | ||
3336 | |||
3337 | fn do_op(self, rhs: RHS) -> Self::Output; | ||
3338 | } | ||
3339 | |||
3340 | impl Op for A { | ||
3341 | type Output = bool; | ||
3342 | |||
3343 | fn do_op(self, rhs: Self) -> Self::Output { | ||
3344 | true | ||
3345 | } | ||
3346 | } | ||
3347 | |||
3348 | fn test() { | ||
3349 | let x = A; | ||
3350 | let y = A; | ||
3351 | let r = x.do_op(y); | ||
3352 | } | ||
3353 | "#, | ||
3354 | expect![[r#" | ||
3355 | 63..67 'self': Self | ||
3356 | 69..72 'rhs': RHS | ||
3357 | 153..157 'self': A | ||
3358 | 159..162 'rhs': A | ||
3359 | 186..206 '{ ... }': bool | ||
3360 | 196..200 'true': bool | ||
3361 | 220..277 '{ ...(y); }': () | ||
3362 | 230..231 'x': A | ||
3363 | 234..235 'A': A | ||
3364 | 245..246 'y': A | ||
3365 | 249..250 'A': A | ||
3366 | 260..261 'r': bool | ||
3367 | 264..265 'x': A | ||
3368 | 264..274 'x.do_op(y)': bool | ||
3369 | 272..273 'y': A | ||
3370 | "#]], | ||
3371 | ) | ||
3372 | } | ||