Skip to content

Commit 5f4d08c

Browse files
committed
Auto merge of #577 - detrumi:clippy-fixes, r=nathanwhit
Fix clippy warnings
2 parents a07ccb1 + 4ccf7ba commit 5f4d08c

File tree

21 files changed

+78
-106
lines changed

21 files changed

+78
-106
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
}
@@ -1418,10 +1418,10 @@ trait LowerQuantifiedInlineBoundVec {
14181418
impl LowerQuantifiedInlineBoundVec for [QuantifiedInlineBound] {
14191419
fn lower(&self, env: &Env) -> LowerResult<Vec<rust_ir::QuantifiedInlineBound<ChalkIr>>> {
14201420
fn trait_identifier(bound: &InlineBound) -> &Identifier {
1421-
return match bound {
1421+
match bound {
14221422
InlineBound::TraitBound(tb) => &tb.trait_name,
14231423
InlineBound::AliasEqBound(ab) => &ab.trait_bound.trait_name,
1424-
};
1424+
}
14251425
}
14261426

14271427
let mut regular_traits = Vec::new();
@@ -1505,10 +1505,7 @@ impl LowerProjectionTy for ProjectionTy {
15051505
trait_id,
15061506
substitution: trait_substitution,
15071507
} = trait_ref.lower(env)?;
1508-
let lookup = match env
1509-
.associated_ty_lookups
1510-
.get(&(trait_id.into(), name.str.clone()))
1511-
{
1508+
let lookup = match env.associated_ty_lookups.get(&(trait_id, name.str.clone())) {
15121509
Some(lookup) => lookup,
15131510
None => Err(RustIrError::MissingAssociatedType(self.name.clone()))?,
15141511
};
@@ -1681,7 +1678,7 @@ impl LowerTy for Ty {
16811678
.intern(interner)),
16821679

16831680
Ty::Scalar { ty } => Ok(chalk_ir::TyData::Apply(chalk_ir::ApplicationTy {
1684-
name: chalk_ir::TypeName::Scalar(ast_scalar_to_chalk_scalar(ty.clone())),
1681+
name: chalk_ir::TypeName::Scalar(ast_scalar_to_chalk_scalar(*ty)),
16851682
substitution: chalk_ir::Substitution::empty(interner),
16861683
})
16871684
.intern(interner)),
@@ -1708,9 +1705,7 @@ impl LowerTy for Ty {
17081705
.intern(interner)),
17091706

17101707
Ty::Raw { mutability, ty } => Ok(chalk_ir::TyData::Apply(chalk_ir::ApplicationTy {
1711-
name: chalk_ir::TypeName::Raw(ast_mutability_to_chalk_mutability(
1712-
mutability.clone(),
1713-
)),
1708+
name: chalk_ir::TypeName::Raw(ast_mutability_to_chalk_mutability(*mutability)),
17141709
substitution: chalk_ir::Substitution::from_fallible(
17151710
interner,
17161711
std::iter::once(Ok(ty.lower(env)?)),
@@ -1723,9 +1718,7 @@ impl LowerTy for Ty {
17231718
lifetime,
17241719
ty,
17251720
} => Ok(chalk_ir::TyData::Apply(chalk_ir::ApplicationTy {
1726-
name: chalk_ir::TypeName::Ref(ast_mutability_to_chalk_mutability(
1727-
mutability.clone(),
1728-
)),
1721+
name: chalk_ir::TypeName::Ref(ast_mutability_to_chalk_mutability(*mutability)),
17291722
substitution: chalk_ir::Substitution::from_iter(
17301723
interner,
17311724
&[
@@ -1772,9 +1765,7 @@ impl LowerConst for Const {
17721765
}
17731766
Const::Value(value) => Ok(chalk_ir::ConstData {
17741767
ty: get_type_of_u32(),
1775-
value: chalk_ir::ConstValue::Concrete(chalk_ir::ConcreteConst {
1776-
interned: value.clone(),
1777-
}),
1768+
value: chalk_ir::ConstValue::Concrete(chalk_ir::ConcreteConst { interned: *value }),
17781769
}
17791770
.intern(interner)),
17801771
}
@@ -1807,14 +1798,13 @@ impl LowerLifetime for Lifetime {
18071798
match self {
18081799
Lifetime::Id { name } => {
18091800
let parameter = env.lookup_generic_arg(&name)?;
1810-
parameter
1811-
.lifetime(interner)
1812-
.map(|l| l.clone())
1813-
.ok_or_else(|| RustIrError::IncorrectParameterKind {
1801+
parameter.lifetime(interner).copied().ok_or_else(|| {
1802+
RustIrError::IncorrectParameterKind {
18141803
identifier: name.clone(),
18151804
expected: Kind::Lifetime,
18161805
actual: parameter.kind(),
1817-
})
1806+
}
1807+
})
18181808
}
18191809
}
18201810
}
@@ -1957,7 +1947,7 @@ impl LowerTrait for TraitDefn {
19571947

19581948
let trait_datum = rust_ir::TraitDatum {
19591949
id: trait_id,
1960-
binders: binders,
1950+
binders,
19611951
flags: self.flags.lower(),
19621952
associated_ty_ids,
19631953
well_known: self.well_known.map(|t| t.lower()),
@@ -2038,7 +2028,7 @@ impl<'k> LowerGoal<Env<'k>> for Goal {
20382028
// in the assumptions of an `if` goal, e.g. `if (T: Trait) { ... }` lowers to
20392029
// `if (FromEnv(T: Trait)) { ... /* this part is untouched */ ... }`.
20402030
let where_clauses = hyp
2041-
.into_iter()
2031+
.iter()
20422032
.flat_map(|h| h.lower_clause(env).apply_result())
20432033
.map(|result| result.map(|h| h.into_from_env_clause(interner)));
20442034
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
@@ -655,7 +655,7 @@ pub struct Angle<'a, T>(pub &'a [T]);
655655

656656
impl<'a, T: Debug> Debug for Angle<'a, T> {
657657
fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> {
658-
if self.0.len() > 0 {
658+
if !self.0.is_empty() {
659659
write!(fmt, "<")?;
660660
for (index, elem) in self.0.iter().enumerate() {
661661
if index > 0 {

chalk-ir/src/fold/binder_impls.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,6 @@ where
8787
let binders = CanonicalVarKinds {
8888
interned: TI::transfer_canonical_var_kinds(self_binders.interned().clone()),
8989
};
90-
Ok(Canonical {
91-
binders: binders,
92-
value: value,
93-
})
90+
Ok(Canonical { binders, value })
9491
}
9592
}

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/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
}

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

+7-11
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,11 @@ impl<'a, I: Interner> Visitor<'a, I> for UnsizeParameterCollector<'a, I> {
4343
fn visit_const(&mut self, constant: &Const<I>, outer_binder: DebruijnIndex) -> Self::Result {
4444
let interner = self.interner;
4545

46-
match constant.data(interner).value {
47-
ConstValue::BoundVar(bound_var) => {
48-
// check if bound var refers to the outermost binder
49-
if bound_var.debruijn.shifted_in() == outer_binder {
50-
self.parameters.insert(bound_var.index);
51-
}
46+
if let ConstValue::BoundVar(bound_var) = constant.data(interner).value {
47+
// check if bound var refers to the outermost binder
48+
if bound_var.debruijn.shifted_in() == outer_binder {
49+
self.parameters.insert(bound_var.index);
5250
}
53-
_ => (),
5451
}
5552
}
5653

@@ -141,12 +138,11 @@ fn principal_id<'a, I: Interner>(
141138
) -> Option<TraitId<I>> {
142139
let interner = db.interner();
143140

144-
return bounds
141+
bounds
145142
.skip_binders()
146143
.iter(interner)
147144
.filter_map(|b| b.trait_id())
148-
.filter(|&id| !db.trait_datum(id).is_auto_trait())
149-
.next();
145+
.find(|&id| !db.trait_datum(id).is_auto_trait())
150146
}
151147

152148
fn auto_trait_ids<'a, I: Interner>(
@@ -384,7 +380,7 @@ pub fn add_unsize_program_clauses<I: Interner>(
384380
let unsize_parameter_candidates =
385381
outer_binder_parameters_used(interner, &adt_tail_field);
386382

387-
if unsize_parameter_candidates.len() == 0 {
383+
if unsize_parameter_candidates.is_empty() {
388384
return;
389385
}
390386
// Ensure none of the other fields mention the parameters used

0 commit comments

Comments
 (0)