Skip to content
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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

Fix most clippy lints #5400

wants to merge 7 commits into from

Conversation

kadiwa4
Copy link
Contributor

@kadiwa4 kadiwa4 commented Jun 22, 2022

I didn't fix the clippy::too_many_arguments and clippy::uninlined_format_args warnings.

@kadiwa4 kadiwa4 force-pushed the clippy_lints branch 2 times, most recently from e522bf4 to 3a804cd Compare July 1, 2022 14:25
@ytmimi ytmimi added p-low pr-merge-conflict This PR has merge conflicts that must be resolved labels Jul 28, 2022
@ytmimi ytmimi removed the pr-merge-conflict This PR has merge conflicts that must be resolved label Aug 8, 2022
@ytmimi ytmimi mentioned this pull request Aug 8, 2022
@kadiwa4 kadiwa4 force-pushed the clippy_lints branch 2 times, most recently from 78175a8 to dfdb05a Compare July 20, 2023 06:55
Copy link
Contributor

@xxchan xxchan left a 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

@ytmimi @calebcartwright I suggest we either close (maybe split in smaller steps like above) or accept this PR, otherwise it will get stale often.

src/cargo-fmt/test/mod.rs Outdated Show resolved Hide resolved
@@ -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())
Copy link
Contributor

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 👀

Copy link
Contributor Author

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

Comment on lines +282 to 290
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);
Copy link
Contributor

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.

Comment on lines -519 to +529
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(),
Copy link
Contributor

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. 🤔

Copy link
Contributor Author

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.

Comment on lines +429 to -448
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))
Copy link
Contributor

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.

Comment on lines -433 to +446
// 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());
Copy link
Contributor

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?

Copy link
Contributor Author

@kadiwa4 kadiwa4 Jul 29, 2023

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?

Comment on lines -205 to +207
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(""))
Copy link
Contributor

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("");
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

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

Successfully merging this pull request may close these issues.

3 participants