Allow recursive static variables.

There isn't any particularly good reason for this restriction, so just
get rid of it, and fix trans to handle this case.
This commit is contained in:
Eli Friedman 2015-06-28 10:36:46 -07:00
parent 82d40cb2ba
commit 8ebf95257b
7 changed files with 95 additions and 58 deletions

View file

@ -8,9 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// error-pattern: recursive constant
static a: isize = b;
static b: isize = a;
const a: isize = b; //~ ERROR recursive constant
const b: isize = a; //~ ERROR recursive constant
fn main() {
}

View file

@ -8,12 +8,12 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
static FOO: usize = FOO; //~ ERROR recursive constant
const FOO: usize = FOO; //~ ERROR recursive constant
fn main() {
let _x: [u8; FOO]; // caused stack overflow prior to fix
let _y: usize = 1 + {
static BAR: usize = BAR; //~ ERROR recursive constant
const BAR: usize = BAR; //~ ERROR recursive constant
let _z: [u8; BAR]; // caused stack overflow prior to fix
1
};

View file

@ -0,0 +1,15 @@
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
static mut S: *const u8 = unsafe { &S as *const *const u8 as *const u8 };
pub fn main() {
unsafe { assert_eq!(S, *(S as *const *const u8)); }
}