rust-lang / rust-lang/reference
Rule around non-dispatchable functions doesn't match the compiler behavior
Nobody has claimed this yet.
- 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: Sizedbound (receiver type ofSelf(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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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