-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Improve suggestions #1060
Improve suggestions #1060
Conversation
ONE == 1f32; //~ERROR ==-comparison of f32 or f64 | ||
ONE == (1.0 + 0.0); //~ERROR ==-comparison of f32 or f64 | ||
|
||
ONE + ONE == (ZERO + ONE + ONE); //~ERROR ==-comparison of f32 or f64 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feeling like cheating anyone?
(This is now based on #1054.) Some more better suggestions. Introducing |
Also don't build suggestion when unnecessary.
Ok, this PR has become big enough. I think it's ready to be merged. |
}; | ||
|
||
let hint = if ret { | ||
format!("return {};", snip) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The semicolon is wrong here, if the if-then-else is a match arm (or a function argument or sth)
I've had a broad look and am very much 🎉 🎈 🎆 for this, but haven't had the time for a thorough review, yet. Thanks for doing this, though! |
I'm through. The Some parts are a little confusing, like Except for the needless bool refactoring, I could not find any bugs that were introduced from the refactoring. |
But
Let's see what % cat a.rs
fn foo() -> i32 {
return match 42 {
1337 => 314,
_ => 0xdeadbeef,
}
}
% rustfmt a.rs
% cat a.rs
fn foo() -> i32 {
return match 42 {
1337 => 314,
_ => 0xdeadbeef,
};
}
% cat b.rs
fn foo() -> i32 {
return if true {
42
} else {
1337
}
}
% rustfmt b.rs
% cat b.rs
fn foo() -> i32 {
return if true {
42
} else {
1337
};
} I think the convention is to always have a semi-colon with an explicit |
@nrc Btw, this API might be useful for a rustfix tool in the future. |
Theoretically we could tweak this API so that it can actually fix the code by editing it directly! 😄 I've always wanted such a mode for rustc and clippy. Still involves some work, but this PR gets most of it done |
I meant |
cough make the method generic over |
Duh me.
Oh right!
Needs more works 😄, but that would be great. |
And now, https://github.com/killercup/rustfix exists! |
@mcarton, before I open a new issue: Does this change by any chance fix that some suggestions for lines that end with Just got this one in my rustfix demo:
(note the missing semicolon in the suggestion). If not, feel free to copy this comment into a new issue 😄 |
@killercup not yet, the context isn't used. But it should. I've been planning to do a second round with that. |
@mcarton Okay, cool. I'll just paste that into a new issue then :) Already worked around this with an ugly patch anyway 😄 |
@killercup the thing is not all suggestions might need a |
I'm not sure. For that specific example probably not many. |
So let's merge this already! |
Fix #1052.
This is a work in progress. I probably have forgotten most suggestions. I'll review them all tomorrow.