Skip to content

Allow implementing traits with statically uncallable methods #35369

@Stebalien

Description

@Stebalien

Basically, given:

trait Foo {
    fn foo(self) where Self: Sized;
    fn bar(&self);
}

The following is valid:

impl<T: ?Sized> Foo for T {
    fn foo(self) where Self: Sized {}
    fn bar(&self) {}
}

But the following isn't:

impl<T> Foo for [T] {
    fn foo(self) where Self: Sized { unreachable!() } // Should disappear at compile-time.
    fn bar(&self) {}
}

This means that, for example, Iterator can't be implemented types that are known to be DSTs, only types that may be DSTs. This is an inconsistent and an unnecessary limitation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions