-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Associated type bound isn't always present for checking #43475
Comments
Pretty sure I encountered the same bug when specifying an associated type explicitly in a signature. pub trait Param<P> {
fn param(p: P) -> Self;
}
pub trait Test: Sized {
type T: Param<Self::Item>;
type Item;
}
// Compiles
fn test<T: Test>(p: T::Item) -> T::T {
T::T::param(p)
}
// Does not compile
fn test2<T: Test<Item = u8>>(p: T::Item) -> T::T {
T::T::param(p)
}
fn main() {
}
https://play.rust-lang.org/?gist=20c9d87e34aecc76754bc687734e00c5&version=nightly |
/cc @arielb1 you wanted to ensure this test case fell into the trait system rewrite. |
I've just run into this as well, it seems. Here's a very simple example: trait Foo {
type Item;
type FnOfItem: Fn(Self::Item);
}
fn test<T>()
where
T: Foo<Item = usize>,
//T::FnOfItem: Fn(T::Item), // <-- Compile error without this
{}
fn main() {}
https://play.rust-lang.org/?gist=add5141b26dc781bd27c5b09c8c14f2d&version=nightly |
The modification to `constance_port_std` in this commit is a work-around for <rust-lang/rust#43475>.
Add some tests for associated-type-bounds issues Closes rust-lang#38917 Closes rust-lang#40093 Closes rust-lang#43475 Closes rust-lang#63591 rust-lang#47897 is likely closable too, but it needs an MCVE ~~rust-lang#38917, rust-lang#40093, rust-lang#43475, rust-lang#47897 all are mislabeled and shouldn't have the `F-associated-type-bounds` label~~ ~~rust-lang#71685 is also mislabeled as commented on in that thread~~
Trait bounds on associated types seem to be required, not implied, when the trait in question mentions an associated type on a type parameter.
Concretely, this code (or playground) produces an error:
despite the
C::BarT: Bar<()>
bound being required by the definition ofBar
itself, and in fact this means that the traitBar<T>
can never be mentioned.This similar example (playground) that doesn't use an associated type in the trait parameter compiles:
while this version (playground), which uses a third trait to avoid the self-reference, does not:
Is this just a missing normalization step?
The text was updated successfully, but these errors were encountered: