diff --git a/crates/compiler/can/src/def.rs b/crates/compiler/can/src/def.rs index 804665e3a9..7d516f2f72 100644 --- a/crates/compiler/can/src/def.rs +++ b/crates/compiler/can/src/def.rs @@ -955,7 +955,7 @@ pub(crate) fn canonicalize_defs<'a>( // there are opaques that implement an ability using a value symbol). But, value symbols might // shadow symbols defined in a local ability def. - for (_, either_index) in loc_defs.tags.iter().enumerate() { + for either_index in loc_defs.tags.iter() { if let Ok(type_index) = either_index.split() { let type_def = &loc_defs.type_defs[type_index.index()]; let pending_type_def = to_pending_type_def(env, type_def, scope, pattern_type); diff --git a/crates/compiler/mono/src/ir/decision_tree.rs b/crates/compiler/mono/src/ir/decision_tree.rs index 631e92d677..2930d42f18 100644 --- a/crates/compiler/mono/src/ir/decision_tree.rs +++ b/crates/compiler/mono/src/ir/decision_tree.rs @@ -452,7 +452,7 @@ enum Match { } fn check_for_match(branches: &[Branch]) -> Match { - match branches.get(0) { + match branches.first() { Some(Branch { goal, patterns, diff --git a/crates/compiler/mono/src/layout/intern.rs b/crates/compiler/mono/src/layout/intern.rs index b86efabe41..f6d2f023f9 100644 --- a/crates/compiler/mono/src/layout/intern.rs +++ b/crates/compiler/mono/src/layout/intern.rs @@ -593,6 +593,9 @@ struct LockedGlobalInterner<'a, 'r> { fn hash(val: V) -> u64 { let mut state = roc_collections::all::BuildHasher::default().build_hasher(); val.hash(&mut state); + + // clippy suggests a stylistic improvement but the suggested fix doesn't seem to work out + #[allow(clippy::manual_hash_one)] state.finish() } diff --git a/crates/compiler/parse/src/blankspace.rs b/crates/compiler/parse/src/blankspace.rs index be518b62aa..7fa07b4654 100644 --- a/crates/compiler/parse/src/blankspace.rs +++ b/crates/compiler/parse/src/blankspace.rs @@ -322,43 +322,6 @@ pub fn fast_eat_until_control_character(bytes: &[u8]) -> usize { simple_eat_until_control_character(&bytes[i..]) + i } -#[cfg(test)] -mod tests { - use super::*; - use proptest::prelude::*; - - #[test] - fn test_eat_whitespace_simple() { - let bytes = &[0, 0, 0, 0, 0, 0, 0, 0]; - assert_eq!(simple_eat_whitespace(bytes), fast_eat_whitespace(bytes)); - } - - proptest! { - #[test] - fn test_eat_whitespace(bytes in proptest::collection::vec(any::(), 0..100)) { - prop_assert_eq!(simple_eat_whitespace(&bytes), fast_eat_whitespace(&bytes)); - } - } - - #[test] - fn test_eat_until_control_character_simple() { - let bytes = &[32, 0, 0, 0, 0, 0, 0, 0]; - assert_eq!( - simple_eat_until_control_character(bytes), - fast_eat_until_control_character(bytes) - ); - } - - proptest! { - #[test] - fn test_eat_until_control_character(bytes in proptest::collection::vec(any::(), 0..100)) { - prop_assert_eq!( - simple_eat_until_control_character(&bytes), - fast_eat_until_control_character(&bytes)); - } - } -} - pub fn space0_e<'a, E>( indent_problem: fn(Position) -> E, ) -> impl Parser<'a, &'a [CommentOrNewline<'a>], E> @@ -514,3 +477,40 @@ where Ok((progress, state)) } + +#[cfg(test)] +mod tests { + use super::*; + use proptest::prelude::*; + + #[test] + fn test_eat_whitespace_simple() { + let bytes = &[0, 0, 0, 0, 0, 0, 0, 0]; + assert_eq!(simple_eat_whitespace(bytes), fast_eat_whitespace(bytes)); + } + + proptest! { + #[test] + fn test_eat_whitespace(bytes in proptest::collection::vec(any::(), 0..100)) { + prop_assert_eq!(simple_eat_whitespace(&bytes), fast_eat_whitespace(&bytes)); + } + } + + #[test] + fn test_eat_until_control_character_simple() { + let bytes = &[32, 0, 0, 0, 0, 0, 0, 0]; + assert_eq!( + simple_eat_until_control_character(bytes), + fast_eat_until_control_character(bytes) + ); + } + + proptest! { + #[test] + fn test_eat_until_control_character(bytes in proptest::collection::vec(any::(), 0..100)) { + prop_assert_eq!( + simple_eat_until_control_character(&bytes), + fast_eat_until_control_character(&bytes)); + } + } +} \ No newline at end of file diff --git a/crates/compiler/solve/src/to_var.rs b/crates/compiler/solve/src/to_var.rs index ab1a7ae425..f3432496f9 100644 --- a/crates/compiler/solve/src/to_var.rs +++ b/crates/compiler/solve/src/to_var.rs @@ -958,7 +958,7 @@ fn sort_and_deduplicate(tag_vars: &mut bumpalo::collections::Vec<(TagName, T) fn find_tag_name_run(slice: &[TagName], subs: &mut Subs) -> Option> { use std::cmp::Ordering; - let tag_name = slice.get(0)?; + let tag_name = slice.first()?; let mut result = None; diff --git a/crates/glue/src/types.rs b/crates/glue/src/types.rs index bb3d3ac3bb..d1b9e7576b 100644 --- a/crates/glue/src/types.rs +++ b/crates/glue/src/types.rs @@ -2284,7 +2284,7 @@ fn tag_to_type<'a, D: Display>( // this isn't recursive and there's 1 payload item, so it doesn't // need its own struct - e.g. for `[Foo Str, Bar Str]` both of them // can have payloads of plain old Str, no struct wrapper needed. - let payload_var = payload_vars.get(0).unwrap(); + let payload_var = payload_vars.first().unwrap(); let payload_layout = env .layout_cache .from_var(env.arena, *payload_var, env.subs) diff --git a/crates/reporting/src/error/type.rs b/crates/reporting/src/error/type.rs index 3ae724ba80..e831346621 100644 --- a/crates/reporting/src/error/type.rs +++ b/crates/reporting/src/error/type.rs @@ -2999,14 +2999,14 @@ fn to_diff<'b>( ErrorType::Type(Symbol::NUM_NUM, args) => { matches!( - &args.get(0), + &args.first(), Some(ErrorType::Type(Symbol::NUM_INTEGER, _)) | Some(ErrorType::Alias(Symbol::NUM_INTEGER, _, _, _)) ) } ErrorType::Alias(Symbol::NUM_NUM, args, _, _) => { matches!( - &args.get(0), + &args.first(), Some(ErrorType::Type(Symbol::NUM_INTEGER, _)) | Some(ErrorType::Alias(Symbol::NUM_INTEGER, _, _, _)) ) @@ -3019,7 +3019,7 @@ fn to_diff<'b>( ErrorType::Type(Symbol::NUM_NUM, args) => { matches!( - &args.get(0), + &args.first(), Some(ErrorType::Type(Symbol::NUM_FLOATINGPOINT, _)) | Some(ErrorType::Alias(Symbol::NUM_FLOATINGPOINT, _, _, _)) ) @@ -3027,7 +3027,7 @@ fn to_diff<'b>( ErrorType::Alias(Symbol::NUM_NUM, args, _, _) => { matches!( - &args.get(0), + &args.first(), Some(ErrorType::Type(Symbol::NUM_FLOATINGPOINT, _)) | Some(ErrorType::Alias(Symbol::NUM_FLOATINGPOINT, _, _, _)) ) @@ -4360,7 +4360,7 @@ fn type_problem_to_pretty<'b>( (FieldTypo(typo, possibilities), _) => { let suggestions = suggest::sort(typo.as_str(), possibilities); - match suggestions.get(0) { + match suggestions.first() { None => alloc.nil(), Some(nearest) => { let typo_str = format!("{typo}"); @@ -4412,7 +4412,7 @@ fn type_problem_to_pretty<'b>( let typo_str = format!("{}", typo.as_ident_str()); let suggestions = suggest::sort(&typo_str, possibilities); - match suggestions.get(0) { + match suggestions.first() { None => alloc.nil(), Some(nearest) => { let nearest_str = format!("{nearest}"); diff --git a/crates/roc_std/src/roc_dict.rs b/crates/roc_std/src/roc_dict.rs index 918c9558c9..c80380c326 100644 --- a/crates/roc_std/src/roc_dict.rs +++ b/crates/roc_std/src/roc_dict.rs @@ -109,7 +109,7 @@ impl Debug for RocDict { f.write_str("RocDict ")?; f.debug_map() - .entries(self.iter().map(|(k, v)| (k, v))) + .entries(self.iter()) .finish() } }