# Multiple associated types in TyS when the user-written type has one

**URL:** <https://internals.rust-lang.org/t/multiple-associated-types-in-tys-when-the-user-written-type-has-one/13939>\
**Category:** compiler\
**Created:** [January 30, 2021, 6:36am UTC](https://internals.rust-lang.org/t/multiple-associated-types-in-tys-when-the-user-written-type-has-one/13939 "2021-01-30T06:36:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![osa1](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/osa1/32/7931_2.png) [@osa1](https://internals.rust-lang.org/u/osa1)\
**Post date:** [January 30, 2021, 6:36am UTC](https://internals.rust-lang.org/t/multiple-associated-types-in-tys-when-the-user-written-type-has-one/13939/1 "2021-01-30T06:36:45Z")

</div>

Hello,

I asked on Zulip but couldn't get any responses, so trying here.

In this program

```rust
trait Restriction {
    type Inner;
}

trait Database: Restriction<Inner = u32> {}

struct Test {}

impl Database for Test {}

impl Restriction for Test {
    type Inner = u32;
}

fn main() {
    let t = Test {};
    let _x: &dyn Database<Inner = _> = &t;
}

```

If I add some debug prints in mir's type checker I see that the annotated type for `_x` is `&dyn Database<Inner = _, Inner = u32>` and normalized type is `&dyn Database<Inner = u32, Inner = u32>`. I'm confused about why we have two `Inner`s in these types when the user-written type only has one associated type.

Intersetingly if I remove the `_` part (what is it called?) the type becomes `&dyn Database<Inner = u32>`.

Is this expected? Could anyone point me to some relevant documentation/code?

I tried enabling trace logs and reading the rustc\_typeck code, but couldn't figure out.

Thanks.

---

<div class="post-metadata">

**Author:** ![steffahn](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/steffahn/32/13288_2.png) [@steffahn](https://internals.rust-lang.org/u/steffahn)\
**Post date:** [January 30, 2021, 8:45am UTC](https://internals.rust-lang.org/t/multiple-associated-types-in-tys-when-the-user-written-type-has-one/13939/2 "2021-01-30T08:45:19Z")

</div>

I have no idea about Rust internals to answer your question, but there is also this issue which seems somewhat related:

> <https://github.com/rust-lang/rust/issues/80800>
>
> Found in #57893 (comment)
> trait SuperTrait {
> type A;
> type B;
> }
> trait Trait: SuperTrait\<A = \<Self as SuperTrait\>::B\> {}
> fn transmute\<A, B\>(x: A) -\>...

---

<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:** [April 30, 2021, 8:45am UTC](https://internals.rust-lang.org/t/multiple-associated-types-in-tys-when-the-user-written-type-has-one/13939/3 "2021-04-30T08:45:46Z")

</div>

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