Skip to content

Commit bdd442e

Browse files
committed
Fix clippy warnings
1 parent ca961b3 commit bdd442e

File tree

22 files changed

+79
-107
lines changed

22 files changed

+79
-107
lines changed

chalk-engine/src/logic.rs

+13-14
Original file line numberDiff line numberDiff line change
@@ -492,13 +492,12 @@ impl<'forest, I: Interner, C: Context<I> + 'forest, CO: ContextOps<I, C> + 'fore
492492
} = canonical_strand;
493493
let (infer, ex_clause) =
494494
context.instantiate_ex_clause(num_universes, &canonical_ex_clause);
495-
let strand = Strand {
495+
Strand {
496496
infer,
497497
ex_clause,
498-
selected_subgoal: selected_subgoal.clone(),
498+
selected_subgoal,
499499
last_pursued_time,
500-
};
501-
strand
500+
}
502501
})
503502
});
504503
match next_strand {
@@ -598,7 +597,7 @@ impl<'forest, I: Interner, C: Context<I> + 'forest, CO: ContextOps<I, C> + 'fore
598597
infer: strand.infer.clone(),
599598
ex_clause: strand.ex_clause.clone(),
600599
selected_subgoal: Some(next_subgoal),
601-
last_pursued_time: strand.last_pursued_time.clone(),
600+
last_pursued_time: strand.last_pursued_time,
602601
};
603602
let table = self.stack.top().table;
604603
let canonical_next_strand = Forest::canonicalize_strand(self.context, next_strand);
@@ -749,7 +748,7 @@ impl<'forest, I: Interner, C: Context<I> + 'forest, CO: ContextOps<I, C> + 'fore
749748
// and maybe come back to it.
750749
self.flounder_subgoal(&mut strand.ex_clause, selected_subgoal.subgoal_index);
751750

752-
return false;
751+
false
753752
}
754753
Literal::Negative(_) => {
755754
// Floundering on a negative literal isn't like a
@@ -771,7 +770,7 @@ impl<'forest, I: Interner, C: Context<I> + 'forest, CO: ContextOps<I, C> + 'fore
771770
// This strand has no solution. It is no longer active,
772771
// so it dropped at the end of this scope.
773772

774-
return true;
773+
true
775774
}
776775
}
777776
}
@@ -803,7 +802,7 @@ impl<'forest, I: Interner, C: Context<I> + 'forest, CO: ContextOps<I, C> + 'fore
803802
strand.ex_clause.delayed_subgoals.push(subgoal);
804803

805804
self.stack.top().active_strand = Some(strand);
806-
return Ok(());
805+
Ok(())
807806
}
808807
Literal::Negative(_) => {
809808
// We don't allow coinduction for negative literals
@@ -961,7 +960,7 @@ impl<'forest, I: Interner, C: Context<I> + 'forest, CO: ContextOps<I, C> + 'fore
961960
return NoRemainingSubgoalsResult::RootSearchFail(RootSearchFail::QuantumExceeded);
962961
}
963962
}
964-
let floundered = strand.ex_clause.floundered_subgoals.len() > 0;
963+
let floundered = !strand.ex_clause.floundered_subgoals.is_empty();
965964
if floundered {
966965
debug!("all remaining subgoals floundered for the table");
967966
} else {
@@ -978,7 +977,7 @@ impl<'forest, I: Interner, C: Context<I> + 'forest, CO: ContextOps<I, C> + 'fore
978977
match self.stack.pop_and_take_caller_strand() {
979978
Some(caller_strand) => {
980979
self.stack.top().active_strand = Some(caller_strand);
981-
return NoRemainingSubgoalsResult::Success;
980+
NoRemainingSubgoalsResult::Success
982981
}
983982
None => {
984983
// That was the root table, so we are done --
@@ -997,9 +996,9 @@ impl<'forest, I: Interner, C: Context<I> + 'forest, CO: ContextOps<I, C> + 'fore
997996
self.forest.tables[table].enqueue_strand(strand);
998997
}
999998

1000-
return NoRemainingSubgoalsResult::RootAnswerAvailable;
999+
NoRemainingSubgoalsResult::RootAnswerAvailable
10011000
}
1002-
};
1001+
}
10031002
}
10041003
None => {
10051004
debug!("answer is not available (or not new)");
@@ -1010,9 +1009,9 @@ impl<'forest, I: Interner, C: Context<I> + 'forest, CO: ContextOps<I, C> + 'fore
10101009

10111010
// Now we yield with `QuantumExceeded`
10121011
self.unwind_stack();
1013-
return NoRemainingSubgoalsResult::RootSearchFail(RootSearchFail::QuantumExceeded);
1012+
NoRemainingSubgoalsResult::RootSearchFail(RootSearchFail::QuantumExceeded)
10141013
}
1015-
};
1014+
}
10161015
}
10171016

10181017
/// A "refinement" strand is used in coinduction. When the root

chalk-engine/src/normalize_deep.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,7 @@ impl<I: Interner> DeepNormalizer<'_, '_, I> {
2828
) -> T::Result {
2929
value
3030
.fold_with(
31-
&mut DeepNormalizer {
32-
interner,
33-
table: table,
34-
},
31+
&mut DeepNormalizer { interner, table },
3532
DebruijnIndex::INNERMOST,
3633
)
3734
.unwrap()

chalk-engine/src/slg.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ pub(crate) struct SlgContextOps<'me, I: Interner> {
3434
}
3535

3636
impl<I: Interner> SlgContextOps<'_, I> {
37-
pub(crate) fn new<'p>(
38-
program: &'p dyn RustIrDatabase<I>,
37+
pub(crate) fn new(
38+
program: &dyn RustIrDatabase<I>,
3939
max_size: usize,
4040
expected_answers: Option<usize>,
41-
) -> SlgContextOps<'p, I> {
41+
) -> SlgContextOps<'_, I> {
4242
SlgContextOps {
4343
program,
4444
max_size,

chalk-engine/src/slg/aggregate.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ impl<I: Interner> AntiUnifier<'_, '_, I> {
307307
if index1 != index2 {
308308
self.new_ty_variable()
309309
} else {
310-
TyData::Placeholder(index1.clone()).intern(interner)
310+
TyData::Placeholder(*index1).intern(interner)
311311
}
312312
}
313313

@@ -465,7 +465,7 @@ impl<I: Interner> AntiUnifier<'_, '_, I> {
465465
}
466466

467467
(ConstValue::BoundVar(_), _) | (_, ConstValue::BoundVar(_)) => {
468-
self.new_const_variable(ty.clone())
468+
self.new_const_variable(ty)
469469
}
470470

471471
(ConstValue::Placeholder(_), ConstValue::Placeholder(_)) => {

chalk-engine/src/solve.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,10 @@ impl<I: Interner> Solver<I> for SLGSolver<I> {
6363
AnswerResult::Answer(answer) => {
6464
if !answer.ambiguous {
6565
SubstitutionResult::Definite(answer.subst)
66+
} else if ops.is_trivial_constrained_substitution(&answer.subst) {
67+
SubstitutionResult::Floundered
6668
} else {
67-
if ops.is_trivial_constrained_substitution(&answer.subst) {
68-
SubstitutionResult::Floundered
69-
} else {
70-
SubstitutionResult::Ambiguous(answer.subst)
71-
}
69+
SubstitutionResult::Ambiguous(answer.subst)
7270
}
7371
}
7472
AnswerResult::Floundered => SubstitutionResult::Floundered,

chalk-integration/src/lowering.rs

+16-26
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ impl<'k> Env<'k> {
140140
});
141141
} else {
142142
return Ok(chalk_ir::TyData::Apply(chalk_ir::ApplicationTy {
143-
name: chalk_ir::TypeName::FnDef(id.clone()),
143+
name: chalk_ir::TypeName::FnDef(*id),
144144
substitution: chalk_ir::Substitution::empty(interner),
145145
})
146146
.intern(interner)
@@ -158,7 +158,7 @@ impl<'k> Env<'k> {
158158
});
159159
} else {
160160
return Ok(chalk_ir::TyData::Apply(chalk_ir::ApplicationTy {
161-
name: chalk_ir::TypeName::Closure(id.clone()),
161+
name: chalk_ir::TypeName::Closure(*id),
162162
// See note in `program`. Unlike rustc, we store upvars separately.
163163
substitution: chalk_ir::Substitution::empty(interner),
164164
})
@@ -526,7 +526,7 @@ impl LowerProgram for Program {
526526
trait_id: TraitId(raw_id),
527527
id: lookup.id,
528528
name: assoc_ty_defn.name.str.clone(),
529-
binders: binders,
529+
binders,
530530
}),
531531
);
532532
}
@@ -1416,10 +1416,10 @@ trait LowerQuantifiedInlineBoundVec {
14161416
impl LowerQuantifiedInlineBoundVec for [QuantifiedInlineBound] {
14171417
fn lower(&self, env: &Env) -> LowerResult<Vec<rust_ir::QuantifiedInlineBound<ChalkIr>>> {
14181418
fn trait_identifier(bound: &InlineBound) -> &Identifier {
1419-
return match bound {
1419+
match bound {
14201420
InlineBound::TraitBound(tb) => &tb.trait_name,
14211421
InlineBound::AliasEqBound(ab) => &ab.trait_bound.trait_name,
1422-
};
1422+
}
14231423
}
14241424

14251425
let mut regular_traits = Vec::new();
@@ -1503,10 +1503,7 @@ impl LowerProjectionTy for ProjectionTy {
15031503
trait_id,
15041504
substitution: trait_substitution,
15051505
} = trait_ref.lower(env)?;
1506-
let lookup = match env
1507-
.associated_ty_lookups
1508-
.get(&(trait_id.into(), name.str.clone()))
1509-
{
1506+
let lookup = match env.associated_ty_lookups.get(&(trait_id, name.str.clone())) {
15101507
Some(lookup) => lookup,
15111508
None => Err(RustIrError::MissingAssociatedType(self.name.clone()))?,
15121509
};
@@ -1673,7 +1670,7 @@ impl LowerTy for Ty {
16731670
.intern(interner)),
16741671

16751672
Ty::Scalar { ty } => Ok(chalk_ir::TyData::Apply(chalk_ir::ApplicationTy {
1676-
name: chalk_ir::TypeName::Scalar(ast_scalar_to_chalk_scalar(ty.clone())),
1673+
name: chalk_ir::TypeName::Scalar(ast_scalar_to_chalk_scalar(*ty)),
16771674
substitution: chalk_ir::Substitution::empty(interner),
16781675
})
16791676
.intern(interner)),
@@ -1700,9 +1697,7 @@ impl LowerTy for Ty {
17001697
.intern(interner)),
17011698

17021699
Ty::Raw { mutability, ty } => Ok(chalk_ir::TyData::Apply(chalk_ir::ApplicationTy {
1703-
name: chalk_ir::TypeName::Raw(ast_mutability_to_chalk_mutability(
1704-
mutability.clone(),
1705-
)),
1700+
name: chalk_ir::TypeName::Raw(ast_mutability_to_chalk_mutability(*mutability)),
17061701
substitution: chalk_ir::Substitution::from_fallible(
17071702
interner,
17081703
std::iter::once(Ok(ty.lower(env)?)),
@@ -1715,9 +1710,7 @@ impl LowerTy for Ty {
17151710
lifetime,
17161711
ty,
17171712
} => Ok(chalk_ir::TyData::Apply(chalk_ir::ApplicationTy {
1718-
name: chalk_ir::TypeName::Ref(ast_mutability_to_chalk_mutability(
1719-
mutability.clone(),
1720-
)),
1713+
name: chalk_ir::TypeName::Ref(ast_mutability_to_chalk_mutability(*mutability)),
17211714
substitution: chalk_ir::Substitution::from_iter(
17221715
interner,
17231716
&[
@@ -1764,9 +1757,7 @@ impl LowerConst for Const {
17641757
}
17651758
Const::Value(value) => Ok(chalk_ir::ConstData {
17661759
ty: get_type_of_u32(),
1767-
value: chalk_ir::ConstValue::Concrete(chalk_ir::ConcreteConst {
1768-
interned: value.clone(),
1769-
}),
1760+
value: chalk_ir::ConstValue::Concrete(chalk_ir::ConcreteConst { interned: *value }),
17701761
}
17711762
.intern(interner)),
17721763
}
@@ -1799,14 +1790,13 @@ impl LowerLifetime for Lifetime {
17991790
match self {
18001791
Lifetime::Id { name } => {
18011792
let parameter = env.lookup_generic_arg(&name)?;
1802-
parameter
1803-
.lifetime(interner)
1804-
.map(|l| l.clone())
1805-
.ok_or_else(|| RustIrError::IncorrectParameterKind {
1793+
parameter.lifetime(interner).copied().ok_or_else(|| {
1794+
RustIrError::IncorrectParameterKind {
18061795
identifier: name.clone(),
18071796
expected: Kind::Lifetime,
18081797
actual: parameter.kind(),
1809-
})
1798+
}
1799+
})
18101800
}
18111801
}
18121802
}
@@ -1949,7 +1939,7 @@ impl LowerTrait for TraitDefn {
19491939

19501940
let trait_datum = rust_ir::TraitDatum {
19511941
id: trait_id,
1952-
binders: binders,
1942+
binders,
19531943
flags: self.flags.lower(),
19541944
associated_ty_ids,
19551945
well_known: self.well_known.map(|t| t.lower()),
@@ -2030,7 +2020,7 @@ impl<'k> LowerGoal<Env<'k>> for Goal {
20302020
// in the assumptions of an `if` goal, e.g. `if (T: Trait) { ... }` lowers to
20312021
// `if (FromEnv(T: Trait)) { ... /* this part is untouched */ ... }`.
20322022
let where_clauses = hyp
2033-
.into_iter()
2023+
.iter()
20342024
.flat_map(|h| h.lower_clause(env).apply_result())
20352025
.map(|result| result.map(|h| h.into_from_env_clause(interner)));
20362026
let where_clauses =

chalk-integration/src/program.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ impl RustIrDatabase<ChalkIr> for Program {
416416
}
417417

418418
fn well_known_trait_id(&self, well_known_trait: WellKnownTrait) -> Option<TraitId<ChalkIr>> {
419-
self.well_known_traits.get(&well_known_trait).map(|x| *x)
419+
self.well_known_traits.get(&well_known_trait).copied()
420420
}
421421

422422
fn program_clauses_for_env(

chalk-ir/src/debug.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ pub struct Angle<'a, T>(pub &'a [T]);
648648

649649
impl<'a, T: Debug> Debug for Angle<'a, T> {
650650
fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> {
651-
if self.0.len() > 0 {
651+
if !self.0.is_empty() {
652652
write!(fmt, "<")?;
653653
for (index, elem) in self.0.iter().enumerate() {
654654
if index > 0 {

chalk-ir/src/fold/binder_impls.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,6 @@ where
8181
let binders = CanonicalVarKinds {
8282
interned: TI::transfer_canonical_var_kinds(self_binders.interned().clone()),
8383
};
84-
Ok(Canonical {
85-
binders: binders,
86-
value: value,
87-
})
84+
Ok(Canonical { binders, value })
8885
}
8986
}

chalk-ir/src/visit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub trait VisitResult: Sized {
5353
/// Unit type for a visitor indicates a "side-effecting" visitor that
5454
/// should visit an entire term.
5555
impl VisitResult for () {
56-
fn new() -> () {}
56+
fn new() -> Self {}
5757

5858
fn return_early(&self) -> bool {
5959
false

chalk-solve/src/clauses/builtin_traits.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub fn add_builtin_program_clauses<I: Interner>(
2525
let ty = self_ty.data(db.interner());
2626
if let Some(force_impl) = db.force_impl_for(well_known, ty) {
2727
if force_impl {
28-
builder.push_fact(trait_ref.clone());
28+
builder.push_fact(trait_ref);
2929
}
3030
return Ok(());
3131
}

chalk-solve/src/clauses/builtin_traits/copy.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ pub fn add_copy_program_clauses<I: Interner>(
5858
let upvars = upvars.substitute(db.interner(), &closure_fn_substitution);
5959
needs_impl_for_tys(db, builder, trait_ref, Some(upvars).into_iter());
6060
}
61-
_ => return,
61+
_ => {}
6262
},
6363
TyData::Function(_) => builder.push_fact(trait_ref.clone()),
6464
// TODO(areredify)
6565
// when #368 lands, extend this to handle everything accordingly
66-
_ => return,
66+
_ => {}
6767
};
6868
}

chalk-solve/src/clauses/builtin_traits/sized.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,11 @@ pub fn add_sized_program_clauses<I: Interner>(
8585
| TypeName::Scalar(_)
8686
| TypeName::Raw(_)
8787
| TypeName::Ref(_) => builder.push_fact(trait_ref.clone()),
88-
_ => return,
88+
_ => {}
8989
},
9090
TyData::Function(_) => builder.push_fact(trait_ref.clone()),
9191
// TODO(areredify)
9292
// when #368 lands, extend this to handle everything accordingly
93-
_ => return,
93+
_ => {}
9494
}
9595
}

0 commit comments

Comments
 (0)