@@ -59,22 +59,35 @@ pub fn report_error<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
59
59
None ) ;
60
60
61
61
// If the item has the name of a field, give a help note
62
- if let ( & ty:: TyStruct ( did, substs) , Some ( _ ) ) = ( & rcvr_ty. sty , rcvr_expr) {
62
+ if let ( & ty:: TyStruct ( did, substs) , Some ( expr ) ) = ( & rcvr_ty. sty , rcvr_expr) {
63
63
let fields = ty:: lookup_struct_fields ( cx, did) ;
64
64
65
65
if let Some ( field) = fields. iter ( ) . find ( |f| f. name == item_name) {
66
+ let expr_string = match cx. sess . codemap ( ) . span_to_snippet ( expr. span ) {
67
+ Ok ( expr_string) => expr_string,
68
+ _ => "s" . into ( ) // default to generic placeholder for expression
69
+ } ;
66
70
71
+ // TODO Fix when closure note is displayed
72
+ // below commented code from eddyb on irc
73
+ // let substs = subst::Substs::new_trait(vec![fcx.inh.infcx.next_ty_var()], Vec::new(), field_ty);
74
+ // let trait_ref = ty::TraitRef::new(trait_def_id, fcx.tcx().mk_substs(substs));
75
+ // let poly_trait_ref = trait_ref.to_poly_trait_ref();
76
+ // let obligation = traits::Obligation::misc(span, fcx.body_id, poly_trait_ref.as_predicate());
77
+ // let mut selcx = traits::SelectionContext::new(fcx.infcx(), fcx);
78
+ // if selcx.evaluate_obligation(&obligation) { /* suggest */ }
79
+
67
80
match ty:: lookup_field_type ( cx, did, field. id , substs) . sty {
68
81
ty:: TyClosure ( _, _) | ty:: TyBareFn ( _, _) => {
69
82
cx. sess . span_note ( span,
70
83
& format ! ( "use `({0}.{1})(...)` if you meant to call the \
71
84
function stored in the `{1}` field",
72
- ty :: item_path_str ( cx , did ) , item_name) ) ;
85
+ expr_string , item_name) ) ;
73
86
} ,
74
87
_ => {
75
88
cx. sess . span_note ( span,
76
89
& format ! ( "did you mean to write `{0}.{1}`?" ,
77
- ty :: item_path_str ( cx , did ) , item_name) ) ;
90
+ expr_string , item_name) ) ;
78
91
} ,
79
92
} ;
80
93
}
0 commit comments