mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-02 16:21:11 +00:00
do what clippy wants
This commit is contained in:
parent
2baf8f1b49
commit
f7cb11afc9
5 changed files with 34 additions and 32 deletions
|
@ -462,7 +462,7 @@ fn canonicalize_def<'a>(
|
|||
&Pattern::Identifier(_, ref defined_symbol),
|
||||
) = (&loc_pattern.value, &loc_can_pattern.value)
|
||||
{
|
||||
fname = name.to_string();
|
||||
fname = (*name).to_string();
|
||||
env.tailcallable_symbol = Some(defined_symbol.clone());
|
||||
variables_by_symbol.insert(defined_symbol.clone(), expr_var);
|
||||
};
|
||||
|
@ -507,7 +507,7 @@ fn canonicalize_def<'a>(
|
|||
// ensure expected type unifies with annotated type
|
||||
state
|
||||
.constraints
|
||||
.push(Eq(expr_type.clone(), annotation_expected, loc_def.region));
|
||||
.push(Eq(expr_type, annotation_expected, loc_def.region));
|
||||
|
||||
// reset the tailcallable_symbol
|
||||
env.tailcallable_symbol = outer_identifier;
|
||||
|
@ -689,7 +689,7 @@ fn canonicalize_def<'a>(
|
|||
scope,
|
||||
loc_expr.region,
|
||||
&loc_expr.value,
|
||||
NoExpectation(expr_type.clone()),
|
||||
NoExpectation(expr_type),
|
||||
);
|
||||
|
||||
// reset the tailcallable_symbol
|
||||
|
|
|
@ -651,7 +651,7 @@ pub fn canonicalize_expr(
|
|||
vec![cond_var],
|
||||
And(vec![
|
||||
// Record the original conditional expression's constraint.
|
||||
expr_con.clone(),
|
||||
expr_con,
|
||||
// Each branch's pattern must have the same type
|
||||
// as the condition expression did.
|
||||
And(branch_cons),
|
||||
|
|
|
@ -136,7 +136,7 @@ pub fn canonicalize_pattern<'a>(
|
|||
scope
|
||||
.idents
|
||||
.insert(new_ident.clone(), symbol_and_region.clone());
|
||||
shadowable_idents.insert(new_ident, symbol_and_region.clone());
|
||||
shadowable_idents.insert(new_ident, symbol_and_region);
|
||||
|
||||
Pattern::Identifier(var_store.fresh(), symbol)
|
||||
}
|
||||
|
|
50
src/unify.rs
50
src/unify.rs
|
@ -3,6 +3,7 @@ use crate::collections::ImMap;
|
|||
use crate::subs::Content::{self, *};
|
||||
use crate::subs::{Descriptor, FlatType, Mark, Subs, Variable};
|
||||
use crate::types::Problem;
|
||||
use std::cmp::Ordering;
|
||||
|
||||
struct Context {
|
||||
first: Variable,
|
||||
|
@ -74,22 +75,25 @@ fn unify_alias(
|
|||
RigidVar(_) => unify(subs, problems, real_var, ctx.second),
|
||||
Alias(other_home, other_name, other_args, other_real_var) => {
|
||||
if name == other_name && home == other_home {
|
||||
if args.len() == other_args.len() {
|
||||
for ((_, l_var), (_, r_var)) in args.iter().zip(other_args.iter()) {
|
||||
unify(subs, problems, *l_var, *r_var);
|
||||
match args.len().cmp(&other_args.len()) {
|
||||
Ordering::Greater => {
|
||||
let problem = Problem::ExtraArguments;
|
||||
|
||||
merge(subs, &ctx, Error(problem.clone()));
|
||||
problems.push(problem);
|
||||
}
|
||||
Ordering::Less => {
|
||||
let problem = Problem::MissingArguments;
|
||||
|
||||
merge(subs, &ctx, other_content.clone());
|
||||
} else if args.len() > other_args.len() {
|
||||
let problem = Problem::ExtraArguments;
|
||||
|
||||
merge(subs, &ctx, Error(problem.clone()));
|
||||
problems.push(problem.clone());
|
||||
} else {
|
||||
let problem = Problem::MissingArguments;
|
||||
|
||||
merge(subs, &ctx, Error(problem.clone()));
|
||||
problems.push(problem.clone());
|
||||
merge(subs, &ctx, Error(problem.clone()));
|
||||
problems.push(problem);
|
||||
}
|
||||
Ordering::Equal => {
|
||||
for ((_, l_var), (_, r_var)) in args.iter().zip(other_args.iter()) {
|
||||
unify(subs, problems, *l_var, *r_var);
|
||||
}
|
||||
merge(subs, &ctx, other_content.clone());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
unify(subs, problems, real_var, *other_real_var)
|
||||
|
@ -120,7 +124,7 @@ fn unify_structure(
|
|||
let problem = Problem::GenericMismatch;
|
||||
// Type mismatch! Rigid can only unify with flex.
|
||||
merge(subs, ctx, Error(problem.clone()));
|
||||
problems.push(problem.clone());
|
||||
problems.push(problem);
|
||||
}
|
||||
Structure(ref other_flat_type) => {
|
||||
// Unify the two flat types
|
||||
|
@ -237,7 +241,7 @@ fn unify_shared_fields(
|
|||
|
||||
// Type mismatch! Rigid can only unify with flex.
|
||||
merge(subs, ctx, Error(problem.clone()));
|
||||
problems.push(problem.clone());
|
||||
problems.push(problem);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -294,22 +298,20 @@ fn unify_flat_type(
|
|||
}),
|
||||
);
|
||||
}
|
||||
(Func(l_args, l_ret), Func(r_args, r_ret)) => {
|
||||
if l_args.len() == r_args.len() {
|
||||
(Func(l_args, l_ret), Func(r_args, r_ret)) => match l_args.len().cmp(&r_args.len()) {
|
||||
Ordering::Greater => merge(subs, ctx, Error(Problem::ExtraArguments)),
|
||||
Ordering::Less => merge(subs, ctx, Error(Problem::MissingArguments)),
|
||||
Ordering::Equal => {
|
||||
unify_zip(subs, problems, l_args.iter(), r_args.iter());
|
||||
unify(subs, problems, *l_ret, *r_ret);
|
||||
merge(subs, ctx, Structure(Func((*r_args).clone(), *r_ret)));
|
||||
} else if l_args.len() > r_args.len() {
|
||||
merge(subs, ctx, Error(Problem::ExtraArguments));
|
||||
} else {
|
||||
merge(subs, ctx, Error(Problem::MissingArguments));
|
||||
}
|
||||
}
|
||||
},
|
||||
_ => {
|
||||
let problem = Problem::GenericMismatch;
|
||||
|
||||
merge(subs, ctx, Error(problem.clone()));
|
||||
problems.push(problem.clone());
|
||||
problems.push(problem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -73,7 +73,7 @@ fn canonicalize_pattern(
|
|||
symbol.clone(),
|
||||
Located {
|
||||
region: pattern.region,
|
||||
value: expected.clone().get_type(),
|
||||
value: expected.get_type(),
|
||||
},
|
||||
);
|
||||
}
|
||||
|
@ -279,7 +279,7 @@ pub fn canonicalize_expr(
|
|||
var_usage,
|
||||
region,
|
||||
&body.value,
|
||||
Expected::NoExpectation(ret_type.clone()),
|
||||
Expected::NoExpectation(ret_type),
|
||||
);
|
||||
|
||||
// remove identifiers bound in the arguments from VarUsage
|
||||
|
@ -500,7 +500,7 @@ pub fn canonicalize_expr(
|
|||
vec![cond_var],
|
||||
And(vec![
|
||||
// Record the original conditional expression's constraint.
|
||||
expr_con.clone(),
|
||||
expr_con,
|
||||
// Each branch's pattern must have the same type
|
||||
// as the condition expression did.
|
||||
And(branch_cons),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue