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

Itertools::max is misdetected as Ord::max, resulting in expected 1 argument, found 0 error #10673

Closed
TonalidadeHidrica opened this issue Oct 31, 2021 · 4 comments · Fixed by #11074
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

@TonalidadeHidrica
Copy link
Contributor

TonalidadeHidrica commented Oct 31, 2021

Steps to reproduce

Create a new bin crate, and replace src/main.rs with the following code.

src/main.rs

fn main() {
    let _ = vec![vec![1, 2, 3]]
        .iter()
        .flat_map(|x| x.iter().flat_map(|x| Some(x)))
        .max()
        .unwrap();
}

When edition = "2021", nothing is wrong.
When edition = "2018", rust-analyzer points out that there is an error on the fifth line (.max()): [rust-analyzer mismatched-arg-count] [E] expected 1 argument, found 0.
Hovering on the max shows core::cmp::Ord, not std::iter::Iterator.

In both case, cargo check shows no errors or warnings.

Probably there is an issue in resolving traits in prelude.

Version info

rustup show

active toolchain
----------------

stable-x86_64-apple-darwin (default)
rustc 1.56.0 (09c42c458 2021-10-18)

:CocInfo

## versions

vim version: NVIM v0.6.0-dev+nightly-756-g8c74c895b
node version: v14.18.1
coc.nvim version: 0.0.80-03c9add7cd
coc.nvim directory: /Users/username/.vim/dein/.cache/init.vim/.dein
term: tmux
platform: darwin
@TonalidadeHidrica
Copy link
Contributor Author

I forgot to mention, but I guess I was using 2021-10-25 then. Now I updated to [coc.nvim] rust-analyzer 04f03a360 2021-11-01 stable. Then I found similar error, even in Edition 2021. I was looking for how to reproduce it, then suddenly everything went well -- even for the one I explained initially!! I have no idea why it happened, but since I cannot reproduce it anymore, I'll close this issue. Please reopen if some could reproduce it.

@lnicola lnicola 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 Nov 1, 2021
@lnicola lnicola reopened this Nov 1, 2021
@lnicola
Copy link
Member

lnicola commented Nov 1, 2021

No, this is a real bug, I can reproduce it in 1.57.0-beta.2, but only in the 2018 edition.

@johnmave126
Copy link

johnmave126 commented Nov 1, 2021

I can reproduce a similar issue in 1.56.1 with 2021-11-01 rust-analyzer in the 2021 edition by shadowing try_into with a custom trait. See an example at rustcc

Submitted as a separated issue #10677

@flodiebold
Copy link
Member

@johnmave126 would you mind reporting that as a separate issue, including the code example and what the problem is? It's not obvious it's actually the same problem, misresolved methods can have many underlying causes.

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

Successfully merging a pull request may close this issue.

4 participants