Skip to content

Possible degradation in const generics #89334

@drskalman

Description

@drskalman

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]$

Activity

BoxyUwU

BoxyUwU commented on Sep 29, 2021

@BoxyUwU
Member

more minimal:

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

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

b-naber commented on Oct 22, 2021

@b-naber
Contributor

@rustbot claim

added a commit that references this issue on Oct 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-const-genericsArea: const generics (parameters and arguments)C-bugCategory: This is a bug.F-generic_const_exprs`#![feature(generic_const_exprs)]`

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Participants

    @BoxyUwU@drskalman@b-naber

    Issue actions

      Possible degradation in const generics · Issue #89334 · rust-lang/rust