-
Notifications
You must be signed in to change notification settings - Fork 13.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ICE when trying to use dyn Fn(...) -> UnsizedTy
#58355
Comments
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. |
Even shorter:
|
|
cc @eddyb based on your commits that day ^^ |
That example should not type-check, you're assigning a cc @rust-lang/compiler |
Using the minimized repro, we have an stable ICE of some sort since 1.27, before then it was rejected due to
|
@estebank You can just remove the Btw, the minimized repro can be minimized further by removing the (rather heavy) use std::cell::RefCell;
pub fn foo(callback: &'static Fn() -> ToString) {
let x: RefCell<Option<Box<Fn() -> ToString>>> = RefCell::new(None);
*x.borrow_mut() = Some(Box::new(callback));
} And we can also get rid of pub fn foo(callback: &'static Fn() -> ToString) {
let mut x: Option<Box<Fn() -> ToString>> = None;
x = Some(Box::new(callback));
}
So the real question is how does this ICE before emitting a type-checking error? |
Okay, so there are two parts to this:
So this has a reason to type-check, despite being very confusing. We can make this simpler by using pub fn foo(callback: fn() -> ToString) {
let mut x: Option<Box<Fn() -> ToString>> = None;
x = Some(Box::new(callback));
} This way, we have But it's impossible for the return type of a function, even with unsized rvalues, to be If we don't want to enforce that return types are |
The original problem is clearer if we add the pub trait JsSerializable {
fn size(&self) -> u32;
fn ser(&self, cursor: &mut Cursor<Vec>);
}
impl JsSerializable for &'static dyn Fn() -> dyn JsSerializable {...} @viftodi You can fix your code by putting a If you want to make sure you find such problems, try to write function that is has implements the right traits, e.g. |
What alternative do we have? |
Reproduces (#58355 (comment)) as of 2020-03-10. |
@rustbot modify labels: +regression-from-stable-to-stable Still reproduces with stable/beta/nightly
|
Assigning |
dyn Fn(...) -> UnsizedTy
The latest nightly fixes the ICE, marking as |
Signed-off-by: Yuki Okushi <jtitor@2k36.org>
Rollup of 5 pull requests Successful merges: - rust-lang#106400 (Point at expressions where inference refines an unexpected type) - rust-lang#106491 (Fix error-index redirect to work with the back button.) - rust-lang#106494 (Add regression test for rust-lang#58355) - rust-lang#106499 (fix [type error] for error E0029 and E0277) - rust-lang#106502 (rustdoc: remove legacy user-select CSS) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
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 (9fda7c2 2019-01-16) running on x86_64-pc-windows-msvc
note: compiler flags: -C debuginfo=2 -C incremental --crate-type lib
The text was updated successfully, but these errors were encountered: