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

RustAnalayzer mistakenly gives error on a.max(b) #6409

Closed
Ten0 opened this issue Oct 29, 2020 · 6 comments
Closed

RustAnalayzer mistakenly gives error on a.max(b) #6409

Ten0 opened this issue Oct 29, 2020 · 6 comments
Labels
A-ty type system / type inference / traits / method resolution

Comments

@Ten0
Copy link

Ten0 commented Oct 29, 2020

It seems to beleive max in a.max(b) is about Iterator::max, whereas it's about Ord::max, and as a consequence gives the error: expected 0 arguments, found 1 (and also when hovering with the mouse, doc points to core::iter::traits::iterator::Iterator). Using std::cmp::max(a, b) makes the error disappear.

Note that the feature that writes inferred types in light gray mentions &{unknown} instead of &Something (despite the type I'm iterating on being explicitly Vec<Something>), I suspect that is linked.

@Veykril
Copy link
Member

Veykril commented Oct 29, 2020

It would be helpful to see a more complete snippet. Are you using any local imports(as in use statements that are inside of functions or expressions)? Because those are currently being ignored by RA which could lead to this problem.

@Ten0
Copy link
Author

Ten0 commented Oct 30, 2020

Are you using any local imports(as in use statements that are inside of functions or expressions)?

I'm not using use statements inside the function, however the Something I'm iterating on is declared in the function, just above, as it's a local structure used only to deserialize the result of a specific database query made there. Could that be the same issue?

Because those are currently being ignored by RA which could lead to this problem.

Why is that? :o

@Ten0
Copy link
Author

Ten0 commented Oct 30, 2020

Why is that? :o

Nvm, I found the answer.

#1165 (comment)

Looks like this issue is the long-standing-much-duplicated #1165 / #1559.

@Ten0 Ten0 closed this as completed Oct 30, 2020
@Ten0
Copy link
Author

Ten0 commented Oct 30, 2020

Hmmm that being said, it looks like we could still improve the method inference when the type is {unknown}, by at least picking functions that have the proper number arguments/the right return type.

@Ten0 Ten0 reopened this Oct 30, 2020
@flodiebold
Copy link
Member

I don't know about that, but we should avoid giving follow-up errors when we have unknown types.

@flodiebold flodiebold added the A-ty type system / type inference / traits / method resolution label Nov 1, 2020
@flodiebold
Copy link
Member

Closing in favour of #6975.

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
Projects
None yet
Development

No branches or pull requests

3 participants