Skip to content
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 in object_safety.rs due to method receiver not having a layout #57276

Open
mikeyhew opened this issue Jan 2, 2019 · 3 comments
Open

ICE in object_safety.rs due to method receiver not having a layout #57276

mikeyhew opened this issue Jan 2, 2019 · 3 comments
Labels
C-bug Category: This is a bug. F-arbitrary_self_types `#![feature(arbitrary_self_types)]` F-dispatch_from_dyn `#![feature(dispatch_from_dyn)]` glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way. S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@mikeyhew
Copy link
Contributor

mikeyhew commented Jan 2, 2019

The following code causes an ICE, Error: the type `T` has an unknown layout:

#![feature(arbitrary_self_types, dispatch_from_dyn)]

use std::ops::{Deref, DispatchFromDyn};

trait Trait<T: Deref<Target=Self> + DispatchFromDyn<T>> {
    fn foo(self: T) -> dyn Trait<T>;
}

Similar to #56806, receiver_is_dispatchable succeeds, and then there is an ICE during the layout sanity checks. In this case, it is because the method receiver is a type parameter and has no layout.

receiver_is_dispatchable checks that the following predicate holds:

forall (U: Trait + ?Sized) {
    if (Self: Unsize<U>) {
        Receiver: DispatchFromDyn<Receiver[Self => U]>
    }
}

In this case, it reduces to T: DispatchFromDyn<T>, which is provided by a where clause. In #56806, it reduced to Box<dyn Trait>: DispatchFromDyn<Box<dyn Trait>>. The check passes in both cases, and then there is an ICE during the layout sanity checks.

One way to fix both of these cases would be to add an extra requirement to receiver_is_dispatchable: that Receiver and Receiver[Self => U] are not the same type. I'm not sure if there are any edge cases that that doesn't cover.

cc @varkor #57229

@estebank estebank added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Jan 2, 2019
@mikeyhew
Copy link
Contributor Author

mikeyhew commented Jan 2, 2019

There is also the straightforward solution of not doing the layout checks if the layout is un-computable. But it seems like receiver_is_dispatchable should return false for this case, where changing Self doesn't change the receiver type. If adding a check for this case makes it impossible to trigger the ICE in user code, then maybe we should bug! unconditionally

@jonas-schievink jonas-schievink added C-bug Category: This is a bug. F-arbitrary_self_types `#![feature(arbitrary_self_types)]` requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. F-dispatch_from_dyn `#![feature(dispatch_from_dyn)]` labels Aug 6, 2019
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Oct 15, 2019
@JohnTitor
Copy link
Member

Triage: This is no longer ICE with the latest nightly, seems #78422 fixed it.

@JohnTitor JohnTitor added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Oct 31, 2020
@JohnTitor
Copy link
Member

It's ICE'd again (https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=dcac74ce4f9ee21c114a7659c5e86783), too late to add a regression test :(, removing the label.
The errors are:

error: internal compiler error: no errors encountered even though `delay_span_bug` issued

error: internal compiler error: error: the type `T` has an unknown layout
                                 while computing layout for type T
 [--> src/main.rs:6:5
](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021#)  |
6 |     fn foo(self: T) -> dyn Trait<T>;
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: delayed at compiler/rustc_trait_selection/src/traits/object_safety.rs:470:34

error: internal compiler error: receiver when `Self = ()` should have a Scalar ABI; found None
 [--> src/main.rs:6:5
](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021#)  |
6 |     fn foo(self: T) -> dyn Trait<T>;
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: delayed at compiler/rustc_trait_selection/src/traits/object_safety.rs:486:30

error: internal compiler error: receiver when `Self = (dyn Trait<T> + 'static)` should have a ScalarPair ABI; found None
 [--> src/main.rs:6:5
](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021#)  |
6 |     fn foo(self: T) -> dyn Trait<T>;
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: delayed at compiler/rustc_trait_selection/src/traits/object_safety.rs:506:30

@JohnTitor JohnTitor removed the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label May 10, 2022
@matthiaskrgr matthiaskrgr added the S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. label Apr 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. F-arbitrary_self_types `#![feature(arbitrary_self_types)]` F-dispatch_from_dyn `#![feature(dispatch_from_dyn)]` glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way. S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

6 participants