Skip to content

Rule around non-dispatchable functions doesn't match the compiler behavior #1247

@upsuper

Description

@upsuper

In the Object Safety section, it says:

  • Explicitly non-dispatchable functions require:
    • Have a where Self: Sized bound (receiver type of Self (i.e. self) implies this).

This implies that if you have any associated function with receiver of self should be counted as non-dispatchable function. However, it is not the case. See the following code:

trait Foo {
    fn a(self);
    // fn b(self, x: &Self);
    // fn c(self) -> Self;
}

fn test() -> Box<dyn Foo> { todo!() }

Uncommenting b or c would make the code fail to compile, unless explicit where Self: Sized is added, but the rule in the reference indicates that having a receiver self already implies that bound exists.

Not sure whether it's something that should be fixed in the reference or the compiler.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-typesArea: TypesLanguage CleanupImprovements to existing language which is correct but not clear, or missing examples, or the like.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions