-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Closed
Closed
Copy link
Labels
A-type-systemArea: Type systemArea: Type systemC-bugCategory: This is a bug.Category: This is a bug.
Description
In the program below, using --cfg works1
or --cfg works2
both compile and run successfully, but --cfg breaks
produces a type mismatch error.
Not clear on how to fix this or what is actually happening, but it might be blocking the placement overloaded-box
desguaring work (rust-lang/rfcs#809)
#![feature(box_syntax)]
use std::cell::RefCell;
type BoxedFunc<'a> = Box<FnMut(&mut u32) -> &u32 + 'a>;
fn to_refcell<'a>(f: BoxedFunc<'a>) -> RefCell<BoxedFunc<'a>>
{
RefCell::new(f)
}
#[cfg(works1)]
fn make_refcell() -> RefCell<BoxedFunc<'static>>
{
to_refcell( box () |a:&mut u32| { *a = *a+1; a } )
}
#[cfg(works2)]
fn make_refcell() -> RefCell<BoxedFunc<'static>>
{
to_refcell( box () |a:&mut u32| { *a = *a+1; a } )
}
#[cfg(breaks)]
fn make_refcell() -> RefCell<BoxedFunc<'static>>
{
to_refcell( box (::std::boxed::HEAP) |a:&mut u32| { *a = *a+1; a } )
}
fn main() {
let b = make_refcell();
let mut a = 9;
b.into_inner()(&mut a);
assert_eq!(a, 10);
}
Transcript of error with --cfg breaks
, from http://is.gd/NgHq2k :
<anon>:27:17: 27:71 error: type mismatch resolving `for<'r> <[closure <anon>:27:42: 27:71] as core::ops::FnMut<(&'r mut u32,)>>::Output == &'r u32`: values differ in mutability [E0271]
<anon>:27 to_refcell( box (::std::boxed::HEAP) |a:&mut u32| { *a = *a+1; a } )
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<anon>:27:17: 27:71 note: required for the cast to the object type `for<'r> core::ops::FnMut(&'r mut u32) -> &'r u32`
<anon>:27 to_refcell( box (::std::boxed::HEAP) |a:&mut u32| { *a = *a+1; a } )
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: aborting due to previous error
playpen: application terminated with error code 101
Metadata
Metadata
Assignees
Labels
A-type-systemArea: Type systemArea: Type systemC-bugCategory: This is a bug.Category: This is a bug.