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

Possible degradation in const generics #89334

Closed
drskalman opened this issue Sep 28, 2021 · 2 comments · Fixed by #90266
Closed

Possible degradation in const generics #89334

drskalman opened this issue Sep 28, 2021 · 2 comments · Fixed by #90266
Assignees
Labels
A-const-generics Area: const generics (parameters and arguments) C-bug Category: This is a bug. F-generic_const_exprs `#![feature(generic_const_exprs)]`

Comments

@drskalman
Copy link

drskalman commented Sep 28, 2021

The following code compiles with rustc 1.56.0-nightly (4e28279 2021-07-31) but not rustc 1.56.0-nightly (5d68044 2021-08-30) or 1.57.0

#![feature(const_generics)]
#![feature(const_evaluatable_checked)]
//#![feature(generic_const_exprs)]

pub trait AnotherTrait{
    const ARRAY_SIZE: usize;
}
pub trait Shard<T: AnotherTrait>:
    AsMut<[[u8; T::ARRAY_SIZE]]>
where
    [(); T::ARRAY_SIZE]: Sized
{
}

fn main() {
    println!("Hello, world!");
}

As you see it compiles with the earlier compiler but not with the new one:

Meta

Build outputs

[user@machine as_mut_bug]$ rustup default nightly-2021-08-01-x86_64-unknown-linux-gnu info: using existing install for 'nightly-2021-08-01-x86_64-unknown-linux-gnu' info: default toolchain set to 'nightly-2021-08-01-x86_64-unknown-linux-gnu'

nightly-2021-08-01-x86_64-unknown-linux-gnu unchanged - rustc 1.56.0-nightly (4e28279 2021-07-31)

[user@machine as_mut_bug]$ cargo build
Compiling as_mut_bug v0.1.0 (/home/user/lazyhole/code/playground/rust-playground/as_mut_bug)
warning: the feature const_generics is incomplete and may not be safe to use and/or cause compiler crashes
--> src/main.rs:1:12
|
1 | #![feature(const_generics)]
| ^^^^^^^^^^^^^^
|
= note: #[warn(incomplete_features)] on by default
= note: see issue #44580 #44580 for more information

warning: the feature const_evaluatable_checked is incomplete and may not be safe to use and/or cause compiler crashes
--> src/main.rs:2:12
|
2 | #![feature(const_evaluatable_checked)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #76560 #76560 for more information

warning: as_mut_bug (bin "as_mut_bug") generated 2 warnings
Finished dev [unoptimized + debuginfo] target(s) in 0.90s
[user@machine as_mut_bug]$ rustup default nightly-2021-08-31-x86_64-unknown-linux-gnu
info: using existing install for 'nightly-2021-08-31-x86_64-unknown-linux-gnu'
info: default toolchain set to 'nightly-2021-08-31-x86_64-unknown-linux-gnu'

nightly-2021-08-31-x86_64-unknown-linux-gnu unchanged - rustc 1.56.0-nightly (5d68044 2021-08-30)

[user@machine as_mut_bug]$ cargo build
Compiling as_mut_bug v0.1.0 (/home/user/lazyhole/code/playground/rust-playground/as_mut_bug)
warning: the feature const_generics is incomplete and may not be safe to use and/or cause compiler crashes
--> src/main.rs:1:12
|
1 | #![feature(const_generics)]
| ^^^^^^^^^^^^^^
|
= note: #[warn(incomplete_features)] on by default
= note: see issue #44580 #44580 for more information

warning: the feature const_evaluatable_checked is incomplete and may not be safe to use and/or cause compiler crashes
--> src/main.rs:2:12
|
2 | #![feature(const_evaluatable_checked)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #76560 #76560 for more information

error[E0283]: type annotations needed
--> src/main.rs:9:5
|
9 | AsMut<[[u8; T::ARRAY_SIZE]]>
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type for type parameter Self
|
= note: cannot satisfy Self: AsMut<[[u8; _]]>
note: required by a bound in AsMut

For more information about this error, try rustc --explain E0283.
warning: as_mut_bug (bin "as_mut_bug") generated 2 warnings
error: could not compile as_mut_bug due to previous error; 2 warnings emitted
[user@machine as_mut_bug]$

@drskalman drskalman added the C-bug Category: This is a bug. label Sep 28, 2021
@BoxyUwU
Copy link
Member

BoxyUwU commented Sep 29, 2021

more minimal:

#![feature(generic_const_exprs)]
#![allow(unused_braces, incomplete_features)]

pub trait Foo<const N: usize> {}
pub trait Bar: Foo<{ 1 }> { }

@b-naber
Copy link
Contributor

b-naber commented Oct 22, 2021

@rustbot claim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-generics Area: const generics (parameters and arguments) C-bug Category: This is a bug. F-generic_const_exprs `#![feature(generic_const_exprs)]`
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants