Closed
Description
This code worked on the nightly from the 18th, and is broken by the nightly on the 21st.
Last nightly working version: rustc 0.13.0-nightly (2a231594c 2014-12-18 12:21:57 +0000)
First nightly broken version: rustc 0.13.0-nightly (cc19e3380 2014-12-20 20:00:36 +0000)
Here's the full error:
<std macros>:4:24: 4:27 error: mismatched types: expected `MyTrait + 'static`, found `MyStruct` (expected trait MyTrait, found struct MyStruct)
<std macros>:4 Ok(val) => val,
^~~
<std macros>:1:1: 8:2 note: in expansion of try!
src/main.rs:16:21: 16:45 note: expansion site
src/main.rs:16:17: 16:68 error: the trait `core::kinds::Sized` is not implemented for the type `MyTrait + 'static`
src/main.rs:16 let boxed = box try!(MyStruct::new()) as Box<MyTrait + 'static>;
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/main.rs:16:17: 16:68 note: only sized types can be made into objects
src/main.rs:16 let boxed = box try!(MyStruct::new()) as Box<MyTrait + 'static>;
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/main.rs:16:17: 16:68 error: the trait `MyTrait` is not implemented for the type `MyTrait + 'static`
src/main.rs:16 let boxed = box try!(MyStruct::new()) as Box<MyTrait + 'static>;
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/main.rs:16:17: 16:68 note: required for the cast to the object type `MyTrait + 'static`
src/main.rs:16 let boxed = box try!(MyStruct::new()) as Box<MyTrait + 'static>;
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: aborting due to 3 previous errors
Here's the code producing the above error:
trait MyTrait {}
struct MyStruct;
impl MyStruct {
fn new() -> Result<MyStruct, String> {
return Ok(MyStruct);
}
}
impl MyTrait for MyStruct {}
/// This used to work, and doesn't work anymore
fn get1() -> Result<Box<MyTrait + 'static>, String> {
let boxed = box try!(MyStruct::new()) as Box<MyTrait + 'static>;
return Ok(boxed);
}
/// This works fine
fn get2() -> Result<Box<MyTrait + 'static>, String> {
let thing = box try!(MyStruct::new());
let boxed = thing as Box<MyTrait + 'static>;
return Ok(boxed);
}
fn main() {}
Rust playpen: http://is.gd/JNqrmN
Metadata
Metadata
Assignees
Labels
No labels