-
Notifications
You must be signed in to change notification settings - Fork 14.1k
Open
Labels
A-associated-itemsArea: Associated items (types, constants & functions)Area: Associated items (types, constants & functions)A-trait-systemArea: Trait systemArea: Trait systemC-bugCategory: This is a bug.Category: This is a bug.T-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.fixed-by-next-solverFixed by the next-generation trait solver, `-Znext-solver`.Fixed by the next-generation trait solver, `-Znext-solver`.
Description
I get compilation errors for a typenum-based code which can be minimized to this snippet (playground):
use core::ops::Add;
use typenum::{Sum, Unsigned, U8};
pub type TagSize = U8;
pub type TagSizePlus1 = typenum::Add1<TagSize>; // does not work
// pub type TagSizePlus1 = typenum::U9; // works
pub fn foo<N>()
where
N: Add<TagSizePlus1>,
Sum<N, TagSizePlus1>: Unsigned,
{
// code
}Add1<A> is an alias for <A as Add<B1>>::Output; and Sum<A, B> is an alias for <A as Add<B>>::Output;
The snippet results in the following compilation error:
error[E0277]: cannot add `UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B1>` to `N`
--> src/lib.rs:10:1
|
10 | / pub fn foo<N>()
11 | | where
12 | | N: Add<TagSizePlus1>,
13 | | Sum<N, TagSizePlus1>: Unsigned,
| |___________________________________^ no implementation for `N + UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B1>`
But replacing Sub1<SomeSize> with U9 (an alias for UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B1>) works just fine!
It looks like the compiler successfully resolves Add1<SomeSize> to UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B1>, but then for some reason gets tripped while resolving the bounds and is unable to see that the bound on N which allows the addition.
Potentially relevant issue: #79629
tyilo and gusinacio
Metadata
Metadata
Assignees
Labels
A-associated-itemsArea: Associated items (types, constants & functions)Area: Associated items (types, constants & functions)A-trait-systemArea: Trait systemArea: Trait systemC-bugCategory: This is a bug.Category: This is a bug.T-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.fixed-by-next-solverFixed by the next-generation trait solver, `-Znext-solver`.Fixed by the next-generation trait solver, `-Znext-solver`.