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

False error for take #6418

Open
tfgast opened this issue Oct 31, 2020 · 7 comments
Open

False error for take #6418

tfgast opened this issue Oct 31, 2020 · 7 comments
Labels
A-ty type system / type inference / traits / method resolution S-actionable Someone could pick this issue up and work on it right now

Comments

@tfgast
Copy link

tfgast commented Oct 31, 2020

I've been seeing this false error. I managed to reduce it down to the following code with no non std dependencies. Rust analyzer thinks it's Iterator::take, but it's actually Option::take

Screenshot (2)

use std::marker::PhantomData;

pub trait SimulationType: Sized {
    type Dim: Dimension;
    type TV: Array<Dim = Self::Dim>;
    type IV: Array<Dim = Self::Dim>;
}

pub trait Array: Sized {
    type Dim: Dimension;
}

pub trait Dimension: Sized {
    type I: Iterator<Item = Self>;
}

impl<S: SimulationType> Sim<S> {
    pub fn bad_error(&mut self) {
        let _ = self.integrator.take().unwrap();
    }
}

pub struct Sim<S> {
    integrator: Option<()>,
    phantom: PhantomData<S>,
}
@flodiebold flodiebold added the A-ty type system / type inference / traits / method resolution label Nov 1, 2020
@lnicola lnicola added the S-actionable Someone could pick this issue up and work on it right now label Nov 1, 2020
@jRimbault
Copy link

Hi, I believe I have the same error here, my scan method is inferred to be the one from Iterator. Before that the min and max methods here were confused with the ones from Iterator also.

@itsfarseen
Copy link

Same error when trying to take() out of Option in std::process::Child.stdin
image

@flodiebold
Copy link
Member

@happycoder97 Local imports are not supported yet: #1165

@itsfarseen
Copy link

@flodiebold moving the imports fixed it. Thanks :)

@eminence
Copy link
Contributor

Here's another way to reproduce the original issue:

pub fn foo<T, U>(_a: T, _b: U)
where
    T: IntoIterator<Item = ()>,
    U: IntoIterator<Item = ()>,
{
    let mut x: Option<()> = None;
    let _ = x.take();
}

Guess on my part: the problem relates to how IntoIterator and SimulationType (from the original report) both have associated types that reference other Self types (either type IntoIter: Iterator<Item = Self::Item> in the case of IntoIterator, or type TV: Array<Dim = Self::Dim> in the case of SimulationType).

(Also just adding for the record that the error issues by RA is a mismatched-arg-count error, to make it easier to search for this issue in the future)

@eminence
Copy link
Contributor

After more than half a year with this error in my project, I'm starting to get motivated to do something about it 😄. But I'm not at all familiar with the code involved. Does anyone have any hints about where to start looking, or any other relevant mentoring tips?

@flodiebold
Copy link
Member

flodiebold commented Oct 11, 2021

Huh! I think that's probably a very similar if not the same issue as #9990, i.e. a Chalk problem with environment clause elaboration (rust-lang/chalk#727). It could maybe serve as a simpler example though 🤔

@lnicola lnicola mentioned this issue Apr 12, 2022
bors bot added a commit that referenced this issue Apr 12, 2022
11970: Bump chalk r=lnicola a=lnicola

Closes #9990, but not #6418, #10653

bors r+

Co-authored-by: Laurențiu Nicola <[email protected]>
jdygert-spok added a commit to aranya-project/aranya-core that referenced this issue Oct 15, 2024
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 S-actionable Someone could pick this issue up and work on it right now
Projects
None yet
Development

No branches or pull requests

6 participants