Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix clippy warnings #577

Merged
merged 1 commit into from
Jul 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -1418,10 +1418,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 @@ -1505,10 +1505,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 @@ -1681,7 +1678,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 @@ -1708,9 +1705,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 @@ -1723,9 +1718,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 @@ -1772,9 +1765,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 @@ -1807,14 +1798,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 @@ -1957,7 +1947,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 @@ -2038,7 +2028,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 @@ -655,7 +655,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
5 changes: 1 addition & 4 deletions chalk-ir/src/fold/binder_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,6 @@ where
let binders = CanonicalVarKinds {
interned: TI::transfer_canonical_var_kinds(self_binders.interned().clone()),
};
Ok(Canonical {
binders: binders,
value: value,
})
Ok(Canonical { 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
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,
_ => {}
}
}
18 changes: 7 additions & 11 deletions chalk-solve/src/clauses/builtin_traits/unsize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,11 @@ impl<'a, I: Interner> Visitor<'a, I> for UnsizeParameterCollector<'a, I> {
fn visit_const(&mut self, constant: &Const<I>, outer_binder: DebruijnIndex) -> Self::Result {
let interner = self.interner;

match constant.data(interner).value {
ConstValue::BoundVar(bound_var) => {
// check if bound var refers to the outermost binder
if bound_var.debruijn.shifted_in() == outer_binder {
self.parameters.insert(bound_var.index);
}
if let ConstValue::BoundVar(bound_var) = constant.data(interner).value {
// check if bound var refers to the outermost binder
if bound_var.debruijn.shifted_in() == outer_binder {
self.parameters.insert(bound_var.index);
}
_ => (),
}
}

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

return bounds
bounds
.skip_binders()
.iter(interner)
.filter_map(|b| b.trait_id())
.filter(|&id| !db.trait_datum(id).is_auto_trait())
.next();
.find(|&id| !db.trait_datum(id).is_auto_trait())
}

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

if unsize_parameter_candidates.len() == 0 {
if unsize_parameter_candidates.is_empty() {
return;
}
// Ensure none of the other fields mention the parameters used
Expand Down
Loading