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 #753

Merged
merged 20 commits into from
Mar 9, 2022
Merged

Fix clippy warnings #753

merged 20 commits into from
Mar 9, 2022

Conversation

Kinrany
Copy link
Contributor

@Kinrany Kinrany commented Mar 7, 2022

This PR contains:

  • Trivial Clippy fixes such as needless_borrow, redundant_clone, match_like_matches_macro, try_err, needless_return, ...
  • Small local refactors, which I will point out in comments.

Each type of change is in a separate commit, except for the last commit that has a mix of unique changes.

The 18 remaining clippy errors are a bit more substantial.

@@ -83,7 +83,7 @@ impl<I: Interner> Table<I> {
}

pub(crate) fn take_strands(&mut self) -> VecDeque<CanonicalStrand<I>> {
mem::replace(&mut self.strands, VecDeque::new())
mem::take(&mut self.strands)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

One of the less common changes.

.items
.iter()
.map(|_| lowerer.next_item_id())
.collect::<Vec<_>>();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added ::<Vec<_>>. Caused by extract_associated_types signature being changed to use &[...].

} else if let Some(_) = self.adt_ids.get(&name.str) {
Err(RustIrError::NotTrait(name.clone()))
} else if let Some(id) = self.trait_ids.get(&name.str) {
Ok(*id)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Refactored:

  1. Check if the identifier is a trait, return ID if it is
  2. Return a custom error if the identifier is a parameter or an ADT node
  3. Return a generic error otherwise

@@ -53,13 +53,13 @@ impl ProgramLowerer {
pub fn extract_associated_types(
&mut self,
program: &Program,
raw_ids: &Vec<RawId>,
raw_ids: &[RawId],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Backwards compatibility note: I don't think this fn is available outside the crate since ProgramLowerer isn't public, so this should be fine.

output += &" ".repeat(11 + start);
output += &"^".repeat(end - start);
output.push('\n');
output
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Refactor:

  • Replaced position_string closure with a fn
  • Simplified match body

@@ -86,7 +85,7 @@ pub fn add_fn_trait_program_clauses<I: Interner>(
builder: &mut ClauseBuilder<'_, I>,
well_known: WellKnownTrait,
self_ty: Ty<I>,
) -> Result<(), Floundered> {
) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Refactor: made add_fn_trait_program_clauses return () because it's infallible.

} else {
self.table
.new_variable(universe_index)
.to_lifetime(self.interner)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Refactor: flattened into two branches.

if level.is_empty() {
println!("debug <level> set debug level to <level>");
} else {
std::env::set_var("CHALK_DEBUG", level);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Small behavior change: repl will print a warning for debug debug debug instead of ignoring everything after the second space.

@Kinrany Kinrany marked this pull request as ready for review March 7, 2022 00:56
@Kinrany Kinrany force-pushed the cleanup-clippy-warnings branch from c63e601 to b38fb85 Compare March 7, 2022 02:35
@jackh726
Copy link
Member

jackh726 commented Mar 9, 2022

@bors r+

Thanks!

@bors
Copy link
Contributor

bors commented Mar 9, 2022

📌 Commit b38fb85 has been approved by jackh726

@bors
Copy link
Contributor

bors commented Mar 9, 2022

⌛ Testing commit b38fb85 with merge f470f2f...

@bors
Copy link
Contributor

bors commented Mar 9, 2022

☀️ Test successful - checks-actions
Approved by: jackh726
Pushing f470f2f to master...

@bors bors merged commit f470f2f into rust-lang:master Mar 9, 2022
@Kinrany Kinrany deleted the cleanup-clippy-warnings branch March 9, 2022 22:44
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.

3 participants