File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -80,6 +80,23 @@ impl Void {
80
80
}
81
81
}
82
82
83
+ /// A zero-sized type hint useful for accessing static methods that don't
84
+ /// mention `Self`.
85
+ ///
86
+ /// # Example
87
+ ///
88
+ /// ~~~rust
89
+ /// trait A {
90
+ /// fn a(_: ForType<Self>) -> uint;
91
+ /// }
92
+ ///
93
+ /// impl A for int {
94
+ /// fn a(_: ForType<Self>) -> uint { 6 }
95
+ /// }
96
+ ///
97
+ /// assert_eq!(A::a(ForType::<int>), 6);
98
+ /// ~~~
99
+ pub struct ForType < T > ;
83
100
84
101
#[ cfg( test) ]
85
102
mod tests {
@@ -151,6 +168,19 @@ mod tests {
151
168
152
169
unsafe { assert_eq ! ( did_run, true ) ; }
153
170
}
171
+
172
+ #[ test]
173
+ fn type_hint ( ) {
174
+ trait A {
175
+ fn a ( _: ForType < Self > ) -> uint ;
176
+ }
177
+
178
+ impl A for int {
179
+ fn a ( _: ForType < Self > ) -> uint { 6 }
180
+ }
181
+
182
+ assert_eq ! ( A :: a( ForType :: <int>) , 6 ) ;
183
+ }
154
184
}
155
185
156
186
/// Completely miscellaneous language-construct benchmarks.
You can’t perform that action at this time.
0 commit comments