@@ -29,14 +29,15 @@ pub struct CheckCrateVisitor {
29
29
30
30
impl Visitor < bool > for CheckCrateVisitor {
31
31
fn visit_item ( & mut self , i : & Item , env : bool ) {
32
- check_item ( self , self . sess , self . def_map , i, env) ;
32
+ check_item ( self , self . sess , self . def_map , self . method_map ,
33
+ self . tcx , i, env)
33
34
}
34
35
fn visit_pat ( & mut self , p : & Pat , env : bool ) {
35
36
check_pat ( self , p, env) ;
36
37
}
37
38
fn visit_expr ( & mut self , ex : & Expr , env : bool ) {
38
39
check_expr ( self , self . sess , self . def_map , self . method_map ,
39
- self . tcx , ex, env) ;
40
+ self . tcx , ex, env, false ) ;
40
41
}
41
42
}
42
43
@@ -58,11 +59,13 @@ pub fn check_crate(sess: Session,
58
59
pub fn check_item ( v : & mut CheckCrateVisitor ,
59
60
sess : Session ,
60
61
def_map : resolve:: DefMap ,
62
+ method_map : typeck:: method_map ,
63
+ tcx : ty:: ctxt ,
61
64
it : & Item ,
62
65
_is_const : bool ) {
63
66
match it. node {
64
- ItemStatic ( _, _ , ex) => {
65
- v . visit_expr ( ex, true ) ;
67
+ ItemStatic ( _, mut_ , ex) => {
68
+ check_expr ( v , sess , def_map , method_map , tcx , ex, true , mut_ == MutMutable ) ;
66
69
check_item_recursion ( sess, & v. tcx . map , def_map, it) ;
67
70
}
68
71
ItemEnum ( ref enum_definition, _) => {
@@ -105,7 +108,8 @@ pub fn check_expr(v: &mut CheckCrateVisitor,
105
108
method_map : typeck:: MethodMap ,
106
109
tcx : ty:: ctxt ,
107
110
e : & Expr ,
108
- is_const : bool ) {
111
+ is_const : bool ,
112
+ is_static_mut : bool ) {
109
113
if is_const {
110
114
match e. node {
111
115
ExprUnary ( UnDeref , _) => { }
@@ -187,6 +191,11 @@ pub fn check_expr(v: &mut CheckCrateVisitor,
187
191
e. span ,
188
192
"references in constants may only refer to \
189
193
immutable values") ;
194
+ }
195
+ ExprVstore ( _, ExprVstoreMutSlice ) => {
196
+ if !is_static_mut {
197
+ sess. span_err ( e. span , "mutable slice is not allowed in immutable constants" )
198
+ }
190
199
} ,
191
200
ExprVstore ( _, ExprVstoreUniq ) => {
192
201
sess. span_err ( e. span , "cannot allocate vectors in constant expressions" )
0 commit comments