Skip to content

Commit 92c409f

Browse files
authored
add #[must_use] to several stub and example functions (#1437)
This fixes the new lint: https://rust-lang.github.io/rust-clippy/master/index.html#return_self_not_must_use
1 parent 976b688 commit 92c409f

File tree

8 files changed

+19
-0
lines changed

8 files changed

+19
-0
lines changed

exercises/practice/custom-set/.meta/example.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ impl<T: Ord + Clone> CustomSet<T> {
4343
!self.collection.iter().any(|x| other.contains(x))
4444
}
4545

46+
#[must_use]
4647
pub fn intersection(&self, other: &Self) -> CustomSet<T> {
4748
CustomSet::new(
4849
&self
@@ -54,6 +55,7 @@ impl<T: Ord + Clone> CustomSet<T> {
5455
)
5556
}
5657

58+
#[must_use]
5759
pub fn union(&self, other: &Self) -> CustomSet<T> {
5860
CustomSet::new(
5961
&self
@@ -65,6 +67,7 @@ impl<T: Ord + Clone> CustomSet<T> {
6567
)
6668
}
6769

70+
#[must_use]
6871
pub fn difference(&self, other: &Self) -> CustomSet<T> {
6972
CustomSet::new(
7073
&self

exercises/practice/custom-set/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,17 @@ impl<T> CustomSet<T> {
3434
unimplemented!();
3535
}
3636

37+
#[must_use]
3738
pub fn intersection(&self, _other: &Self) -> Self {
3839
unimplemented!();
3940
}
4041

42+
#[must_use]
4143
pub fn difference(&self, _other: &Self) -> Self {
4244
unimplemented!();
4345
}
4446

47+
#[must_use]
4548
pub fn union(&self, _other: &Self) -> Self {
4649
unimplemented!();
4750
}

exercises/practice/fizzy/.meta/example.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ where
3131
Fizzy(Vec::new())
3232
}
3333

34+
#[must_use]
3435
pub fn add_matcher(mut self, matcher: Matcher<T>) -> Self {
3536
let Fizzy(ref mut matchers) = self;
3637
matchers.push(matcher);

exercises/practice/fizzy/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ impl<T> Fizzy<T> {
2828
}
2929

3030
// feel free to change the signature to `mut self` if you like
31+
#[must_use]
3132
pub fn add_matcher(self, _matcher: Matcher<T>) -> Self {
3233
unimplemented!()
3334
}

exercises/practice/robot-simulator/.meta/example.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,22 @@ impl Robot {
6565
}
6666
}
6767

68+
#[must_use]
6869
pub fn turn_right(&self) -> Self {
6970
Self::build(self.position, self.direction.next_clockwise())
7071
}
7172

73+
#[must_use]
7274
pub fn turn_left(&self) -> Self {
7375
Self::build(self.position, self.direction.previous_clockwise())
7476
}
7577

78+
#[must_use]
7679
pub fn advance(&self) -> Self {
7780
Self::build(self.position.advance(&self.direction), self.direction)
7881
}
7982

83+
#[must_use]
8084
pub fn instructions(&self, instructions: &str) -> Self {
8185
instructions
8286
.chars()
@@ -93,6 +97,7 @@ impl Robot {
9397
&self.direction
9498
}
9599

100+
#[must_use]
96101
fn execute(self, command: char) -> Self {
97102
match command {
98103
'R' => self.turn_right(),

exercises/practice/robot-simulator/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,22 @@ impl Robot {
1616
unimplemented!("Create a robot at (x, y) ({}, {}) facing {:?}", x, y, d,)
1717
}
1818

19+
#[must_use]
1920
pub fn turn_right(self) -> Self {
2021
unimplemented!()
2122
}
2223

24+
#[must_use]
2325
pub fn turn_left(self) -> Self {
2426
unimplemented!()
2527
}
2628

29+
#[must_use]
2730
pub fn advance(self) -> Self {
2831
unimplemented!()
2932
}
3033

34+
#[must_use]
3135
pub fn instructions(self, instructions: &str) -> Self {
3236
unimplemented!(
3337
"Follow the given sequence of instructions: {}",

exercises/practice/simple-linked-list/.meta/example.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ impl<T> SimpleLinkedList<T> {
4747
self.head.as_ref().map(|node| &node.data)
4848
}
4949

50+
#[must_use]
5051
pub fn rev(self) -> SimpleLinkedList<T> {
5152
let mut rev_list = SimpleLinkedList::new();
5253
let mut vec: Vec<_> = self.into();

exercises/practice/simple-linked-list/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ impl<T> SimpleLinkedList<T> {
3636
unimplemented!()
3737
}
3838

39+
#[must_use]
3940
pub fn rev(self) -> SimpleLinkedList<T> {
4041
unimplemented!()
4142
}

0 commit comments

Comments
 (0)