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


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

In this program

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


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

1 Like

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