auto clippy fixes

This commit is contained in:
Folkert 2023-06-26 20:42:50 +02:00
parent 72c85efc83
commit ef39bad7c6
No known key found for this signature in database
GPG key ID: 1F17F6FFD112B97C
146 changed files with 750 additions and 1005 deletions

View file

@ -181,8 +181,7 @@ impl<'a> PartialProcs<'a> {
pub fn insert(&mut self, symbol: Symbol, partial_proc: PartialProc<'a>) -> PartialProcId {
debug_assert!(
!self.contains_key(symbol),
"The {:?} is inserted as a partial proc twice: that's a bug!",
symbol,
"The {symbol:?} is inserted as a partial proc twice: that's a bug!",
);
let id = PartialProcId(self.symbols.len());
@ -675,7 +674,7 @@ impl<'a> Specialized<'a> {
} else {
match in_progress {
InProgressProc::InProgress => {
panic!("Function {:?} ({:?}) is not done specializing", s, l)
panic!("Function {s:?} ({l:?}) is not done specializing")
}
InProgressProc::Done(proc) => Some((s, l, proc)),
}
@ -838,11 +837,7 @@ impl<'a> SymbolSpecializations<'a> {
/// Only those bound to number literals can be compiled polymorphically.
fn mark_eligible(&mut self, symbol: Symbol) {
let _old = self.0.insert(symbol, VecMap::with_capacity(1));
debug_assert!(
_old.is_none(),
"overwriting specializations for {:?}",
symbol
);
debug_assert!(_old.is_none(), "overwriting specializations for {symbol:?}");
}
/// Removes all specializations for a symbol, returning the type and symbol of each specialization.
@ -945,8 +940,7 @@ impl<'a> Procs<'a> {
.expect("specialization stack is empty");
debug_assert_eq!(
popped, specialization,
"incorrect popped specialization: passed {:?}, but was {:?}",
specialization, popped
"incorrect popped specialization: passed {specialization:?}, but was {popped:?}"
);
}
@ -1026,7 +1020,7 @@ impl<'a> Procs<'a> {
) -> Result<ProcLayout<'a>, RuntimeError> {
let raw_layout = layout_cache
.raw_from_var(env.arena, annotation, env.subs)
.unwrap_or_else(|err| panic!("TODO turn fn_var into a RuntimeError {:?}", err));
.unwrap_or_else(|err| panic!("TODO turn fn_var into a RuntimeError {err:?}"));
let top_level = ProcLayout::from_raw_named(env.arena, name, raw_layout);
@ -1054,7 +1048,7 @@ impl<'a> Procs<'a> {
// if we've already specialized this one, no further work is needed.
if !already_specialized {
if self.is_module_thunk(name.name()) {
debug_assert!(layout.arguments.is_empty(), "{:?}", name);
debug_assert!(layout.arguments.is_empty(), "{name:?}");
}
let needs_suspended_specialization =
@ -1145,7 +1139,7 @@ impl<'a> Procs<'a> {
);
}
Err(error) => {
panic!("TODO generate a RuntimeError message for {:?}", error);
panic!("TODO generate a RuntimeError message for {error:?}");
}
}
}
@ -1234,7 +1228,7 @@ impl<'a> Procs<'a> {
.insert_specialized(proc_name.name(), proc_layout, proc);
}
Err(error) => {
panic!("TODO generate a RuntimeError message for {:?}", error);
panic!("TODO generate a RuntimeError message for {error:?}");
}
}
}
@ -1918,13 +1912,13 @@ pub(crate) fn symbol_to_doc_string(symbol: Symbol, force_pretty: bool) -> String
use roc_module::ident::ModuleName;
if pretty_print_ir_symbols() || force_pretty {
format!("{:?}", symbol)
format!("{symbol:?}")
} else {
let text = format!("{}", symbol);
let text = format!("{symbol}");
if text.starts_with(ModuleName::APP) {
let name: String = text.trim_start_matches(ModuleName::APP).into();
format!("Test{}", name)
format!("Test{name}")
} else {
text
}
@ -2016,7 +2010,7 @@ impl<'a> Expr<'a> {
.text("Reset { symbol: ")
.append(symbol_to_doc(alloc, *symbol, pretty))
.append(", id: ")
.append(format!("{:?}", update_mode))
.append(format!("{update_mode:?}"))
.append(" }"),
ResetRef {
symbol,
@ -2025,7 +2019,7 @@ impl<'a> Expr<'a> {
.text("ResetRef { symbol: ")
.append(symbol_to_doc(alloc, *symbol, pretty))
.append(", id: ")
.append(format!("{:?}", update_mode))
.append(format!("{update_mode:?}"))
.append(" }"),
Struct(args) => {
let it = args.iter().map(|s| symbol_to_doc(alloc, *s, pretty));
@ -3036,7 +3030,7 @@ fn specialize_external_help<'a>(
let partial_proc_id = match procs.partial_procs.symbol_to_id(name.name()) {
Some(v) => v,
None => {
panic!("Cannot find a partial proc for {:?}", name);
panic!("Cannot find a partial proc for {name:?}");
}
};
@ -3765,8 +3759,7 @@ fn build_specialized_proc<'a>(
debug_assert_eq!(
pattern_layouts_len + 1,
pattern_symbols.len(),
"Tried to zip two vecs with different lengths in {:?}!",
proc_name,
"Tried to zip two vecs with different lengths in {proc_name:?}!",
);
let proc_args = proc_args.into_bump_slice();
@ -3806,14 +3799,12 @@ fn build_specialized_proc<'a>(
// so far, the problem when hitting this branch was always somewhere else
// I think this branch should not be reachable in a bugfree compiler
panic!(
"more arguments (according to the layout) than argument symbols for {:?}",
proc_name
"more arguments (according to the layout) than argument symbols for {proc_name:?}"
)
}
}
Ordering::Less => panic!(
"more argument symbols than arguments (according to the layout) for {:?}",
proc_name
"more argument symbols than arguments (according to the layout) for {proc_name:?}"
),
}
}
@ -3845,14 +3836,12 @@ fn build_specialized_proc<'a>(
// so far, the problem when hitting this branch was always somewhere else
// I think this branch should not be reachable in a bugfree compiler
panic!(
"more arguments (according to the layout) than argument symbols for {:?}",
proc_name
"more arguments (according to the layout) than argument symbols for {proc_name:?}"
)
}
}
Ordering::Less => panic!(
"more argument symbols than arguments (according to the layout) for {:?}",
proc_name
"more argument symbols than arguments (according to the layout) for {proc_name:?}"
),
}
}
@ -3881,7 +3870,7 @@ fn specialize_variable<'a>(
// TODO: can we get rid of raw entirely?
let raw = layout_cache
.raw_from_var(env.arena, fn_var, env.subs)
.unwrap_or_else(|err| panic!("TODO handle invalid function {:?}", err));
.unwrap_or_else(|err| panic!("TODO handle invalid function {err:?}"));
let raw = if procs.is_module_thunk(proc_name.name()) {
match raw {
@ -4043,7 +4032,7 @@ fn specialize_naked_symbol<'a>(
return result;
} else if env.is_imported_symbol(symbol) {
match layout_cache.from_var(env.arena, variable, env.subs) {
Err(e) => panic!("invalid layout {:?}", e),
Err(e) => panic!("invalid layout {e:?}"),
Ok(_) => {
// this is a 0-arity thunk
let result = call_by_name(
@ -4573,7 +4562,7 @@ pub fn with_hole<'a>(
let layout = layout_cache
.from_var(env.arena, branch_var, env.subs)
.unwrap_or_else(|err| {
panic!("TODO turn fn_var into a RuntimeError {:?}", err)
panic!("TODO turn fn_var into a RuntimeError {err:?}")
});
let param = Param {
@ -4639,7 +4628,7 @@ pub fn with_hole<'a>(
let layout = layout_cache
.from_var(env.arena, expr_var, env.subs)
.unwrap_or_else(|err| panic!("TODO turn fn_var into a RuntimeError {:?}", err));
.unwrap_or_else(|err| panic!("TODO turn fn_var into a RuntimeError {err:?}"));
let param = Param {
symbol: assigned,
@ -4692,7 +4681,7 @@ pub fn with_hole<'a>(
let elem_layout = layout_cache
.from_var(env.arena, elem_var, env.subs)
.unwrap_or_else(|err| panic!("TODO turn fn_var into a RuntimeError {:?}", err));
.unwrap_or_else(|err| panic!("TODO turn fn_var into a RuntimeError {err:?}"));
for arg_expr in loc_elems.into_iter() {
if let Some(literal) =
@ -5033,7 +5022,7 @@ pub fn with_hole<'a>(
let record_layout = layout_cache
.from_var(env.arena, record_var, env.subs)
.unwrap_or_else(|err| panic!("TODO turn fn_var into a RuntimeError {:?}", err));
.unwrap_or_else(|err| panic!("TODO turn fn_var into a RuntimeError {err:?}"));
let field_layouts = match layout_cache.get_repr(record_layout) {
LayoutRepr::Struct(field_layouts) => field_layouts,
@ -5181,7 +5170,7 @@ pub fn with_hole<'a>(
if let Err(e) = inserted {
return runtime_error(
env,
env.arena.alloc(format!("RuntimeError: {:?}", e,)),
env.arena.alloc(format!("RuntimeError: {e:?}",)),
);
} else {
drop(inserted);
@ -5754,7 +5743,7 @@ fn compile_struct_like_access<'a>(
let layout = layout_cache
.from_var(env.arena, elem_var, env.subs)
.unwrap_or_else(|err| panic!("TODO turn fn_var into a RuntimeError {:?}", err));
.unwrap_or_else(|err| panic!("TODO turn fn_var into a RuntimeError {err:?}"));
Stmt::Let(assigned, expr, layout, hole)
}
@ -6197,7 +6186,7 @@ fn convert_tag_union<'a>(
// Layout will unpack this unwrapped tack if it only has one (non-zero-sized) field
let layout = layout_cache
.from_var(env.arena, variant_var, env.subs)
.unwrap_or_else(|err| panic!("TODO turn fn_var into a RuntimeError {:?}", err));
.unwrap_or_else(|err| panic!("TODO turn fn_var into a RuntimeError {err:?}"));
// even though this was originally a Tag, we treat it as a Struct from now on
let stmt = if let [only_field] = field_symbols {
@ -6231,7 +6220,7 @@ fn convert_tag_union<'a>(
// Layout will unpack this unwrapped tack if it only has one (non-zero-sized) field
let layout = layout_cache
.from_var(env.arena, variant_var, env.subs)
.unwrap_or_else(|err| panic!("TODO turn fn_var into a RuntimeError {:?}", err));
.unwrap_or_else(|err| panic!("TODO turn fn_var into a RuntimeError {err:?}"));
// even though this was originally a Tag, we treat it as a Struct from now on
let stmt = if let [only_field] = field_symbols {
@ -6496,8 +6485,7 @@ fn tag_union_to_function<'a>(
Err(e) => runtime_error(
env,
env.arena.alloc(format!(
"Could not produce tag function due to a runtime error: {:?}",
e,
"Could not produce tag function due to a runtime error: {e:?}",
)),
),
}
@ -8284,17 +8272,13 @@ fn call_by_name<'a>(
match layout_cache.raw_from_var(env.arena, fn_var, env.subs) {
Err(LayoutProblem::UnresolvedTypeVar(var)) => {
let msg = format!(
"Hit an unresolved type variable {:?} when creating a layout for {:?} (var {:?})",
var, proc_name, fn_var
"Hit an unresolved type variable {var:?} when creating a layout for {proc_name:?} (var {fn_var:?})"
);
evaluate_arguments_then_runtime_error(env, procs, layout_cache, msg, loc_args)
}
Err(LayoutProblem::Erroneous) => {
let msg = format!(
"Hit an erroneous type when creating a layout for {:?}",
proc_name
);
let msg = format!("Hit an erroneous type when creating a layout for {proc_name:?}");
evaluate_arguments_then_runtime_error(env, procs, layout_cache, msg, loc_args)
}
@ -8446,9 +8430,7 @@ fn call_by_name_help<'a>(
Some(name) => {
debug_assert!(
iter_lambda_names.next().is_none(),
"Somehow, call by name for {:?} has multiple capture niches: {:?}",
proc_name,
lambda_set
"Somehow, call by name for {proc_name:?} has multiple capture niches: {lambda_set:?}"
);
name
}
@ -8487,8 +8469,7 @@ fn call_by_name_help<'a>(
debug_assert_eq!(
argument_layouts.len(),
field_symbols.len(),
"see call_by_name for background (scroll down a bit), function is {:?}",
proc_name,
"see call_by_name for background (scroll down a bit), function is {proc_name:?}",
);
call_specialized_proc(
env,
@ -8539,8 +8520,7 @@ fn call_by_name_help<'a>(
debug_assert_eq!(
argument_layouts.len(),
field_symbols.len(),
"see call_by_name for background (scroll down a bit), function is {:?}",
proc_name,
"see call_by_name for background (scroll down a bit), function is {proc_name:?}",
);
let field_symbols = field_symbols.into_bump_slice();
@ -8592,8 +8572,7 @@ fn call_by_name_help<'a>(
debug_assert_eq!(
argument_layouts.len(),
field_symbols.len(),
"see call_by_name for background (scroll down a bit), function is {:?}",
proc_name,
"see call_by_name for background (scroll down a bit), function is {proc_name:?}",
);
let field_symbols = field_symbols.into_bump_slice();
@ -8784,8 +8763,7 @@ fn call_by_name_module_thunk<'a>(
Ok((proc, raw_layout)) => {
debug_assert!(
raw_layout.is_zero_argument_thunk(),
"but actually {:?}",
raw_layout
"but actually {raw_layout:?}"
);
let was_present = procs
@ -9044,10 +9022,9 @@ where
}
None => {
eprintln!(
"a function passed to `{:?}` LowLevel call has an empty lambda set!
"a function passed to `{op:?}` LowLevel call has an empty lambda set!
The most likely reason is that some symbol you use is not in scope.
",
op
"
);
hole.clone()
@ -10073,7 +10050,7 @@ fn unique_glue_symbol(
use std::fmt::Write;
let mut string = bumpalo::collections::String::with_capacity_in(32, arena);
let _result = write!(&mut string, "roc__getter_{}_{}", module_name, unique_id);
let _result = write!(&mut string, "roc__getter_{module_name}_{unique_id}");
debug_assert_eq!(_result, Ok(())); // This should never fail, but doesn't hurt to debug-check!
let bump_string = string.into_bump_str();