-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Associated type bound isn't always present for checking #43475
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Labels
A-associated-items
Area: Associated items (types, constants & functions)
C-bug
Category: This is a bug.
T-lang
Relevant to the language team, which will review and decide on the PR/issue.
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 |
Twey
added a commit
to Twey/rust
that referenced
this issue
Aug 4, 2017
Closed
/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 |
This was referenced Dec 10, 2017
yvt
added a commit
to r3-os/r3
that referenced
this issue
Jun 9, 2020
The modification to `constance_port_std` in this commit is a work-around for <rust-lang/rust#43475>.
JohnTitor
added a commit
to JohnTitor/rust
that referenced
this issue
Feb 2, 2021
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~~
# for free
to join this conversation on GitHub.
Already have an account?
# to comment
Labels
A-associated-items
Area: Associated items (types, constants & functions)
C-bug
Category: This is a bug.
T-lang
Relevant to the language team, which will review and decide on the PR/issue.
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: