Skip to content

Commit 66b2be4

Browse files
committed
chore: apply clippy --fix, remove dead code
1 parent fdb2b32 commit 66b2be4

File tree

30 files changed

+96
-156
lines changed

30 files changed

+96
-156
lines changed

core/src/bytecode/ast/compat.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
use super::{primop::PrimOp, *};
88
use crate::{
99
bytecode::value::{
10-
ArrayData, Container, EnumVariantData, InlineValue, NickelValue, TypeData, ValueContentRef,
10+
ArrayData, Container, EnumVariantData, NickelValue, TypeData, ValueContentRef,
1111
ValueContentRefMut,
1212
},
1313
combine::Combine,
1414
label,
15-
position::{PosIdx, PosTable, RawSpan},
15+
position::{PosTable, RawSpan},
1616
term, typ as mline_type,
1717
};
1818
use indexmap::IndexMap;

core/src/bytecode/value/lens.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ impl TermContent {
271271
};
272272

273273
// unwrap(): if the lens is a TermContent, then the underlying value must be a term block.
274-
&value.as_term().unwrap()
274+
value.as_term().unwrap()
275275
}
276276

277277
/// Unconditionally take the inner `Term` out, ignoring the actual shape of the content.

core/src/bytecode/value/mod.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ impl NickelValue {
612612
/// block with an enum variant inside, which has no arguments, or `None` otherwise.
613613
pub fn as_enum_tag(&self) -> Option<LocIdent> {
614614
let enum_var = self.as_enum_variant()?;
615-
enum_var.arg.is_none().then(|| enum_var.tag)
615+
enum_var.arg.is_none().then_some(enum_var.tag)
616616
}
617617

618618
/// Returns a reference to the inner sealing key stored in this value if `self` is a value
@@ -1205,7 +1205,7 @@ impl NickelValue {
12051205
ValueBlockRc::header_from_raw(NonNull::new_unchecked(self.data as *mut u8)).pos_idx
12061206
},
12071207
// unwrap(): if the tag is `Inline`, then `inline_pos_idx()` must be `Some`
1208-
ValueTag::Inline => self.inline_pos_idx().unwrap().into(),
1208+
ValueTag::Inline => self.inline_pos_idx().unwrap(),
12091209
}
12101210
}
12111211

@@ -1939,10 +1939,10 @@ impl ValueBlockRc {
19391939
Self::encode(self.decode::<EnumVariantData>().clone(), self.pos_idx())
19401940
}
19411941
DataTag::ForeignId => {
1942-
Self::encode(self.decode::<ForeignIdData>().clone(), self.pos_idx())
1942+
Self::encode(*self.decode::<ForeignIdData>(), self.pos_idx())
19431943
}
19441944
DataTag::SealingKey => {
1945-
Self::encode(self.decode::<SealingKeyData>().clone(), self.pos_idx())
1945+
Self::encode(*self.decode::<SealingKeyData>(), self.pos_idx())
19461946
}
19471947
DataTag::CustomContract => {
19481948
Self::encode(self.decode::<CustomContractData>().clone(), self.pos_idx())
@@ -2244,16 +2244,14 @@ impl Container<&ArrayData> {
22442244
pub fn iter(&self) -> impl Iterator<Item = &NickelValue> {
22452245
self.into_opt()
22462246
.into_iter()
2247-
.map(|array_data| array_data.array.iter())
2248-
.flatten()
2247+
.flat_map(|array_data| array_data.array.iter())
22492248
}
22502249

22512250
/// Iterates over the pending contracts.
22522251
pub fn iter_pending_contracts(&self) -> impl Iterator<Item = &RuntimeContract> {
22532252
self.into_opt()
22542253
.into_iter()
2255-
.map(|array_data| array_data.pending_contracts.iter())
2256-
.flatten()
2254+
.flat_map(|array_data| array_data.pending_contracts.iter())
22572255
}
22582256

22592257
/// Retrieves an element from the underlying array at the given index, or returns `None` if `self`

core/src/cache.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use crate::{
1616
},
1717
closurize::Closurize as _,
1818
error::{Error, ImportError, ParseError, ParseErrors, TypecheckError},
19-
eval::Closure,
2019
eval::cache::Cache as EvalCache,
2120
files::{FileId, Files},
2221
identifier::LocIdent,
@@ -26,10 +25,10 @@ use crate::{
2625
position::{PosTable, TermPos},
2726
program::FieldPath,
2827
stdlib::{self as nickel_stdlib, StdlibModule},
29-
term::{self, Term},
28+
term::{self},
3029
transform::{Wildcards, import_resolution},
3130
traverse::{Traverse, TraverseOrder},
32-
typ::{self as mainline_typ, UnboundTypeVariableError},
31+
typ::UnboundTypeVariableError,
3332
typecheck::{self, HasApparentType, TypecheckMode, typecheck},
3433
{eval, parser, transform},
3534
};
@@ -612,7 +611,7 @@ impl SourceCache {
612611
.map(|v| v.with_pos_idx(pos_idx))
613612
.map_err(|err| ParseError::from_serde_json(err, file_id, &self.files))
614613
}
615-
InputFormat::Text => Ok(NickelValue::string(source, pos_idx).into()),
614+
InputFormat::Text => Ok(NickelValue::string(source, pos_idx)),
616615
}
617616
}
618617

@@ -2922,15 +2921,15 @@ mod ast_cache {
29222921
let ast = term.to_ast(slf.alloc, pos_table);
29232922
let mut resolver = AstResolver::new(slf.alloc, slf.asts, slice.reborrow());
29242923

2925-
let ret = typecheck::env_add_term(
2924+
2925+
typecheck::env_add_term(
29262926
slf.alloc,
29272927
&mut slf.type_ctxt.type_env,
29282928
ast,
29292929
&slf.type_ctxt.term_env,
29302930
&mut resolver,
29312931
)
2932-
.map_err(|_| NotARecord);
2933-
ret
2932+
.map_err(|_| NotARecord)
29342933
})
29352934
}
29362935
}

core/src/error/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1496,7 +1496,7 @@ impl IntoDiagnostics for EvalError {
14961496
notes.push("Values of different types can't be merged".to_owned());
14971497
}
14981498
"String" | "Number" | "Bool" | "Array" | "EnumTag" => {
1499-
push_merge_note(&mut notes, &left_ty);
1499+
push_merge_note(&mut notes, left_ty);
15001500
}
15011501
"Function" | "MatchExpression" => {
15021502
notes.push(
@@ -1945,7 +1945,7 @@ mod blame_error {
19451945
(TermPos::Inherited(ref val_pos), Some(arg_pos)) if val_pos == arg_pos => {
19461946
evaluated_arg = evaluated_arg.with_pos_idx(PosIdx::NONE);
19471947
labels.push(
1948-
secondary_term(&pos_table, &evaluated_arg, files)
1948+
secondary_term(pos_table, &evaluated_arg, files)
19491949
.with_message("evaluated to this value"),
19501950
);
19511951
}
@@ -1959,12 +1959,12 @@ mod blame_error {
19591959

19601960
evaluated_arg = evaluated_arg.with_pos_idx(PosIdx::NONE);
19611961
labels.push(
1962-
secondary_term(&pos_table, &evaluated_arg, files)
1962+
secondary_term(pos_table, &evaluated_arg, files)
19631963
.with_message("evaluated to this value"),
19641964
);
19651965
}
19661966
(TermPos::None, _) => labels.push(
1967-
secondary_term(&pos_table, &evaluated_arg, files)
1967+
secondary_term(pos_table, &evaluated_arg, files)
19681968
.with_message("evaluated to this value"),
19691969
),
19701970
}

core/src/eval/contract_eq.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ fn contract_eq_bounded(
123123
// Test for physical equality as both an optimization and a way to cheaply equate complex
124124
// contracts that happen to point to the same definition (while the purposely limited
125125
// structural checks below may reject the equality)
126-
if t1.phys_eq(&t2) && Environment::ptr_eq(env1, env2) {
126+
if t1.phys_eq(t2) && Environment::ptr_eq(env1, env2) {
127127
return true;
128128
}
129129

core/src/eval/fixpoint.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
//! Compute the fixpoint of a recursive record.
22
use super::{merge::RevertClosurize, *};
3-
use crate::{
4-
position::{PosIdx, PosTable, TermPos},
5-
};
3+
use crate::position::PosIdx;
64

75
/// Updates the environment of an expression by extending it with a recursive environment. In the
86
/// general case, the expression is expected to be a variable pointing to the element to be patched.

core/src/eval/mod.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
use crate::{
7777
bytecode::value::{
7878
Container, EnumVariantData, NickelValue, ValueContent,
79-
ValueContentRef, ValueContentRefMut, lens::TermContent,
79+
ValueContentRef, ValueContentRefMut,
8080
},
8181
cache::{CacheHub as ImportCaches, ImportResolver},
8282
closurize::{Closurize, closurize_rec_record},
@@ -85,7 +85,7 @@ use crate::{
8585
files::{FileId, Files},
8686
identifier::{Ident, LocIdent},
8787
metrics::{increment, measure_runtime},
88-
position::{PosIdx, PosTable, TermPos},
88+
position::{PosIdx, PosTable},
8989
program::FieldPath,
9090
term::{
9191
BinaryOp, BindingType, Import, LetAttrs, MatchBranch, MatchData, RecordOpKind,
@@ -823,7 +823,7 @@ impl<'ctxt, R: ImportResolver, C: Cache> VirtualMachine<'ctxt, R, C> {
823823
ValueContentRef::Term(Term::OpN(op, args)) => {
824824
// Arguments are passed as a stack to the operation continuation, so we reverse
825825
// the original list.
826-
let mut args_iter = args.into_iter();
826+
let mut args_iter = args.iter();
827827
let fst_arg = args_iter.next().ok_or_else(|| {
828828
EvalErrorData::NotEnoughArgs(op.arity(), op.to_string(), pos_idx)
829829
})?;
@@ -1518,7 +1518,6 @@ pub fn subst<C: Cache>(
15181518
};
15191519

15201520
let array = array_data.array.into_iter()
1521-
.into_iter()
15221521
.map(|t| subst(pos_table, cache, t, initial_env, env))
15231522
.collect();
15241523

core/src/eval/operation.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,19 @@ use crate::nix_ffi;
2020

2121
use crate::{
2222
bytecode::value::{
23-
Array, ArrayData, Container, EnumVariantData, InlineValue, NickelValue, TypeData,
23+
Array, ArrayData, Container, EnumVariantData, NickelValue, TypeData,
2424
ValueContent, ValueContentRef, ValueContentRefMut,
2525
},
2626
cache::InputFormat,
2727
closurize::Closurize,
2828
combine::Combine,
29-
error::{EvalCtxt, EvalError, EvalErrorData, IllegalPolymorphicTailAction, Warning},
29+
error::{EvalErrorData, IllegalPolymorphicTailAction, Warning},
3030
identifier::LocIdent,
3131
label::{Polarity, TypeVarData, ty_path},
3232
metrics::increment,
3333
mk_app, mk_fun, mk_record,
3434
parser::utils::parse_number_sci,
35-
position::{PosIdx, PosTable, TermPos},
35+
position::{PosIdx, PosTable},
3636
serialize::{self, ExportFormat},
3737
stdlib::internals,
3838
term::{make as mk_term, record::*, string::NickelString, *},
@@ -102,7 +102,7 @@ pub enum OperationCont {
102102

103103
/// A string represention of the type of the first argument of serialization-related primitive
104104
/// operations. This is a Nickel enum of the supported serialization formats.
105-
static ENUM_FORMAT: &'static str = "[| 'Json, 'Yaml, 'Toml |]";
105+
static ENUM_FORMAT: &str = "[| 'Json, 'Yaml, 'Toml |]";
106106

107107
impl std::fmt::Debug for OperationCont {
108108
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
@@ -315,7 +315,7 @@ impl<'ctxt, R: ImportResolver, C: Cache> VirtualMachine<'ctxt, R, C> {
315315
// _ => mk_type_error!("Label"),
316316
// }),
317317
UnaryOp::EnumEmbed(_id) => {
318-
if let Some(_) = value.as_enum_variant() {
318+
if value.as_enum_variant().is_some() {
319319
Ok(value.with_pos_idx(pos_op_inh).into())
320320
} else {
321321
mk_type_error!("Enum")
@@ -729,13 +729,13 @@ impl<'ctxt, R: ImportResolver, C: Cache> VirtualMachine<'ctxt, R, C> {
729729
ValueContentRef::Array(Container::Alloc(array_data)) => {
730730
let terms = seq_terms(
731731
array_data.array.iter().map(|t| {
732-
let t_with_ctr = RuntimeContract::apply_all(
732+
733+
RuntimeContract::apply_all(
733734
t.clone(),
734735
array_data.pending_contracts.iter().cloned(),
735736
pos.to_inherited(&mut self.context.pos_table),
736737
)
737-
.closurize(&mut self.context.cache, env.clone());
738-
t_with_ctr
738+
.closurize(&mut self.context.cache, env.clone())
739739
}),
740740
pos_op,
741741
);
@@ -1130,7 +1130,7 @@ impl<'ctxt, R: ImportResolver, C: Cache> VirtualMachine<'ctxt, R, C> {
11301130
})
11311131
} else {
11321132
Ok(Closure {
1133-
value: NickelValue::enum_tag(tag, pos_op_inh).into(),
1133+
value: NickelValue::enum_tag(tag, pos_op_inh),
11341134
env,
11351135
})
11361136
}
@@ -1237,7 +1237,7 @@ impl<'ctxt, R: ImportResolver, C: Cache> VirtualMachine<'ctxt, R, C> {
12371237
}
12381238
UnaryOp::Trace => {
12391239
if let Some(s) = value.as_string() {
1240-
let _ = writeln!(self.context.trace, "std.trace: {}", s);
1240+
let _ = writeln!(self.context.trace, "std.trace: {s}");
12411241
Ok(())
12421242
} else {
12431243
mk_type_error!("String")
@@ -1312,7 +1312,7 @@ impl<'ctxt, R: ImportResolver, C: Cache> VirtualMachine<'ctxt, R, C> {
13121312
let arg = NickelValue::thunk(Thunk::new(arg_clos), arg_pos);
13131313

13141314
Ok(NickelValue::enum_variant(
1315-
LocIdent::new(&tag).with_pos(self.context.pos_table.get(pos)),
1315+
LocIdent::new(tag).with_pos(self.context.pos_table.get(pos)),
13161316
Some(arg),
13171317
pos_op_inh,
13181318
)
@@ -1327,7 +1327,7 @@ impl<'ctxt, R: ImportResolver, C: Cache> VirtualMachine<'ctxt, R, C> {
13271327
UnaryOp::EnumIsVariant => Ok(NickelValue::bool_value(
13281328
value
13291329
.as_enum_variant()
1330-
.map_or(false, |enum_variant| enum_variant.arg.is_some()),
1330+
.is_some_and(|enum_variant| enum_variant.arg.is_some()),
13311331
pos_op_inh,
13321332
)
13331333
.into()),
@@ -1452,7 +1452,7 @@ impl<'ctxt, R: ImportResolver, C: Cache> VirtualMachine<'ctxt, R, C> {
14521452
}
14531453
// The stack should already contain the default label to attach, so push
14541454
// the (potential) error data.
1455-
self.stack.push_arg(Closure { value: value, env }, pos_arg);
1455+
self.stack.push_arg(Closure { value, env }, pos_arg);
14561456

14571457
Ok(Closure {
14581458
value: internals::add_default_check_label(),
@@ -1770,7 +1770,7 @@ impl<'ctxt, R: ImportResolver, C: Cache> VirtualMachine<'ctxt, R, C> {
17701770
return mk_type_error!("String", 2, value2);
17711771
};
17721772

1773-
Ok(NickelValue::string(format!("{}{}", s1, s2), pos_op_inh).into())
1773+
Ok(NickelValue::string(format!("{s1}{s2}"), pos_op_inh).into())
17741774
}
17751775
BinaryOp::ContractApply | BinaryOp::ContractCheck => {
17761776
// Performing only one match `if let Term::Type` and putting the call to
@@ -2340,7 +2340,7 @@ impl<'ctxt, R: ImportResolver, C: Cache> VirtualMachine<'ctxt, R, C> {
23402340
)
23412341
{
23422342
match record.sealed_tail.as_ref() {
2343-
Some(t) if t.has_dyn_field(&id) => {
2343+
Some(t) if t.has_dyn_field(id) => {
23442344
Err(EvalErrorData::IllegalPolymorphicTailAccess {
23452345
action: IllegalPolymorphicTailAction::FieldRemove {
23462346
field: id.to_string(),
@@ -2948,19 +2948,19 @@ impl<'ctxt, R: ImportResolver, C: Cache> VirtualMachine<'ctxt, R, C> {
29482948
fields: IndexMap::from([
29492949
(
29502950
LocIdent::from("left_only"),
2951-
Field::from(NickelValue::from(left_only)),
2951+
Field::from(left_only),
29522952
),
29532953
(
29542954
LocIdent::from("left_center"),
2955-
Field::from(NickelValue::from(left_center)),
2955+
Field::from(left_center),
29562956
),
29572957
(
29582958
LocIdent::from("right_center"),
2959-
Field::from(NickelValue::from(right_center)),
2959+
Field::from(right_center),
29602960
),
29612961
(
29622962
LocIdent::from("right_only"),
2963-
Field::from(NickelValue::from(right_only)),
2963+
Field::from(right_only),
29642964
),
29652965
]),
29662966
attrs: RecordAttrs::default(),
@@ -3180,7 +3180,7 @@ impl<'ctxt, R: ImportResolver, C: Cache> VirtualMachine<'ctxt, R, C> {
31803180
expected: expected.to_owned(),
31813181
arg_number,
31823182
pos_arg,
3183-
arg_evaluated: arg_evaluated,
3183+
arg_evaluated,
31843184
pos_op,
31853185
})
31863186
};

core/src/eval/stack.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ impl<C: Cache> std::fmt::Debug for Stack<C> {
351351
mod tests {
352352
use super::*;
353353
use crate::eval::cache::CacheImpl;
354-
use crate::term::{Term, UnaryOp};
354+
use crate::term::UnaryOp;
355355
use assert_matches::assert_matches;
356356

357357
impl Stack<CacheImpl> {

0 commit comments

Comments
 (0)