8
8
// option. This file may not be copied, modified, or distributed
9
9
// except according to those terms.
10
10
11
- /*!
12
- * This module contains the code to convert from the wacky tcx data
13
- * structures into the hair. The `builder` is generally ignorant of
14
- * the tcx etc, and instead goes through the `Cx` for most of its
15
- * work.
16
- */
11
+ //! This module contains the code to convert from the wacky tcx data
12
+ //! structures into the hair. The `builder` is generally ignorant of
13
+ //! the tcx etc, and instead goes through the `Cx` for most of its
14
+ //! work.
15
+ //!
17
16
18
17
use hair:: * ;
19
18
use rustc:: mir:: transform:: MirSource ;
@@ -32,27 +31,25 @@ use rustc::hir;
32
31
use rustc_const_math:: { ConstInt , ConstUsize } ;
33
32
34
33
#[ derive( Copy , Clone ) ]
35
- pub struct Cx < ' a , ' gcx : ' a + ' tcx , ' tcx : ' a > {
34
+ pub struct Cx < ' a , ' gcx : ' a + ' tcx , ' tcx : ' a > {
36
35
tcx : TyCtxt < ' a , ' gcx , ' tcx > ,
37
36
infcx : & ' a InferCtxt < ' a , ' gcx , ' tcx > ,
38
37
constness : hir:: Constness ,
39
38
40
39
/// True if this constant/function needs overflow checks.
41
- check_overflow : bool
40
+ check_overflow : bool ,
42
41
}
43
42
44
43
impl < ' a , ' gcx , ' tcx > Cx < ' a , ' gcx , ' tcx > {
45
- pub fn new ( infcx : & ' a InferCtxt < ' a , ' gcx , ' tcx > ,
46
- src : MirSource )
47
- -> Cx < ' a , ' gcx , ' tcx > {
44
+ pub fn new ( infcx : & ' a InferCtxt < ' a , ' gcx , ' tcx > , src : MirSource ) -> Cx < ' a , ' gcx , ' tcx > {
48
45
let constness = match src {
49
46
MirSource :: Const ( _) |
50
47
MirSource :: Static ( ..) => hir:: Constness :: Const ,
51
48
MirSource :: Fn ( id) => {
52
49
let fn_like = FnLikeNode :: from_node ( infcx. tcx . map . get ( id) ) ;
53
50
fn_like. map_or ( hir:: Constness :: NotConst , |f| f. constness ( ) )
54
51
}
55
- MirSource :: Promoted ( ..) => bug ! ( )
52
+ MirSource :: Promoted ( ..) => bug ! ( ) ,
56
53
} ;
57
54
58
55
let src_node_id = src. item_id ( ) ;
@@ -70,13 +67,16 @@ impl<'a, 'gcx, 'tcx> Cx<'a, 'gcx, 'tcx> {
70
67
// Some functions always have overflow checks enabled,
71
68
// however, they may not get codegen'd, depending on
72
69
// the settings for the crate they are translated in.
73
- let mut check_overflow = attrs. iter ( ) . any ( |item| {
74
- item. check_name ( "rustc_inherit_overflow_checks" )
75
- } ) ;
70
+ let mut check_overflow = attrs. iter ( )
71
+ . any ( |item| item. check_name ( "rustc_inherit_overflow_checks" ) ) ;
76
72
77
73
// Respect -Z force-overflow-checks=on and -C debug-assertions.
78
- check_overflow |= infcx. tcx . sess . opts . debugging_opts . force_overflow_checks
79
- . unwrap_or ( infcx. tcx . sess . opts . debug_assertions ) ;
74
+ check_overflow |= infcx. tcx
75
+ . sess
76
+ . opts
77
+ . debugging_opts
78
+ . force_overflow_checks
79
+ . unwrap_or ( infcx. tcx . sess . opts . debug_assertions ) ;
80
80
81
81
// Constants and const fn's always need overflow checks.
82
82
check_overflow |= constness == hir:: Constness :: Const ;
@@ -85,7 +85,7 @@ impl<'a, 'gcx, 'tcx> Cx<'a, 'gcx, 'tcx> {
85
85
tcx : infcx. tcx ,
86
86
infcx : infcx,
87
87
constness : constness,
88
- check_overflow : check_overflow
88
+ check_overflow : check_overflow,
89
89
}
90
90
}
91
91
}
@@ -102,7 +102,7 @@ impl<'a, 'gcx, 'tcx> Cx<'a, 'gcx, 'tcx> {
102
102
103
103
pub fn usize_literal ( & mut self , value : u64 ) -> Literal < ' tcx > {
104
104
match ConstUsize :: new ( value, self . tcx . sess . target . uint_type ) {
105
- Ok ( val) => Literal :: Value { value : ConstVal :: Integral ( ConstInt :: Usize ( val) ) } ,
105
+ Ok ( val) => Literal :: Value { value : ConstVal :: Integral ( ConstInt :: Usize ( val) ) } ,
106
106
Err ( _) => bug ! ( "usize literal out of range for target" ) ,
107
107
}
108
108
}
@@ -128,9 +128,7 @@ impl<'a, 'gcx, 'tcx> Cx<'a, 'gcx, 'tcx> {
128
128
}
129
129
130
130
pub fn const_eval_literal ( & mut self , e : & hir:: Expr ) -> Literal < ' tcx > {
131
- Literal :: Value {
132
- value : const_eval:: eval_const_expr ( self . tcx . global_tcx ( ) , e)
133
- }
131
+ Literal :: Value { value : const_eval:: eval_const_expr ( self . tcx . global_tcx ( ) , e) }
134
132
}
135
133
136
134
pub fn trait_method ( & mut self ,
@@ -145,10 +143,11 @@ impl<'a, 'gcx, 'tcx> Cx<'a, 'gcx, 'tcx> {
145
143
if item. kind == ty:: AssociatedKind :: Method && item. name == method_name {
146
144
let method_ty = self . tcx . item_type ( item. def_id ) ;
147
145
let method_ty = method_ty. subst ( self . tcx , substs) ;
148
- return ( method_ty, Literal :: Item {
149
- def_id : item. def_id ,
150
- substs : substs,
151
- } ) ;
146
+ return ( method_ty,
147
+ Literal :: Item {
148
+ def_id : item. def_id ,
149
+ substs : substs,
150
+ } ) ;
152
151
}
153
152
}
154
153
@@ -168,7 +167,8 @@ impl<'a, 'gcx, 'tcx> Cx<'a, 'gcx, 'tcx> {
168
167
pub fn needs_drop ( & mut self , ty : Ty < ' tcx > ) -> bool {
169
168
let ty = self . tcx . lift_to_global ( & ty) . unwrap_or_else ( || {
170
169
bug ! ( "MIR: Cx::needs_drop({}) got \
171
- type with inference types/regions", ty) ;
170
+ type with inference types/regions",
171
+ ty) ;
172
172
} ) ;
173
173
self . tcx . type_needs_drop_given_env ( ty, & self . infcx . parameter_environment )
174
174
}
0 commit comments