@@ -2009,6 +2009,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
2009
2009
}
2010
2010
2011
2011
fn check_struct_or_variant_fields ( fcx : @mut FnCtxt ,
2012
+ struct_ty : ty:: t ,
2012
2013
span : Span ,
2013
2014
class_id : ast:: DefId ,
2014
2015
node_id : ast:: NodeId ,
@@ -2033,10 +2034,12 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
2033
2034
let pair = class_field_map. find ( & field. ident . node . name ) . map ( |x| * x) ;
2034
2035
match pair {
2035
2036
None => {
2036
- tcx. sess . span_err (
2037
- field. ident . span ,
2038
- format ! ( "structure has no field named `{}`" ,
2039
- tcx. sess. str_of( field. ident. node) ) ) ;
2037
+ fcx. type_error_message (
2038
+ field. ident . span ,
2039
+ |actual| {
2040
+ format ! ( "structure `{}` has no field named `{}`" ,
2041
+ actual, tcx. sess. str_of( field. ident. node) )
2042
+ } , struct_ty, None ) ;
2040
2043
error_happened = true ;
2041
2044
}
2042
2045
Some ( ( _, true ) ) => {
@@ -2161,6 +2164,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
2161
2164
// Look up and check the fields.
2162
2165
let class_fields = ty:: lookup_struct_fields ( tcx, class_id) ;
2163
2166
check_struct_or_variant_fields ( fcx,
2167
+ struct_type,
2164
2168
span,
2165
2169
class_id,
2166
2170
id,
@@ -2248,6 +2252,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
2248
2252
// Look up and check the enum variant fields.
2249
2253
let variant_fields = ty:: lookup_struct_fields ( tcx, variant_id) ;
2250
2254
check_struct_or_variant_fields ( fcx,
2255
+ enum_type,
2251
2256
span,
2252
2257
variant_id,
2253
2258
id,
0 commit comments