-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Apply clippy suggestions for rustc and core #89709
Apply clippy suggestions for rustc and core #89709
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @petrochenkov (or someone else) soon. Please see the contribution instructions for more information. |
This comment has been minimized.
This comment has been minimized.
a08bdbb
to
1141998
Compare
1141998
to
0e8704d
Compare
@@ -14,7 +14,7 @@ const BASE_64: &[u8; MAX_BASE as usize] = | |||
|
|||
#[inline] | |||
pub fn push_str(mut n: u128, base: usize, output: &mut String) { | |||
debug_assert!(base >= 2 && base <= MAX_BASE); | |||
debug_assert!((2..=MAX_BASE).contains(&base)); |
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 would be nice if we could use debug_assert_matches!
(assuming it exists) for range checks.
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.
debug_assert_matches!
is currently unstable
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.
Compiler code can use unstable library features.
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.
@clemenswasser If this PR is re-landed (after the #89905 revert), it would be good to fix this.
@@ -388,7 +388,7 @@ impl<'a> SessionDiagnosticDeriveBuilder<'a> { | |||
let formatted_str = self.build_format(&s.value(), attr.span()); | |||
match name { | |||
"message" => { | |||
if type_matches_path(&info.ty, &["rustc_span", "Span"]) { | |||
if type_matches_path(info.ty, &["rustc_span", "Span"]) { |
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.
Nice, removing redundant &
should maybe be more forcefully handled (i.e. deny
ed in rustc
crates) - and if you open a PR with just that lint being accounted for, I will r+ it immediately.
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 there a simple way I can deny
the lints for all rustc
crates, without copy pasting in all lib.rs
?
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 theory we could simply deny the lint via x.py clippy, but in reality it seems that --cap-lints warn
prevents this from working 😆
diff --git a/src/bootstrap/check.rs b/src/bootstrap/check.rs
index 28e7f1fdca7..cf21a4dc857 100644
--- a/src/bootstrap/check.rs
+++ b/src/bootstrap/check.rs
@@ -44,6 +44,7 @@ fn strings<'a>(arr: &'a [&str]) -> impl Iterator<Item = String> + 'a {
}
args.extend(strings(&["--", "--cap-lints", "warn"]));
args.extend(ignored_lints.iter().map(|lint| format!("-Aclippy::{}", lint)));
+ args.push("-Dclippy::needless_borrow".into());
args
} else {
vec![]
0e8704d
to
3111c12
Compare
3111c12
to
a669733
Compare
a669733
to
71dd0b9
Compare
r=me with #89709 (comment) addressed. |
@bors r+ |
📌 Commit 14b6cf6 has been approved by |
@bors rollup=iffy just in case this has some unforeseen perf implications |
☀️ Test successful - checks-actions |
Finished benchmarking commit (6ae8912): comparison url. Summary: This change led to large relevant regressions 😿 in compiler performance.
If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf. Next Steps: If you can justify the regressions found in this perf run, please indicate this with @rustbot label: +perf-regression |
I think its fair to say this had some unforeseen perf implications We see instruction-count regressions in the 1.1% to 2.7% range in keccak and inflate |
I suggest reverting. |
I reverted parts of the merge in #89855 can we get a perf run there to see if that fixes the regression? |
} else { | ||
None | ||
} | ||
array.iter().position(|(k, _v)| k == key).map(|index| array.swap_remove(index).1) |
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 know other data structures have some instances of open coding map
to reduce the amount of monomorphization bloat that needs to be compiled, so this is a potential perf culprit
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 would worry less about bloat and more about that instance of Option::map
having the closure inlined into it, but not being inlined itself (because of inlining swap_remove
?).
for index in 0..orig_nodes_len { | ||
for (index, node_rewrite) in node_rewrites.iter_mut().enumerate() { |
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 possible enumerate
is less efficient than range iteration?
let words = &mut self.words[..]; | ||
for index in start..end { | ||
words[index] = !0; | ||
for word in self.words[start..end].iter_mut() { |
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 didn't get to this in time, but xs[range].iter_mut()
should just be writen &mut xs[range]
- surprised clippy doesn't have a lint for this.
let words = &mut self.words[..]; | ||
for index in start..end { | ||
words[index] = !0; | ||
for word in self.words[start..end].iter_mut() { | ||
*word = !0; | ||
} |
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 entire thing can just be self.words[start..end].fill(!0)
, just realized.
…chaelwoerister Revert "Auto merge of rust-lang#89709 - clemenswasser:apply_clippy_suggestions… …_2, r=petrochenkov" The PR had some unforseen perf regressions that are not as easy to find. Revert the PR for now. This reverts commit 6ae8912, reversing changes made to 86d6d2b.
No description provided.