-
Notifications
You must be signed in to change notification settings - Fork 902
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
Fix most clippy lints #5400
base: master
Are you sure you want to change the base?
Fix most clippy lints #5400
Conversation
e522bf4
to
3a804cd
Compare
78175a8
to
dfdb05a
Compare
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.
I've browsed changes. Mostly LGTM, but there are some non-trivial changes.
So
- It might be better to fix in multiple smaller PRs to make review easier.
- It might be better to add a clippy check in CI to avoid future lint issues. BTW, I think
#[expect(lint)]
Tracking issue for RFC 2383, "Lint Reasons RFC" rust#54503 is useful to progressively fix lints.
@ytmimi @calebcartwright I suggest we either close (maybe split in smaller steps like above) or accept this PR, otherwise it will get stale often.
@@ -202,7 +202,7 @@ impl ChainItemKind { | |||
fn is_tup_field_access(expr: &ast::Expr) -> bool { | |||
match expr.kind { | |||
ast::ExprKind::Field(_, ref field) => { | |||
field.name.to_string().chars().all(|c| c.is_digit(10)) | |||
field.name.to_string().bytes().all(|c| c.is_ascii_digit()) |
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.
Why chars to bytes? Seems not equivalent 👀
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.
It's true that it is unrelated. But if all the chars are ASCII digits, then none of them are multi-byte, so it is equivalent
impl PartialEq for UseSegment { | ||
fn eq(&self, other: &Self) -> bool { | ||
self.kind == other.kind | ||
} | ||
} | ||
|
||
impl Hash for UseSegment { | ||
fn hash<H: Hasher>(&self, state: &mut H) { | ||
self.kind.hash(state); |
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.
This is inconsistent eq and hash? May need to check the correctness.
Box::new(emitter::FilesWithBackupEmitter::default()) | ||
<Box<emitter::FilesWithBackupEmitter>>::default() | ||
} | ||
EmitMode::Files => Box::new(emitter::FilesEmitter::new( | ||
config.print_misformatted_file_names(), | ||
)), | ||
EmitMode::Stdout | EmitMode::Coverage => { | ||
Box::new(emitter::StdoutEmitter::new(config.verbose())) | ||
} | ||
EmitMode::Json => Box::new(emitter::JsonEmitter::default()), | ||
EmitMode::ModifiedLines => Box::new(emitter::ModifiedLinesEmitter::default()), | ||
EmitMode::Checkstyle => Box::new(emitter::CheckstyleEmitter::default()), | ||
EmitMode::Json => <Box<emitter::JsonEmitter>>::default(), | ||
EmitMode::ModifiedLines => <Box<emitter::ModifiedLinesEmitter>>::default(), | ||
EmitMode::Checkstyle => <Box<emitter::CheckstyleEmitter>>::default(), |
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.
I feel it's not better than before. 🤔
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.
Certainly not easier to understand, but maybe a bit more efficient in a future version of Rust. But you're right, it doesn't seem to be worth it.
let semicolon = | ||
if context.config.version() != Version::One && semicolon_for_expr(context, body) { | ||
";" | ||
} else { | ||
"" | ||
}; | ||
let semicolon = if context.config.version() == Version::One { | ||
"" | ||
} else { | ||
if semicolon_for_expr(context, body) { | ||
";" | ||
} else { | ||
"" | ||
} | ||
}; | ||
("{", format!("{}{}}}{}", semicolon, indent_str, comma)) |
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.
Maybe the original version's logic is more clear.
// splitn(2, *).next().unwrap() is always safe. | ||
let rewrite_first_line = Some(rewrite.splitn(2, '\n').next().unwrap().to_owned()); | ||
// split(*).next().unwrap() never panics. | ||
let rewrite_first_line = Some(rewrite.split('\n').next().unwrap().to_owned()); |
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.
Is it split_once instead of split?
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.
I can also use split_once
but that's longer
let rewrite_first_line = Some(
rewrite
.split_once('\n')
.map_or(&*rewrite, |(f, _)| f)
.to_owned(),
);
Maybe str::lines
is the best option here?
unicode_str_width(s.splitn(2, '\n').next().unwrap_or("")) | ||
unicode_str_width(s.split('\n').next().unwrap_or("")) | ||
} | ||
|
||
/// The width of the last line in s. | ||
#[inline] | ||
pub(crate) fn last_line_width(s: &str) -> usize { | ||
unicode_str_width(s.rsplitn(2, '\n').next().unwrap_or("")) | ||
unicode_str_width(s.rsplit('\n').next().unwrap_or("")) |
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.
ditto
let first_lines = comment_snippet.splitn(2, '/').next().unwrap_or(""); | ||
let first_lines = comment_snippet.split('/').next().unwrap_or(""); |
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.
ditto
dfdb05a
to
e732afb
Compare
I didn't fix the
clippy::too_many_arguments
andclippy::uninlined_format_args
warnings.