-
Notifications
You must be signed in to change notification settings - Fork 467
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
Fix clippy warnings #775
Conversation
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>
bin/gcc-shim.rs
bin/gcc-shim.rs
bin/gcc-shim.rs
bin/gcc-shim.rs
bin/gcc-shim.rs
bin/gcc-shim.rs
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
src/bin/gcc-shim.rs
Outdated
} | ||
}).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())); |
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.
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.
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'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.
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
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(|| { |
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.
@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...
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). |
Sure, I will do that. |
bin/gcc-shim.rs
Closing this since cc doesn't use clippy and there isn't anything worth fixing. |
Signed-off-by: Jiahao XU Jiahao_XU@outlook.com