Skip to content

Commit

Permalink
Fix miscellaneous clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Kinrany committed Mar 7, 2022
1 parent 2b9f88c commit b38fb85
Show file tree
Hide file tree
Showing 12 changed files with 36 additions and 41 deletions.
2 changes: 1 addition & 1 deletion chalk-engine/src/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

/// Remove the next strand from the queue that meets the given criteria
Expand Down
4 changes: 2 additions & 2 deletions chalk-integration/src/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ impl LowerWithEnv for (&AdtDefn, chalk_ir::AdtId<ChalkIr>) {
fn lower(&self, env: &Env) -> LowerResult<Self::Lowered> {
let (adt_defn, adt_id) = self;

if adt_defn.flags.fundamental && adt_defn.all_parameters().len() < 1 {
if adt_defn.flags.fundamental && adt_defn.all_parameters().is_empty() {
return Err(RustIrError::InvalidFundamentalTypesParameters(
adt_defn.name.clone(),
));
Expand Down Expand Up @@ -669,7 +669,7 @@ impl LowerWithEnv for Ty {
Ok(match self {
Ty::Id { name } => {
let parameter = env.lookup_generic_arg(name)?;
parameter.ty(interner).map(|ty| ty.clone()).ok_or_else(|| {
parameter.ty(interner).cloned().ok_or_else(|| {
RustIrError::IncorrectParameterKind {
identifier: name.clone(),
expected: Kind::Ty,
Expand Down
2 changes: 1 addition & 1 deletion chalk-integration/src/lowering/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ impl Env<'_> {
) -> LowerResult<&AssociatedTyLookup> {
self.associated_ty_lookups
.get(&(trait_id, ident.str.clone()))
.ok_or(RustIrError::MissingAssociatedType(ident.clone()))
.ok_or_else(|| RustIrError::MissingAssociatedType(ident.clone()))
}

/// Introduces new parameters, shifting the indices of existing
Expand Down
14 changes: 6 additions & 8 deletions chalk-integration/src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -447,8 +447,7 @@ impl RustIrDatabase<ChalkIr> for Program {
let trait_ref = &impl_datum.binders.skip_binders().trait_ref;
trait_id == trait_ref.trait_id && {
assert_eq!(trait_ref.substitution.len(interner), parameters.len());
<[_] as CouldMatch<[_]>>::could_match(
parameters,
parameters.could_match(
interner,
self.unification_database(),
trait_ref.substitution.as_slice(interner),
Expand Down Expand Up @@ -594,12 +593,11 @@ impl RustIrDatabase<ChalkIr> for Program {
fn discriminant_type(&self, ty: Ty<ChalkIr>) -> Ty<ChalkIr> {
let interner = self.interner();
match ty.data(interner).kind {
TyKind::Adt(id, _) => {
let repr = self.adt_repr(id);
repr.int
.clone()
.unwrap_or(TyKind::Scalar(Scalar::Int(IntTy::Isize)).intern(interner))
}
TyKind::Adt(id, _) => self
.adt_repr(id)
.int
.clone()
.unwrap_or_else(|| TyKind::Scalar(Scalar::Int(IntTy::Isize)).intern(interner)),
TyKind::Generator(..) => TyKind::Scalar(Scalar::Uint(UintTy::U32)).intern(interner),
_ => TyKind::Scalar(Scalar::Uint(UintTy::U8)).intern(interner),
}
Expand Down
2 changes: 1 addition & 1 deletion chalk-recursive/src/fulfill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ impl<'s, I: Interner, Solver: SolveDatabase<I>> Fulfill<'s, I, Solver> {
}
}

self.obligations.extend(obligations.drain(..));
self.obligations.append(&mut obligations);
debug!("end of round, {} obligations left", self.obligations.len());
}

Expand Down
7 changes: 3 additions & 4 deletions chalk-solve/src/clauses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1089,12 +1089,11 @@ fn match_alias_ty<I: Interner>(
environment: &Environment<I>,
alias: &AliasTy<I>,
) {
match alias {
AliasTy::Projection(projection_ty) => builder
if let AliasTy::Projection(projection_ty) = alias {
builder
.db
.associated_ty_data(projection_ty.associated_ty_id)
.to_program_clauses(builder, environment),
_ => (),
.to_program_clauses(builder, environment)
}
}

Expand Down
4 changes: 2 additions & 2 deletions chalk-solve/src/infer/unify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,11 @@ impl<'t, I: Interner> Unifier<'t, I> {
(_, &TyKind::Alias(ref alias)) => self.relate_alias_ty(variance.invert(), alias, a),
(&TyKind::Alias(ref alias), _) => self.relate_alias_ty(variance, alias, b),

(&TyKind::InferenceVar(var, kind), ty_data @ _) => {
(&TyKind::InferenceVar(var, kind), ty_data) => {
let ty = ty_data.clone().intern(interner);
self.relate_var_ty(variance, var, kind, &ty)
}
(ty_data @ _, &TyKind::InferenceVar(var, kind)) => {
(ty_data, &TyKind::InferenceVar(var, kind)) => {
// We need to invert the variance if inference var is `b` because we pass it in
// as `a` to relate_var_ty
let ty = ty_data.clone().intern(interner);
Expand Down
4 changes: 3 additions & 1 deletion chalk-solve/src/logging_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,9 @@ where
well_known_trait: crate::rust_ir::WellKnownTrait,
) -> Option<TraitId<I>> {
let trait_id = self.ws.db().well_known_trait_id(well_known_trait);
trait_id.map(|id| self.record(id));
if let Some(id) = trait_id {
self.record(id);
}
trait_id
}

Expand Down
7 changes: 4 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl LoadedProgram {
let goal = lower_goal(&*chalk_parse::parse_goal(text)?, &*program)?;
let peeled_goal = goal.into_peeled_goal(self.db.interner());
if multiple_answers {
if self.db.solve_multiple(&peeled_goal, &mut |v, has_next| {
let no_more_solutions = self.db.solve_multiple(&peeled_goal, &mut |v, has_next| {
println!("{}\n", v.as_ref().map(|v| v.display(ChalkIr)));
if has_next {
if let Some(ref mut rl) = rl {
Expand All @@ -94,7 +94,8 @@ impl LoadedProgram {
} else {
true
}
}) {
});
if no_more_solutions {
println!("No more solutions");
}
} else {
Expand Down Expand Up @@ -290,7 +291,7 @@ fn read_program(rl: &mut rustyline::Editor<()>) -> Result<String> {

impl Args {
fn solver_choice(&self) -> SolverChoice {
match self.flag_solver.as_ref().map(String::as_str) {
match self.flag_solver.as_deref() {
None | Some("slg") => SolverChoice::SLG {
max_size: self.flag_overflow_depth,
expected_answers: None,
Expand Down
10 changes: 4 additions & 6 deletions tests/display/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,7 @@ pub fn program_item_ids(program: &Program) -> impl Iterator<Item = RecordedItemI

// then discard the RawId since the RecordedItemId has the same information,
// and is what we actually want to consume.
let ids = ids.into_iter().map(|(_, id)| id);

ids
ids.into_iter().map(|(_, id)| id)
}

/// Sends all items in a `chalk_integration::Program` through `display` code and
Expand Down Expand Up @@ -146,9 +144,9 @@ fn program_diff(original: &impl Debug, produced: &impl Debug) -> String {
let produced = format!("{:#?}", produced);
for line in diff::lines(&original, &produced) {
match line {
diff::Result::Left(l) => write!(out, "-{}\n", l),
diff::Result::Both(l, _) => write!(out, " {}\n", l),
diff::Result::Right(r) => write!(out, "+{}\n", r),
diff::Result::Left(l) => writeln!(out, "-{}", l),
diff::Result::Both(l, _) => writeln!(out, " {}", l),
diff::Result::Right(r) => writeln!(out, "+{}", r),
}
.expect("writing to string never fails");
}
Expand Down
2 changes: 1 addition & 1 deletion tests/logging_db/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub fn logging_db_output_sufficient(

let goals = goals
.iter()
.flat_map(|(a, bs, c)| bs.into_iter().map(move |b| (a, b, c)));
.flat_map(|(a, bs, c)| bs.iter().map(move |b| (a, b, c)));

let output_text = {
let db = ChalkDatabase::with(
Expand Down
19 changes: 8 additions & 11 deletions tests/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,14 @@ mod wf_lowering;

fn format_solution(mut result: Option<Solution<ChalkIr>>, interner: ChalkIr) -> String {
// sort constraints, since the different solvers may output them in different order
match &mut result {
Some(Solution::Unique(solution)) => {
let mut sorted = solution.value.constraints.as_slice(interner).to_vec();
sorted.sort_by_key(|c| format!("{:?}", c));
solution.value.constraints = Constraints::from_iter(interner, sorted);
}
_ => {}
if let Some(Solution::Unique(solution)) = &mut result {
let mut sorted = solution.value.constraints.as_slice(interner).to_vec();
sorted.sort_by_key(|c| format!("{:?}", c));
solution.value.constraints = Constraints::from_iter(interner, sorted);
}
match result {
Some(v) => format!("{}", v.display(ChalkIr)),
None => format!("No possible solution"),
Some(v) => v.display(ChalkIr).to_string(),
None => "No possible solution".to_string(),
}
}

Expand Down Expand Up @@ -310,7 +307,7 @@ fn solve_goal(
assert_result(result, expected, db.interner());
}
TestGoal::All(expected) => {
let mut expected = expected.into_iter();
let mut expected = expected.iter();
assert!(
db.solve_multiple(&peeled_goal, &mut |result, next_result| {
match expected.next() {
Expand All @@ -334,7 +331,7 @@ fn solve_goal(
}
}
TestGoal::First(expected) => {
let mut expected = expected.into_iter();
let mut expected = expected.iter();
db.solve_multiple(&peeled_goal, &mut |result, next_result| match expected
.next()
{
Expand Down

0 comments on commit b38fb85

Please sign in to comment.