Skip to content
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

Bogus error when using .. in struct expr with all fields present, in a const ("error[E0016]: blocks in constants are limited to items and tail expressions") #39161

Closed
2 tasks
jorendorff opened this issue Jan 18, 2017 · 1 comment · Fixed by #86381
Labels
A-const-fn Area: const fn foo(..) {..}. Pure functions which can be applied at compile time. C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@jorendorff
Copy link
Contributor

struct X { a: i32, b: i32 }

#[allow(unused_variables)]
fn main() {
    const DX: X = X { a: 0, b: 0 };
    const X1: X = X { a: 1, ..DX };  // ok
    let   x2    = X { a: 1, b: 2, ..DX };  // ok
    const X3: X = X { a: 1, b: 2, ..DX };  // error[E0016]
}
  • It's weird that X1 and x2 are allowed, but not X3.
  • Even if that's intentional, the error message seems off.
@Mark-Simulacrum Mark-Simulacrum added the A-const-fn Area: const fn foo(..) {..}. Pure functions which can be applied at compile time. label May 20, 2017
@Mark-Simulacrum Mark-Simulacrum added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Jul 26, 2017
@jakubadamw
Copy link
Contributor

The provided code compiles fine both in 1.36 and the 2019-08-12 nightly.

I did a quick search through the test suite and there's none for this particular case. Marking as such.

@rustbot modify labels: E-needstest

@rustbot rustbot added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Aug 13, 2019
@jonas-schievink jonas-schievink added C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed C-enhancement Category: An issue proposing an enhancement or a PR with one. labels Apr 19, 2020
yerke added a commit to yerke/rust that referenced this issue Jun 16, 2021
JohnTitor added a commit to JohnTitor/rust that referenced this issue Jun 21, 2021
…ohnTitor

Add regression test for issue rust-lang#39161

Closes rust-lang#39161

Based on feedback from `@JohnTitor` in rust-lang#71333

r? `@JohnTitor`
bors added a commit to rust-lang-ci/rust that referenced this issue Jun 22, 2021
Rollup of 11 pull requests

Successful merges:

 - rust-lang#85054 (Revert SGX inline asm syntax)
 - rust-lang#85182 (Move `available_concurrency` implementation to `sys`)
 - rust-lang#86037 (Add `io::Cursor::{remaining, remaining_slice, is_empty}`)
 - rust-lang#86114 (Reopen rust-lang#79692 (Format symbols under shared frames))
 - rust-lang#86297 (Allow to pass arguments to rustdoc-gui tool)
 - rust-lang#86334 (Resolve type aliases to the type they point to in intra-doc links)
 - rust-lang#86367 (Fix comment about rustc_inherit_overflow_checks in abs().)
 - rust-lang#86381 (Add regression test for issue rust-lang#39161)
 - rust-lang#86387 (Remove `#[allow(unused_lifetimes)]` which is now unnecessary)
 - rust-lang#86398 (Add regression test for issue rust-lang#54685)
 - rust-lang#86493 (Say "this enum variant takes"/"this struct takes" instead of "this function takes")

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors closed this as completed in 4d73300 Jun 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-fn Area: const fn foo(..) {..}. Pure functions which can be applied at compile time. C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants