Skip to content

Commit cb4716e

Browse files
committed
chore: make clippy more annoying
1 parent c4ff7a0 commit cb4716e

16 files changed

Lines changed: 106 additions & 100 deletions

File tree

Cargo.toml

Lines changed: 47 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -86,48 +86,54 @@ unexpected_cfgs = { level = "warn", check-cfg = [
8686
unused_qualifications = "warn"
8787

8888
[workspace.lints.clippy]
89-
# The counts were generated with this command:
90-
# cargo clippy --all-targets --workspace --message-format=json --quiet \
91-
# | jq -r '.message.code.code | select(. != null and startswith("clippy::"))' \
92-
# | sort | uniq -c | sort -h -r
93-
#
89+
# Groups
9490
all = { level = "warn", priority = -1 }
9591
cargo = { level = "warn", priority = -1 }
9692
pedantic = { level = "warn", priority = -1 }
97-
print_stdout = "warn" # restriction: forbid print/println macros
98-
print_stderr = "warn" # restriction: forbid eprint/eprintln macros
99-
use_self = "warn" # nursery lint
100-
cargo_common_metadata = "allow" # 3240
101-
multiple_crate_versions = "allow" # 2882
102-
missing_errors_doc = "allow" # 1572
103-
missing_panics_doc = "allow" # 946
104-
must_use_candidate = "allow" # 322
105-
match_same_arms = "allow" # 204
106-
cast_possible_truncation = "allow" # 122
107-
too_many_lines = "allow" # 101
108-
cast_possible_wrap = "allow" # 78
109-
cast_sign_loss = "allow" # 70
110-
struct_excessive_bools = "allow" # 68
111-
cast_precision_loss = "allow" # 52
112-
cast_lossless = "allow" # 35
113-
ignored_unit_patterns = "allow" # 21
114-
similar_names = "allow" # 20
115-
needless_pass_by_value = "allow" # 16
116-
float_cmp = "allow" # 12
117-
items_after_statements = "allow" # 11
118-
return_self_not_must_use = "allow" # 8
119-
inline_always = "allow" # 6
120-
fn_params_excessive_bools = "allow" # 6
121-
used_underscore_items = "allow" # 2
122-
should_panic_without_expect = "allow" # 2
123-
124-
doc_markdown = "allow"
125-
unused_self = "allow"
126-
enum_glob_use = "allow"
127-
unnested_or_patterns = "allow"
128-
implicit_hasher = "allow"
129-
doc_link_with_quotes = "allow"
93+
perf = { level = "warn", priority = -1 }
94+
95+
# Restrictions
96+
print_stderr = "warn"
97+
print_stdout = "warn"
98+
99+
# Casts; TODO: replace with fancy std methods when available
100+
cast_lossless = "allow"
101+
cast_possible_truncation = "allow"
102+
cast_possible_wrap = "allow"
103+
cast_precision_loss = "allow"
104+
cast_sign_loss = "allow"
105+
106+
# Others (mostly, curated nursery lints)
107+
assigning_clones = "warn"
108+
branches_sharing_code = "warn"
109+
fallible_impl_from = "warn"
110+
imprecise_flops = "warn"
111+
iter_on_empty_collections = "warn"
112+
iter_on_single_items = "warn"
113+
large_stack_frames = "warn"
114+
missing_const_for_fn = "warn"
115+
needless_collect = "warn"
116+
set_contains_or_insert = "warn"
117+
use_self = "warn"
118+
useless_let_if_seq = "warn"
119+
120+
# Shut up
121+
cargo_common_metadata = "allow"
122+
fn_params_excessive_bools = "allow"
130123
format_push_string = "allow"
131-
flat_map_option = "allow"
132-
from_iter_instead_of_collect = "allow"
133-
large_types_passed_by_value = "allow"
124+
ignored_unit_patterns = "allow"
125+
inline_always = "allow"
126+
items_after_statements = "allow"
127+
match_same_arms = "allow"
128+
missing_errors_doc = "allow"
129+
missing_panics_doc = "allow"
130+
multiple_crate_versions = "allow"
131+
must_use_candidate = "allow"
132+
needless_pass_by_value = "allow"
133+
return_self_not_must_use = "allow"
134+
should_panic_without_expect = "allow"
135+
struct_excessive_bools = "allow"
136+
too_many_lines = "allow"
137+
undocumented_unsafe_blocks = "allow"
138+
unnested_or_patterns = "allow"
139+
unused_self = "allow"

interpreter/src/builtins.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub(crate) enum BuiltinError {
3232
}
3333

3434
impl BuiltinError {
35-
pub(crate) fn into_interpreter_error(self, span: AriadneSpan) -> InterpreterError {
35+
pub(crate) const fn into_interpreter_error(self, span: AriadneSpan) -> InterpreterError {
3636
match self {
3737
Self::Arity { expected, given } => {
3838
InterpreterError::ArityMismatch(span, expected, given)
@@ -123,7 +123,7 @@ impl<'a> Interpreter<'a> {
123123
}
124124
}
125125

126-
fn require_args<'a, 'b>(
126+
const fn require_args<'a, 'b>(
127127
args: &'b [Value<'a>],
128128
min: u8,
129129
max: u8,

interpreter/src/ir.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ impl Instruction {
165165
}
166166
}
167167

168-
fn br(condition: Reg, then_label: Label) -> Self {
168+
const fn br(condition: Reg, then_label: Label) -> Self {
169169
Self::Branch { then_label, else_label: Label(0), condition }
170170
}
171171

@@ -375,7 +375,7 @@ impl Display for Instruction {
375375
}
376376

377377
impl Instruction {
378-
fn display_name(self) -> &'static str {
378+
const fn display_name(self) -> &'static str {
379379
match self {
380380
Self::LoadF { .. } => "fload",
381381
Self::Negation { .. } => "not",

interpreter/src/ir/lower.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ impl<'a> CodeGen<'a> {
186186
Statement::If { condition, then_body, else_body, metadata } => {
187187
self.with_metadata(*metadata, |this| {
188188
let state = this.regs.clone();
189-
let (if_label, _) =
189+
let (if_label, ()) =
190190
this.emit_branch(condition, |this| this.lower_body(then_body));
191191

192192
if let Some(else_body) = else_body {
@@ -831,7 +831,7 @@ impl<'a> CodeGen<'a> {
831831
}
832832

833833
fn lower_and_into(&mut self, lhs: &Expr<'_>, rhs: &Expr<'_>, dest: Reg) {
834-
let (if_label, _) = self.emit_branch(lhs, |this| {
834+
let (if_label, ()) = self.emit_branch(lhs, |this| {
835835
this.scoped_reg(|this, rhs_reg| {
836836
this.lower_expr_into(rhs, rhs_reg);
837837
this.truthify(dest, rhs_reg);
@@ -845,7 +845,7 @@ impl<'a> CodeGen<'a> {
845845
}
846846

847847
fn lower_or_into(&mut self, lhs: &Expr<'_>, rhs: &Expr<'_>, dest: Reg) {
848-
let (if_label, _) = self.emit_branch(lhs, |this| {
848+
let (if_label, ()) = self.emit_branch(lhs, |this| {
849849
let (arg, ty) = TypedArg::new_imm(1).into_arg();
850850
this.emit(Instruction::CopyP { dest, arg, ty });
851851
});
@@ -1015,33 +1015,33 @@ impl<'a> Bytecode<'a> {
10151015
&mut self.code[label.0 as usize]
10161016
}
10171017

1018-
pub fn begin_code(&self) -> CodeRange {
1018+
pub const fn begin_code(&self) -> CodeRange {
10191019
CodeRange(self.begin_label.0..self.begin_file_label.0)
10201020
}
10211021

1022-
pub fn begin_file_code(&self) -> CodeRange {
1022+
pub const fn begin_file_code(&self) -> CodeRange {
10231023
CodeRange(self.begin_file_label.0..self.end_file_label.0)
10241024
}
10251025

1026-
pub fn end_file_code(&self) -> CodeRange {
1026+
pub const fn end_file_code(&self) -> CodeRange {
10271027
CodeRange(self.end_file_label.0..self.end_label.0)
10281028
}
10291029

1030-
pub fn end_code(&self) -> CodeRange {
1030+
pub const fn end_code(&self) -> CodeRange {
10311031
CodeRange(self.end_label.0..self.rules_label.0)
10321032
}
10331033

10341034
pub fn rules_code(&self) -> CodeRange {
10351035
CodeRange(self.rules_label.0..self.len())
10361036
}
10371037

1038-
pub fn funs_code(&self) -> CodeRange {
1038+
pub const fn funs_code(&self) -> CodeRange {
10391039
CodeRange(self.funs_label.0..self.begin_label.0)
10401040
}
10411041
}
10421042

10431043
impl Instruction {
1044-
pub(super) fn from_unary(op: UnaryOperator, dest: Reg, arg: TypedArg) -> Self {
1044+
pub(super) const fn from_unary(op: UnaryOperator, dest: Reg, arg: TypedArg) -> Self {
10451045
let (arg, ty) = arg.into_arg();
10461046
match op {
10471047
UnaryOperator::Record => Self::LoadF { dest, arg, ty },
@@ -1076,7 +1076,7 @@ impl Instruction {
10761076
}
10771077
}
10781078

1079-
fn lower_assign_ops(op: BinaryPlaceOperator) -> Option<BinaryOperator> {
1079+
const fn lower_assign_ops(op: BinaryPlaceOperator) -> Option<BinaryOperator> {
10801080
match op {
10811081
BinaryPlaceOperator::Assignment => None,
10821082
BinaryPlaceOperator::AddAssign => Some(BinaryOperator::Add),

interpreter/src/ir/lower/utils.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pub enum Operand {
4343
}
4444

4545
impl LinearReg {
46-
pub fn into_inner(self) -> Reg {
46+
pub const fn into_inner(self) -> Reg {
4747
let inner = self.0;
4848
forget(self);
4949
inner
@@ -74,7 +74,7 @@ impl TypedArg {
7474
TypedPlace::new_is(var).into()
7575
}
7676

77-
pub fn new_imm(imm: i32) -> Self {
77+
pub const fn new_imm(imm: i32) -> Self {
7878
Self(Arg { imm }, ArgTy::Imm)
7979
}
8080

@@ -92,7 +92,7 @@ impl TypedArg {
9292
TypedPlace::new_reg(reg).into()
9393
}
9494

95-
pub fn as_reg(self) -> Option<Reg> {
95+
pub const fn as_reg(self) -> Option<Reg> {
9696
if matches!(self.1, ArgTy::Reg) {
9797
// SAFETY: has been type-checked.
9898
Some(unsafe { self.0.reg })
@@ -262,7 +262,7 @@ impl From<Reg> for LinearReg {
262262

263263
impl TypedArg {
264264
#[inline(always)]
265-
pub fn into_arg(self) -> (Arg, ArgTy) {
265+
pub const fn into_arg(self) -> (Arg, ArgTy) {
266266
(self.0, self.1)
267267
}
268268
}
@@ -274,7 +274,7 @@ impl TypedPlace {
274274
}
275275

276276
#[inline(always)]
277-
pub fn into_place(self) -> (Arg, PlaceTy) {
277+
pub const fn into_place(self) -> (Arg, PlaceTy) {
278278
(self.0, self.1)
279279
}
280280
}

interpreter/src/vm.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ pub struct Consts<'a>(pub(crate) Vec<'a, Value<'a>>);
100100
#[derive(Debug, Clone)]
101101
pub struct CodeRange(pub(crate) Range<IxWidth>);
102102

103-
/// Newtype of (Arg, PlaceTy).
103+
/// Newtype of `(Arg, PlaceTy)`.
104104
#[derive(Clone, Copy)]
105105
struct Place {
106106
arg: Arg,
@@ -296,7 +296,7 @@ impl<'a> Interpreter<'a> {
296296
}
297297
Instruction::LoadA { dest, arg, start, end, ty } => {
298298
let key = self.make_array_key(start, end);
299-
let val = self.array_elem_get(Place::new(arg, ty), key, metadata)?;
299+
let val = self.array_elem_get(Place::new(arg, ty), &key, metadata)?;
300300

301301
self.write_reg(dest, val);
302302
}
@@ -344,13 +344,13 @@ impl<'a> Interpreter<'a> {
344344
}
345345
Instruction::In { dest, lhs, rhs, tyr, tyl } => {
346346
let key = self.get_val(rhs, tyr, metadata, Value::to_string)?;
347-
let val = self.has_array_elem(Place::new(lhs, tyl), key, metadata)?;
347+
let val = self.has_array_elem(Place::new(lhs, tyl), &key, metadata)?;
348348

349349
self.write_reg(dest, val);
350350
}
351351
Instruction::InA { dest, arg, start, end, ty } => {
352352
let key = self.make_array_key(start, end);
353-
let val = self.has_array_elem(Place::new(arg, ty), key, metadata)?;
353+
let val = self.has_array_elem(Place::new(arg, ty), &key, metadata)?;
354354

355355
self.write_reg(dest, val);
356356
}
@@ -459,7 +459,7 @@ impl<'a> Interpreter<'a> {
459459
fn array_elem_get(
460460
&mut self,
461461
place: Place,
462-
key: String,
462+
key: &str,
463463
metadata: &[MetaId],
464464
) -> Result<Value<'a>> {
465465
place
@@ -493,7 +493,7 @@ impl<'a> Interpreter<'a> {
493493
.ok_or_else(|| InterpreterError::ArrayUseOfScalar(self.get_span(metadata)))
494494
}
495495

496-
fn has_array_elem(&mut self, place: Place, key: String, metadata: &[MetaId]) -> Result<bool> {
496+
fn has_array_elem(&mut self, place: Place, key: &str, metadata: &[MetaId]) -> Result<bool> {
497497
place
498498
.array(self)
499499
.and_then(|arr| arr.has_array_elem(key))
@@ -665,7 +665,7 @@ impl<'a> Registers<'a> {
665665
}
666666
}
667667
#[inline(always)]
668-
fn index_of(reg: Reg, offset: IxWidth) -> usize {
668+
const fn index_of(reg: Reg, offset: IxWidth) -> usize {
669669
reg.0 as usize + offset as usize
670670
}
671671
#[inline(always)]
@@ -803,7 +803,7 @@ impl Arg {
803803

804804
impl Place {
805805
#[inline(always)]
806-
fn new(arg: Arg, ty: PlaceTy) -> Self {
806+
const fn new(arg: Arg, ty: PlaceTy) -> Self {
807807
Self { arg, ty }
808808
}
809809

interpreter/src/vm/symbols.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ impl Record {
293293
let len = self.raw.len();
294294
let buf = self.fields.get_or_insert_default();
295295
buf.clear();
296-
buf.push(Span::from(0..self.raw.len())); // $0
296+
buf.push(Span::from(0..len)); // $0
297297

298298
// Aren't iterators beautiful?
299299
regex::automaton(symbols.fs.to_string().as_bytes(), mode, false)?
@@ -351,7 +351,7 @@ impl Record {
351351
self.write_record_raw(val);
352352
Ok(())
353353
} else {
354-
self.write_field_raw(val, n, symbols, mode)
354+
self.write_field_raw(&val, n, symbols, mode)
355355
}
356356
}
357357

@@ -365,7 +365,7 @@ impl Record {
365365
/// the public function for more details.
366366
fn write_field_raw(
367367
&mut self,
368-
val: Value<'_>,
368+
val: &Value<'_>,
369369
n: usize,
370370
symbols: &mut SymbolTable<'_>,
371371
mode: ExecMode,

interpreter/src/vm/types.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use hashbrown::HashMap;
2121
use crate::{ExecMode, vm::regex};
2222

2323
#[inline(always)]
24-
fn likely(b: bool) -> bool {
24+
const fn likely(b: bool) -> bool {
2525
if !b {
2626
cold_path();
2727
}
@@ -128,13 +128,13 @@ impl<'a> Value<'a> {
128128
Some(())
129129
}
130130

131-
pub fn get_array_elem(&mut self, key: String) -> Option<Self> {
131+
pub fn get_array_elem(&mut self, key: &str) -> Option<Self> {
132132
self.as_array()
133-
.map(|arr| arr.borrow().get(&key).cloned().unwrap_or(Self::Untyped))
133+
.map(|arr| arr.borrow().get(key).cloned().unwrap_or(Self::Untyped))
134134
}
135135

136-
pub fn has_array_elem(&mut self, key: String) -> Option<bool> {
137-
self.as_array().map(|arr| arr.borrow().get(&key).is_some())
136+
pub fn has_array_elem(&mut self, key: &str) -> Option<bool> {
137+
self.as_array().map(|arr| arr.borrow().get(key).is_some())
138138
}
139139

140140
pub fn array_elem_mdim(&mut self, key: String) -> Option<Self> {

lexer/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -647,11 +647,11 @@ impl<'a> Identifier<'a> {
647647
}
648648
}
649649

650-
fn accept_expression(lex: &mut Lexer<'_>) {
650+
const fn accept_expression(lex: &mut Lexer<'_>) {
651651
lex.extras.ctx = Context::AcceptExpression;
652652
}
653653

654-
fn accept_operator(lex: &mut Lexer<'_>) {
654+
const fn accept_operator(lex: &mut Lexer<'_>) {
655655
lex.extras.ctx = Context::AcceptOperator;
656656
}
657657

@@ -733,7 +733,7 @@ impl Ord for Slice<'_> {
733733
}
734734

735735
impl Extra {
736-
fn arena<'a>(&self) -> &'a Bump {
736+
const fn arena<'a>(&self) -> &'a Bump {
737737
// SAFETY: lives for as long as self because it's the same lifetime as
738738
// the source being lexed; Logos just can't take lifetimes on extras.
739739
unsafe { self.arena.as_ref() }

0 commit comments

Comments
 (0)