Skip to content

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

Open

Description

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.F-arbitrary_self_types`#![feature(arbitrary_self_types)]`F-dispatch_from_dyn`#![feature(dispatch_from_dyn)]`I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️S-bug-has-testStatus: This bug is tracked inside the repo by a `known-bug` test.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.glacierICE tracked in rust-lang/glacier.requires-nightlyThis issue requires a nightly compiler in some way.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions