@@ -46,30 +46,17 @@ pub fn check_expr_closure<'a,'tcx>(fcx: &FnCtxt<'a,'tcx>,
46
46
// evidence than an unboxed closure is desired, we'll use
47
47
// that, otherwise we'll fall back to boxed closures.
48
48
match expected_sig_and_kind {
49
- None => { // doesn't look like an unboxed closure
50
- let region = astconv:: opt_ast_region_to_region ( fcx,
51
- fcx,
52
- expr. span ,
53
- & None ) ;
54
-
55
- check_boxed_closure ( fcx,
56
- expr,
57
- ty:: RegionTraitStore ( region, ast:: MutMutable ) ,
58
- decl,
59
- body,
60
- expected) ;
61
-
62
- match capture {
63
- CaptureByValue => {
64
- fcx. ccx . tcx . sess . span_err (
65
- expr. span ,
66
- "boxed closures can't capture by value, \
67
- if you want to use an unboxed closure, \
68
- explicitly annotate its kind: e.g. `move |:|`") ;
69
- } ,
70
- CaptureByRef => { }
71
- }
72
- }
49
+ None => { // don't have information about the kind, request explicit annotation
50
+ // HACK We still need to typeck the body, so assume `FnMut` kind just for that
51
+ let kind = ty:: FnMutUnboxedClosureKind ;
52
+
53
+ check_unboxed_closure ( fcx, expr, kind, decl, body, None ) ;
54
+
55
+ fcx. ccx . tcx . sess . span_err (
56
+ expr. span ,
57
+ "Can't infer the \" kind\" of the closure, explicitly annotate it. e.g. \
58
+ `|&:| {}`") ;
59
+ } ,
73
60
Some ( ( sig, kind) ) => {
74
61
check_unboxed_closure ( fcx, expr, kind, decl, body, Some ( sig) ) ;
75
62
}
@@ -254,91 +241,3 @@ fn deduce_unboxed_closure_expectations_from_obligations<'a,'tcx>(
254
241
255
242
None
256
243
}
257
-
258
-
259
- fn check_boxed_closure < ' a , ' tcx > ( fcx : & FnCtxt < ' a , ' tcx > ,
260
- expr : & ast:: Expr ,
261
- store : ty:: TraitStore ,
262
- decl : & ast:: FnDecl ,
263
- body : & ast:: Block ,
264
- expected : Expectation < ' tcx > ) {
265
- let tcx = fcx. ccx . tcx ;
266
-
267
- // Find the expected input/output types (if any). Substitute
268
- // fresh bound regions for any bound regions we find in the
269
- // expected types so as to avoid capture.
270
- let expected_cenv = expected. map_to_option ( fcx, |ty| match ty. sty {
271
- _ => None
272
- } ) ;
273
- let ( expected_sig, expected_onceness, expected_bounds) = match expected_cenv {
274
- Some ( cenv) => {
275
- let ( sig, _) =
276
- ty:: replace_late_bound_regions (
277
- tcx,
278
- & cenv. sig ,
279
- |_, debruijn| fcx. inh . infcx . fresh_bound_region ( debruijn) ) ;
280
- let onceness = match ( & store, & cenv. store ) {
281
- // As the closure type and onceness go, only three
282
- // combinations are legit:
283
- // once closure
284
- // many closure
285
- // once proc
286
- // If the actual and expected closure type disagree with
287
- // each other, set expected onceness to be always Once or
288
- // Many according to the actual type. Otherwise, it will
289
- // yield either an illegal "many proc" or a less known
290
- // "once closure" in the error message.
291
- ( & ty:: UniqTraitStore , & ty:: UniqTraitStore ) |
292
- ( & ty:: RegionTraitStore ( ..) , & ty:: RegionTraitStore ( ..) ) =>
293
- cenv. onceness ,
294
- ( & ty:: UniqTraitStore , _) => ast:: Once ,
295
- ( & ty:: RegionTraitStore ( ..) , _) => ast:: Many ,
296
- } ;
297
- ( Some ( sig) , onceness, cenv. bounds . clone ( ) )
298
- }
299
- _ => {
300
- // Not an error! Means we're inferring the closure type
301
- let region = fcx. infcx ( ) . next_region_var (
302
- infer:: AddrOfRegion ( expr. span ) ) ;
303
- let bounds = ty:: region_existential_bound ( region) ;
304
- let onceness = ast:: Many ;
305
- ( None , onceness, bounds)
306
- }
307
- } ;
308
-
309
- // construct the function type
310
- let fn_ty = astconv:: ty_of_closure ( fcx,
311
- ast:: Unsafety :: Normal ,
312
- expected_onceness,
313
- expected_bounds,
314
- store,
315
- decl,
316
- abi:: Rust ,
317
- expected_sig) ;
318
- let fn_sig = fn_ty. sig . clone ( ) ;
319
- let fty = panic ! ( "stub" ) ;
320
- debug ! ( "check_expr_fn fty={}" , fcx. infcx( ) . ty_to_string( fty) ) ;
321
-
322
- fcx. write_ty ( expr. id , fty) ;
323
-
324
- // If the closure is a stack closure and hasn't had some non-standard
325
- // style inferred for it, then check it under its parent's style.
326
- // Otherwise, use its own
327
- let ( inherited_style, inherited_style_id) = match store {
328
- ty:: RegionTraitStore ( ..) => ( fcx. ps . borrow ( ) . unsafety ,
329
- fcx. ps . borrow ( ) . def ) ,
330
- ty:: UniqTraitStore => ( ast:: Unsafety :: Normal , expr. id )
331
- } ;
332
-
333
- let fn_sig =
334
- ty:: liberate_late_bound_regions ( tcx, CodeExtent :: from_node_id ( body. id ) , & fn_sig) ;
335
-
336
- check_fn ( fcx. ccx ,
337
- inherited_style,
338
- inherited_style_id,
339
- & fn_sig,
340
- & * decl,
341
- expr. id ,
342
- & * body,
343
- fcx. inh ) ;
344
- }
0 commit comments