diff options
Diffstat (limited to 'crates/hir_ty/src/tests/traits.rs')
-rw-r--r-- | crates/hir_ty/src/tests/traits.rs | 96 |
1 files changed, 96 insertions, 0 deletions
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 | } | ||