|
| 1 | +//@ pretty-compare-only |
| 2 | +//@ pretty-mode:hir |
| 3 | +//@ pp-exact:generics.pp |
| 4 | + |
| 5 | +#![allow(incomplete_features)] |
| 6 | +#![attr = Feature([fn_delegation#0])] |
| 7 | +extern crate std; |
| 8 | +#[attr = PreludeImport] |
| 9 | +use ::std::prelude::rust_2015::*; |
| 10 | + |
| 11 | +mod free_to_trait { |
| 12 | + trait Trait<'a, XX, Y, T = (), const N: usize = 2> { |
| 13 | + fn method<A, B>(&self, t: (T, A, B), slice: &'_ [usize; N]) { } |
| 14 | + fn r#static<A, B>(t: (T, A, B), slice: &'_ [usize; N]) { } |
| 15 | + } |
| 16 | + |
| 17 | + struct X; |
| 18 | + impl <XX, Y, T, const N: usize> Trait<'_, XX, Y, T, N> for X { } |
| 19 | +
|
| 20 | + // When infer is specified for default parameter the generic param is generated. |
| 21 | + #[attr = Inline(Hint)] |
| 22 | + fn foo<'a, Self, XX, Y, T, const N: _, A, B>(self: _, arg1: _, arg2: _) |
| 23 | + -> _ where |
| 24 | + 'a:'a { |
| 25 | + <Self as Trait::<'a, XX, Y, T, N>>::method::<A, B>(self, arg1, arg2) |
| 26 | + } |
| 27 | + #[attr = Inline(Hint)] |
| 28 | + fn static_foo<'a, Self, XX, Y, T, const N: _, A, B>(arg0: _, arg1: _) -> _ |
| 29 | + where |
| 30 | + 'a:'a { |
| 31 | + <Self as Trait::<'a, XX, Y, T, N>>::r#static::<A, B>(arg0, arg1) |
| 32 | + } |
| 33 | +
|
| 34 | + // When default params are omitted they are not generated but used in signature inheritance. |
| 35 | + #[attr = Inline(Hint)] |
| 36 | + fn bar<'a, Self, XX, Y, A, B>(self: _, arg1: _, arg2: _) -> _ where |
| 37 | + 'a:'a { |
| 38 | + <Self as Trait::<'a, XX, Y>>::method::<A, B>(self, arg1, arg2) |
| 39 | + } |
| 40 | + #[attr = Inline(Hint)] |
| 41 | + fn static_bar<'a, Self, XX, Y, A, B>(arg0: _, arg1: _) -> _ where |
| 42 | + 'a:'a { <Self as Trait::<'a, XX, Y>>::r#static::<A, B>(arg0, arg1) } |
| 43 | +
|
| 44 | + // Check with user specified args in child: |
| 45 | + // When infer is specified for default parameter the generic param is generated. |
| 46 | + #[attr = Inline(Hint)] |
| 47 | + fn foo1<'a, Self, XX, Y, T, const N: _, B>(self: _, arg1: _, arg2: _) -> _ |
| 48 | + where |
| 49 | + 'a:'a { |
| 50 | + <Self as Trait::<'a, XX, Y, T, N>>::method::<(), B>(self, arg1, arg2) |
| 51 | + } |
| 52 | + #[attr = Inline(Hint)] |
| 53 | + fn static_foo1<'a, Self, XX, Y, T, const N: _, B>(arg0: _, arg1: _) -> _ |
| 54 | + where |
| 55 | + 'a:'a { |
| 56 | + <Self as Trait::<'a, XX, Y, T, N>>::r#static::<(), B>(arg0, arg1) |
| 57 | + } |
| 58 | +
|
| 59 | + // When default params are omitted they are not generated but used in signature inheritance. |
| 60 | + #[attr = Inline(Hint)] |
| 61 | + fn bar1<'a, Self, XX, Y, A>(self: _, arg1: _, arg2: _) -> _ where |
| 62 | + 'a:'a { |
| 63 | + <Self as Trait::<'a, XX, Y>>::method::<A, ()>(self, arg1, arg2) |
| 64 | + } |
| 65 | + #[attr = Inline(Hint)] |
| 66 | + fn static_bar1<'a, Self, XX, Y, A>(arg0: _, arg1: _) -> _ where |
| 67 | + 'a:'a { <Self as Trait::<'a, XX, Y>>::r#static::<A, ()>(arg0, arg1) } |
| 68 | +
|
| 69 | + // Check with explicit self type. |
| 70 | + #[attr = Inline(Hint)] |
| 71 | + fn foo2<'a, XX, Y, T, const N: _, A, B>(self: _, arg1: _, arg2: _) -> _ |
| 72 | + where |
| 73 | + 'a:'a { |
| 74 | + <X as Trait::<'a, XX, Y, T, N>>::method::<A, B>(self, arg1, arg2) |
| 75 | + } |
| 76 | + #[attr = Inline(Hint)] |
| 77 | + fn static_foo2<'a, XX, Y, T, const N: _, A, B>(arg0: _, arg1: _) -> _ |
| 78 | + where |
| 79 | + 'a:'a { |
| 80 | + <X as Trait::<'a, XX, Y, T, N>>::r#static::<A, B>(arg0, arg1) |
| 81 | + } |
| 82 | +
|
| 83 | + #[attr = Inline(Hint)] |
| 84 | + fn bar2<'a, XX, Y, A, B>(self: _, arg1: _, arg2: _) -> _ where |
| 85 | + 'a:'a { <X as Trait::<'a, XX, Y>>::method::<A, B>(self, arg1, arg2) } |
| 86 | + #[attr = Inline(Hint)] |
| 87 | + fn static_bar2<'a, XX, Y, A, B>(arg0: _, arg1: _) -> _ where |
| 88 | + 'a:'a { <X as Trait::<'a, XX, Y>>::r#static::<A, B>(arg0, arg1) } |
| 89 | +
|
| 90 | + #[attr = Inline(Hint)] |
| 91 | + fn foo3<'a, XX, Y, T, const N: _, B>(self: _, arg1: _, arg2: _) -> _ where |
| 92 | + 'a:'a { |
| 93 | + <X as Trait::<'a, XX, Y, T, N>>::method::<(), B>(self, arg1, arg2) |
| 94 | + } |
| 95 | + #[attr = Inline(Hint)] |
| 96 | + fn static_foo3<'a, XX, Y, T, const N: _, B>(arg0: _, arg1: _) -> _ where |
| 97 | + 'a:'a { |
| 98 | + <X as Trait::<'a, XX, Y, T, N>>::r#static::<(), B>(arg0, arg1) |
| 99 | + } |
| 100 | +
|
| 101 | + #[attr = Inline(Hint)] |
| 102 | + fn bar3<'a, XX, Y, A>(self: _, arg1: _, arg2: _) -> _ where |
| 103 | + 'a:'a { <X as Trait::<'a, XX, Y>>::method::<A, ()>(self, arg1, arg2) } |
| 104 | + #[attr = Inline(Hint)] |
| 105 | + fn static_bar3<'a, XX, Y, A>(arg0: _, arg1: _) -> _ where |
| 106 | + 'a:'a { <X as Trait::<'a, XX, Y>>::r#static::<A, ()>(arg0, arg1) } |
| 107 | +} |
| 108 | +
|
| 109 | +mod trait_impl_to_trait { |
| 110 | + trait Trait<'a, X, Y, T = (), const N: usize = 2> { |
| 111 | + fn foo(&self, t: (T, T, T), slice: &'_ [usize; N]) { } |
| 112 | + fn bar(&self, t: (T, T, T), slice: &'_ [usize; N]) { } |
| 113 | + } |
| 114 | + |
| 115 | + struct S; |
| 116 | + impl <X, Y> Trait<'_, X, Y> for S { } |
| 117 | +
|
| 118 | + struct W(S); |
| 119 | + impl <X, Y> Trait<'_, X, Y> for W { |
| 120 | + // Generics of both methods match generics of their signature |
| 121 | + // functions in `Trait` declaration, no matter specified infers. |
| 122 | + #[attr = Inline(Hint)] |
| 123 | + fn foo(self: _, arg1: _, arg2: _) |
| 124 | + -> _ { Trait::<'static, X, Y>::foo(self.0, arg1, arg2) } |
| 125 | + #[attr = Inline(Hint)] |
| 126 | + fn bar(self: _, arg1: _, arg2: _) |
| 127 | + -> _ { Trait::<'static, X, Y, _, _>::foo(self.0, arg1, arg2) } |
| 128 | + } |
| 129 | +} |
| 130 | + |
| 131 | +fn main() { } |
0 commit comments