rust-lang / rust-lang/reference

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

Open
#1,247 5 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-types Language Cleanup
Dominant language
Rust
Stars
1.6k
Forks
607
PR merge metrics
PR metrics pending

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Object Safety section in the Rust Reference and compile the provided Foo examples, including the commented-out methods, to compare the wording with compiler behavior. Determine whether the reference rule or the compiler behavior is incorrect, then update the documentation or clarify the discrepancy so the stated requirements match the observed behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
documentation
Issue type
Documentation
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.