Open
Description
The following code compiles on Rust 1.67 (nightly) but not on Rust 1.68 (nightly)
Code
#![allow(incomplete_features)]
#![feature(generic_const_exprs)]
fn main() {
println!("Hello, world!");
}
// FUNCTION THAT IS NOW BROKEN
fn do_something<T: SuperTrait>() where [(); T::MyType::LEN]:, [(); T::SUPER_SIZE]: {
let _ = T::do_something_super().to_bytes();
}
// Trait I implement for a few subtypes of my main type "SuperTrait"
trait MySerde {
const LEN: usize;
fn to_bytes(&self) -> [u8; Self::LEN];
fn from_bytes(bytes: [u8; Self::LEN]) -> Self;
}
// each subtrait would have its own requirements
trait SubTrait: MySerde {
// stuff
}
// We need a subtrait for constants or we get a cycle when defining SUPER_ARR
trait ConstantsForSuper {
const SUPER_SIZE: usize;
}
// in my actual example SuperTrait has several types implementing differeent subtraits
// (all of which require serde)
trait SuperTrait: ConstantsForSuper where [(); Self::SUPER_SIZE]: {
type MyType: SubTrait;
const SUPER_ARR: [Self::MyType; Self::SUPER_SIZE];
fn do_something_super() -> Self::MyType;
}
Version it worked on
It most recently worked on: 1.67
Version with regression
rustc --version --verbose
:
rustc 1.68.0-nightly (4781233a7 2023-01-16)
binary: rustc
commit-hash: 4781233a77e879e49cb5ce3c98d2abba6a6ade7a
commit-date: 2023-01-16
host: x86_64-unknown-linux-gnu
release: 1.68.0-nightly
LLVM version: 15.0.6
Backtrace
Backtrace
/~/project$ RUST_BACKTRACE=1 cargo build
Compiling minimal_breakage v0.1.0 (/~/project)
error[E0391]: cycle detected when building an abstract representation for `do_something::{constant#0}`
--> src/main.rs:9:45
|
9 | fn do_something<T: SuperTrait>() where [(); T::MyType::LEN]:, [(); T::SUPER_SIZE]: {
| ^^^^^^^^^^^^^^
|
note: ...which requires building THIR for `do_something::{constant#0}`...
--> src/main.rs:9:45
|
9 | fn do_something<T: SuperTrait>() where [(); T::MyType::LEN]:, [(); T::SUPER_SIZE]: {
| ^^^^^^^^^^^^^^
note: ...which requires type-checking `do_something::{constant#0}`...
--> src/main.rs:9:45
|
9 | fn do_something<T: SuperTrait>() where [(); T::MyType::LEN]:, [(); T::SUPER_SIZE]: {
| ^^^^^^^^^^^^^^
= note: ...which again requires building an abstract representation for `do_something::{constant#0}`, completing the cycle
note: cycle used when checking that `do_something` is well-formed
--> src/main.rs:9:1
|
9 | fn do_something<T: SuperTrait>() where [(); T::MyType::LEN]:, [(); T::SUPER_SIZE]: {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
For more information about this error, try `rustc --explain E0391`.
error: could not compile `minimal_breakage` due to previous error