mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-04 19:29:07 +00:00
rustc_typeck: extract common placeholder type diagnostic code
This commit is contained in:
parent
d56128d291
commit
d9ad04a0f0
@ -160,6 +160,16 @@ impl Visitor<'tcx> for CollectItemTypesVisitor<'tcx> {
|
|||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
// Utility types and common code for the above passes.
|
// Utility types and common code for the above passes.
|
||||||
|
|
||||||
|
fn bad_placeholder_type(tcx: TyCtxt<'tcx>, span: Span) -> errors::DiagnosticBuilder<'tcx> {
|
||||||
|
let mut diag = tcx.sess.struct_span_err_with_code(
|
||||||
|
span,
|
||||||
|
"the type placeholder `_` is not allowed within types on item signatures",
|
||||||
|
DiagnosticId::Error("E0121".into()),
|
||||||
|
);
|
||||||
|
diag.span_label(span, "not allowed in type signatures");
|
||||||
|
diag
|
||||||
|
}
|
||||||
|
|
||||||
impl ItemCtxt<'tcx> {
|
impl ItemCtxt<'tcx> {
|
||||||
pub fn new(tcx: TyCtxt<'tcx>, item_def_id: DefId) -> ItemCtxt<'tcx> {
|
pub fn new(tcx: TyCtxt<'tcx>, item_def_id: DefId) -> ItemCtxt<'tcx> {
|
||||||
ItemCtxt { tcx, item_def_id }
|
ItemCtxt { tcx, item_def_id }
|
||||||
@ -191,12 +201,7 @@ impl AstConv<'tcx> for ItemCtxt<'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn ty_infer(&self, _: Option<&ty::GenericParamDef>, span: Span) -> Ty<'tcx> {
|
fn ty_infer(&self, _: Option<&ty::GenericParamDef>, span: Span) -> Ty<'tcx> {
|
||||||
self.tcx().sess.struct_span_err_with_code(
|
bad_placeholder_type(self.tcx(), span).emit();
|
||||||
span,
|
|
||||||
"the type placeholder `_` is not allowed within types on item signatures",
|
|
||||||
DiagnosticId::Error("E0121".into()),
|
|
||||||
).span_label(span, "not allowed in type signatures")
|
|
||||||
.emit();
|
|
||||||
|
|
||||||
self.tcx().types.err
|
self.tcx().types.err
|
||||||
}
|
}
|
||||||
@ -207,12 +212,7 @@ impl AstConv<'tcx> for ItemCtxt<'tcx> {
|
|||||||
_: Option<&ty::GenericParamDef>,
|
_: Option<&ty::GenericParamDef>,
|
||||||
span: Span,
|
span: Span,
|
||||||
) -> &'tcx Const<'tcx> {
|
) -> &'tcx Const<'tcx> {
|
||||||
self.tcx().sess.struct_span_err_with_code(
|
bad_placeholder_type(self.tcx(), span).emit();
|
||||||
span,
|
|
||||||
"the const placeholder `_` is not allowed within types on item signatures",
|
|
||||||
DiagnosticId::Error("E0121".into()),
|
|
||||||
).span_label(span, "not allowed in type signatures")
|
|
||||||
.emit();
|
|
||||||
|
|
||||||
self.tcx().consts.err
|
self.tcx().consts.err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user