@@ -8,7 +8,9 @@ use rustc_infer::traits::{ImplSource, Obligation, ObligationCause};
8
8
use rustc_middle:: mir;
9
9
use rustc_middle:: ty:: print:: with_no_trimmed_paths;
10
10
use rustc_middle:: ty:: subst:: { GenericArgKind , SubstsRef } ;
11
- use rustc_middle:: ty:: { suggest_constraining_type_param, Adt , Param , TraitPredicate , Ty } ;
11
+ use rustc_middle:: ty:: {
12
+ suggest_constraining_type_param, Adt , Closure , FnDef , FnPtr , Param , TraitPredicate , Ty ,
13
+ } ;
12
14
use rustc_middle:: ty:: { Binder , BoundConstness , ImplPolarity , TraitRef } ;
13
15
use rustc_session:: parse:: feature_err;
14
16
use rustc_span:: symbol:: sym;
@@ -155,7 +157,7 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
155
157
CallKind :: Normal { desugaring : Some ( ( kind, self_ty) ) , .. } => {
156
158
macro_rules! error {
157
159
( $fmt: literal) => {
158
- struct_span_err!( tcx. sess, span, E0015 , $fmt, self_ty, ccx. const_kind( ) , )
160
+ struct_span_err!( tcx. sess, span, E0015 , $fmt, self_ty, ccx. const_kind( ) )
159
161
} ;
160
162
}
161
163
@@ -176,6 +178,41 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
176
178
177
179
diag_trait ( err, self_ty, kind. trait_def_id ( tcx) )
178
180
}
181
+ CallKind :: FnCall { fn_trait_id, self_ty } => {
182
+ let mut err = struct_span_err ! (
183
+ tcx. sess,
184
+ span,
185
+ E0015 ,
186
+ "cannot call non-const closure in {}s" ,
187
+ ccx. const_kind( ) ,
188
+ ) ;
189
+
190
+ match self_ty. kind ( ) {
191
+ FnDef ( def_id, ..) => {
192
+ let span = tcx. sess . source_map ( ) . guess_head_span ( tcx. def_span ( * def_id) ) ;
193
+ if ccx. tcx . is_const_fn_raw ( * def_id) {
194
+ span_bug ! ( span, "calling const FnDef errored when it shouldn't" ) ;
195
+ }
196
+
197
+ err. span_note ( span, "function defined here, but it is not `const`" ) ;
198
+ }
199
+ FnPtr ( ..) => {
200
+ err. note ( & format ! (
201
+ "function pointers need an RFC before allowed to be called in {}s" ,
202
+ ccx. const_kind( )
203
+ ) ) ;
204
+ }
205
+ Closure ( ..) => {
206
+ err. note ( & format ! (
207
+ "closures need an RFC before allowed to be called in {}s" ,
208
+ ccx. const_kind( )
209
+ ) ) ;
210
+ }
211
+ _ => { }
212
+ }
213
+
214
+ diag_trait ( err, self_ty, fn_trait_id)
215
+ }
179
216
CallKind :: Operator { trait_id, self_ty, .. } => {
180
217
let mut err = struct_span_err ! (
181
218
tcx. sess,
0 commit comments