Closed
Description
From: https://gist.github.com/pnkfelix/7198893
Part of #5551 metabug.
First, an illustration that field-dereference can be used in some const expressions. This compiles and runs:
struct foo { x: int, y: int }
static A : foo = foo { x: 3, y: 4 };
static B : int = A.x;
fn main() {
println!("{:?}", B);
But, even though the above compiles and runs, a use of B
as the length of a fixed length vec fails to compile.
struct foo { x: int, y: int }
static A : foo = foo { x: 3, y: 4 };
#[cfg(field_proj)]
static B : int = A.x;
#[cfg(inline_val)]
static B : int = 3;
fn main() {
let v : [int, ..B] = [5, 6, 7];
println!("{:?}", v);
}
% ./x86_64-apple-darwin/stage0/bin/rustc --cfg inline_val /tmp/f.rs && /tmp/f
warning: no debug symbols in executable (-arch x86_64)
[5, 6, 7]
% ./x86_64-apple-darwin/stage0/bin/rustc --cfg field_proj /tmp/f.rs && /tmp/f
/tmp/f.rs:11:12: 11:22 error: expected constant expr for vector length: Unsupported constant expr
/tmp/f.rs:11 let v : [int, ..B] = [5, 6, 7];
^~~~~~~~~~
task '<unnamed>' failed at 'explicit failure', /Users/rustbuild/src/rust-buildbot/slave/snap3-mac/build/src/libsyntax/diagnostic.rs:75
task '<unnamed>' failed at 'explicit failure', /Users/rustbuild/src/rust-buildbot/slave/snap3-mac/build/src/librustc/rustc.rs:395
%
Metadata
Metadata
Assignees
Labels
No labels