Skip to content

Add suggestions to EXPLICIT_[INTO_]ITER_LOOP #1486

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

Merged
merged 4 commits into from
Jan 28, 2017

Conversation

killercup
Copy link
Member

Also reduces the highlighted span to the expr containing the .[into_]iter() call (so the suggestion is probably applicable by rustfix.)

Fixes #1484

Also reduces the highlighted span to the expr containing the
`.[into_]iter()` call (so the suggestion is probably applicable by
rustfix.)

Fixes rust-lang#1484
@killercup
Copy link
Member Author

Didn't hear anything from you, @mcarton, so here is my PR :)

Changing this code once again reminded me of how crazy deeply indented everything in clippy is. Or maybe I just need a wider screen?

for i in (10..0).map(|x| x * 2) {
println!("{}", i);
}*/
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason this was commented out before? Seems fine to me

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dunno. But 10..0 is an empty range so that's a bad example anyway.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, right. I'll just remove it, okay?

for _v in vec.iter() { }
//~^ ERROR it is more idiomatic to loop over `&vec`
//~| HELP to write this more concisely, try looping over
//~| SUGGESTION &vec
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I usually prefer to had a bit of context around the suggestion, just to be sure:

//~| SUGGESTION for _v in &vec {

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is compile-test clever enough to pick this up even if my suggestion only contains &vec? (Let's find out!)

@mcarton
Copy link
Member

mcarton commented Jan 28, 2017

Looks good 😄

Changing this code once again reminded me of how crazy deeply indented everything in clippy is.

I can display 91 columns on half a screen, but yeah, it might be hard to fit there :sad:

@mcarton
Copy link
Member

mcarton commented Jan 28, 2017

Come on, the travis failure is rustfmt requesting

                                    |db| {⏎
-                    db.span_suggestion(arg.span,⏎
-                                       "to write this more concisely, try looping over",⏎
-                                       object.to_string());⏎
+                    db.span_suggestion(arg.span, "to write this more concisely, try looping over", object.to_string());});

How is that better?

@killercup
Copy link
Member Author

killercup commented Jan 28, 2017

Lol, I reinstalled rustfmt an hour ago. Literally! This is my prompt when I scroll up (notice the time on the right):

 ~/P/t/rust-clippy  cargo reinstall rustfmt                                                                                                                                 1.4m  Sat Jan 28 13:14:41 2017

But fine, I'll make you happy, Travis.

@mcarton mcarton merged commit f2f6637 into rust-lang:master Jan 28, 2017
@mcarton
Copy link
Member

mcarton commented Jan 28, 2017

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add actual suggestion for explicit_iter_loop
2 participants