-
Notifications
You must be signed in to change notification settings - Fork 13.8k
Closed
Labels
A-trait-systemArea: Trait systemArea: Trait systemC-bugCategory: This is a bug.Category: This is a bug.regression-from-stable-to-nightlyPerformance or correctness regression from stable to nightly.Performance or correctness regression from stable to nightly.
Description
This code fails to compile on the latest nightly (1.85):
Playground link: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=c912d455ab2679f04d8b3e8dedf694dc
pub struct Vec2;
pub trait Point {
type S: Scalar;
}
impl Point for Vec2 {
type S = f32;
}
pub trait Point2: Point<S = Self::S2> {
type S2: Scalar;
}
impl Point2 for Vec2 {
type S2 = Self::S;
}
pub trait Scalar: Default {}
impl Scalar for f32 {}
pub struct Bar<T: Default>(pub Vec<T>);
pub struct Foo<P: Point>(pub Vec<P>);
impl<P: Point2> From<Foo<P>> for Bar<P::S> {
fn from(r: Foo<P>) -> Self {
Self(r.0.iter().map(|_| Default::default()).collect())
}
}
pub trait DoThing {
fn do_thing();
}
impl DoThing for Foo<Vec2> {
fn do_thing() {
let _ = Bar::from(Foo::<Vec2>(vec![]));
}
}
I expected to see this happen: It compiles without any errors
Instead, this happened: On nightly, it fails to compile with
error[E0275]: overflow evaluating the requirement `<Vec2 as Point>::S == _`
On stable (1.83.0) and beta (1.84.0-beta.6), it compiles just fine.
I encountered this bug while compiling this library, and then reduced the code until I got the example above: https://github.com/MetabuildDev/selo
Meta
rustc --version --verbose
:
rustc 1.85.0-nightly (14ee63a3c 2024-12-29)
binary: rustc
commit-hash: 14ee63a3c651bb7a243c8b07333749ab4b152e13
commit-date: 2024-12-29
host: x86_64-unknown-linux-gnu
release: 1.85.0-nightly
LLVM version: 19.1.6
Metadata
Metadata
Assignees
Labels
A-trait-systemArea: Trait systemArea: Trait systemC-bugCategory: This is a bug.Category: This is a bug.regression-from-stable-to-nightlyPerformance or correctness regression from stable to nightly.Performance or correctness regression from stable to nightly.
Activity
theemathas commentedon Jan 6, 2025
My attempt at "simplifying" the reproducer code (requires an unstable feature):
Playground link
Note that removing the
TrustedLen
impl makes the code compile on nightly, which implies that the issue is probably related to specialization.Replacing
RepeatWith
with a call tostd::iter::repeat_with
makes the code compile on stable while still erroring on nightly. Playground link@rustbot labels +regression-from-stable-to-nightly +A-trait-system +A-specialization
compiler-errors commentedon Jan 6, 2025
This seems to have regressed in #134081.
compiler-errors commentedon Jan 6, 2025
Anyways I have a fix but I'll need to minimize this futher. I don't believe this relies on specialization.
@rustbot claim
compiler-errors commentedon Jan 6, 2025
Overflows on nightly with no specialization:
Rollup merge of rust-lang#135149 - compiler-errors:mangle, r=oli-obk
Rollup merge of rust-lang#135149 - compiler-errors:mangle, r=oli-obk
Unrolled build for rust-lang#135149