Change:
Hello, I am trying to implement this trait: I get a compiler panic error: internal compiler error: unexpected panic I try to compile it for target=wasm32-unknown-unknown note: rustc 1.32.0 ( 2019-01-16) running on x86_64-pc-windows-msvc note: compiler flags: -C debuginfo=2 -C incremental --crate-type lib
Can you provide a self-contained example that reproduces the ICE?
Hello, This is the shortest example I could create: If you just build this you should get the error. It looks like it works? when not in lib mode, not sure
Even shorter:
<strikeBug was introduced between 1.23 and 1.24 (...)</strikeBetween 2017-11-20 and 2017-11-21 (...)
cc based on your commits that day ^^
That example should not type-check, you're assigning a where a is expected. cc
Using , we have , before then it was rejected due to syntax being unstable: 1.271.281.301.32
You can just remove the keyword, it really shouldn't matter. Btw, the minimized repro can be minimized further by removing the (rather heavy) : And we can also get rid of : is , none of this can work. So the real question is how does this ICE before emitting a type-checking error?
Okay, so there are two parts to this: the associated type of doesn't require implements the trait, so can be unsized to So this has a reason to type-check, despite being very confusing. We can make this simpler by using pointers: This way, we have , so can be unsized to . But it's impossible for the return type of a function, even with unsized rvalues, to be (i.e. we have no mechanism for supporting that), and here I think at the very least the vtable of has to have a shim that would need to return a return type (, i.e. in the original repro), so we ICE. If we don't want to enforce that return types are in pointers or trait objects methods, this case will continue ICE-ing.
The original problem is clearer if we add the keyword: You can fix your code by putting a around the return type of this , or figure out some other way to do it. If you want to make sure you find such problems, try to write function that is has implements the right traits, e.g. . That will error because the return type of a function with a body must be .
What alternative do we have?
Thank you , I will look into an alternative
Reproduces () as of 2020-03-10.
modify labels: +regression-from-stable-to-stable Still reproduces with stable/beta/nightly `
Assigning .
The latest nightly fixes the ICE, marking as .

Discussion:
<ins> #![crate_type = "lib"] pub fn foo(callback: fn() -> dyn ToString) { let mut x: Option<Box<dyn Fn() -> dyn ToString>> = None; x = Some(Box::new(callback)); //~^ ERROR: the size for values of type `dyn ToString` cannot be known at compilation time } </ins>

<ins> error[E0277]: the size for values of type `dyn ToString` cannot be known at compilation time --> $DIR/issue-58355.rs:5:14 | LL |     x = Some(Box::new(callback)); |              ^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time | = help: within `fn() -> dyn ToString`, the trait `Sized` is not implemented for `dyn ToString` = note: required because it appears within the type `fn() -> dyn ToString` = note: required for the cast from `fn() -> dyn ToString` to the object type `dyn Fn() -> (dyn ToString + 'static)` error: aborting due to previous error For more information about this error, try `rustc --explain E0277`. </ins>