|
| 1 | +//! Test for well-formedness checking of default type parameters. |
| 2 | +//! |
| 3 | +//! This test verifies that the compiler correctly handles various cases |
| 4 | +//! where default type parameters may or may not be checked for well-formedness |
| 5 | +//! in where clauses. |
| 6 | +//! |
| 7 | +//! Issue: https://github.com/rust-lang/rust/issues/49344 |
| 8 | +
|
| 9 | +//@ run-pass |
| 10 | + |
| 11 | +#![allow(dead_code)] |
| 12 | + |
| 13 | +trait Trait<T> {} |
| 14 | +struct Foo<U, V = i32>(U, V) |
| 15 | +where |
| 16 | + U: Trait<V>; |
| 17 | + |
| 18 | +trait Marker {} |
| 19 | +struct TwoParams<T, U>(T, U); |
| 20 | +impl Marker for TwoParams<i32, i32> {} |
| 21 | + |
| 22 | +// Clauses with more than 1 param are not checked. |
| 23 | +struct IndividuallyBogus<T = i32, U = i32>(TwoParams<T, U>) |
| 24 | +where |
| 25 | + TwoParams<T, U>: Marker; |
| 26 | + |
| 27 | +struct BogusTogether<T = u32, U = i32>(T, U) |
| 28 | +where |
| 29 | + TwoParams<T, U>: Marker; |
| 30 | + |
| 31 | +// Clauses with non-defaulted params are not checked. |
| 32 | +struct NonDefaultedInClause<T, U = i32>(TwoParams<T, U>) |
| 33 | +where |
| 34 | + TwoParams<T, U>: Marker; |
| 35 | + |
| 36 | +struct DefaultedLhs<U, V = i32>(U, V) |
| 37 | +where |
| 38 | + V: Trait<U>; |
| 39 | + |
| 40 | +// Dependent defaults are not checked. |
| 41 | +struct Dependent<T, U = T>(T, U) |
| 42 | +where |
| 43 | + U: Copy; |
| 44 | + |
| 45 | +trait SelfBound<T: Copy = Self> {} |
| 46 | + |
| 47 | +// Not even for well-formedness. |
| 48 | +struct WellFormedProjection<A, T = <A as Iterator>::Item>(A, T); |
| 49 | + |
| 50 | +// Issue #49344, predicates with lifetimes should not be checked. |
| 51 | +trait Scope<'a> {} |
| 52 | +struct Request<'a, S: Scope<'a> = i32>(S, &'a ()); |
| 53 | + |
| 54 | +fn main() {} |
0 commit comments