Closed
Description
Hello folks,
I'm dutifully reporting this as the compiler told me to so. The bug is the same reported already by #24504 and #22897, although it appeared on a different circumstance. I have this simple program (I'm a Rust newbie so It's very likely I'm doing things terribly wrong):
use std::io::*;
const initial_height: u32 = 1;
fn summer_growth(h: u32) -> u32 {
h + 1
}
fn spring_growth(h: u32) -> u32 {
h * 2
}
fn utopian_tree(cycles: u32) -> u32 {
(0..cycles).fold(|acc, x| grow(acc,x), initial_height);
}
fn grow(acc: u32, cycle: u32) -> u32 {
match cycle % 2 == 0 {
true => spring_growth(acc),
false => summer_growth(acc)
}
}
fn main () {
let mut buf = String::new();
stdin().read_line(&mut buf).unwrap();
let test_cases: u32 = buf.trim().parse().unwrap();
for _ in 0..test_cases {
stdin().read_line(&mut buf).unwrap();
let cycle: u32 = buf.trim().parse().unwrap();
println!("{}", utopian_tree(cycle));
}
}
Expected outcome:
- The compile to tell me how wrong I am
Actual outcome:
☁ algorithms rustc utopian_tree.rs -o utopian_tree
utopian_tree.rs:14:5: 14:59 error: internal compiler error: cat_expr Errd
utopian_tree.rs:14 (0..cycles).fold(|acc, x| grow(acc,x), initial_height);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
note: the compiler unexpectedly panicked. this is a bug.
note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/m
aster/CONTRIBUTING.md#bug-reports
note: run with `RUST_BACKTRACE=1` for a backtrace
thread 'rustc' panicked at 'Box<Any>', /Users/rustbuild/src/rust-buildbot/slave/
beta-dist-rustc-mac/build/src/libsyntax/diagnostic.rs:149
Meta
☁ algorithms rustc --version --verbose
rustc 1.0.0-beta.2 (e9080ec39 2015-04-16) (built 2015-04-16)
binary: rustc
commit-hash: e9080ec39d9a44eb0773d648b348575b19f655e5
commit-date: 2015-04-16
build-date: 2015-04-16
host: x86_64-apple-darwin
release: 1.0.0-beta.2
☁ algorithms
Shows up with latest beta as well:
☁ algorithms rustc utopian_tree.rs -o utopian_tree
utopian_tree.rs:14:5: 14:59 error: internal compiler error: cat_expr Errd
utopian_tree.rs:14 (0..cycles).fold(|acc, x| grow(acc,x), initial_height);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
note: the compiler unexpectedly panicked. this is a bug.
note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports
note: run with `RUST_BACKTRACE=1` for a backtrace
thread 'rustc' panicked at 'Box<Any>', /Users/rustbuild/src/rust-buildbot/slave/beta-dist-rustc-mac/build/src/libsyntax/diagnostic.rs:149
☁ algorithms rustc --verbose --version
rustc 1.0.0-beta.4 (850151a75 2015-04-30) (built 2015-04-30)
binary: rustc
commit-hash: 850151a75709f146addd30bbbf1f23d384f0b381
commit-date: 2015-04-30
build-date: 2015-04-30
host: x86_64-apple-darwin
release: 1.0.0-beta.4
☁ algorithms