-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-attributesArea: Attributes (`#[…]`, `#![…]`)Area: Attributes (`#[…]`, `#![…]`)A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.A-trait-systemArea: Trait systemArea: Trait system
Description
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.
Metadata
Metadata
Assignees
Labels
A-attributesArea: Attributes (`#[…]`, `#![…]`)Area: Attributes (`#[…]`, `#![…]`)A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.A-trait-systemArea: Trait systemArea: Trait system