-
-
Notifications
You must be signed in to change notification settings - Fork 14.6k
Open
Labels
A-trait-systemArea: Trait systemArea: Trait systemC-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
Possibly related to #85063
It seems that the compiler tried to guess the type, which is recursive to itself, even if not required to.
Code below does have pieces that can hint the compiler to compile properly
#![recursion_limit = "8"] // doesn't matter, lower numbers makes error more readable
#[derive(Default)] pub struct Base;
pub struct Null;
pub struct Wrap<M>(M);
pub trait Pop<T> {
type Output;
fn pop(self, rhs: T) -> <Self as Pop<T>>::Output;
}
impl Pop<Null> for Base {
type Output = Null;
fn pop(self, rhs: Null) -> Self::Output { rhs }
}
impl<T> Pop<Wrap<T>> for Base where
Base: Pop<T>,
// === this line uncommented with the one mentioned in tests makes compiler act weird
<Base as Pop<T>>::Output: Copy,
{
type Output = <Base as Pop<T>>::Output;
fn pop(self, rhs: Wrap<T>) -> Self::Output {
let x = <Base as Pop<T>>::pop(self, rhs.0);
x
}
}
#[test]
fn test() {
// === this line uncommented makes bug dissapear, regardless for the next one.
// === probably it hints the compiler what T is,
// Base.pop(Null);
// === additionally this usage is also okay for the compiler.
// === uncommenting this one hints the compiler
// let b: Base = Base::default();
// let _b = b.pop(Null);
let _a = Pop::pop(Base, Null);
// === this below works
// let _a = <Base as Pop<Null>>::pop(Base, Null);
// === same usage as above, however this usage will not help
// let b: Base = Base::default();
// let _b = b.pop(Null);
}
fn main() {
todo!();
}
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
A-trait-systemArea: Trait systemArea: Trait systemC-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.