Skip to content

Commit

Permalink
Auto merge of #753 - Kinrany:cleanup-clippy-warnings, r=jackh726
Browse files Browse the repository at this point in the history
Fix clippy warnings

This PR contains:

* Trivial Clippy fixes such as `needless_borrow`, `redundant_clone`, `match_like_matches_macro`, `try_err`, `needless_return`, ...
* Small local refactors, which I will point out in comments.

Each type of change is in a separate commit, except for the last commit that has a mix of unique changes.

The 18 remaining clippy errors are a bit more substantial.
  • Loading branch information
bors committed Mar 9, 2022
2 parents 9af1cb1 + b38fb85 commit f470f2f
Show file tree
Hide file tree
Showing 51 changed files with 337 additions and 416 deletions.
4 changes: 2 additions & 2 deletions chalk-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ fn find_interner(s: &mut synstructure::Structure) -> (TokenStream, DeriveKind) {

let generic_param0 = get_generic_param(input);

if let Some(param) = has_interner(&generic_param0) {
if let Some(param) = has_interner(generic_param0) {
// HasInterner bound:
//
// Example:
Expand All @@ -98,7 +98,7 @@ fn find_interner(s: &mut synstructure::Structure) -> (TokenStream, DeriveKind) {
);

(quote! { _I }, DeriveKind::FromHasInterner)
} else if let Some(i) = is_interner(&generic_param0) {
} else if let Some(i) = is_interner(generic_param0) {
// Interner bound:
//
// Example:
Expand Down
15 changes: 3 additions & 12 deletions chalk-engine/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ pub enum AnswerResult<I: Interner> {

impl<I: Interner> AnswerResult<I> {
pub fn is_answer(&self) -> bool {
match self {
Self::Answer(_) => true,
_ => false,
}
matches!(self, Self::Answer(_))
}

pub fn answer(self) -> CompleteAnswer<I> {
Expand All @@ -41,17 +38,11 @@ impl<I: Interner> AnswerResult<I> {
}

pub fn is_no_more_solutions(&self) -> bool {
match self {
Self::NoMoreSolutions => true,
_ => false,
}
matches!(self, Self::NoMoreSolutions)
}

pub fn is_quantum_exceeded(&self) -> bool {
match self {
Self::QuantumExceeded => true,
_ => false,
}
matches!(self, Self::QuantumExceeded)
}
}

Expand Down
16 changes: 8 additions & 8 deletions chalk-engine/src/logic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ impl<'forest, I: Interner> SolveState<'forest, I> {
ex_clause.answer_time.increment();

// Ok, we've applied the answer to this Strand.
return Ok(());
Ok(())
}

// This answer led nowhere. Give up for now, but of course
Expand All @@ -700,7 +700,7 @@ impl<'forest, I: Interner> SolveState<'forest, I> {

// Now we want to propogate back to the up with `QuantumExceeded`
self.unwind_stack();
return Err(RootSearchFail::QuantumExceeded);
Err(RootSearchFail::QuantumExceeded)
}
}
}
Expand Down Expand Up @@ -749,9 +749,9 @@ impl<'forest, I: Interner> SolveState<'forest, I> {
strand.ex_clause.ambiguous = true;

// Strand is ambigious.
return Ok(());
Ok(())
}
};
}
}

/// This is called when the selected subgoal for a strand has floundered.
Expand Down Expand Up @@ -951,7 +951,7 @@ impl<'forest, I: Interner> SolveState<'forest, I> {
Ok(_) => {
debug!(?strand, "merged answer into current strand");
canonical_strand =
Forest::canonicalize_strand_from(&self.context, &mut infer, &strand);
Forest::canonicalize_strand_from(self.context, &mut infer, &strand);
self.stack.top().active_strand = Some(canonical_strand);
return Ok(());
}
Expand Down Expand Up @@ -1224,7 +1224,7 @@ impl<'forest, I: Interner> SolveState<'forest, I> {

// Now we yield with `QuantumExceeded`
self.unwind_stack();
return Err(RootSearchFail::QuantumExceeded);
Err(RootSearchFail::QuantumExceeded)
} else {
debug!("table part of a cycle");

Expand Down Expand Up @@ -1267,7 +1267,7 @@ impl<'forest, I: Interner> SolveState<'forest, I> {
self.forest.tables[table].enqueue_strand(active_strand);

// The strand isn't active, but the table is, so just continue
return Ok(());
Ok(())
}
}

Expand Down Expand Up @@ -1483,7 +1483,7 @@ impl<'forest, I: Interner> SolveState<'forest, I> {
.collect();

let subst = Canonical {
binders: binders.clone(),
binders,
value: AnswerSubst {
subst,
constraints: Constraints::from_iter(self.context.program().interner(), constraints),
Expand Down
6 changes: 3 additions & 3 deletions chalk-engine/src/slg/aggregate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl<I: Interner> AggregateOps<I> for SlgContextOps<'_, I> {
should_continue: impl std::ops::Fn() -> bool,
) -> Option<Solution<I>> {
let interner = self.program.interner();
let CompleteAnswer { subst, ambiguous } = match answers.next_answer(|| should_continue()) {
let CompleteAnswer { subst, ambiguous } = match answers.next_answer(&should_continue) {
AnswerResult::NoMoreSolutions => {
// No answers at all
return None;
Expand All @@ -47,7 +47,7 @@ impl<I: Interner> AggregateOps<I> for SlgContextOps<'_, I> {
};

// Exactly 1 unconditional answer?
let next_answer = answers.peek_answer(|| should_continue());
let next_answer = answers.peek_answer(&should_continue);
if next_answer.is_quantum_exceeded() {
if subst.value.subst.is_identity_subst(interner) {
return Some(Solution::Ambig(Guidance::Unknown));
Expand Down Expand Up @@ -95,7 +95,7 @@ impl<I: Interner> AggregateOps<I> for SlgContextOps<'_, I> {
}
}

let new_subst = match answers.next_answer(|| should_continue()) {
let new_subst = match answers.next_answer(&should_continue) {
AnswerResult::Answer(answer1) => answer1.subst,
AnswerResult::Floundered => {
// FIXME: this doesn't trigger for any current tests
Expand Down
2 changes: 1 addition & 1 deletion chalk-engine/src/slg/resolvent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ impl<I: Interner> AnswerSubstitutor<'_, I> {
let result = self.table.relate(
interner,
db,
&self.environment,
self.environment,
variance,
answer_param,
&GenericArg::new(interner, pending_shifted),
Expand Down
2 changes: 1 addition & 1 deletion chalk-engine/src/strand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl<I: Interner> Fold<I> for Strand<I> {
Ok(Strand {
ex_clause: self.ex_clause.fold_with(folder, outer_binder)?,
last_pursued_time: self.last_pursued_time,
selected_subgoal: self.selected_subgoal.clone(),
selected_subgoal: self.selected_subgoal,
})
}
}
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
2 changes: 1 addition & 1 deletion chalk-integration/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl ChalkDatabase {

pub fn with_program<R>(&self, op: impl FnOnce(&Program) -> R) -> R {
let program = &self.checked_program().unwrap();
tls::set_current_program(&program, || op(&program))
tls::set_current_program(program, || op(program))
}

pub fn parse_and_lower_goal(&self, text: &str) -> Result<Goal<ChalkIr>, ChalkError> {
Expand Down
56 changes: 22 additions & 34 deletions chalk-integration/src/interner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,23 +241,23 @@ impl Interner for ChalkIr {
Arc::new(TyData { kind, flags })
}

fn ty_data<'a>(self, ty: &'a Arc<TyData<ChalkIr>>) -> &'a TyData<Self> {
fn ty_data(self, ty: &Arc<TyData<ChalkIr>>) -> &TyData<Self> {
ty
}

fn intern_lifetime(self, lifetime: LifetimeData<ChalkIr>) -> LifetimeData<ChalkIr> {
lifetime
}

fn lifetime_data<'a>(self, lifetime: &'a LifetimeData<ChalkIr>) -> &'a LifetimeData<ChalkIr> {
fn lifetime_data(self, lifetime: &LifetimeData<ChalkIr>) -> &LifetimeData<ChalkIr> {
lifetime
}

fn intern_const(self, constant: ConstData<ChalkIr>) -> Arc<ConstData<ChalkIr>> {
Arc::new(constant)
}

fn const_data<'a>(self, constant: &'a Arc<ConstData<ChalkIr>>) -> &'a ConstData<ChalkIr> {
fn const_data(self, constant: &Arc<ConstData<ChalkIr>>) -> &ConstData<ChalkIr> {
constant
}

Expand All @@ -269,18 +269,15 @@ impl Interner for ChalkIr {
generic_arg
}

fn generic_arg_data<'a>(
self,
generic_arg: &'a GenericArgData<ChalkIr>,
) -> &'a GenericArgData<ChalkIr> {
fn generic_arg_data(self, generic_arg: &GenericArgData<ChalkIr>) -> &GenericArgData<ChalkIr> {
generic_arg
}

fn intern_goal(self, goal: GoalData<ChalkIr>) -> Arc<GoalData<ChalkIr>> {
Arc::new(goal)
}

fn goal_data<'a>(self, goal: &'a Arc<GoalData<ChalkIr>>) -> &'a GoalData<ChalkIr> {
fn goal_data(self, goal: &Arc<GoalData<ChalkIr>>) -> &GoalData<ChalkIr> {
goal
}

Expand All @@ -291,7 +288,7 @@ impl Interner for ChalkIr {
data.into_iter().collect()
}

fn goals_data<'a>(self, goals: &'a Vec<Goal<ChalkIr>>) -> &'a [Goal<ChalkIr>] {
fn goals_data(self, goals: &Vec<Goal<ChalkIr>>) -> &[Goal<ChalkIr>] {
goals
}

Expand All @@ -302,21 +299,15 @@ impl Interner for ChalkIr {
data.into_iter().collect()
}

fn substitution_data<'a>(
self,
substitution: &'a Vec<GenericArg<ChalkIr>>,
) -> &'a [GenericArg<ChalkIr>] {
fn substitution_data(self, substitution: &Vec<GenericArg<ChalkIr>>) -> &[GenericArg<ChalkIr>] {
substitution
}

fn intern_program_clause(self, data: ProgramClauseData<Self>) -> ProgramClauseData<Self> {
data
}

fn program_clause_data<'a>(
self,
clause: &'a ProgramClauseData<Self>,
) -> &'a ProgramClauseData<Self> {
fn program_clause_data(self, clause: &ProgramClauseData<Self>) -> &ProgramClauseData<Self> {
clause
}

Expand All @@ -327,10 +318,7 @@ impl Interner for ChalkIr {
data.into_iter().collect()
}

fn program_clauses_data<'a>(
self,
clauses: &'a Vec<ProgramClause<Self>>,
) -> &'a [ProgramClause<Self>] {
fn program_clauses_data(self, clauses: &Vec<ProgramClause<Self>>) -> &[ProgramClause<Self>] {
clauses
}

Expand All @@ -341,10 +329,10 @@ impl Interner for ChalkIr {
data.into_iter().collect()
}

fn quantified_where_clauses_data<'a>(
fn quantified_where_clauses_data(
self,
clauses: &'a Self::InternedQuantifiedWhereClauses,
) -> &'a [QuantifiedWhereClause<Self>] {
clauses: &Self::InternedQuantifiedWhereClauses,
) -> &[QuantifiedWhereClause<Self>] {
clauses
}
fn intern_generic_arg_kinds<E>(
Expand All @@ -354,10 +342,10 @@ impl Interner for ChalkIr {
data.into_iter().collect()
}

fn variable_kinds_data<'a>(
fn variable_kinds_data(
self,
variable_kinds: &'a Self::InternedVariableKinds,
) -> &'a [VariableKind<ChalkIr>] {
variable_kinds: &Self::InternedVariableKinds,
) -> &[VariableKind<ChalkIr>] {
variable_kinds
}

Expand All @@ -368,10 +356,10 @@ impl Interner for ChalkIr {
data.into_iter().collect()
}

fn canonical_var_kinds_data<'a>(
fn canonical_var_kinds_data(
self,
canonical_var_kinds: &'a Self::InternedCanonicalVarKinds,
) -> &'a [CanonicalVarKind<ChalkIr>] {
canonical_var_kinds: &Self::InternedCanonicalVarKinds,
) -> &[CanonicalVarKind<ChalkIr>] {
canonical_var_kinds
}

Expand All @@ -382,10 +370,10 @@ impl Interner for ChalkIr {
data.into_iter().collect()
}

fn constraints_data<'a>(
fn constraints_data(
self,
constraints: &'a Self::InternedConstraints,
) -> &'a [InEnvironment<Constraint<Self>>] {
constraints: &Self::InternedConstraints,
) -> &[InEnvironment<Constraint<Self>>] {
constraints
}

Expand All @@ -396,7 +384,7 @@ impl Interner for ChalkIr {
data.into_iter().collect()
}

fn variances_data<'a>(self, variances: &'a Self::InternedVariances) -> &'a [Variance] {
fn variances_data(self, variances: &Self::InternedVariances) -> &[Variance] {
variances
}
}
Expand Down
Loading

0 comments on commit f470f2f

Please sign in to comment.