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 clippy warnings #775

Closed
wants to merge 17 commits into from
Closed

Fix clippy warnings #775

wants to merge 17 commits into from

Conversation

NobodyXu
Copy link
Collaborator

Signed-off-by: Jiahao XU Jiahao_XU@outlook.com

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
to reduce code duplication and ensure the behavior of the code does not
change.

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
Use iterator instead of the for-loop that can terminates either due to
all `i32`s are iterated or `break`.

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
and remove hidden variant
`__Nonexhaustive_do_not_match_this_or_your_code_will_break`.

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
@NobodyXu NobodyXu changed the title Fix clippy warnings and fix bin/gcc-shim.rs Fix clippy and fmt plus fix bin/gcc-shim.rs Jan 24, 2023
@NobodyXu NobodyXu changed the title Fix clippy and fmt plus fix bin/gcc-shim.rs Apply clippy and fmt plus fix bin/gcc-shim.rs Jan 24, 2023
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
@NobodyXu NobodyXu changed the title Apply clippy and fmt plus fix bin/gcc-shim.rs Fix clippy warnings and fix bug in bin/gcc-shim.rs Jan 24, 2023
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
}
}).expect_fmt(format_args!("Cannot find the first nonexistent candidate file to which the program's args can be written under out_dir '{}'", out_dir.display()));
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In the original for-loop, after iterating over 0.. and cannot find a nonexistent candidate file, it would simply continue to create the libfoo.a even if no candidate file is written to.

Using iterator-style loop here, we avoid the implicit break by having Iterator::find_map returns an Option<PathBuf> which we then calls expect_fmt on.

Copy link
Member

@thomcc thomcc left a comment

Choose a reason for hiding this comment

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

I'm unsure here. We don't use clippy at the moment, and none of these are issues that seem that worth catching, so I'm not sure how worthwhile it is that we start. If we wanted to start using clippy, I feel like we probably want to add it to CI too.

Regarding the gcc-shim bugfix, obviously that's fine. I think the other changes in gcc-shim.rs are a bit more involved than they need to be.

src/bin/gcc-shim.rs Outdated Show resolved Hide resolved
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
@NobodyXu
Copy link
Collaborator Author

NobodyXu commented Jan 26, 2023

I'm unsure here. We don't use clippy at the moment, and none of these are issues that seem that worth catching, so I'm not sure how worthwhile it is that we start. If we wanted to start using clippy, I feel like we probably want to add it to CI too.

I know this PR is quite large and probably would cause merge conflicts in other PR, so I'm also a bit unsure.

However, I do think some of the clippy suggestion indeed improves the codebase, making it more readable or even more efficient.

_ => linker_prefix,
}
.map(|x| x.to_owned()))
cross_compile.or_else(|| {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@thomcc This is an example where clippy suggestion makes the code more efficient by evaluating this match block lazily, although it also creates a lot of diff...

@thomcc
Copy link
Member

thomcc commented Jan 26, 2023

Can you pull the gcc-shim changes into their own PR? I think we want that regardless of whether or not we're going to turn on clippy (which needs some more thought -- I'd like to do a more careful look at the changes to decide if there are any lints we'd rather disable, for example).

@NobodyXu
Copy link
Collaborator Author

Sure, I will do that.

@NobodyXu NobodyXu changed the title Fix clippy warnings and fix bug in bin/gcc-shim.rs Fix clippy warnings Jan 30, 2023
@NobodyXu
Copy link
Collaborator Author

Closing this since cc doesn't use clippy and there isn't anything worth fixing.
This PR also introduces a lot of change that will create merge conflicts for other PRs, so I don't think it worth continuing.

@NobodyXu NobodyXu closed this Jul 20, 2023
@NobodyXu NobodyXu deleted the fix/clippy branch July 20, 2023 04:49
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.

2 participants