-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Constants in array repeat expression feature doesn't work with unit structs #80890
Comments
This pull request acknowledges that constants in array repeat expressions are already stable, which is how I was able to make this work with the explicit |
Only a small subset:
|
I'm saying is that this is part of the stabilized subset: #[derive(Debug)]
struct Foo{}
const Foo: Foo = Foo{};
fn main(){
let repeated = [Foo; 4];
println!("{:?}", repeated);
} so this should also work: #[derive(Debug)]
struct Foo;
fn main(){
let repeated = [Foo; 4];
println!("{:?}", repeated);
} I fail to see how they're not exactly equivalent. |
As far as I am aware, it is not. Read the pull request again but carefully. I don't intend to sound rude but the subset solely contains the syntactic class of paths to constants defined by a const item. |
This seems like an appropriate and correct explanation for why this happens, but not an appropriate justification. This should work, in my opinion. Is there some argument against this just working as is? In the RFC it seems clear that it was decided that it's acceptable for this subset to be stable anyway, and this makes the stable subset more confusing. From a user's perspective, these cases are not different and undocumented compiler internal distinctions seem immaterial to whether this behavior should exist. |
The difference is that the case with a constant was accidentally stabilized since 1.38, this wasn't. It was figured that using a Will unit structs be allowed in the future in this position? This is very likely, but there is no need to decide on stabilization of that right now. |
I tried this code:
I expected to the code to compile without errors, since
Foo
is a constant and constants in array repeat expression is stableInstead, this happened: the code doesn't compile, saying that
Foo
isn'tCopy
Unit structs are described as creating a constant of the same name in the reference:
https://doc.rust-lang.org/nightly/reference/items/structs.html
Meta
rustc --version --verbose
:Workarounds
Defining the
Foo
constant explicitly does compile:https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=675dd9fdcc63bde83dfb33a5f0e19054
The text was updated successfully, but these errors were encountered: