diff --git a/examples/example.rs b/examples/example.rs index 9beef71df31..7afbb0b0b65 100644 --- a/examples/example.rs +++ b/examples/example.rs @@ -170,3 +170,7 @@ fn int_to_float(a: u8, b: i32) -> (f64, f32) { fn make_array() -> [u8; 3] { [42, 0, 5] } + +fn some_promoted_tuple() -> &'static (&'static str, &'static str) { + &("abc", "some") +} diff --git a/examples/mini_core.rs b/examples/mini_core.rs index 60c4a249eeb..5ff9c93a975 100644 --- a/examples/mini_core.rs +++ b/examples/mini_core.rs @@ -59,11 +59,26 @@ pub trait Mul { impl Mul for u8 { type Output = Self; - fn mul(self, rhs: Self) -> Self { + fn mul(self, rhs: Self) -> Self::Output { self * rhs } } +#[lang = "sub"] +pub trait Sub { + type Output; + + fn sub(self, rhs: RHS) -> Self::Output; +} + +impl Sub for usize { + type Output = Self; + + fn sub(self, rhs: Self) -> Self { + self - rhs + } +} + #[lang = "bitor"] pub trait BitOr { type Output; diff --git a/src/constant.rs b/src/constant.rs index ec0a737c3f7..6c735e74eee 100644 --- a/src/constant.rs +++ b/src/constant.rs @@ -104,17 +104,7 @@ fn trans_const_place<'a, 'tcx: 'a>( ) -> CPlace<'tcx> { let ty = fx.monomorphize(&const_.ty); let layout = fx.layout_of(ty); - if !fx - .tcx - .sess - .crate_types - .get() - .contains(&CrateType::Executable) - { - // TODO: cranelift-module api seems to be used wrong, - // thus causing panics for some consts, so this disables it - return CPlace::Addr(fx.bcx.ins().iconst(types::I64, 0), layout); - } + let alloc = fx.tcx.const_value_to_allocation(const_); //println!("const value: {:?} allocation: {:?}", value, alloc); let alloc_id = fx.tcx.alloc_map.lock().allocate(alloc); @@ -161,10 +151,16 @@ fn get_global_for_alloc_id<'a, 'tcx: 'a, B: Backend + 'a>( let mut todo = HashMap::new(); define_global_for_alloc_id(module, cx, alloc_id, &mut todo); - while let Some((alloc_id, data_id)) = { - let next = todo.drain().next(); - next - } { + loop { + let (alloc_id, data_id) = { + if let Some(alloc_id) = todo.keys().next().map(|alloc_id| *alloc_id) { + let data_id = todo.remove(&alloc_id).unwrap(); + (alloc_id, data_id) + } else { + break; + } + }; + println!( "cur: {:?}:{:?} todo: {:?} done: {:?}", alloc_id, data_id, todo, cx.done