Skip to content

Commit

Permalink
Fix clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
detrumi committed Jul 20, 2020
1 parent ca961b3 commit 9792faf
Show file tree
Hide file tree
Showing 22 changed files with 80 additions and 105 deletions.
27 changes: 13 additions & 14 deletions chalk-engine/src/logic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -492,13 +492,12 @@ impl<'forest, I: Interner, C: Context<I> + 'forest, CO: ContextOps<I, C> + 'fore
} = canonical_strand;
let (infer, ex_clause) =
context.instantiate_ex_clause(num_universes, &canonical_ex_clause);
let strand = Strand {
Strand {
infer,
ex_clause,
selected_subgoal: selected_subgoal.clone(),
selected_subgoal,
last_pursued_time,
};
strand
}
})
});
match next_strand {
Expand Down Expand Up @@ -598,7 +597,7 @@ impl<'forest, I: Interner, C: Context<I> + 'forest, CO: ContextOps<I, C> + 'fore
infer: strand.infer.clone(),
ex_clause: strand.ex_clause.clone(),
selected_subgoal: Some(next_subgoal),
last_pursued_time: strand.last_pursued_time.clone(),
last_pursued_time: strand.last_pursued_time,
};
let table = self.stack.top().table;
let canonical_next_strand = Forest::canonicalize_strand(self.context, next_strand);
Expand Down Expand Up @@ -749,7 +748,7 @@ impl<'forest, I: Interner, C: Context<I> + 'forest, CO: ContextOps<I, C> + 'fore
// and maybe come back to it.
self.flounder_subgoal(&mut strand.ex_clause, selected_subgoal.subgoal_index);

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

return true;
true
}
}
}
Expand Down Expand Up @@ -803,7 +802,7 @@ impl<'forest, I: Interner, C: Context<I> + 'forest, CO: ContextOps<I, C> + 'fore
strand.ex_clause.delayed_subgoals.push(subgoal);

self.stack.top().active_strand = Some(strand);
return Ok(());
Ok(())
}
Literal::Negative(_) => {
// We don't allow coinduction for negative literals
Expand Down Expand Up @@ -961,7 +960,7 @@ impl<'forest, I: Interner, C: Context<I> + 'forest, CO: ContextOps<I, C> + 'fore
return NoRemainingSubgoalsResult::RootSearchFail(RootSearchFail::QuantumExceeded);
}
}
let floundered = strand.ex_clause.floundered_subgoals.len() > 0;
let floundered = !strand.ex_clause.floundered_subgoals.is_empty();
if floundered {
debug!("all remaining subgoals floundered for the table");
} else {
Expand All @@ -978,7 +977,7 @@ impl<'forest, I: Interner, C: Context<I> + 'forest, CO: ContextOps<I, C> + 'fore
match self.stack.pop_and_take_caller_strand() {
Some(caller_strand) => {
self.stack.top().active_strand = Some(caller_strand);
return NoRemainingSubgoalsResult::Success;
NoRemainingSubgoalsResult::Success
}
None => {
// That was the root table, so we are done --
Expand All @@ -997,9 +996,9 @@ impl<'forest, I: Interner, C: Context<I> + 'forest, CO: ContextOps<I, C> + 'fore
self.forest.tables[table].enqueue_strand(strand);
}

return NoRemainingSubgoalsResult::RootAnswerAvailable;
NoRemainingSubgoalsResult::RootAnswerAvailable
}
};
}
}
None => {
debug!("answer is not available (or not new)");
Expand All @@ -1010,9 +1009,9 @@ impl<'forest, I: Interner, C: Context<I> + 'forest, CO: ContextOps<I, C> + 'fore

// Now we yield with `QuantumExceeded`
self.unwind_stack();
return NoRemainingSubgoalsResult::RootSearchFail(RootSearchFail::QuantumExceeded);
NoRemainingSubgoalsResult::RootSearchFail(RootSearchFail::QuantumExceeded)
}
};
}
}

/// A "refinement" strand is used in coinduction. When the root
Expand Down
5 changes: 1 addition & 4 deletions chalk-engine/src/normalize_deep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ impl<I: Interner> DeepNormalizer<'_, '_, I> {
) -> T::Result {
value
.fold_with(
&mut DeepNormalizer {
interner,
table: table,
},
&mut DeepNormalizer { interner, table },
DebruijnIndex::INNERMOST,
)
.unwrap()
Expand Down
6 changes: 3 additions & 3 deletions chalk-engine/src/slg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ pub(crate) struct SlgContextOps<'me, I: Interner> {
}

impl<I: Interner> SlgContextOps<'_, I> {
pub(crate) fn new<'p>(
program: &'p dyn RustIrDatabase<I>,
pub(crate) fn new(
program: &dyn RustIrDatabase<I>,
max_size: usize,
expected_answers: Option<usize>,
) -> SlgContextOps<'p, I> {
) -> SlgContextOps<'_, I> {
SlgContextOps {
program,
max_size,
Expand Down
4 changes: 2 additions & 2 deletions chalk-engine/src/slg/aggregate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ impl<I: Interner> AntiUnifier<'_, '_, I> {
if index1 != index2 {
self.new_ty_variable()
} else {
TyData::Placeholder(index1.clone()).intern(interner)
TyData::Placeholder(*index1).intern(interner)
}
}

Expand Down Expand Up @@ -465,7 +465,7 @@ impl<I: Interner> AntiUnifier<'_, '_, I> {
}

(ConstValue::BoundVar(_), _) | (_, ConstValue::BoundVar(_)) => {
self.new_const_variable(ty.clone())
self.new_const_variable(ty)
}

(ConstValue::Placeholder(_), ConstValue::Placeholder(_)) => {
Expand Down
8 changes: 3 additions & 5 deletions chalk-engine/src/solve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,10 @@ impl<I: Interner> Solver<I> for SLGSolver<I> {
AnswerResult::Answer(answer) => {
if !answer.ambiguous {
SubstitutionResult::Definite(answer.subst)
} else if ops.is_trivial_constrained_substitution(&answer.subst) {
SubstitutionResult::Floundered
} else {
if ops.is_trivial_constrained_substitution(&answer.subst) {
SubstitutionResult::Floundered
} else {
SubstitutionResult::Ambiguous(answer.subst)
}
SubstitutionResult::Ambiguous(answer.subst)
}
}
AnswerResult::Floundered => SubstitutionResult::Floundered,
Expand Down
42 changes: 16 additions & 26 deletions chalk-integration/src/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ impl<'k> Env<'k> {
});
} else {
return Ok(chalk_ir::TyData::Apply(chalk_ir::ApplicationTy {
name: chalk_ir::TypeName::FnDef(id.clone()),
name: chalk_ir::TypeName::FnDef(*id),
substitution: chalk_ir::Substitution::empty(interner),
})
.intern(interner)
Expand All @@ -158,7 +158,7 @@ impl<'k> Env<'k> {
});
} else {
return Ok(chalk_ir::TyData::Apply(chalk_ir::ApplicationTy {
name: chalk_ir::TypeName::Closure(id.clone()),
name: chalk_ir::TypeName::Closure(*id),
// See note in `program`. Unlike rustc, we store upvars separately.
substitution: chalk_ir::Substitution::empty(interner),
})
Expand Down Expand Up @@ -526,7 +526,7 @@ impl LowerProgram for Program {
trait_id: TraitId(raw_id),
id: lookup.id,
name: assoc_ty_defn.name.str.clone(),
binders: binders,
binders,
}),
);
}
Expand Down Expand Up @@ -1416,10 +1416,10 @@ trait LowerQuantifiedInlineBoundVec {
impl LowerQuantifiedInlineBoundVec for [QuantifiedInlineBound] {
fn lower(&self, env: &Env) -> LowerResult<Vec<rust_ir::QuantifiedInlineBound<ChalkIr>>> {
fn trait_identifier(bound: &InlineBound) -> &Identifier {
return match bound {
match bound {
InlineBound::TraitBound(tb) => &tb.trait_name,
InlineBound::AliasEqBound(ab) => &ab.trait_bound.trait_name,
};
}
}

let mut regular_traits = Vec::new();
Expand Down Expand Up @@ -1503,10 +1503,7 @@ impl LowerProjectionTy for ProjectionTy {
trait_id,
substitution: trait_substitution,
} = trait_ref.lower(env)?;
let lookup = match env
.associated_ty_lookups
.get(&(trait_id.into(), name.str.clone()))
{
let lookup = match env.associated_ty_lookups.get(&(trait_id, name.str.clone())) {
Some(lookup) => lookup,
None => Err(RustIrError::MissingAssociatedType(self.name.clone()))?,
};
Expand Down Expand Up @@ -1673,7 +1670,7 @@ impl LowerTy for Ty {
.intern(interner)),

Ty::Scalar { ty } => Ok(chalk_ir::TyData::Apply(chalk_ir::ApplicationTy {
name: chalk_ir::TypeName::Scalar(ast_scalar_to_chalk_scalar(ty.clone())),
name: chalk_ir::TypeName::Scalar(ast_scalar_to_chalk_scalar(*ty)),
substitution: chalk_ir::Substitution::empty(interner),
})
.intern(interner)),
Expand All @@ -1700,9 +1697,7 @@ impl LowerTy for Ty {
.intern(interner)),

Ty::Raw { mutability, ty } => Ok(chalk_ir::TyData::Apply(chalk_ir::ApplicationTy {
name: chalk_ir::TypeName::Raw(ast_mutability_to_chalk_mutability(
mutability.clone(),
)),
name: chalk_ir::TypeName::Raw(ast_mutability_to_chalk_mutability(*mutability)),
substitution: chalk_ir::Substitution::from_fallible(
interner,
std::iter::once(Ok(ty.lower(env)?)),
Expand All @@ -1715,9 +1710,7 @@ impl LowerTy for Ty {
lifetime,
ty,
} => Ok(chalk_ir::TyData::Apply(chalk_ir::ApplicationTy {
name: chalk_ir::TypeName::Ref(ast_mutability_to_chalk_mutability(
mutability.clone(),
)),
name: chalk_ir::TypeName::Ref(ast_mutability_to_chalk_mutability(*mutability)),
substitution: chalk_ir::Substitution::from_iter(
interner,
&[
Expand Down Expand Up @@ -1764,9 +1757,7 @@ impl LowerConst for Const {
}
Const::Value(value) => Ok(chalk_ir::ConstData {
ty: get_type_of_u32(),
value: chalk_ir::ConstValue::Concrete(chalk_ir::ConcreteConst {
interned: value.clone(),
}),
value: chalk_ir::ConstValue::Concrete(chalk_ir::ConcreteConst { interned: *value }),
}
.intern(interner)),
}
Expand Down Expand Up @@ -1799,14 +1790,13 @@ impl LowerLifetime for Lifetime {
match self {
Lifetime::Id { name } => {
let parameter = env.lookup_generic_arg(&name)?;
parameter
.lifetime(interner)
.map(|l| l.clone())
.ok_or_else(|| RustIrError::IncorrectParameterKind {
parameter.lifetime(interner).copied().ok_or_else(|| {
RustIrError::IncorrectParameterKind {
identifier: name.clone(),
expected: Kind::Lifetime,
actual: parameter.kind(),
})
}
})
}
}
}
Expand Down Expand Up @@ -1949,7 +1939,7 @@ impl LowerTrait for TraitDefn {

let trait_datum = rust_ir::TraitDatum {
id: trait_id,
binders: binders,
binders,
flags: self.flags.lower(),
associated_ty_ids,
well_known: self.well_known.map(|t| t.lower()),
Expand Down Expand Up @@ -2030,7 +2020,7 @@ impl<'k> LowerGoal<Env<'k>> for Goal {
// in the assumptions of an `if` goal, e.g. `if (T: Trait) { ... }` lowers to
// `if (FromEnv(T: Trait)) { ... /* this part is untouched */ ... }`.
let where_clauses = hyp
.into_iter()
.iter()
.flat_map(|h| h.lower_clause(env).apply_result())
.map(|result| result.map(|h| h.into_from_env_clause(interner)));
let where_clauses =
Expand Down
2 changes: 1 addition & 1 deletion chalk-integration/src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ impl RustIrDatabase<ChalkIr> for Program {
}

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

fn program_clauses_for_env(
Expand Down
2 changes: 1 addition & 1 deletion chalk-ir/src/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ pub struct Angle<'a, T>(pub &'a [T]);

impl<'a, T: Debug> Debug for Angle<'a, T> {
fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> {
if self.0.len() > 0 {
if !self.0.is_empty() {
write!(fmt, "<")?;
for (index, elem) in self.0.iter().enumerate() {
if index > 0 {
Expand Down
4 changes: 2 additions & 2 deletions chalk-ir/src/fold/binder_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ where
interned: TI::transfer_canonical_var_kinds(self_binders.interned().clone()),
};
Ok(Canonical {
binders: binders,
value: value,
binders,
value,
})
}
}
2 changes: 1 addition & 1 deletion chalk-ir/src/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub trait VisitResult: Sized {
/// Unit type for a visitor indicates a "side-effecting" visitor that
/// should visit an entire term.
impl VisitResult for () {
fn new() -> () {}
fn new() -> Self {}

fn return_early(&self) -> bool {
false
Expand Down
2 changes: 1 addition & 1 deletion chalk-solve/src/clauses/builtin_traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub fn add_builtin_program_clauses<I: Interner>(
let ty = self_ty.data(db.interner());
if let Some(force_impl) = db.force_impl_for(well_known, ty) {
if force_impl {
builder.push_fact(trait_ref.clone());
builder.push_fact(trait_ref);
}
return Ok(());
}
Expand Down
4 changes: 2 additions & 2 deletions chalk-solve/src/clauses/builtin_traits/copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ pub fn add_copy_program_clauses<I: Interner>(
let upvars = upvars.substitute(db.interner(), &closure_fn_substitution);
needs_impl_for_tys(db, builder, trait_ref, Some(upvars).into_iter());
}
_ => return,
_ => {}
},
TyData::Function(_) => builder.push_fact(trait_ref.clone()),
// TODO(areredify)
// when #368 lands, extend this to handle everything accordingly
_ => return,
_ => {}
};
}
4 changes: 2 additions & 2 deletions chalk-solve/src/clauses/builtin_traits/sized.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ pub fn add_sized_program_clauses<I: Interner>(
| TypeName::Scalar(_)
| TypeName::Raw(_)
| TypeName::Ref(_) => builder.push_fact(trait_ref.clone()),
_ => return,
_ => {}
},
TyData::Function(_) => builder.push_fact(trait_ref.clone()),
// TODO(areredify)
// when #368 lands, extend this to handle everything accordingly
_ => return,
_ => {}
}
}
Loading

0 comments on commit 9792faf

Please sign in to comment.