Skip to content

Type inference not working for Deref #10312

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

Closed
sticnarf opened this issue Sep 22, 2021 · 3 comments
Closed

Type inference not working for Deref #10312

sticnarf opened this issue Sep 22, 2021 · 3 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

Comments

@sticnarf
Copy link
Contributor

sticnarf commented Sep 22, 2021

The issue title is not so accurate. It is a bit complex to produce the failure. Any simplification to those traits will make the issue disappear.

use std::{marker::PhantomData, ops::Deref};

trait Trait1: Trait3 {
    type Assoc: Trait2;
}

trait Trait2
where
    Self: Trait3,
{
}

trait Trait3 {
    type Bytes: Bytes;
}

trait Bytes: Deref<Target = [u8]> {}

struct S<T: Trait1> {
    s: Box<str>,
    _phantom: PhantomData<T>,
}

impl<T: Trait1> S<T> {
    fn f(&self) {
        let s /* &Box<str> */ = &self.s;
        let s /* &{unknown} */ = &**s;
    }
}

In the example above, the type of self.s is resolved successfully, but it cannot resolve the type of the deref target.

@flodiebold
Copy link
Member

This might actually be a similar or the same issue as #9990, where Chalk gets confused by unnecessary (for the current goal) clauses in the environment.

@flodiebold flodiebold added 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 labels Sep 22, 2021
@andylizi
Copy link
Contributor

andylizi commented Oct 4, 2021

I'm not sure this is the same issue, but Deref inference is also failing on Cow<T>:

deref_cow

str.as_ref().find() works fine. Switching from std::borrow::Cow to a minimal version (copy-pasted from std and removed all but necessary) works fine.

@lowr
Copy link
Contributor

lowr commented May 6, 2023

Both snippets in this issue seem to work fine today 😄 Closing as completed, but feel free to file a new issue if you're still having similar problems.

@lowr lowr closed this as completed May 6, 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
Projects
None yet
Development

No branches or pull requests

4 participants