hir_typeck: suggest removing redundant .iter() and iter_mut ()calls#153700
hir_typeck: suggest removing redundant .iter() and iter_mut ()calls#153700vishnupoddar12 wants to merge 1 commit intorust-lang:mainfrom
Conversation
|
r? @fmease rustbot has assigned @fmease. Use Why was this reviewer chosen?The reviewer was selected based on:
|
8f0debd to
7dc8033
Compare
There was a problem hiding this comment.
You're doing a lot of Span wrangling and dealing with code snippets to try and create a suitable Span for the suggestion, but instead you should be leveraging the hir Exprs to find the right spans. you can do things like rcvr.span.between(arg[0].span) to construct a span that points at
rcvr.method(arg0, arg1);
^^^^^^^^
This diagnostic intercepts cases where `.iter()` is called on a type that already implements `Iterator` Instead of confusing trait fallback suggestions, it explicitly guides the user to remove the `.iter()` call. It implements precise span computation to support `cargo fix` while carefully preserving all inline comments and horizontal whitespace during the AST string replacement.
7dc8033 to
f67a0cf
Compare
|
Thanks @estebank, I was able to reduce lot of unnecessary span wrangling reducing code change by 30-40 lines. It should be cleaner now. |
|
Hi @estebank, Friendly ping! I updated the PR to use |
This diagnostic intercepts cases where
.iter()or.iter_mut()is called on a type that already implementsIteratorInstead of confusing trait fallback suggestions, it explicitly guides the user to remove the
.iter()call. It implements precise span computation to supportcargo fixwhile carefully preserving all inline comments and horizontal whitespace during the AST string replacement.Fixes #153667