@@ -92,31 +92,39 @@ pub fn report_error<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
92
92
93
93
// Determine if the field can be used as a function in some way
94
94
let field_ty = field. ty ( cx, substs) ;
95
- if let Ok ( fn_once_trait_did) = cx. lang_items . require ( FnOnceTraitLangItem ) {
96
- let infcx = fcx. infcx ( ) ;
97
- infcx. probe ( |_| {
98
- let fn_once_substs = Substs :: new_trait ( vec ! [ infcx. next_ty_var( ) ] ,
99
- Vec :: new ( ) ,
100
- field_ty) ;
101
- let trait_ref = ty:: TraitRef :: new ( fn_once_trait_did,
102
- cx. mk_substs ( fn_once_substs) ) ;
103
- let poly_trait_ref = trait_ref. to_poly_trait_ref ( ) ;
104
- let obligation = Obligation :: misc ( span,
105
- fcx. body_id ,
106
- poly_trait_ref. to_predicate ( ) ) ;
107
- let mut selcx = SelectionContext :: new ( infcx) ;
108
-
109
- if selcx. evaluate_obligation ( & obligation) {
110
- span_stored_function ( ) ;
95
+
96
+ match field_ty. sty {
97
+ // Not all of these (e.g. unsafe fns) implement FnOnce
98
+ // so we look for these beforehand
99
+ ty:: TyClosure ( ..) | ty:: TyBareFn ( ..) => span_stored_function ( ) ,
100
+ // If it's not a simple function, look for things which implement FnOnce
101
+ _ => {
102
+ if let Ok ( fn_once_trait_did) =
103
+ cx. lang_items . require ( FnOnceTraitLangItem ) {
104
+ let infcx = fcx. infcx ( ) ;
105
+ infcx. probe ( |_| {
106
+ let fn_once_substs = Substs :: new_trait ( vec ! [
107
+ infcx. next_ty_var( ) ] ,
108
+ Vec :: new ( ) ,
109
+ field_ty) ;
110
+ let trait_ref = ty:: TraitRef :: new ( fn_once_trait_did,
111
+ cx. mk_substs ( fn_once_substs) ) ;
112
+ let poly_trait_ref = trait_ref. to_poly_trait_ref ( ) ;
113
+ let obligation = Obligation :: misc ( span,
114
+ fcx. body_id ,
115
+ poly_trait_ref
116
+ . to_predicate ( ) ) ;
117
+ let mut selcx = SelectionContext :: new ( infcx) ;
118
+
119
+ if selcx. evaluate_obligation ( & obligation) {
120
+ span_stored_function ( ) ;
121
+ } else {
122
+ span_did_you_mean ( ) ;
123
+ }
124
+ } ) ;
111
125
} else {
112
- span_did_you_mean ( ) ;
126
+ span_did_you_mean ( )
113
127
}
114
- } ) ;
115
- } else {
116
- match field_ty. sty {
117
- // fallback to matching a closure or function pointer
118
- ty:: TyClosure ( ..) | ty:: TyBareFn ( ..) => span_stored_function ( ) ,
119
- _ => span_did_you_mean ( ) ,
120
128
}
121
129
}
122
130
}
0 commit comments