Advertisement
LemmingAvalanche

Rust compiler output missing conditional

Apr 12th, 2014
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. /*I've commented where the error is. I think the compiler output was weird for this kind of error.*/
  2.  
  3. /***** Code ******/
  4.  
  5. use std::io::println;
  6.  
  7. fn is_three(num: int) -> bool {
  8. num % 3 == 0
  9. }
  10.  
  11. fn is_five(num: int) -> bool {
  12. num % 5 == 0
  13. }
  14.  
  15. fn is_fftn(num: int) -> bool {
  16. num % 15 == 0
  17. }
  18.  
  19. #[test]
  20. fn test_is_three_with_not_three() {
  21. if is_three(1) {
  22. fail!("One is not three");
  23. }
  24. }
  25.  
  26. #[test]
  27. fn test_is_three() {
  28. if is_three(1) {
  29. fail!("One is not three");
  30. }
  31. }
  32.  
  33. fn main() {
  34. for num in range(1,101) {
  35. let answer =
  36. if is_fftn(num) {
  37. "FizzBuzz"
  38. }
  39. else if is_three(num) {
  40. "Fizz"
  41. }
  42. else if { //missing conditional
  43. "Buzz"
  44. }
  45. else {
  46. ""
  47. };
  48. println(answer);
  49. }
  50. }
  51.  
  52. /***** Compiler output *****/
  53.  
  54. ~/Dropbox/rust$ rustc fizzbuzz.rs
  55. fizzbuzz.rs:41:7: 41:11 error: expected `{` but found `else`
  56. fizzbuzz.rs:41 else {
  57. ^~~~
  58.  
  59. ***
  60.  
  61. I would have expected something like "error: missing/expected conditional at line 38, but found '{'"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement