mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-03 08:34:33 +00:00
clippy
This commit is contained in:
parent
69c224843e
commit
e0039b94c9
7 changed files with 28 additions and 30 deletions
|
@ -564,7 +564,7 @@ fn struct_to_ast<'a>(
|
|||
let mut output = Vec::with_capacity_in(field_layouts.len(), arena);
|
||||
|
||||
let sorted_fields: Vec<_> = Vec::from_iter_in(
|
||||
record_fields.sorted_iterator(&env.subs, Variable::EMPTY_RECORD),
|
||||
record_fields.sorted_iterator(env.subs, Variable::EMPTY_RECORD),
|
||||
env.arena,
|
||||
);
|
||||
|
||||
|
@ -646,7 +646,7 @@ fn bool_to_ast<'a>(env: &Env<'a, '_>, value: bool, content: &Content) -> Expr<'a
|
|||
debug_assert_eq!(fields.len(), 1);
|
||||
|
||||
let (label, field) = fields
|
||||
.sorted_iterator(&env.subs, Variable::EMPTY_RECORD)
|
||||
.sorted_iterator(env.subs, Variable::EMPTY_RECORD)
|
||||
.next()
|
||||
.unwrap();
|
||||
|
||||
|
@ -762,7 +762,7 @@ fn byte_to_ast<'a>(env: &Env<'a, '_>, value: u8, content: &Content) -> Expr<'a>
|
|||
debug_assert_eq!(fields.len(), 1);
|
||||
|
||||
let (label, field) = fields
|
||||
.sorted_iterator(&env.subs, Variable::EMPTY_RECORD)
|
||||
.sorted_iterator(env.subs, Variable::EMPTY_RECORD)
|
||||
.next()
|
||||
.unwrap();
|
||||
|
||||
|
@ -882,7 +882,7 @@ fn num_to_ast<'a>(env: &Env<'a, '_>, num_expr: Expr<'a>, content: &Content) -> E
|
|||
debug_assert_eq!(fields.len(), 1);
|
||||
|
||||
let (label, field) = fields
|
||||
.sorted_iterator(&env.subs, Variable::EMPTY_RECORD)
|
||||
.sorted_iterator(env.subs, Variable::EMPTY_RECORD)
|
||||
.next()
|
||||
.unwrap();
|
||||
|
||||
|
|
|
@ -1210,7 +1210,7 @@ fn layout_from_flat_type<'a>(
|
|||
Record(fields, ext_var) => {
|
||||
// extract any values from the ext_var
|
||||
// TODO short-circuit the sorting here
|
||||
let mut fields_map: MutMap<_, _> = fields.sorted_iterator(subs, ext_var).collect();
|
||||
let fields_map: MutMap<_, _> = fields.sorted_iterator(subs, ext_var).collect();
|
||||
|
||||
// discard optional fields
|
||||
let mut layouts = sort_stored_record_fields(env, fields_map);
|
||||
|
|
|
@ -419,7 +419,7 @@ fn write_flat_type(env: &Env, flat_type: &FlatType, subs: &Subs, buf: &mut Strin
|
|||
let RecordStructure {
|
||||
fields: sorted_fields,
|
||||
ext,
|
||||
} = gather_fields(subs, fields.clone(), *ext_var);
|
||||
} = gather_fields(subs, *fields, *ext_var);
|
||||
let ext_var = ext;
|
||||
|
||||
if fields.is_empty() {
|
||||
|
|
|
@ -2,9 +2,8 @@ use crate::types::{name_type_var, ErrorType, Problem, RecordField, TypeExt};
|
|||
use roc_collections::all::{ImMap, ImSet, MutMap, MutSet, SendMap};
|
||||
use roc_module::ident::{Lowercase, TagName};
|
||||
use roc_module::symbol::Symbol;
|
||||
use std::cmp::Ordering;
|
||||
use std::fmt;
|
||||
use std::iter::{once, Extend, FromIterator, Iterator, Map, Zip};
|
||||
use std::iter::{once, Iterator, Map};
|
||||
use ven_ena::unify::{InPlace, Snapshot, UnificationTable, UnifyKey};
|
||||
|
||||
// if your changes cause this number to go down, great!
|
||||
|
@ -865,6 +864,8 @@ fn first<K: Ord, V>(x: &(K, V), y: &(K, V)) -> std::cmp::Ordering {
|
|||
x.0.cmp(&y.0)
|
||||
}
|
||||
|
||||
pub type SortedIterator<'a> = Box<dyn Iterator<Item = (Lowercase, RecordField<Variable>)> + 'a>;
|
||||
|
||||
impl RecordFields {
|
||||
pub fn len(&self) -> usize {
|
||||
self.length as usize
|
||||
|
@ -932,11 +933,7 @@ impl RecordFields {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn sorted_iterator<'a>(
|
||||
&'_ self,
|
||||
subs: &'a Subs,
|
||||
ext: Variable,
|
||||
) -> Box<dyn Iterator<Item = (Lowercase, RecordField<Variable>)> + 'a> {
|
||||
pub fn sorted_iterator<'a>(&'_ self, subs: &'a Subs, ext: Variable) -> SortedIterator<'a> {
|
||||
self.sorted_iterator_help(subs, ext).0
|
||||
}
|
||||
|
||||
|
@ -945,10 +942,7 @@ impl RecordFields {
|
|||
&'_ self,
|
||||
subs: &'a Subs,
|
||||
ext: Variable,
|
||||
) -> (
|
||||
Box<dyn Iterator<Item = (Lowercase, RecordField<Variable>)> + 'a>,
|
||||
Variable,
|
||||
) {
|
||||
) -> (SortedIterator<'a>, Variable) {
|
||||
if is_empty_record(subs, ext) {
|
||||
(
|
||||
Box::new(self.iter_all().map(move |(i1, i2, i3)| {
|
||||
|
@ -1178,7 +1172,7 @@ fn explicit_substitute(
|
|||
Structure(RecursiveTagUnion(rec_var, tags, new_ext_var)),
|
||||
);
|
||||
}
|
||||
Record(mut vars_by_field, ext_var) => {
|
||||
Record(vars_by_field, ext_var) => {
|
||||
let new_ext_var = explicit_substitute(subs, from, to, ext_var, seen);
|
||||
|
||||
for index in vars_by_field.iter_variables() {
|
||||
|
|
|
@ -1521,12 +1521,12 @@ pub fn name_type_var(letters_used: u32, taken: &mut MutSet<Lowercase>) -> (Lower
|
|||
}
|
||||
}
|
||||
|
||||
pub fn gather_fields_unsorted_iter<'a>(
|
||||
subs: &'a Subs,
|
||||
pub fn gather_fields_unsorted_iter(
|
||||
subs: &Subs,
|
||||
other_fields: RecordFields,
|
||||
mut var: Variable,
|
||||
) -> (
|
||||
impl Iterator<Item = (&'a Lowercase, RecordField<Variable>)> + 'a,
|
||||
impl Iterator<Item = (&Lowercase, RecordField<Variable>)> + '_,
|
||||
Variable,
|
||||
) {
|
||||
use crate::subs::Content::*;
|
||||
|
|
|
@ -5,7 +5,7 @@ use roc_types::subs::Content::{self, *};
|
|||
use roc_types::subs::{
|
||||
Descriptor, FlatType, GetSubsSlice, Mark, OptVariable, RecordFields, Subs, SubsSlice, Variable,
|
||||
};
|
||||
use roc_types::types::{gather_fields, ErrorType, Mismatch, RecordField, RecordStructure};
|
||||
use roc_types::types::{ErrorType, Mismatch, RecordField};
|
||||
|
||||
macro_rules! mismatch {
|
||||
() => {{
|
||||
|
@ -367,11 +367,13 @@ enum OtherFields {
|
|||
Other(RecordFields, RecordFields),
|
||||
}
|
||||
|
||||
type SharedFields = Vec<(Lowercase, (RecordField<Variable>, RecordField<Variable>))>;
|
||||
|
||||
fn unify_shared_fields(
|
||||
subs: &mut Subs,
|
||||
pool: &mut Pool,
|
||||
ctx: &Context,
|
||||
shared_fields: Vec<(Lowercase, (RecordField<Variable>, RecordField<Variable>))>,
|
||||
shared_fields: SharedFields,
|
||||
other_fields: OtherFields,
|
||||
ext: Variable,
|
||||
) -> Outcome {
|
||||
|
@ -480,9 +482,8 @@ fn separate_record_fields(
|
|||
let (it1, new_ext1) = fields1.sorted_iterator_help(subs, ext1);
|
||||
let (it2, new_ext2) = fields2.sorted_iterator_help(subs, ext2);
|
||||
|
||||
use std::iter::FromIterator;
|
||||
let it1 = Vec::from_iter(it1);
|
||||
let it2 = Vec::from_iter(it2);
|
||||
let it1 = it1.collect::<Vec<_>>();
|
||||
let it2 = it2.collect::<Vec<_>>();
|
||||
|
||||
(separate(it1, it2), new_ext1, new_ext2)
|
||||
}
|
||||
|
@ -512,7 +513,7 @@ where
|
|||
|
||||
loop {
|
||||
let which = match (it1.peek(), it2.peek()) {
|
||||
(Some((l, _)), Some((r, _))) => Some(l.cmp(&r)),
|
||||
(Some((l, _)), Some((r, _))) => Some(l.cmp(r)),
|
||||
(Some(_), None) => Some(Ordering::Less),
|
||||
(None, Some(_)) => Some(Ordering::Greater),
|
||||
(None, None) => None,
|
||||
|
@ -561,7 +562,7 @@ where
|
|||
|
||||
loop {
|
||||
let which = match (it1.peek(), it2.peek()) {
|
||||
(Some((l, _)), Some((r, _))) => Some(l.cmp(&r)),
|
||||
(Some((l, _)), Some((r, _))) => Some(l.cmp(r)),
|
||||
(Some(_), None) => Some(Ordering::Less),
|
||||
(None, Some(_)) => Some(Ordering::Greater),
|
||||
(None, None) => None,
|
||||
|
|
|
@ -1521,7 +1521,7 @@ fn deep_copy_var_help(
|
|||
|
||||
same @ EmptyRecord | same @ EmptyTagUnion | same @ Erroneous(_) => same,
|
||||
|
||||
Record(mut fields, ext_var) => {
|
||||
Record(fields, ext_var) => {
|
||||
let mut new_vars = Vec::with_capacity(fields.len());
|
||||
for index in fields.iter_variables() {
|
||||
let var = subs[index];
|
||||
|
@ -1541,7 +1541,10 @@ fn deep_copy_var_help(
|
|||
|
||||
let record_fields = RecordFields::insert_into_subs(subs, vec);
|
||||
|
||||
Record(fields, deep_copy_var_help(subs, max_rank, pools, ext_var))
|
||||
Record(
|
||||
record_fields,
|
||||
deep_copy_var_help(subs, max_rank, pools, ext_var),
|
||||
)
|
||||
}
|
||||
|
||||
TagUnion(tags, ext_var) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue