compiler: suggest .collect() when String is expected and `Iterato…#156121
compiler: suggest .collect() when String is expected and `Iterato…#156121thiago-fealves wants to merge 2 commits intorust-lang:mainfrom
.collect() when String is expected and `Iterato…#156121Conversation
|
r? @JohnTitor rustbot has assigned @JohnTitor. Use Why was this reviewer chosen?The reviewer was selected based on:
|
5513a24 to
41aa2be
Compare
This comment has been minimized.
This comment has been minimized.
Looks like you need to run Most of the failures are:
Is this a useful suggestion? |
I didn't anticipate this could happen, i was alway thinking about more concrete types like I'm gonna implement more tests for non- |
The docs say this is intended for cases like So skipping the suggestion when the expected type is just |
I agree, gonna finish implementing that and adding the UI tests. |
…r` is found This commit adds a diagnostic suggestion to help users who forget to call `.collect()` when they have an iterator and the function or variable expects a `String`. The logic checks if the expected type is `std::string::String` and if the found type implements the `Iterator` trait, if so the compiler provides a suggestion to add `.collect()` Includes also a UI test to verify if the suggestion appears correctly
41aa2be to
a4bd5f5
Compare
|
Just added a check for the unit type, let's see if the tests pass now |
|
Looks like tests succeeded! |
Co-authored-by: Qai Juang <[email protected]>
…r` is found
This commit adds a diagnostic suggestion to help users who forget to call
.collect()when they have an iterator and the function or variable expects aString.The logic checks if the expected type is
std::string::Stringand if the found type implements theIteratortrait, if so the compiler provides a suggestion to add.collect()Includes also a UI test to verify if the suggestion appears correctly