Skip to content
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

Type inference fails to deduce blanket-implemented trait of super traits with associated types #9881

Open
Veetaha opened this issue Aug 13, 2021 · 2 comments
Labels
A-ty type system / type inference / traits / method resolution C-bug Category: bug S-actionable Someone could pick this issue up and work on it right now S-blocked Status: marked as blocked ❌ on something else such as an RFC or other implementation work.

Comments

@Veetaha
Copy link
Contributor

Veetaha commented Aug 13, 2021

In the following code (minimized from futures::{Stream, TryStream}) try_poll_next() method is displayed as unresolved reference, however it is compilable

pub trait TryStream: Stream {
    fn try_poll_next(&self) {}
}

pub trait Stream {
    // Removing associated type makes the error disappear
    type Item;
    fn poll_next(&self) {}
}

// Trait that only has `Stream` as super-trait
trait StreamAlias: Stream<Item = ()> {}

// Blanket impls
impl<S: Stream<Item = ()>> TryStream for S {}

impl<S: Stream<Item = ()>> StreamAlias for S {}

// Concrete implementor of `Stream`
struct StreamImpl;

impl Stream for StreamImpl {
    type Item = ();
}

fn foo() -> impl StreamAlias {
    StreamImpl
}

fn main() {
    let alias = foo();
	// try_poll_next() here is unresolved, though the code compiles
    alias.try_poll_next();

    // However direct `Stream` supertrait works, this method is resolved
	alias.poll_next();
}
@lnicola
Copy link
Member

lnicola commented Aug 13, 2021

Ah, we have some long-standing type inference issues with the futures crate, you might have found a minimization.

@flodiebold flodiebold added A-ty type system / type inference / traits / method resolution S-actionable Someone could pick this issue up and work on it right now labels Aug 13, 2021
@lowr
Copy link
Contributor

lowr commented Feb 13, 2023

I believe this is rust-lang/chalk#777 (the issue only mentions dyn types but the same problem happens for opaque types; see its linked PR).

@Veykril Veykril added S-blocked Status: marked as blocked ❌ on something else such as an RFC or other implementation work. C-bug Category: bug labels Feb 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ty type system / type inference / traits / method resolution C-bug Category: bug S-actionable Someone could pick this issue up and work on it right now S-blocked Status: marked as blocked ❌ on something else such as an RFC or other implementation work.
Projects
None yet
Development

No branches or pull requests

5 participants