@@ -160,6 +160,16 @@ impl Visitor<'tcx> for CollectItemTypesVisitor<'tcx> {
160
160
///////////////////////////////////////////////////////////////////////////
161
161
// Utility types and common code for the above passes.
162
162
163
+ fn bad_placeholder_type ( tcx : TyCtxt < ' tcx > , span : Span ) -> errors:: DiagnosticBuilder < ' tcx > {
164
+ let mut diag = tcx. sess . struct_span_err_with_code (
165
+ span,
166
+ "the type placeholder `_` is not allowed within types on item signatures" ,
167
+ DiagnosticId :: Error ( "E0121" . into ( ) ) ,
168
+ ) ;
169
+ diag. span_label ( span, "not allowed in type signatures" ) ;
170
+ diag
171
+ }
172
+
163
173
impl ItemCtxt < ' tcx > {
164
174
pub fn new ( tcx : TyCtxt < ' tcx > , item_def_id : DefId ) -> ItemCtxt < ' tcx > {
165
175
ItemCtxt { tcx, item_def_id }
@@ -191,12 +201,7 @@ impl AstConv<'tcx> for ItemCtxt<'tcx> {
191
201
}
192
202
193
203
fn ty_infer ( & self , _: Option < & ty:: GenericParamDef > , span : Span ) -> Ty < ' tcx > {
194
- self . tcx ( ) . sess . struct_span_err_with_code (
195
- span,
196
- "the type placeholder `_` is not allowed within types on item signatures" ,
197
- DiagnosticId :: Error ( "E0121" . into ( ) ) ,
198
- ) . span_label ( span, "not allowed in type signatures" )
199
- . emit ( ) ;
204
+ bad_placeholder_type ( self . tcx ( ) , span) . emit ( ) ;
200
205
201
206
self . tcx ( ) . types . err
202
207
}
@@ -207,12 +212,7 @@ impl AstConv<'tcx> for ItemCtxt<'tcx> {
207
212
_: Option < & ty:: GenericParamDef > ,
208
213
span : Span ,
209
214
) -> & ' tcx Const < ' tcx > {
210
- self . tcx ( ) . sess . struct_span_err_with_code (
211
- span,
212
- "the const placeholder `_` is not allowed within types on item signatures" ,
213
- DiagnosticId :: Error ( "E0121" . into ( ) ) ,
214
- ) . span_label ( span, "not allowed in type signatures" )
215
- . emit ( ) ;
215
+ bad_placeholder_type ( self . tcx ( ) , span) . emit ( ) ;
216
216
217
217
self . tcx ( ) . consts . err
218
218
}
0 commit comments