@@ -160,6 +160,16 @@ impl Visitor<'tcx> for CollectItemTypesVisitor<'tcx> {
160160///////////////////////////////////////////////////////////////////////////
161161// Utility types and common code for the above passes.
162162
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+
163173impl ItemCtxt<'tcx> {
164174 pub fn new(tcx: TyCtxt<'tcx>, item_def_id: DefId) -> ItemCtxt<'tcx> {
165175 ItemCtxt { tcx, item_def_id }
@@ -191,12 +201,7 @@ impl AstConv<'tcx> for ItemCtxt<'tcx> {
191201 }
192202
193203 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();
200205
201206 self.tcx().types.err
202207 }
@@ -207,12 +212,7 @@ impl AstConv<'tcx> for ItemCtxt<'tcx> {
207212 _: Option<&ty::GenericParamDef>,
208213 span: Span,
209214 ) -> &'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();
216216
217217 self.tcx().consts.err
218218 }
0 commit comments