Skip to content

Can't use symbolic enum in struct constant #3934

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
burg opened this issue Nov 7, 2012 · 2 comments
Closed

Can't use symbolic enum in struct constant #3934

burg opened this issue Nov 7, 2012 · 2 comments
Milestone

Comments

@burg
Copy link

burg commented Nov 7, 2012

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
@catamorphism
Copy link
Contributor

Yeah, you can't use enums in constants at all. If we want to revisit that, it would have to be an RFC. (It would certainly make sense to use C-like enums, anyway.)

@burg
Copy link
Author

burg commented Nov 7, 2012

At the least, maybe we should document the "conditions for success" somewhere 😉

@pcwalton pcwalton closed this as completed Dec 4, 2012
bors pushed a commit to rust-lang-ci/rust that referenced this issue May 15, 2021
This commit partially reverts rust-lang#3934, opting to create a span that covers
the entire body of a closure when formatting a closure body with a
block-formatting strategy, rather than having the block-formatting code
determine if the visitor pointer should be rewound. The problem with
rewinding the visitor pointer is it may be incorrect for other (i.e.
non-artificial) AST nodes, as in the case of rust-lang#4382.

Closes rust-lang#4382
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants