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

Broken from_iter_instead_of_collect / FromIterator::from_iter lint #10104

Open
caseykneale opened this issue Dec 19, 2022 · 3 comments
Open

Broken from_iter_instead_of_collect / FromIterator::from_iter lint #10104

caseykneale opened this issue Dec 19, 2022 · 3 comments
Labels
C-bug Category: Clippy is not doing the correct thing I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied

Comments

@caseykneale
Copy link

Summary

I think the code examples explain it better than I can.

Reproducer

I tried this code:

        let _break_clippy: HashSet<String> = HashSet::from_iter(
            vec![vec!["ab", "cd"],vec!["xy", "za"]]
                .iter()
                .map(|x| (*x).iter().fold(String::new(),|a,b| a+b)),
        );

I expected to see this happen: Honestly I expect clippy to either be okay with this or suggest valid rust syntax. Also this isn't the actual code that is failing the lint, but it is a MWE so don't judge too harshly :).

Instead, this happened:

error: usage of `FromIterator::from_iter`
    |
262 |           let _break_clippy: HashSet<String> = HashSet::from_iter(
    |  ______________________________________________^
263 | |             vec![vec!["ab", "cd"],vec!["xy", "za"]]
264 | |                 .iter()
265 | |                 .map(|x| (*x).iter().fold(String::new(),|a,b| a+b)),
266 | |         );
    | |_________^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#from_iter_instead_of_collect
help: use `.collect()` instead of `::from_iter()`
    |
262 ~         let _break_clippy: HashSet<String> = vec![vec!["ab", "cd"],vec!["xy", "za"]]
263 +                 .iter()
264 +                 .map(|x| (*x).iter().fold(String::new(),|a,b| a+b)).collect::<HashSet::from_iter(
265 +             vec![vec!["ab", "cd"],vec!["xy", "za"]]
266 +                 .iter()
267 ~                 .map(|x| (*x).iter().fold(String<_>>();

Version

rustc 1.65.0 (897e37553 2022-11-02)
binary: rustc
commit-hash: 897e37553bba8b42751c67658967889d11ecd120
commit-date: 2022-11-02
host: x86_64-apple-darwin
release: 1.65.0
LLVM version: 15.0.0

Additional Labels

No response

@caseykneale caseykneale added the C-bug Category: Clippy is not doing the correct thing label Dec 19, 2022
@feniljain
Copy link
Contributor

feniljain commented Dec 22, 2022

Few things which comes to my mind:

  • Lint suggests to use collect instead of from_iter, and it is named from_iter_instead_of_collect, seems weird to me. Maybe I am just missing something?

@Manishearth
Copy link
Member

  • Lint suggests to use collect instead of from_iter, and it is named from_iter_instead_of_collect, seems weird to me. Maybe I am just missing something?

Lint names are named according to the code pattern they wish to forbid, not the fix they apply.

@Niki4tap
Copy link
Contributor

@rustbot label +I-suggestion-causes-error

@rustbot rustbot added the I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied label Dec 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied
Projects
None yet
Development

No branches or pull requests

5 participants