# Pre-RFC: Type aliases in trait bounds

**URL:** <https://internals.rust-lang.org/t/pre-rfc-type-aliases-in-trait-bounds/1644>\
**Category:** ideas (deprecated)\
**Created:** [February 23, 2015, 10:39pm UTC](https://internals.rust-lang.org/t/pre-rfc-type-aliases-in-trait-bounds/1644 "2015-02-23T22:39:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Centril](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/centril/32/3334_2.png) [@Centril](https://internals.rust-lang.org/u/Centril)\
**Post date:** [February 23, 2015, 10:39pm UTC](https://internals.rust-lang.org/t/pre-rfc-type-aliases-in-trait-bounds/1644/1 "2015-02-23T22:39:35Z")

</div>

# Consider the following example:

```rust
trait MapSlot<'a, V>
where V: 'a {
    fn insert( self, val: V ) -> &'a mut V;
}

trait KeyTuple<O, I>
where O: Eq + Hash, I: Eq + Hash {
    fn keys( self ) -> (O, I);
}

trait DeepEntriable<'a, O, I, V>
where O: 'a + Eq + Hash, I: 'a + Eq + Hash, V: 'a {
    fn entry( &'a mut self, o: O ) -> Entry<O, HashMap<I, V>>;
}

trait DeepEntry<'a, O, I, V, DE>
where O: 'a + Eq + Hash, I: 'a + Eq + Hash, V: 'a,
      KT: KeyTuple<O, I>, DE: DeepEntriable<'a, O, I, V> {

    type Slot: MapSlot<'a, V>;
    fn deep_entry( de: &'a mut DE, key: KT ) -> Self::Slot;
}

```

The example itself is not that important. But we are constantly repeating `Eq + Hash`…

What if we could reduce this?

```rust
type K = Eq + Hash;
type KA<'a> = 'a + K;

trait MapSlot<'a, V>
where V: 'a {
    fn insert( self, val: V ) -> &'a mut V;
}

trait KeyTuple<O, I>
where O: K, I: K {
    fn keys( self ) -> (O, I);
}

trait DeepEntriable<'a, O, I, V>
where O: KA<'a>, I: KA<'a>, V: 'a {
    fn entry( &'a mut self, o: O ) -> Entry<O, HashMap<I, V>>;
}

trait DeepEntry<'a, O, I, V, DE>
where O: KA<'a>, I: KA'<a>, V: 'a,
      KT: KeyTuple<O, I>, DE: DeepEntriable<'a, O, I, V> {

    type Slot: MapSlot<'a, V>;
    fn deep_entry( de: &'a mut DE, key: KT ) -> Self::Slot;
}

```

# The idea is that you can use type aliases in trait bounds.

So that this would be legal:

```rust
type ValType = Add + Sub + Mul + Div;

trait CompositeOpA<V>
where V: ValType {
    fn opA( a: V, b: V ) -> V
}

trait CompositeOpB<V>
where V: ValType {
    fn opB( a: V, b: V ) -> V
}

```

# Drawbacks

Perhaps there are semantic issues…? If `type` is not the appropriate keyword - maybe `using` could work?

---

<div class="post-metadata">

**Author:** ![Centril](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/centril/32/3334_2.png) [@Centril](https://internals.rust-lang.org/u/Centril)\
**Post date:** [February 24, 2015, 1:49am UTC](https://internals.rust-lang.org/t/pre-rfc-type-aliases-in-trait-bounds/1644/2 "2015-02-24T01:49:27Z")

</div>

This issue is also relevant: [https://github.com/rust-lang/rust/issues/8634](https://github.com/rust-lang/rust/issues/8634)

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/system/32/14092_2.png) [@system](https://internals.rust-lang.org/u/system)\
**Post date:** [March 25, 2019, 8:23am UTC](https://internals.rust-lang.org/t/pre-rfc-type-aliases-in-trait-bounds/1644/3 "2019-03-25T08:23:59Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
