Skip to content

Commit e76a46a

Browse files
GuillaumeGomezarielb1
authored andcommitted
Add new error codes in librustc_typeck
1 parent 93a9683 commit e76a46a

File tree

3 files changed

+23
-10
lines changed

3 files changed

+23
-10
lines changed

src/librustc/infer/mod.rs

+14-5
Original file line numberDiff line numberDiff line change
@@ -1510,26 +1510,35 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
15101510
self.type_error_struct(sp, mk_msg, actual_ty).emit();
15111511
}
15121512

1513+
// FIXME: this results in errors without an error code. Deprecate?
15131514
pub fn type_error_struct<M>(&self,
15141515
sp: Span,
15151516
mk_msg: M,
15161517
actual_ty: Ty<'tcx>)
15171518
-> DiagnosticBuilder<'tcx>
15181519
where M: FnOnce(String) -> String,
15191520
{
1520-
debug!("type_error_struct({:?}, {:?})", sp, actual_ty);
1521+
self.type_error_struct_with_diag(sp, |actual_ty| {
1522+
self.tcx.sess.struct_span_err(sp, &mk_msg(actual_ty))
1523+
}, actual_ty)
1524+
}
15211525

1526+
pub fn type_error_struct_with_diag<M>(&self,
1527+
sp: Span,
1528+
mk_diag: M,
1529+
actual_ty: Ty<'tcx>)
1530+
-> DiagnosticBuilder<'tcx>
1531+
where M: FnOnce(String) -> DiagnosticBuilder<'tcx>,
1532+
{
15221533
let actual_ty = self.resolve_type_vars_if_possible(&actual_ty);
1534+
debug!("type_error_struct_with_diag({:?}, {:?})", sp, actual_ty);
15231535

15241536
// Don't report an error if actual type is TyError.
15251537
if actual_ty.references_error() {
15261538
return self.tcx.sess.diagnostic().struct_dummy();
15271539
}
15281540

1529-
let msg = mk_msg(self.ty_to_string(actual_ty));
1530-
1531-
// FIXME: use an error code.
1532-
self.tcx.sess.struct_span_err(sp, &msg)
1541+
mk_diag(self.ty_to_string(actual_ty))
15331542
}
15341543

15351544
pub fn report_mismatched_types(&self,

src/librustc_typeck/check/mod.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -3028,14 +3028,16 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
30283028
variant: ty::VariantDef<'tcx>,
30293029
field: &hir::Field,
30303030
skip_fields: &[hir::Field]) {
3031-
let mut err = self.type_error_struct(
3031+
let mut err = self.type_error_struct_with_diag(
30323032
field.name.span,
30333033
|actual| if let ty::TyEnum(..) = ty.sty {
3034-
format!("struct variant `{}::{}` has no field named `{}`",
3035-
actual, variant.name.as_str(), field.name.node)
3034+
struct_span_err!(self.tcx.sess, field.name.span, E0559,
3035+
"struct variant `{}::{}` has no field named `{}`",
3036+
actual, variant.name.as_str(), field.name.node)
30363037
} else {
3037-
format!("structure `{}` has no field named `{}`",
3038-
actual, field.name.node)
3038+
struct_span_err!(self.tcx.sess, field.name.span, E0560,
3039+
"structure `{}` has no field named `{}`",
3040+
actual, field.name.node)
30393041
},
30403042
ty);
30413043
// prevent all specified fields from being suggested

src/librustc_typeck/diagnostics.rs

+2
Original file line numberDiff line numberDiff line change
@@ -4053,4 +4053,6 @@ register_diagnostics! {
40534053
E0528, // expected at least {} elements, found {}
40544054
E0529, // slice pattern expects array or slice, not `{}`
40554055
E0533, // `{}` does not name a unit variant, unit struct or a constant
4056+
E0559,
4057+
E0560,
40564058
}

0 commit comments

Comments
 (0)