Skip to content

Can't use symbolic enum in struct constant #3934

Closed
@burg

Description

@burg

Not exactly sure what's going on here. The string and enum seem to be two separate errors.

Test case

enum Weight {
    Light,
    Medium,
    Heavy,
}

struct Bike {
    name: ~str,
    weight: Weight,
}

const town_bike: Bike = Bike {
    name: ~"Schwinn",
    weight: Heavy,
};

pub fn main() {
    debug!("%?", town_bike);    
}

Result

[burg@host-5-178 Desktop]# rustc test.rs
test.rs:13:10: 13:20 error: constant contains unimplemented expression type
test.rs:13     name: ~"Schwinn",
                     ^~~~~~~~~~
test.rs:14:12: 14:17 error: paths in constants may only refer to constants
test.rs:14     weight: Heavy,
                       ^~~~~
error: aborting due to 2 previous errors

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions