Skip to content

Commit f7d444a

Browse files
authored
Merge pull request #497 from coriolinus/eliminate-unused-variable-warnings
Eliminate stub warnings
2 parents 5ccd62d + 1418849 commit f7d444a

File tree

17 files changed

+65
-25
lines changed

17 files changed

+65
-25
lines changed

_test/check-stubs.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/bash
2+
3+
# This checks every stub which exists, and emits all of their warnings.
4+
# To get a list of exercises for which there are warnings on compilation,
5+
# run it like this:
6+
#
7+
# $ _test/check-stubs.sh 2>/dev/null | rev | cut -d/ -f1 | rev
8+
9+
# run 'cargo check' on every exercise which possesses a stub
10+
repo=$(cd "$(dirname "$0")/.." && pwd)
11+
12+
for stub in $repo/exercises/*/src/lib.rs; do
13+
exercise=$(dirname $(dirname $stub))
14+
(
15+
cd "$exercise"
16+
# copy the original stub to a backup
17+
backup=$(dirname $stub)/lib.rs.bak
18+
cp $stub $backup
19+
# deny warnings in the stub
20+
sed -i -e '1i #![deny(warnings)]' $stub
21+
# quiet so that we only get output when there's an error
22+
cargo check --quiet
23+
if [ $? != 0 ]; then
24+
echo "^- $exercise"
25+
fi
26+
# reset
27+
mv -f $backup $stub
28+
)
29+
done

exercises/beer-song/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
pub fn verse(n: i32) -> String {
2-
unimplemented!()
2+
unimplemented!("emit verse {}", n)
33
}
44

55
pub fn sing(start: i32, end: i32) -> String {
6-
unimplemented!()
6+
unimplemented!("sing verses {} to {}, inclusive", start, end)
77
}

exercises/bob/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
pub fn reply(message: &str) -> &str {
2-
unimplemented!()
2+
unimplemented!("have Bob reply to the incoming message: {}", message)
33
}
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
// return Some(x) where x is the number of steps required to reach 1
21
pub fn collatz(n: u64) -> Option<u64> {
3-
unimplemented!()
2+
unimplemented!(
3+
"return Some(x) where x is the number of steps required to reach 1 starting with {}",
4+
n,
5+
)
46
}
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
pub fn square_of_sum(n: usize) -> usize {
2-
unimplemented!()
2+
unimplemented!("square of sum of 1...{}", n)
33
}
44

55
pub fn sum_of_squares(n: usize) -> usize {
6-
unimplemented!()
6+
unimplemented!("sum of squares of 1...{}", n)
77
}
88

99
pub fn difference(n: usize) -> usize {
10-
unimplemented!()
10+
unimplemented!(
11+
"difference between square of sum of 1...{n} and sum of squares of 1...{n}",
12+
n=n,
13+
)
1114
}

exercises/forth/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ impl Forth {
2121
}
2222

2323
pub fn eval(&mut self, input: &str) -> ForthResult {
24-
unimplemented!()
24+
unimplemented!("result of evaluating '{}'", input)
2525
}
2626
}

exercises/grains/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
pub fn square(s: u32) -> u64 {
2-
unimplemented!();
2+
unimplemented!("grains of rice on square {}", s);
33
}
44

55
pub fn total() -> u64 {

exercises/leap/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
pub fn is_leap_year(year: i32) -> bool {
2-
unimplemented!()
2+
unimplemented!("true if {} is a leap year", year)
33
}

exercises/pascals-triangle/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ pub struct PascalsTriangle;
22

33
impl PascalsTriangle {
44
pub fn new(row_count: u32) -> Self {
5-
unimplemented!();
5+
unimplemented!("create Pascal's triangle with {} rows", row_count);
66
}
77

88
pub fn rows(&self) -> Vec<Vec<u32>> {

exercises/perfect-numbers/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ pub enum Classification {
66
}
77

88
pub fn classify(num: u64) -> Option<Classification> {
9-
unimplemented!();
9+
unimplemented!("classify {}", num);
1010
}

exercises/proverb/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
pub fn build_proverb(list: Vec<&str>) -> String {
2-
unimplemented!()
2+
unimplemented!("build a proverb from this list of items: {:?}", list)
33
}

exercises/raindrops/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
pub fn raindrops(n: usize) -> String {
2-
unimplemented!()
2+
unimplemented!("what sound does Raindrop #{} make?", n)
33
}

exercises/saddle-points/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
pub fn find_saddle_points(input: &[Vec<u64>]) -> Vec<(usize, usize)> {
2-
unimplemented!()
2+
unimplemented!("find the saddle points of the following matrix: {:?}", input)
33
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
pub struct SimpleLinkedList<T> {
22
// Delete this field
3-
// _dummy is needed to avoid unused parameter error during compilation
4-
_dummy: T,
3+
// dummy is needed to avoid unused parameter error during compilation
4+
dummy: ::std::marker::PhantomData<T>,
55
}
66

77
impl<T> SimpleLinkedList<T> {
@@ -13,7 +13,7 @@ impl<T> SimpleLinkedList<T> {
1313
unimplemented!()
1414
}
1515

16-
pub fn push(&mut self, element: T) {
16+
pub fn push(&mut self, _element: T) {
1717
unimplemented!()
1818
}
1919

@@ -34,13 +34,13 @@ impl<T: Clone> SimpleLinkedList<T> {
3434

3535

3636
impl<'a, T: Clone> From<&'a [T]> for SimpleLinkedList<T> {
37-
fn from(item: &[T]) -> Self {
37+
fn from(_item: &[T]) -> Self {
3838
unimplemented!()
3939
}
4040
}
4141

4242
impl<T> Into<Vec<T>> for SimpleLinkedList<T> {
43-
fn into(mut self) -> Vec<T> {
43+
fn into(self) -> Vec<T> {
4444
unimplemented!()
4545
}
4646
}

exercises/sum-of-multiples/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
pub fn sum_of_multiples(limit: u32, factors: &[u32]) -> u32 {
2-
unimplemented!()
2+
unimplemented!("Sum the multiples of all of {:?} which are less than {}", factors, limit)
33
}

exercises/two-bucket/src/lib.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,11 @@ pub fn solve(capacity_1: u8,
2222
goal: u8,
2323
start_bucket: &Bucket) -> BucketStats
2424
{
25-
unimplemented!();
25+
unimplemented!(
26+
"Given one bucket of capacity {}, another of capacity {}, starting with {:?}, find pours to reach {}",
27+
capacity_1,
28+
capacity_2,
29+
start_bucket,
30+
goal,
31+
);
2632
}

exercises/variable-length-quantity/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ pub enum Error {
66

77
/// Convert a list of numbers to a stream of bytes encoded with variable length encoding.
88
pub fn to_bytes(values: &[u32]) -> Vec<u8> {
9-
unimplemented!()
9+
unimplemented!("Convert the values {:?} to a list of bytes", values)
1010
}
1111

1212
/// Given a stream of bytes, extract all numbers which are encoded in there.
1313
pub fn from_bytes(bytes: &[u8]) -> Result<Vec<u32>, Error> {
14-
unimplemented!()
14+
unimplemented!("Convert the list of bytes {:?} to a list of numbers", bytes)
1515
}

0 commit comments

Comments
 (0)