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
}

0 commit comments

Comments
 (0)