Skip to content

Commit d68c177

Browse files
committed
lint: fix clippy::return_self_not_must_use
1 parent 475f554 commit d68c177

File tree

15 files changed

+63
-1
lines changed

15 files changed

+63
-1
lines changed

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ inline_always = "allow" # TODO: benchmark inlines
2121
missing_panics_doc = "allow" # TODO
2222
similar_names = "allow" # 26
2323
float_cmp = "allow" # 41
24-
return_self_not_must_use = "allow" # 63
2524
needless_pass_by_value = "allow" # 70
2625
redundant_closure_for_method_calls = "allow" # 76
2726
items_after_statements = "allow" # 81

parser/src/ast.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -857,6 +857,7 @@ impl From<Result<Complex, String>> for NumWord {
857857

858858
impl NumWord {
859859
/// Map the number
860+
#[must_use]
860861
pub fn map<R, C>(self, real: impl FnOnce(f64) -> R, complex: impl FnOnce(Complex) -> C) -> Self
861862
where
862863
C: Into<Self>,
@@ -869,6 +870,7 @@ impl NumWord {
869870
}
870871
}
871872
/// Map the number with another
873+
#[must_use]
872874
pub fn map_with<R, C>(
873875
self,
874876
other: Self,

parser/src/complex.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ impl Complex {
4848
Self { re, im }
4949
}
5050
/// Get the minimum of the real and imaginary parts of two complex numbers, ignoring NaN
51+
#[must_use]
5152
pub fn min(self, rhs: impl Into<Self>) -> Self {
5253
let rhs = rhs.into();
5354
Self {
@@ -56,6 +57,7 @@ impl Complex {
5657
}
5758
}
5859
/// Get the maximum of the real and imaginary parts of two complex numbers, ignoring NaN
60+
#[must_use]
5961
pub fn max(self, rhs: impl Into<Self>) -> Self {
6062
let rhs = rhs.into();
6163
Self {
@@ -64,20 +66,23 @@ impl Complex {
6466
}
6567
}
6668
/// Get the floor of the real and imaginary parts of a complex number
69+
#[must_use]
6770
pub fn floor(self) -> Self {
6871
Self {
6972
re: self.re.floor(),
7073
im: self.im.floor(),
7174
}
7275
}
7376
/// Get the ceiling of the real and imaginary parts of a complex number
77+
#[must_use]
7478
pub fn ceil(self) -> Self {
7579
Self {
7680
re: self.re.ceil(),
7781
im: self.im.ceil(),
7882
}
7983
}
8084
/// Round the real and imaginary parts of a complex number
85+
#[must_use]
8186
pub fn round(self) -> Self {
8287
Self {
8388
re: self.re.round(),
@@ -90,12 +95,14 @@ impl Complex {
9095
(self.re * self.re + self.im * self.im).sqrt()
9196
}
9297
/// Get the arctangent of a complex number
98+
#[must_use]
9399
pub fn atan2(self, x: impl Into<Self>) -> Complex {
94100
let y = self;
95101
let x = x.into();
96102
-Complex::I * ((x + Complex::I * y) / (y * y + x * x).sqrt()).ln()
97103
}
98104
/// Normalize a complex number
105+
#[must_use]
99106
pub fn normalize(self) -> Self {
100107
let len = self.abs();
101108
if len == 0.0 {
@@ -117,6 +124,7 @@ impl Complex {
117124
r * Self::new(theta.cos(), theta.sin())
118125
}
119126
/// Raise a complex number to a complex power
127+
#[must_use]
120128
pub fn powc(self, power: impl Into<Self>) -> Self {
121129
let power = power.into();
122130
if power.im == 0.0 {
@@ -126,6 +134,7 @@ impl Complex {
126134
((r.ln() + Self::I * theta) * power).exp()
127135
}
128136
/// Raise a complex number to a real power
137+
#[must_use]
129138
pub fn powf(self, power: f64) -> Self {
130139
if power == 0.0 {
131140
return Self::ONE;
@@ -137,20 +146,24 @@ impl Complex {
137146
Self::from_polar(r.powf(power), theta * power)
138147
}
139148
/// Calculate the exponential of a complex number
149+
#[must_use]
140150
pub fn exp(self) -> Self {
141151
Self::from_polar(E.powf(self.re), self.im)
142152
}
143153
/// Calculate the natural logarithm of a complex number
154+
#[must_use]
144155
pub fn ln(self) -> Self {
145156
let (r, theta) = self.to_polar();
146157
Self::new(r.ln(), theta)
147158
}
148159
/// Calculate the logarithm of a complex number
160+
#[must_use]
149161
pub fn log(self, base: impl Into<Self>) -> Self {
150162
let base = base.into();
151163
Self::new(self.abs().ln(), self.arg()) / (Self::new(base.abs().ln(), base.arg()))
152164
}
153165
/// Calculate the square root of a complex number
166+
#[must_use]
154167
pub fn sqrt(self) -> Self {
155168
if self.im == 0.0 {
156169
return if self.re >= 0.0 {
@@ -163,24 +176,28 @@ impl Complex {
163176
Self::from_polar(r.sqrt(), theta / 2.0)
164177
}
165178
/// Calculate the sine of a complex number
179+
#[must_use]
166180
pub fn sin(self) -> Self {
167181
Self::new(
168182
self.re.sin() * self.im.cosh(),
169183
self.re.cos() * self.im.sinh(),
170184
)
171185
}
172186
/// Calculate the cosine of a complex number
187+
#[must_use]
173188
pub fn cos(self) -> Self {
174189
Self::new(
175190
self.re.cos() * self.im.cosh(),
176191
-self.re.sin() * self.im.sinh(),
177192
)
178193
}
179194
/// Calculate the arc sine of a complex number
195+
#[must_use]
180196
pub fn asin(self) -> Self {
181197
-Self::I * ((Self::ONE - self * self).sqrt() + Self::I * self).ln()
182198
}
183199
/// Calculate the arc cosine of a complex number
200+
#[must_use]
184201
pub fn acos(self) -> Self {
185202
-Self::I * (Self::I * (Self::ONE - self * self).sqrt() + self).ln()
186203
}
@@ -197,13 +214,15 @@ impl Complex {
197214
}
198215
}
199216
/// Multiply by another complex number, with 0 × ∞ = 0
217+
#[must_use]
200218
pub fn safe_mul(self, rhs: impl Into<Self>) -> Self {
201219
let rhs = rhs.into();
202220
Self {
203221
re: safe_mul(self.re, rhs.re) - safe_mul(self.im, rhs.im),
204222
im: safe_mul(self.re, rhs.im) + safe_mul(self.im, rhs.re),
205223
}
206224
}
225+
#[must_use]
207226
pub fn recip(self) -> Self {
208227
Self::ONE / self
209228
}

parser/src/error.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ impl Report {
139139
/// Change whether to color the report with ANSI escape codes when converting it to a string
140140
///
141141
/// Defaults to `true`
142+
#[must_use]
142143
pub fn color(mut self, color: bool) -> Self {
143144
self.color = color;
144145
self

parser/src/lex.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ impl Span {
168168
Sp { value, span: self }
169169
}
170170
/// Merge two spans
171+
#[must_use]
171172
pub fn merge(self, other: Self) -> Self {
172173
match (self, other) {
173174
(Span::Code(a), Span::Code(b)) => Span::Code(a.merge(b)),
@@ -396,6 +397,7 @@ impl CodeSpan {
396397
self.end.char_pos.saturating_sub(self.start.char_pos)
397398
}
398399
/// Merge two spans
400+
#[must_use]
399401
pub fn merge(mut self, end: Self) -> Self {
400402
self.merge_with(end);
401403
self
@@ -406,6 +408,7 @@ impl CodeSpan {
406408
self.end = self.end.max(end.end);
407409
}
408410
/// Get the span between this span and another after it
411+
#[must_use]
409412
pub fn end_to(self, other: &Self) -> Self {
410413
CodeSpan {
411414
start: self.end,
@@ -458,6 +461,7 @@ impl CodeSpan {
458461
inputs.try_get_with(&self.src, |input| f(&input[self.byte_range()]))
459462
}
460463
/// Get just the span of the first character
464+
#[must_use]
461465
pub fn just_start(&self, inputs: &Inputs) -> Self {
462466
let start = self.start;
463467
let mut end = self.start;
@@ -473,6 +477,7 @@ impl CodeSpan {
473477
}
474478
}
475479
/// Get just the span of the last character
480+
#[must_use]
476481
pub fn just_end(&self, inputs: &Inputs) -> Self {
477482
let end = self.end;
478483
let mut start = self.end;

parser/src/signature.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ impl Signature {
3939
}
4040
}
4141
/// Set the number of arguments and outputs of the under stack
42+
#[must_use]
4243
pub fn with_under(self, under_args: usize, under_outputs: usize) -> Self {
4344
Self {
4445
args: self.args,
@@ -108,6 +109,7 @@ impl Signature {
108109
self.is_compatible_with(other) && self.args <= other.args
109110
}
110111
/// Get the signature that has the maximum of the arguments and outputs of this signature and another
112+
#[must_use]
111113
pub fn max_with(self, other: Self) -> Self {
112114
Self::new(
113115
self.args().max(other.args()),
@@ -119,6 +121,7 @@ impl Signature {
119121
)
120122
}
121123
/// Compose signatures as if a function with signature `other` was called before a function with signature `self`
124+
#[must_use]
122125
pub fn compose(self, other: Self) -> Self {
123126
let args = other.args() + self.args().saturating_sub(other.outputs());
124127
let outputs = self.outputs() + other.outputs().saturating_sub(self.args());
@@ -129,6 +132,7 @@ impl Signature {
129132
Self::new(args, outputs).with_under(under_args, under_outputs)
130133
}
131134
/// Get the un-inverse of this signature
135+
#[must_use]
132136
pub fn inverse(self) -> Self {
133137
Self::new(self.outputs(), self.args())
134138
}
@@ -140,6 +144,7 @@ impl Signature {
140144
Some(Signature::new(self.outputs() + 1, self.args() - 1))
141145
}
142146
/// The signature on the under stack
147+
#[must_use]
143148
pub fn under(self) -> Signature {
144149
Signature::new(self.under_args(), self.under_outputs())
145150
}

src/algorithm/dyadic/combine.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ impl Value {
113113
///
114114
/// # Panics
115115
/// Panics if the arrays have incompatible shapes
116+
#[must_use]
116117
pub fn join_infallible(self, other: Self, allow_ext: bool) -> Self {
117118
self.join_impl(other, allow_ext, &()).unwrap()
118119
}
@@ -233,6 +234,7 @@ impl<T: ArrayValue> Array<T> {
233234
///
234235
/// # Panics
235236
/// Panics if the arrays have incompatible shapes
237+
#[must_use]
236238
pub fn join_infallible(self, other: Self, allow_ext: bool) -> Self {
237239
self.join_impl(other, allow_ext, &()).unwrap()
238240
}
@@ -767,6 +769,7 @@ impl Value {
767769
///
768770
/// # Panics
769771
/// Panics if the values have incompatible shapes
772+
#[must_use]
770773
pub fn couple_infallible(mut self, other: Self, allow_ext: bool) -> Self {
771774
self.couple_impl(other, allow_ext, &()).unwrap();
772775
self
@@ -833,6 +836,7 @@ impl<T: ArrayValue> Array<T> {
833836
///
834837
/// # Panics
835838
/// Panics if the arrays have incompatible shapes
839+
#[must_use]
836840
pub fn couple_infallible(mut self, other: Self, allow_ext: bool) -> Self {
837841
self.couple_impl(other, allow_ext, &()).unwrap();
838842
self

src/algorithm/monadic/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,6 +1333,7 @@ impl<T: ArrayValue> Array<T> {
13331333

13341334
impl Value {
13351335
/// `classify` the rows of the value
1336+
#[must_use]
13361337
pub fn classify(&self) -> Self {
13371338
if self.rank() == 0 {
13381339
return 0.into();
@@ -1360,6 +1361,7 @@ impl Value {
13601361
val_as_arr!(self, |a| a.deduplicate(env))
13611362
}
13621363
/// Mask the `unique` rows of the value
1364+
#[must_use]
13631365
pub fn unique(&self) -> Self {
13641366
val_as_arr!(self, Array::unique).into()
13651367
}

src/array.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ pub struct PersistentMeta {
321321

322322
impl PersistentMeta {
323323
/// XOR this metadata with another
324+
#[must_use]
324325
pub fn xor(self, other: Self) -> Self {
325326
Self {
326327
label: self.label.xor(other.label),
@@ -492,6 +493,7 @@ impl<T: Clone> Array<T> {
492493
}
493494
/// Get a row array
494495
#[track_caller]
496+
#[must_use]
495497
pub fn row(&self, row: usize) -> Self {
496498
if self.rank() == 0 {
497499
let mut row = self.clone();
@@ -633,6 +635,7 @@ impl<T: ArrayValue> Array<T> {
633635
/// - `start` must be <= `end`
634636
/// - `start` must be < `self.row_count()`
635637
/// - `end` must be <= `self.row_count()`
638+
#[must_use]
636639
pub fn slice_rows(&self, start: usize, end: usize) -> Self {
637640
assert!(start <= end);
638641
assert!(start < self.row_count());

src/compile/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ impl Compiler {
307307
}
308308
}
309309
/// Set the compiler's assembly
310+
#[must_use]
310311
pub fn with_assembly(self, asm: Assembly) -> Self {
311312
Self { asm, ..self }
312313
}

0 commit comments

Comments
 (0)