Skip to content

Commit f470f2f

Browse files
committed
Auto merge of #753 - Kinrany:cleanup-clippy-warnings, r=jackh726
Fix clippy warnings 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.
2 parents 9af1cb1 + b38fb85 commit f470f2f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+337
-416
lines changed

chalk-derive/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ fn find_interner(s: &mut synstructure::Structure) -> (TokenStream, DeriveKind) {
8484

8585
let generic_param0 = get_generic_param(input);
8686

87-
if let Some(param) = has_interner(&generic_param0) {
87+
if let Some(param) = has_interner(generic_param0) {
8888
// HasInterner bound:
8989
//
9090
// Example:
@@ -98,7 +98,7 @@ fn find_interner(s: &mut synstructure::Structure) -> (TokenStream, DeriveKind) {
9898
);
9999

100100
(quote! { _I }, DeriveKind::FromHasInterner)
101-
} else if let Some(i) = is_interner(&generic_param0) {
101+
} else if let Some(i) = is_interner(generic_param0) {
102102
// Interner bound:
103103
//
104104
// Example:

chalk-engine/src/context.rs

+3-12
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,7 @@ pub enum AnswerResult<I: Interner> {
2727

2828
impl<I: Interner> AnswerResult<I> {
2929
pub fn is_answer(&self) -> bool {
30-
match self {
31-
Self::Answer(_) => true,
32-
_ => false,
33-
}
30+
matches!(self, Self::Answer(_))
3431
}
3532

3633
pub fn answer(self) -> CompleteAnswer<I> {
@@ -41,17 +38,11 @@ impl<I: Interner> AnswerResult<I> {
4138
}
4239

4340
pub fn is_no_more_solutions(&self) -> bool {
44-
match self {
45-
Self::NoMoreSolutions => true,
46-
_ => false,
47-
}
41+
matches!(self, Self::NoMoreSolutions)
4842
}
4943

5044
pub fn is_quantum_exceeded(&self) -> bool {
51-
match self {
52-
Self::QuantumExceeded => true,
53-
_ => false,
54-
}
45+
matches!(self, Self::QuantumExceeded)
5546
}
5647
}
5748

chalk-engine/src/logic.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@ impl<'forest, I: Interner> SolveState<'forest, I> {
687687
ex_clause.answer_time.increment();
688688

689689
// Ok, we've applied the answer to this Strand.
690-
return Ok(());
690+
Ok(())
691691
}
692692

693693
// This answer led nowhere. Give up for now, but of course
@@ -700,7 +700,7 @@ impl<'forest, I: Interner> SolveState<'forest, I> {
700700

701701
// Now we want to propogate back to the up with `QuantumExceeded`
702702
self.unwind_stack();
703-
return Err(RootSearchFail::QuantumExceeded);
703+
Err(RootSearchFail::QuantumExceeded)
704704
}
705705
}
706706
}
@@ -749,9 +749,9 @@ impl<'forest, I: Interner> SolveState<'forest, I> {
749749
strand.ex_clause.ambiguous = true;
750750

751751
// Strand is ambigious.
752-
return Ok(());
752+
Ok(())
753753
}
754-
};
754+
}
755755
}
756756

757757
/// This is called when the selected subgoal for a strand has floundered.
@@ -951,7 +951,7 @@ impl<'forest, I: Interner> SolveState<'forest, I> {
951951
Ok(_) => {
952952
debug!(?strand, "merged answer into current strand");
953953
canonical_strand =
954-
Forest::canonicalize_strand_from(&self.context, &mut infer, &strand);
954+
Forest::canonicalize_strand_from(self.context, &mut infer, &strand);
955955
self.stack.top().active_strand = Some(canonical_strand);
956956
return Ok(());
957957
}
@@ -1224,7 +1224,7 @@ impl<'forest, I: Interner> SolveState<'forest, I> {
12241224

12251225
// Now we yield with `QuantumExceeded`
12261226
self.unwind_stack();
1227-
return Err(RootSearchFail::QuantumExceeded);
1227+
Err(RootSearchFail::QuantumExceeded)
12281228
} else {
12291229
debug!("table part of a cycle");
12301230

@@ -1267,7 +1267,7 @@ impl<'forest, I: Interner> SolveState<'forest, I> {
12671267
self.forest.tables[table].enqueue_strand(active_strand);
12681268

12691269
// The strand isn't active, but the table is, so just continue
1270-
return Ok(());
1270+
Ok(())
12711271
}
12721272
}
12731273

@@ -1483,7 +1483,7 @@ impl<'forest, I: Interner> SolveState<'forest, I> {
14831483
.collect();
14841484

14851485
let subst = Canonical {
1486-
binders: binders.clone(),
1486+
binders,
14871487
value: AnswerSubst {
14881488
subst,
14891489
constraints: Constraints::from_iter(self.context.program().interner(), constraints),

chalk-engine/src/slg/aggregate.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ impl<I: Interner> AggregateOps<I> for SlgContextOps<'_, I> {
3131
should_continue: impl std::ops::Fn() -> bool,
3232
) -> Option<Solution<I>> {
3333
let interner = self.program.interner();
34-
let CompleteAnswer { subst, ambiguous } = match answers.next_answer(|| should_continue()) {
34+
let CompleteAnswer { subst, ambiguous } = match answers.next_answer(&should_continue) {
3535
AnswerResult::NoMoreSolutions => {
3636
// No answers at all
3737
return None;
@@ -47,7 +47,7 @@ impl<I: Interner> AggregateOps<I> for SlgContextOps<'_, I> {
4747
};
4848

4949
// Exactly 1 unconditional answer?
50-
let next_answer = answers.peek_answer(|| should_continue());
50+
let next_answer = answers.peek_answer(&should_continue);
5151
if next_answer.is_quantum_exceeded() {
5252
if subst.value.subst.is_identity_subst(interner) {
5353
return Some(Solution::Ambig(Guidance::Unknown));
@@ -95,7 +95,7 @@ impl<I: Interner> AggregateOps<I> for SlgContextOps<'_, I> {
9595
}
9696
}
9797

98-
let new_subst = match answers.next_answer(|| should_continue()) {
98+
let new_subst = match answers.next_answer(&should_continue) {
9999
AnswerResult::Answer(answer1) => answer1.subst,
100100
AnswerResult::Floundered => {
101101
// FIXME: this doesn't trigger for any current tests

chalk-engine/src/slg/resolvent.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ impl<I: Interner> AnswerSubstitutor<'_, I> {
329329
let result = self.table.relate(
330330
interner,
331331
db,
332-
&self.environment,
332+
self.environment,
333333
variance,
334334
answer_param,
335335
&GenericArg::new(interner, pending_shifted),

chalk-engine/src/strand.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ impl<I: Interner> Fold<I> for Strand<I> {
4545
Ok(Strand {
4646
ex_clause: self.ex_clause.fold_with(folder, outer_binder)?,
4747
last_pursued_time: self.last_pursued_time,
48-
selected_subgoal: self.selected_subgoal.clone(),
48+
selected_subgoal: self.selected_subgoal,
4949
})
5050
}
5151
}

chalk-engine/src/table.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ impl<I: Interner> Table<I> {
8383
}
8484

8585
pub(crate) fn take_strands(&mut self) -> VecDeque<CanonicalStrand<I>> {
86-
mem::replace(&mut self.strands, VecDeque::new())
86+
mem::take(&mut self.strands)
8787
}
8888

8989
/// Remove the next strand from the queue that meets the given criteria

chalk-integration/src/db.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl ChalkDatabase {
4040

4141
pub fn with_program<R>(&self, op: impl FnOnce(&Program) -> R) -> R {
4242
let program = &self.checked_program().unwrap();
43-
tls::set_current_program(&program, || op(&program))
43+
tls::set_current_program(program, || op(program))
4444
}
4545

4646
pub fn parse_and_lower_goal(&self, text: &str) -> Result<Goal<ChalkIr>, ChalkError> {

chalk-integration/src/interner.rs

+22-34
Original file line numberDiff line numberDiff line change
@@ -241,23 +241,23 @@ impl Interner for ChalkIr {
241241
Arc::new(TyData { kind, flags })
242242
}
243243

244-
fn ty_data<'a>(self, ty: &'a Arc<TyData<ChalkIr>>) -> &'a TyData<Self> {
244+
fn ty_data(self, ty: &Arc<TyData<ChalkIr>>) -> &TyData<Self> {
245245
ty
246246
}
247247

248248
fn intern_lifetime(self, lifetime: LifetimeData<ChalkIr>) -> LifetimeData<ChalkIr> {
249249
lifetime
250250
}
251251

252-
fn lifetime_data<'a>(self, lifetime: &'a LifetimeData<ChalkIr>) -> &'a LifetimeData<ChalkIr> {
252+
fn lifetime_data(self, lifetime: &LifetimeData<ChalkIr>) -> &LifetimeData<ChalkIr> {
253253
lifetime
254254
}
255255

256256
fn intern_const(self, constant: ConstData<ChalkIr>) -> Arc<ConstData<ChalkIr>> {
257257
Arc::new(constant)
258258
}
259259

260-
fn const_data<'a>(self, constant: &'a Arc<ConstData<ChalkIr>>) -> &'a ConstData<ChalkIr> {
260+
fn const_data(self, constant: &Arc<ConstData<ChalkIr>>) -> &ConstData<ChalkIr> {
261261
constant
262262
}
263263

@@ -269,18 +269,15 @@ impl Interner for ChalkIr {
269269
generic_arg
270270
}
271271

272-
fn generic_arg_data<'a>(
273-
self,
274-
generic_arg: &'a GenericArgData<ChalkIr>,
275-
) -> &'a GenericArgData<ChalkIr> {
272+
fn generic_arg_data(self, generic_arg: &GenericArgData<ChalkIr>) -> &GenericArgData<ChalkIr> {
276273
generic_arg
277274
}
278275

279276
fn intern_goal(self, goal: GoalData<ChalkIr>) -> Arc<GoalData<ChalkIr>> {
280277
Arc::new(goal)
281278
}
282279

283-
fn goal_data<'a>(self, goal: &'a Arc<GoalData<ChalkIr>>) -> &'a GoalData<ChalkIr> {
280+
fn goal_data(self, goal: &Arc<GoalData<ChalkIr>>) -> &GoalData<ChalkIr> {
284281
goal
285282
}
286283

@@ -291,7 +288,7 @@ impl Interner for ChalkIr {
291288
data.into_iter().collect()
292289
}
293290

294-
fn goals_data<'a>(self, goals: &'a Vec<Goal<ChalkIr>>) -> &'a [Goal<ChalkIr>] {
291+
fn goals_data(self, goals: &Vec<Goal<ChalkIr>>) -> &[Goal<ChalkIr>] {
295292
goals
296293
}
297294

@@ -302,21 +299,15 @@ impl Interner for ChalkIr {
302299
data.into_iter().collect()
303300
}
304301

305-
fn substitution_data<'a>(
306-
self,
307-
substitution: &'a Vec<GenericArg<ChalkIr>>,
308-
) -> &'a [GenericArg<ChalkIr>] {
302+
fn substitution_data(self, substitution: &Vec<GenericArg<ChalkIr>>) -> &[GenericArg<ChalkIr>] {
309303
substitution
310304
}
311305

312306
fn intern_program_clause(self, data: ProgramClauseData<Self>) -> ProgramClauseData<Self> {
313307
data
314308
}
315309

316-
fn program_clause_data<'a>(
317-
self,
318-
clause: &'a ProgramClauseData<Self>,
319-
) -> &'a ProgramClauseData<Self> {
310+
fn program_clause_data(self, clause: &ProgramClauseData<Self>) -> &ProgramClauseData<Self> {
320311
clause
321312
}
322313

@@ -327,10 +318,7 @@ impl Interner for ChalkIr {
327318
data.into_iter().collect()
328319
}
329320

330-
fn program_clauses_data<'a>(
331-
self,
332-
clauses: &'a Vec<ProgramClause<Self>>,
333-
) -> &'a [ProgramClause<Self>] {
321+
fn program_clauses_data(self, clauses: &Vec<ProgramClause<Self>>) -> &[ProgramClause<Self>] {
334322
clauses
335323
}
336324

@@ -341,10 +329,10 @@ impl Interner for ChalkIr {
341329
data.into_iter().collect()
342330
}
343331

344-
fn quantified_where_clauses_data<'a>(
332+
fn quantified_where_clauses_data(
345333
self,
346-
clauses: &'a Self::InternedQuantifiedWhereClauses,
347-
) -> &'a [QuantifiedWhereClause<Self>] {
334+
clauses: &Self::InternedQuantifiedWhereClauses,
335+
) -> &[QuantifiedWhereClause<Self>] {
348336
clauses
349337
}
350338
fn intern_generic_arg_kinds<E>(
@@ -354,10 +342,10 @@ impl Interner for ChalkIr {
354342
data.into_iter().collect()
355343
}
356344

357-
fn variable_kinds_data<'a>(
345+
fn variable_kinds_data(
358346
self,
359-
variable_kinds: &'a Self::InternedVariableKinds,
360-
) -> &'a [VariableKind<ChalkIr>] {
347+
variable_kinds: &Self::InternedVariableKinds,
348+
) -> &[VariableKind<ChalkIr>] {
361349
variable_kinds
362350
}
363351

@@ -368,10 +356,10 @@ impl Interner for ChalkIr {
368356
data.into_iter().collect()
369357
}
370358

371-
fn canonical_var_kinds_data<'a>(
359+
fn canonical_var_kinds_data(
372360
self,
373-
canonical_var_kinds: &'a Self::InternedCanonicalVarKinds,
374-
) -> &'a [CanonicalVarKind<ChalkIr>] {
361+
canonical_var_kinds: &Self::InternedCanonicalVarKinds,
362+
) -> &[CanonicalVarKind<ChalkIr>] {
375363
canonical_var_kinds
376364
}
377365

@@ -382,10 +370,10 @@ impl Interner for ChalkIr {
382370
data.into_iter().collect()
383371
}
384372

385-
fn constraints_data<'a>(
373+
fn constraints_data(
386374
self,
387-
constraints: &'a Self::InternedConstraints,
388-
) -> &'a [InEnvironment<Constraint<Self>>] {
375+
constraints: &Self::InternedConstraints,
376+
) -> &[InEnvironment<Constraint<Self>>] {
389377
constraints
390378
}
391379

@@ -396,7 +384,7 @@ impl Interner for ChalkIr {
396384
data.into_iter().collect()
397385
}
398386

399-
fn variances_data<'a>(self, variances: &'a Self::InternedVariances) -> &'a [Variance] {
387+
fn variances_data(self, variances: &Self::InternedVariances) -> &[Variance] {
400388
variances
401389
}
402390
}

0 commit comments

Comments
 (0)