@@ -60,19 +60,21 @@ pub(super) fn compare_impl_method<'tcx>(
60
60
} ;
61
61
}
62
62
63
- /// This function is best explained by example. Consider a trait:
63
+ /// This function is best explained by example. Consider a trait with it's implementation :
64
64
///
65
- /// trait Trait<'t, T> {
66
- /// // `trait_m`
67
- /// fn method<'a, M>(t: &'t T, m: &'a M) -> Self;
68
- /// }
65
+ /// ```rust
66
+ /// trait Trait<'t, T> {
67
+ /// // `trait_m`
68
+ /// fn method<'a, M>(t: &'t T, m: &'a M) -> Self;
69
+ /// }
69
70
///
70
- /// And an impl:
71
+ /// struct Foo;
71
72
///
72
- /// impl<'i, 'j, U> Trait<'j, &'i U> for Foo {
73
- /// // `impl_m`
74
- /// fn method<'b, N>(t: &'j &'i U, m: &'b N) -> Foo;
75
- /// }
73
+ /// impl<'i, 'j, U> Trait<'j, &'i U> for Foo {
74
+ /// // `impl_m`
75
+ /// fn method<'b, N>(t: &'j &'i U, m: &'b N) -> Foo { Foo }
76
+ /// }
77
+ /// ```
76
78
///
77
79
/// We wish to decide if those two method types are compatible.
78
80
/// For this we have to show that, assuming the bounds of the impl hold, the
@@ -82,7 +84,9 @@ pub(super) fn compare_impl_method<'tcx>(
82
84
/// type parameters to impl type parameters. This is taken from the
83
85
/// impl trait reference:
84
86
///
85
- /// trait_to_impl_substs = {'t => 'j, T => &'i U, Self => Foo}
87
+ /// ```rust,ignore (pseudo-Rust)
88
+ /// trait_to_impl_substs = {'t => 'j, T => &'i U, Self => Foo}
89
+ /// ```
86
90
///
87
91
/// We create a mapping `dummy_substs` that maps from the impl type
88
92
/// parameters to fresh types and regions. For type parameters,
@@ -91,13 +95,17 @@ pub(super) fn compare_impl_method<'tcx>(
91
95
/// regions (Note: but only early-bound regions, i.e., those
92
96
/// declared on the impl or used in type parameter bounds).
93
97
///
94
- /// impl_to_placeholder_substs = {'i => 'i0, U => U0, N => N0 }
98
+ /// ```rust,ignore (pseudo-Rust)
99
+ /// impl_to_placeholder_substs = {'i => 'i0, U => U0, N => N0 }
100
+ /// ```
95
101
///
96
102
/// Now we can apply `placeholder_substs` to the type of the impl method
97
103
/// to yield a new function type in terms of our fresh, placeholder
98
104
/// types:
99
105
///
100
- /// <'b> fn(t: &'i0 U0, m: &'b) -> Foo
106
+ /// ```rust,ignore (pseudo-Rust)
107
+ /// <'b> fn(t: &'i0 U0, m: &'b) -> Foo
108
+ /// ```
101
109
///
102
110
/// We now want to extract and substitute the type of the *trait*
103
111
/// method and compare it. To do so, we must create a compound
@@ -106,11 +114,15 @@ pub(super) fn compare_impl_method<'tcx>(
106
114
/// type parameters. We extend the mapping to also include
107
115
/// the method parameters.
108
116
///
109
- /// trait_to_placeholder_substs = { T => &'i0 U0, Self => Foo, M => N0 }
117
+ /// ```rust,ignore (pseudo-Rust)
118
+ /// trait_to_placeholder_substs = { T => &'i0 U0, Self => Foo, M => N0 }
119
+ /// ```
110
120
///
111
121
/// Applying this to the trait method type yields:
112
122
///
113
- /// <'a> fn(t: &'i0 U0, m: &'a) -> Foo
123
+ /// ```rust,ignore (pseudo-Rust)
124
+ /// <'a> fn(t: &'i0 U0, m: &'a) -> Foo
125
+ /// ```
114
126
///
115
127
/// This type is also the same but the name of the bound region (`'a`
116
128
/// vs `'b`). However, the normal subtyping rules on fn types handle
@@ -1163,7 +1175,7 @@ fn compare_self_type<'tcx>(
1163
1175
/// as the number of generics on the respective assoc item in the trait definition.
1164
1176
///
1165
1177
/// For example this code emits the errors in the following code:
1166
- /// ```
1178
+ /// ```rust,compile_fail
1167
1179
/// trait Trait {
1168
1180
/// fn foo();
1169
1181
/// type Assoc<T>;
@@ -1547,7 +1559,7 @@ fn compare_synthetic_generics<'tcx>(
1547
1559
/// the same kind as the respective generic parameter in the trait def.
1548
1560
///
1549
1561
/// For example all 4 errors in the following code are emitted here:
1550
- /// ```
1562
+ /// ```rust,ignore (pseudo-Rust)
1551
1563
/// trait Foo {
1552
1564
/// fn foo<const N: u8>();
1553
1565
/// type bar<const N: u8>;
0 commit comments