Skip to content

Commit

Permalink
Fix clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
yannham committed Feb 15, 2024
1 parent ecdd137 commit b9eb971
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 17 deletions.
10 changes: 5 additions & 5 deletions core/src/typecheck/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1847,7 +1847,7 @@ fn check<V: TypecheckVisitor>(
.pattern_types(state, &ctxt, pattern::TypecheckMode::Enforce)?;
// In the destructuring case, there's no alternative pattern, and we must thus
// immediatly close all the row types.
pattern::close_all_enums(pat_types.enum_open_tails, state, &ctxt);
pattern::close_all_enums(pat_types.enum_open_tails, state);

let src = pat_types.typ;
let trg = state.table.fresh_type_uvar(ctxt.var_level);
Expand Down Expand Up @@ -1911,7 +1911,7 @@ fn check<V: TypecheckVisitor>(

// In the destructuring case, there's no alternative pattern, and we must thus
// immediatly close all the row types.
pattern::close_all_enums(pat_types.enum_open_tails, state, &ctxt);
pattern::close_all_enums(pat_types.enum_open_tails, state);

// The inferred type of the expr being bound
let ty_let = binding_type(state, re.as_ref(), &ctxt, true);
Expand Down Expand Up @@ -1996,7 +1996,7 @@ fn check<V: TypecheckVisitor>(
}

for (id, typ) in pat_types.bindings.iter() {
visitor.visit_ident(&id, typ.clone());
visitor.visit_ident(id, typ.clone());
ctxt.type_env.insert(id.ident(), typ.clone());
}

Expand Down Expand Up @@ -2040,9 +2040,9 @@ fn check<V: TypecheckVisitor>(

if data.default.is_some() {
// If there is a default value, we don't close the potential top-level enum type
pattern::close_enums(enum_open_tails, |path| !path.is_empty(), state, &ctxt);
pattern::close_enums(enum_open_tails, |path| !path.is_empty(), state);
} else {
pattern::close_all_enums(enum_open_tails, state, &ctxt);
pattern::close_all_enums(enum_open_tails, state);
}

pat_unif_result.map_err(|err| err.into_typecheck_err(state, rt.pos))?;
Expand Down
15 changes: 5 additions & 10 deletions core/src/typecheck/pattern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,36 +82,31 @@ pub fn close_enums(
enum_open_tails: Vec<(PatternPath, UnifEnumRows)>,
mut filter: impl FnMut(&PatternPath) -> bool,
state: &mut State,
ctxt: &Context,
) {
enum_open_tails
.into_iter()
.filter_map(|(path, tail)| filter(&path).then_some(tail))
.for_each(|tail| {
close_enum(tail, state, ctxt);
close_enum(tail, state);
})
}

/// Close all the enum row types left open when typechecking a match expression.
pub fn close_all_enums(
enum_open_tails: Vec<(PatternPath, UnifEnumRows)>,
state: &mut State,
ctxt: &Context,
) {
pub fn close_all_enums(enum_open_tails: Vec<(PatternPath, UnifEnumRows)>, state: &mut State) {
// Note: both for this function and for `close_enums`, for a given pattern path, all the tail
// variables should ultimately be part of the same enum type, and we just need to close it
// once. We might thus save a bit of work if we kept equivalence classes of tuples (path, tail)
// (equality being given by the equality of paths). Closing one arbitrary member per class
// should then be enough. It's not obvious that this would make any difference in practice,
// though.
for (_path, tail) in enum_open_tails {
close_enum(tail, state, ctxt);
close_enum(tail, state);
}
}

/// Take an enum row, find its final tail (in case of multiple indirection through unification
/// variables) and close it if it's a free unification variable.
pub fn close_enum(tail: UnifEnumRows, state: &mut State, ctxt: &Context) {
pub fn close_enum(tail: UnifEnumRows, state: &mut State) {
let root = tail.into_root(state.table);

if let UnifEnumRows::UnifVar { id, .. } = root {
Expand Down Expand Up @@ -147,7 +142,7 @@ pub fn close_enum(tail: UnifEnumRows, state: &mut State, ctxt: &Context) {
});

if let Some(tail) = tail {
close_enum(tail, state, ctxt)
close_enum(tail, state)
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions lsp/nls/src/position.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,7 @@ impl PositionLookup {
let ids = data
.branches
.iter()
.map(|(pat, _branch)| pat.bindings().into_iter())
.flatten()
.flat_map(|(pat, _branch)| pat.bindings().into_iter())
.map(|(_path, id, _)| id);
idents.extend(ids);
}
Expand Down

0 comments on commit b9eb971

Please sign in to comment.