rust-lang / rust-lang/rfcs

RFC: Allow inference of argument/return value in trait impls

Open
#309 2 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-impls A-inference A-traits A-typesystem T-lang
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 called insert and remove with 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

  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 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.