1
1
//! See docs in build/expr/mod.rs
2
2
3
3
use crate :: build:: { BlockAnd , BlockAndExtension , Builder } ;
4
+ use crate :: build:: scope:: { CachedBlock , DropKind } ;
4
5
use crate :: hair:: * ;
5
6
use rustc:: middle:: region;
6
7
use rustc:: mir:: * ;
@@ -63,6 +64,8 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
63
64
}
64
65
this. local_decls . push ( local_decl)
65
66
} ;
67
+ let temp_place = & Place :: Base ( PlaceBase :: Local ( temp) ) ;
68
+
66
69
if !expr_ty. is_never ( ) {
67
70
this. cfg . push (
68
71
block,
@@ -71,25 +74,38 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
71
74
kind : StatementKind :: StorageLive ( temp) ,
72
75
} ,
73
76
) ;
77
+
78
+ // In constants, temp_lifetime is None for temporaries that live for the
79
+ // 'static lifetime. Thus we do not drop these temporaries and simply leak them.
80
+ // This is equivalent to what `let x = &foo();` does in functions. The temporary
81
+ // is lifted to their surrounding scope. In a function that means the temporary lives
82
+ // until just before the function returns. In constants that means it outlives the
83
+ // constant's initialization value computation. Anything outliving a constant
84
+ // must have the `'static` lifetime and live forever.
85
+ // Anything with a shorter lifetime (e.g the `&foo()` in `bar(&foo())` or anything
86
+ // within a block will keep the regular drops just like runtime code.
87
+ if let Some ( temp_lifetime) = temp_lifetime {
88
+ this. schedule_drop (
89
+ expr_span,
90
+ temp_lifetime,
91
+ temp_place,
92
+ expr_ty,
93
+ DropKind :: Storage ,
94
+ ) ;
95
+ }
74
96
}
75
97
76
- unpack ! ( block = this. into( & Place :: Base ( PlaceBase :: Local ( temp ) ) , block, expr) ) ;
98
+ unpack ! ( block = this. into( temp_place , block, expr) ) ;
77
99
78
- // In constants, temp_lifetime is None for temporaries that live for the
79
- // 'static lifetime. Thus we do not drop these temporaries and simply leak them.
80
- // This is equivalent to what `let x = &foo();` does in functions. The temporary
81
- // is lifted to their surrounding scope. In a function that means the temporary lives
82
- // until just before the function returns. In constants that means it outlives the
83
- // constant's initialization value computation. Anything outliving a constant
84
- // must have the `'static` lifetime and live forever.
85
- // Anything with a shorter lifetime (e.g the `&foo()` in `bar(&foo())` or anything
86
- // within a block will keep the regular drops just like runtime code.
87
100
if let Some ( temp_lifetime) = temp_lifetime {
88
- this. schedule_drop_storage_and_value (
101
+ this. schedule_drop (
89
102
expr_span,
90
103
temp_lifetime,
91
- & Place :: Base ( PlaceBase :: Local ( temp ) ) ,
104
+ temp_place ,
92
105
expr_ty,
106
+ DropKind :: Value {
107
+ cached_block : CachedBlock :: default ( ) ,
108
+ } ,
93
109
) ;
94
110
}
95
111
0 commit comments