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

Using inline-const in array repeat fails typeck, when it works fine without inline-const #78330

Closed
camelid opened this issue Oct 24, 2020 · 3 comments
Labels
A-inference Area: Type inference C-bug Category: This is a bug. F-inline_const Inline constants (aka: const blocks, const expressions, anonymous constants)

Comments

@camelid
Copy link
Member

camelid commented Oct 24, 2020

This works fine

#![feature(inline_const)]
fn main() {
    println!("{:?}", [1; 1 + 2]);
}

(Playground)

Output:

[1, 1, 1]

Errors:

   Compiling playground v0.0.1 (/playground)
warning: the feature `inline_const` is incomplete and may not be safe to use and/or cause compiler crashes
 --> src/main.rs:1:12
  |
1 | #![feature(inline_const)]
  |            ^^^^^^^^^^^^
  |
  = note: `#[warn(incomplete_features)]` on by default
  = note: see issue #76001 <https://github.com/rust-lang/rust/issues/76001> for more information

warning: 1 warning emitted

    Finished dev [unoptimized + debuginfo] target(s) in 0.83s
     Running `target/debug/playground`


This fails

#![feature(inline_const)]
fn main() {
    println!("{:?}", [1; const { 1 + 2 }]);
}

(Playground)

Errors:

   Compiling playground v0.0.1 (/playground)
warning: the feature `inline_const` is incomplete and may not be safe to use and/or cause compiler crashes
 --> src/main.rs:1:12
  |
1 | #![feature(inline_const)]
  |            ^^^^^^^^^^^^
  |
  = note: `#[warn(incomplete_features)]` on by default
  = note: see issue #76001 <https://github.com/rust-lang/rust/issues/76001> for more information

error[E0308]: mismatched types
 --> src/main.rs:3:26
  |
3 |     println!("{:?}", [1; const { 1 + 2 }]);
  |                          ^^^^^ expected `usize`, found `i32`

error: aborting due to previous error; 1 warning emitted

For more information about this error, try `rustc --explain E0308`.
error: could not compile `playground`

To learn more, run the command again with --verbose.

@camelid camelid added A-inference Area: Type inference C-bug Category: This is a bug. F-inline_const Inline constants (aka: const blocks, const expressions, anonymous constants) labels Oct 24, 2020
@camelid
Copy link
Member Author

camelid commented Oct 24, 2020

I'm guessing this might be an expected limitation because of how inline-const is desugared.

@lcnr
Copy link
Contributor

lcnr commented Oct 25, 2020

we probably have to treat inline consts similar to closures during typeck. That might be somewhat complicated and I don't have the time to look into this myself.

If someone wants to work on this feel free to open a topic on zulip and ping me there though

@camelid
Copy link
Member Author

camelid commented Oct 30, 2020

Duplicate of #78132.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-inference Area: Type inference C-bug Category: This is a bug. F-inline_const Inline constants (aka: const blocks, const expressions, anonymous constants)
Projects
None yet
Development

No branches or pull requests

2 participants