Skip to content

Commit b38fb85

Browse files
committed
Fix miscellaneous clippy warnings
1 parent 2b9f88c commit b38fb85

File tree

12 files changed

+36
-41
lines changed

12 files changed

+36
-41
lines changed

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/lowering.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ impl LowerWithEnv for (&AdtDefn, chalk_ir::AdtId<ChalkIr>) {
285285
fn lower(&self, env: &Env) -> LowerResult<Self::Lowered> {
286286
let (adt_defn, adt_id) = self;
287287

288-
if adt_defn.flags.fundamental && adt_defn.all_parameters().len() < 1 {
288+
if adt_defn.flags.fundamental && adt_defn.all_parameters().is_empty() {
289289
return Err(RustIrError::InvalidFundamentalTypesParameters(
290290
adt_defn.name.clone(),
291291
));
@@ -669,7 +669,7 @@ impl LowerWithEnv for Ty {
669669
Ok(match self {
670670
Ty::Id { name } => {
671671
let parameter = env.lookup_generic_arg(name)?;
672-
parameter.ty(interner).map(|ty| ty.clone()).ok_or_else(|| {
672+
parameter.ty(interner).cloned().ok_or_else(|| {
673673
RustIrError::IncorrectParameterKind {
674674
identifier: name.clone(),
675675
expected: Kind::Ty,

chalk-integration/src/lowering/env.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ impl Env<'_> {
219219
) -> LowerResult<&AssociatedTyLookup> {
220220
self.associated_ty_lookups
221221
.get(&(trait_id, ident.str.clone()))
222-
.ok_or(RustIrError::MissingAssociatedType(ident.clone()))
222+
.ok_or_else(|| RustIrError::MissingAssociatedType(ident.clone()))
223223
}
224224

225225
/// Introduces new parameters, shifting the indices of existing

chalk-integration/src/program.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -447,8 +447,7 @@ impl RustIrDatabase<ChalkIr> for Program {
447447
let trait_ref = &impl_datum.binders.skip_binders().trait_ref;
448448
trait_id == trait_ref.trait_id && {
449449
assert_eq!(trait_ref.substitution.len(interner), parameters.len());
450-
<[_] as CouldMatch<[_]>>::could_match(
451-
parameters,
450+
parameters.could_match(
452451
interner,
453452
self.unification_database(),
454453
trait_ref.substitution.as_slice(interner),
@@ -594,12 +593,11 @@ impl RustIrDatabase<ChalkIr> for Program {
594593
fn discriminant_type(&self, ty: Ty<ChalkIr>) -> Ty<ChalkIr> {
595594
let interner = self.interner();
596595
match ty.data(interner).kind {
597-
TyKind::Adt(id, _) => {
598-
let repr = self.adt_repr(id);
599-
repr.int
600-
.clone()
601-
.unwrap_or(TyKind::Scalar(Scalar::Int(IntTy::Isize)).intern(interner))
602-
}
596+
TyKind::Adt(id, _) => self
597+
.adt_repr(id)
598+
.int
599+
.clone()
600+
.unwrap_or_else(|| TyKind::Scalar(Scalar::Int(IntTy::Isize)).intern(interner)),
603601
TyKind::Generator(..) => TyKind::Scalar(Scalar::Uint(UintTy::U32)).intern(interner),
604602
_ => TyKind::Scalar(Scalar::Uint(UintTy::U8)).intern(interner),
605603
}

chalk-recursive/src/fulfill.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ impl<'s, I: Interner, Solver: SolveDatabase<I>> Fulfill<'s, I, Solver> {
495495
}
496496
}
497497

498-
self.obligations.extend(obligations.drain(..));
498+
self.obligations.append(&mut obligations);
499499
debug!("end of round, {} obligations left", self.obligations.len());
500500
}
501501

chalk-solve/src/clauses.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1089,12 +1089,11 @@ fn match_alias_ty<I: Interner>(
10891089
environment: &Environment<I>,
10901090
alias: &AliasTy<I>,
10911091
) {
1092-
match alias {
1093-
AliasTy::Projection(projection_ty) => builder
1092+
if let AliasTy::Projection(projection_ty) = alias {
1093+
builder
10941094
.db
10951095
.associated_ty_data(projection_ty.associated_ty_id)
1096-
.to_program_clauses(builder, environment),
1097-
_ => (),
1096+
.to_program_clauses(builder, environment)
10981097
}
10991098
}
11001099

chalk-solve/src/infer/unify.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -184,11 +184,11 @@ impl<'t, I: Interner> Unifier<'t, I> {
184184
(_, &TyKind::Alias(ref alias)) => self.relate_alias_ty(variance.invert(), alias, a),
185185
(&TyKind::Alias(ref alias), _) => self.relate_alias_ty(variance, alias, b),
186186

187-
(&TyKind::InferenceVar(var, kind), ty_data @ _) => {
187+
(&TyKind::InferenceVar(var, kind), ty_data) => {
188188
let ty = ty_data.clone().intern(interner);
189189
self.relate_var_ty(variance, var, kind, &ty)
190190
}
191-
(ty_data @ _, &TyKind::InferenceVar(var, kind)) => {
191+
(ty_data, &TyKind::InferenceVar(var, kind)) => {
192192
// We need to invert the variance if inference var is `b` because we pass it in
193193
// as `a` to relate_var_ty
194194
let ty = ty_data.clone().intern(interner);

chalk-solve/src/logging_db.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,9 @@ where
210210
well_known_trait: crate::rust_ir::WellKnownTrait,
211211
) -> Option<TraitId<I>> {
212212
let trait_id = self.ws.db().well_known_trait_id(well_known_trait);
213-
trait_id.map(|id| self.record(id));
213+
if let Some(id) = trait_id {
214+
self.record(id);
215+
}
214216
trait_id
215217
}
216218

src/main.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ impl LoadedProgram {
7171
let goal = lower_goal(&*chalk_parse::parse_goal(text)?, &*program)?;
7272
let peeled_goal = goal.into_peeled_goal(self.db.interner());
7373
if multiple_answers {
74-
if self.db.solve_multiple(&peeled_goal, &mut |v, has_next| {
74+
let no_more_solutions = self.db.solve_multiple(&peeled_goal, &mut |v, has_next| {
7575
println!("{}\n", v.as_ref().map(|v| v.display(ChalkIr)));
7676
if has_next {
7777
if let Some(ref mut rl) = rl {
@@ -94,7 +94,8 @@ impl LoadedProgram {
9494
} else {
9595
true
9696
}
97-
}) {
97+
});
98+
if no_more_solutions {
9899
println!("No more solutions");
99100
}
100101
} else {
@@ -290,7 +291,7 @@ fn read_program(rl: &mut rustyline::Editor<()>) -> Result<String> {
290291

291292
impl Args {
292293
fn solver_choice(&self) -> SolverChoice {
293-
match self.flag_solver.as_ref().map(String::as_str) {
294+
match self.flag_solver.as_deref() {
294295
None | Some("slg") => SolverChoice::SLG {
295296
max_size: self.flag_overflow_depth,
296297
expected_answers: None,

tests/display/util.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,7 @@ pub fn program_item_ids(program: &Program) -> impl Iterator<Item = RecordedItemI
7474

7575
// then discard the RawId since the RecordedItemId has the same information,
7676
// and is what we actually want to consume.
77-
let ids = ids.into_iter().map(|(_, id)| id);
78-
79-
ids
77+
ids.into_iter().map(|(_, id)| id)
8078
}
8179

8280
/// Sends all items in a `chalk_integration::Program` through `display` code and
@@ -146,9 +144,9 @@ fn program_diff(original: &impl Debug, produced: &impl Debug) -> String {
146144
let produced = format!("{:#?}", produced);
147145
for line in diff::lines(&original, &produced) {
148146
match line {
149-
diff::Result::Left(l) => write!(out, "-{}\n", l),
150-
diff::Result::Both(l, _) => write!(out, " {}\n", l),
151-
diff::Result::Right(r) => write!(out, "+{}\n", r),
147+
diff::Result::Left(l) => writeln!(out, "-{}", l),
148+
diff::Result::Both(l, _) => writeln!(out, " {}", l),
149+
diff::Result::Right(r) => writeln!(out, "+{}", r),
152150
}
153151
.expect("writing to string never fails");
154152
}

tests/logging_db/util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub fn logging_db_output_sufficient(
3535

3636
let goals = goals
3737
.iter()
38-
.flat_map(|(a, bs, c)| bs.into_iter().map(move |b| (a, b, c)));
38+
.flat_map(|(a, bs, c)| bs.iter().map(move |b| (a, b, c)));
3939

4040
let output_text = {
4141
let db = ChalkDatabase::with(

tests/test/mod.rs

+8-11
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,14 @@ mod wf_lowering;
2424

2525
fn format_solution(mut result: Option<Solution<ChalkIr>>, interner: ChalkIr) -> String {
2626
// sort constraints, since the different solvers may output them in different order
27-
match &mut result {
28-
Some(Solution::Unique(solution)) => {
29-
let mut sorted = solution.value.constraints.as_slice(interner).to_vec();
30-
sorted.sort_by_key(|c| format!("{:?}", c));
31-
solution.value.constraints = Constraints::from_iter(interner, sorted);
32-
}
33-
_ => {}
27+
if let Some(Solution::Unique(solution)) = &mut result {
28+
let mut sorted = solution.value.constraints.as_slice(interner).to_vec();
29+
sorted.sort_by_key(|c| format!("{:?}", c));
30+
solution.value.constraints = Constraints::from_iter(interner, sorted);
3431
}
3532
match result {
36-
Some(v) => format!("{}", v.display(ChalkIr)),
37-
None => format!("No possible solution"),
33+
Some(v) => v.display(ChalkIr).to_string(),
34+
None => "No possible solution".to_string(),
3835
}
3936
}
4037

@@ -310,7 +307,7 @@ fn solve_goal(
310307
assert_result(result, expected, db.interner());
311308
}
312309
TestGoal::All(expected) => {
313-
let mut expected = expected.into_iter();
310+
let mut expected = expected.iter();
314311
assert!(
315312
db.solve_multiple(&peeled_goal, &mut |result, next_result| {
316313
match expected.next() {
@@ -334,7 +331,7 @@ fn solve_goal(
334331
}
335332
}
336333
TestGoal::First(expected) => {
337-
let mut expected = expected.into_iter();
334+
let mut expected = expected.iter();
338335
db.solve_multiple(&peeled_goal, &mut |result, next_result| match expected
339336
.next()
340337
{

0 commit comments

Comments
 (0)