rust-lang / rust-lang/rfcs

Allow a minimum complete implementation to be specified for mutually recursive default methods

Open
#628 1 comment 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

T-lang
Dominant language
Markdown
Stars
6.6k
Forks
1.7k
Avg merge
16h 14m
Merged PRs (30d)
1

Description

Issue by huonw
Saturday Jul 13, 2013 at 08:41 GMT

For earlier discussion, see https://github.com/rust-lang/rust/issues/7771

This issue was labelled with: A-attributes, A-diagnostics, A-lint, A-traits, B-RFC, I-wishlist in the Rust repository


It should be possible to tell the compiler that at least one of a given set of default methods is required to be implemented, e.g.

#[requires(one_of(foo, bar), one_of(baz, qux))]
trait A {
   fn foo(&self) { self.bar() }
   fn bar(&self) { self.foo() }

   fn baz(&self) { self.qux() }
   fn qux(&self) { self.baz() }
}

impl A for int { // ok
   fn foo(&self) {}
   fn bar(&self) {}

   fn baz(&self) {} 
}

impl A for uint { // "requires at least one of foo or bar"
   fn baz(&self) {}
}

impl A for float { // "requires at least one of baz or qux"
   fn foo(&self) {}
}

This allows e.g. Eq to write eq and ne in terms of each other, without allowing the infinitely recursive impl Eq for Foo {}.

It could even allow saying "either foo or both bar and baz", e.g. #[requires(one_of(foo, all_of(bar, baz)))], and would hopefully warn if a non-default method was listed.

Contributor guide

No contributing guide indexed for this repository

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

No files, tests, or compiler entry points are named. Start by reading the earlier discussion in issue 7771 and the mutually recursive trait examples here; clarify the semantics for one_of, all_of, and non-default methods. Done means the compiler can enforce the stated minimum implementations and diagnose an empty implementation.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.