Skip to content

Nested associated type bounds not accessible via fully-qualified path #11376

@vezenovm

Description

@vezenovm

Aim

trait HasQux {
    type Qux;
}
trait Foo {
    type Bar: HasQux;
}
trait Result {
    type Output;
}
impl<T> Result for T
where
    T: Foo,
{
    type Output = <T::Bar as HasQux>::Qux;
}
fn main() {}

Expected Behavior

I would expect this code to compile as each generic and associated type is bound to a single trait. It does compile in Rust.

Bug

We get a "No matching impl" error. It seems that the bound Bar: HasQux is an internal type variable rather than <T as Foo>::Bar. The type system does not make this connection at the moment.

To Reproduce

  1. Run the test below in noirc_frontend/tests
#[test]
fn fully_qualified_nested_associated_type() {
    let src = "                                                                                                                              
      trait HasQux { type Qux; }                                                                                                               
      trait Foo { type Bar: HasQux; }                                                                                                          
      trait Result { type Output; }                                                                                                            
                                                                                                                                               
      impl<T> Result for T where T: Foo {                                                                                                      
          type Output = <T::Bar as HasQux>::Qux;  
                                   ^^^^^^ No matching impl found for `<T as Foo>::Bar: HasQux<Qux = _>`
                                   ~~~~~~ No impl for `<T as Foo>::Bar: HasQux<Qux = _>`                                                                             
      }                                                                                                                                        
      fn main() {}                                                                                                                             
      ";
    assert_no_errors(src);
}

Workaround

None

Workaround Description

Fundamental limitation in trait bound desugaring

Additional Context

No response

Project Impact

None

Blocker Context

No response

Nargo Version

No response

NoirJS Version

No response

Proving Backend Tooling & Version

No response

Would you like to submit a PR for this Issue?

None

Support Needs

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions