Closed
Description
rustc --version --verbose:
rustc 1.0.0-nightly (f4f10dba2 2015-01-17 20:31:08 +0000)
binary: rustc
commit-hash: f4f10dba2975b51c2d2c92157018db3ac13d4d4a
commit-date: 2015-01-17 20:31:08 +0000
host: x86_64-pc-windows-gnu
release: 1.0.0-nightly
Backtrace: (the offending line 111 is at the bottom of the source snippet below)
source.rs:111:22: 111:78 error: internal compiler error: aliasability violation with closure
source.rs:111 try_consume( key, &|&: value| item.effects.effects.push( consume( value ) ) );
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
note: the compiler unexpectedly panicked. this is a bug.
note: we would appreciate a bug report: http://doc.rust-lang.org/complement-bugreport.html
note: run with `RUST_BACKTRACE=1` for a backtrace
thread 'rustc' panicked at 'Box<Any>', C:\bot\slave\nightly-dist-rustc-win-64\build\src\libsyntax\diagnostic.rs:126
stack backtrace:
1: 0x69beb95b - sys::backtrace::write::h3574a74d3ac66ba0Dcu
2: 0x69bff6c3 - rt::unwind::register::hb202fe2a2fd24f5eyYz
3: 0x69b8363f - rt::unwind::begin_unwind_inner::h24cce2e033842dba7Vz
4: 0x6f89b58c - diagnostic::SpanHandler::span_bug::he7f492467f6ccae95qF
5: 0x6f89b543 - diagnostic::SpanHandler::span_bug::he7f492467f6ccae95qF
6: 0x591d82 - session::Session::span_bug::hbbd1fa2194e20c7cfBp
7: 0x705e170c - borrowck::move_data::MovePathIndex...std..cmp..PartialEq::ne::h1a3439607cb47b24mTd
8: 0x705e84bd - borrowck::gather_loans::GatherLoanCtxt<'a, 'tcx>.euv..Delegate<'tcx>::mutate::hdc7adcebb6b13c04Nsc
9: 0x705e66c9 - borrowck::gather_loans::GatherLoanCtxt<'a, 'tcx>.euv..Delegate<'tcx>::borrow::h4842d9e140720d87kqc
10: 0x705d92f3 - borrowck::check_loans::CheckLoanCtxt<'a, 'tcx>.euv..Delegate<'tcx>::decl_without_init::h9c67fbfec08849cbHoa
11: 0x705d5152 - borrowck::check_loans::CheckLoanCtxt<'a, 'tcx>.euv..Delegate<'tcx>::decl_without_init::h9c67fbfec08849cbHoa
12: 0x705d8ef6 - borrowck::check_loans::CheckLoanCtxt<'a, 'tcx>.euv..Delegate<'tcx>::decl_without_init::h9c67fbfec08849cbHoa
13: 0x705d4d13 - borrowck::check_loans::CheckLoanCtxt<'a, 'tcx>.euv..Delegate<'tcx>::decl_without_init::h9c67fbfec08849cbHoa
14: 0x705d8c17 - borrowck::check_loans::CheckLoanCtxt<'a, 'tcx>.euv..Delegate<'tcx>::decl_without_init::h9c67fbfec08849cbHoa
15: 0x705d51df - borrowck::check_loans::CheckLoanCtxt<'a, 'tcx>.euv..Delegate<'tcx>::decl_without_init::h9c67fbfec08849cbHoa
16: 0x705d8c17 - borrowck::check_loans::CheckLoanCtxt<'a, 'tcx>.euv..Delegate<'tcx>::decl_without_init::h9c67fbfec08849cbHoa
17: 0x705d3b11 - borrowck::check_loans::CheckLoanCtxt<'a, 'tcx>.euv..Delegate<'tcx>::decl_without_init::h9c67fbfec08849cbHoa
18: 0x705d3fc7 - borrowck::check_loans::CheckLoanCtxt<'a, 'tcx>.euv..Delegate<'tcx>::decl_without_init::h9c67fbfec08849cbHoa
19: 0x705d8c17 - borrowck::check_loans::CheckLoanCtxt<'a, 'tcx>.euv..Delegate<'tcx>::decl_without_init::h9c67fbfec08849cbHoa
20: 0x705d3c0a - borrowck::check_loans::CheckLoanCtxt<'a, 'tcx>.euv..Delegate<'tcx>::decl_without_init::h9c67fbfec08849cbHoa
21: 0x705fcc12 - borrowck::check_crate::hb708c27b837bb24bUIe
22: 0x705f9986 - borrowck::BorrowckCtxt<'a, 'tcx>.Visitor<'v>::visit_fn::h85e169569b3db6adOHe
23: 0x705fbb13 - borrowck::check_crate::hb708c27b837bb24bUIe
Could not compile `DotA_Simulator`.
Source code (only the parts related to the problem):
...
let string = File::open( &Path::new( filename ) ).read_to_string().unwrap();
let json = json::from_str( string.as_slice() ).unwrap();
let object = json.as_object().unwrap();
let mut item = Item::new();
item.name = object["Name".to_string()].as_string().unwrap().to_string();
item.cost = object["ItemCost".to_string()].as_f64().unwrap();
//get the corresponding f64 to a key
let get_f64 = |&: key: &str| -> f64 {
object.get( &key.to_string() ).unwrap().as_f64().unwrap()
};
//Checks if all keys are mapped
let contains_all = |&: keys: &[&str]| -> bool {
for k in keys.iter() {
if !object.contains_key( &k.to_string() ) { return false; }
}
true
};
//Consumes a value if its key exists.
let try_consume = |&: key: &str, consume: &Fn(f64)| {
match object.get(&key.to_string()) {
Some(ref json) => consume( json.as_f64().unwrap() ),
None => ()
};
};
{
//Same as above but consume creates an Effect that gets pushed onto the item.
//This is in a separate scope because the Closure captures item.effects.effects until it goes out of scope.
let try_consume_push = |&: key: &str, consume: &Fn(f64) -> Effect| {
try_consume( key, &|&: value| item.effects.effects.push( consume( value ) ) );
};
...
If some info about my code matters:
I have a json object from which I want to extract a bunch of values that are all f64 and which get turned into a struct called Effect depending on their key which are put into a struct called Item. To have less duplicate code I define a few helper closures that use the same json object, Item and eachother.
The closures take other closures as arguments which I pass by reference because the compiler complains about them not being sized otherwise.