RFC: Allow inference of argument/return value in trait impls
Nobody has claimed this yet.
- Dominant language
- Markdown
- Stars
- 6.6k
- Forks
- 1.7k
- Avg merge
- 16h 14m
- Merged PRs (30d)
- 1
Description
Issue by huonw
Saturday Feb 22, 2014 at 11:38 GMT
For earlier discussion, see https://github.com/rust-lang/rust/issues/12468
This issue was labelled with: A-typesystem, B-RFC in the Rust repository
From reddit.
The trait definition entirely determines the signatures of impl'd methods, and so the signature is known without examining the function body, e.g.
trait Foo<T> { fn bar(&self, x: T, y: Self, z: ~str) -> bool; }
impl Foo<int> for f64 {
fn bar(&self, x: int, y: f64, z: ~str) -> bool { ... }
}
// could be
impl Foo<int> for f64 {
fn bar(&self, x, y, z) { ... }
}
(Or something like fn bar(&self, x: _, y: _, z: _) -> _ { ... } to make it obvious that a inferred/blank type is being used.)
I'm personally ambivalent on this; it may result in
- some tooling being harder to write,
- confusing error messages,
- code that subtly changes behaviour if an upstream trait changes method definitions slightly, but the method body uses that argument in a way that is satisfied by both the old and new types. e.g.
TreeMap<uint, T>becoming~[T]: they both have a methods calledinsertandremovewith the same signature, but they have different performance and semantics. (WIth explicit signatures, the downstream code would stop compiling, rather than changing behaviour.)
Contributor guide
No contributing guide indexed for this repository
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 by reading the earlier discussion in rust-lang/rust issue 12468 and the examples in this issue. Determine whether trait implementation method arguments and return values should support inference, and document the accepted syntax, tooling implications, and behavior-change risks before 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