@@ -28,10 +28,8 @@ type binding = @{node_id: node_id,
28
28
unsafe_tys: [ unsafe_ty] ,
29
29
mutable copied: copied} ;
30
30
31
- tag ret_info { by_ref( bool, node_id) ; other; }
32
31
// FIXME it may be worthwhile to use a linked list of bindings instead
33
32
type scope = { bs : [ binding ] ,
34
- ret_info : ret_info ,
35
33
invalid : @mutable list < @invalid > } ;
36
34
37
35
fn mk_binding ( cx : ctx , id : node_id , span : span , root_var : option:: t < node_id > ,
@@ -67,7 +65,7 @@ fn check_crate(tcx: ty::ctxt, crate: @ast::crate) -> (copy_map, ref_map) {
67
65
visit_expr: bind visit_expr ( cx, _, _, _) ,
68
66
visit_block: bind visit_block ( cx, _, _, _)
69
67
with * visit:: default_visitor :: < scope > ( ) } ;
70
- let sc = { bs: [ ] , ret_info : other , invalid: @mutable list:: nil} ;
68
+ let sc = { bs: [ ] , invalid: @mutable list:: nil} ;
71
69
visit:: visit_crate ( * crate , sc, visit:: mk_vt ( v) ) ;
72
70
tcx. sess . abort_if_errors ( ) ;
73
71
ret ( cx. copy_map , cx. ref_map ) ;
@@ -84,24 +82,12 @@ fn visit_fn(cx: @ctx, f: ast::_fn, _tp: [ast::ty_param], sp: span,
84
82
}
85
83
}
86
84
87
- if ast_util:: ret_by_ref ( f. decl . cf ) && !is_none ( f. body . node . expr ) {
88
- // FIXME this will be easier to lift once have DPS
89
- err ( * cx, option:: get ( f. body . node . expr ) . span ,
90
- "reference-returning functions may not return implicitly" ) ;
91
- }
92
- let ret_info = alt f. decl . cf {
93
- ast:: return_ref ( mut, n_arg) {
94
- by_ref ( mut, f. decl . inputs [ n_arg - 1 u] . id )
95
- }
96
- _ { other }
97
- } ;
98
85
// Blocks need to obey any restrictions from the enclosing scope, and may
99
86
// be called multiple times.
100
87
if f. proto == ast:: proto_block {
101
- let sc = { ret_info: ret_info with sc} ;
102
88
check_loop ( * cx, sc) { || v. visit_block ( f. body , sc, v) ; }
103
89
} else {
104
- let sc = { bs: [ ] , ret_info : ret_info , invalid: @mutable list:: nil} ;
90
+ let sc = { bs: [ ] , invalid: @mutable list:: nil} ;
105
91
v. visit_block ( f. body , sc, v) ;
106
92
}
107
93
}
@@ -134,17 +120,6 @@ fn visit_expr(cx: @ctx, ex: @ast::expr, sc: scope, v: vt<scope>) {
134
120
ast:: expr_assign ( dest, src) | ast:: expr_assign_op ( _, dest, src) {
135
121
check_assign ( cx, dest, src, sc, v) ;
136
122
}
137
- ast:: expr_ret ( oexpr) {
138
- if !is_none ( oexpr) {
139
- alt sc. ret_info {
140
- by_ref ( mut, arg_node_id) {
141
- check_ret_ref ( * cx, sc, mut, arg_node_id, option:: get ( oexpr) ) ;
142
- }
143
- _ { }
144
- }
145
- }
146
- handled = false ;
147
- }
148
123
ast:: expr_if ( c, then, els) { check_if ( c, then, els, sc, v) ; }
149
124
ast:: expr_while ( _, _) | ast:: expr_do_while ( _, _) {
150
125
check_loop ( * cx, sc) { || visit:: visit_expr ( ex, sc, v) ; }
@@ -237,9 +212,6 @@ fn cant_copy(cx: ctx, b: binding) -> bool {
237
212
fn check_call ( cx : ctx , sc : scope , f : @ast:: expr , args : [ @ast:: expr ] )
238
213
-> [ binding ] {
239
214
let fty = ty:: expr_ty ( cx. tcx , f) ;
240
- let by_ref = alt ty:: ty_fn_ret_style ( cx. tcx , fty) {
241
- ast:: return_ref ( _, arg_n) { arg_n } _ { 0 u }
242
- } ;
243
215
let arg_ts = ty:: ty_fn_args ( cx. tcx , fty) ;
244
216
let mut_roots: [ { arg : uint , node : node_id } ] = [ ] ;
245
217
let bindings = [ ] ;
@@ -265,7 +237,7 @@ fn check_call(cx: ctx, sc: scope, f: @ast::expr, args: [@ast::expr])
265
237
mutable copied: alt arg_t. mode {
266
238
ast:: by_move. | ast:: by_copy. { copied }
267
239
ast:: by_mut_ref. { not_allowed }
268
- _ { i + 1 u == by_ref ? not_allowed : not_copied }
240
+ _ { not_copied }
269
241
} } ] ;
270
242
i += 1 u;
271
243
}
@@ -338,69 +310,6 @@ fn check_call(cx: ctx, sc: scope, f: @ast::expr, args: [@ast::expr])
338
310
ret bindings;
339
311
}
340
312
341
- fn check_ret_ref ( cx : ctx , sc : scope , mut : bool , arg_node_id : node_id ,
342
- expr : @ast:: expr ) {
343
- let root = expr_root ( cx, expr, false ) ;
344
- let bad = none;
345
- let mut_field = !is_none ( root. mut ) ;
346
- alt path_def( cx, root. ex ) {
347
- none. {
348
- bad = some ( "a temporary" ) ;
349
- }
350
- some ( ast:: def_local ( did, _) ) | some ( ast:: def_binding ( did) ) |
351
- some ( ast:: def_arg ( did, _) ) {
352
- let cur_node = did. node ;
353
- while true {
354
- alt cx. tcx . items . find ( cur_node) {
355
- some ( ast_map:: node_arg ( arg, _) ) {
356
- if arg. mode == ast:: by_move {
357
- bad = some ( "a move-mode parameter" ) ;
358
- }
359
- if arg. mode == ast:: by_copy {
360
- bad = some ( "a copy-mode parameter" ) ;
361
- }
362
- if cur_node != arg_node_id {
363
- bad = some ( "the wrong parameter" ) ;
364
- }
365
- break ;
366
- }
367
- _ { }
368
- }
369
- alt vec:: find ( { |b| b. node_id == cur_node} , sc. bs ) {
370
- some ( b) {
371
- if vec:: len ( b. unsafe_tys ) > 0 u {
372
- mut_field = true ;
373
- break ;
374
- }
375
- if is_none ( b. root_var ) {
376
- bad = some ( "a function-local value" ) ;
377
- break ;
378
- }
379
- if b. copied == copied {
380
- bad = some ( "an implicitly copied reference" ) ;
381
- break ;
382
- }
383
- b. copied = not_allowed;
384
- cur_node = option:: get ( b. root_var ) ;
385
- }
386
- none. {
387
- bad = some ( "a function-local value" ) ;
388
- break ;
389
- }
390
- }
391
- }
392
- }
393
- _ { bad = some ( "a non-local value" ) ; }
394
- }
395
- if mut_field && !mut { bad = some ( "a mutable field" ) ; }
396
- alt bad {
397
- some( name) {
398
- err ( cx, expr. span , "can not return a reference to " + name) ;
399
- }
400
- _ { }
401
- }
402
- }
403
-
404
313
fn check_alt ( cx : ctx , input : @ast:: expr , arms : [ ast:: arm ] , sc : scope ,
405
314
v : vt < scope > ) {
406
315
v. visit_expr ( input, sc, v) ;
@@ -733,22 +642,6 @@ fn expr_root(cx: ctx, ex: @ast::expr, autoderef: bool)
733
642
_ { }
734
643
}
735
644
}
736
- ast:: expr_call ( f, args, _) {
737
- let fty = ty:: expr_ty ( cx. tcx , f) ;
738
- alt ty:: ty_fn_ret_style ( cx. tcx , fty) {
739
- ast:: return_ref ( mut, arg_n) {
740
- let arg = args[ arg_n - 1 u] ;
741
- let arg_root = expr_root ( cx, arg, false ) ;
742
- if mut {
743
- let ret_ty = ty:: expr_ty ( cx. tcx , base_root. ex ) ;
744
- unsafe_ty = some ( mut_contains ( ret_ty) ) ;
745
- }
746
- if !is_none ( arg_root. mut ) { unsafe_ty = arg_root. mut ; }
747
- ret { ex : arg_root. ex , mut : unsafe_ty} ;
748
- }
749
- _ { }
750
- }
751
- }
752
645
_ { }
753
646
}
754
647
ret { ex : base_root. ex , mut : unsafe_ty} ;
0 commit comments