Skip to content

Regression in 1.56.0 - Trait bound not satisfied error even though the impl exists #90662

Closed
@AzureMarker

Description

@AzureMarker

Code

I tried this code (minimized from this test in my library):

trait HasProvider<T: ?Sized> {}
trait Provider<M> {
    type Interface: ?Sized;
}

trait Repository {}
trait Service {}

struct DbConnection;
impl<M> Provider<M> for DbConnection {
    type Interface = DbConnection;
}

struct RepositoryImpl;
impl<M: HasProvider<DbConnection>> Provider<M> for RepositoryImpl {
    type Interface = dyn Repository;
}

struct ServiceImpl;
impl<M: HasProvider<dyn Repository>> Provider<M> for ServiceImpl {
    type Interface = dyn Service;
}

struct TestModule;
impl HasProvider<<DbConnection as Provider<Self>>::Interface> for TestModule {}
impl HasProvider<<RepositoryImpl as Provider<Self>>::Interface> for TestModule {}
impl HasProvider<<ServiceImpl as Provider<Self>>::Interface> for TestModule {}

fn main() {}

I expected to see this happen: Compile without errors.

Instead, this happened: Compiled with errors:

error[E0277]: the trait bound `TestModule: HasProvider<(dyn Repository + 'static)>` is not satisfied
  --> shaku/tests/debug_rust_1_56.rs:26:6
   |
26 | impl HasProvider<<RepositoryImpl as Provider<Self>>::Interface> for TestModule {}
   |      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `HasProvider<(dyn Repository + 'static)>` is not implemented for `TestModule`
   |
   = help: the following implementations were found:
             <TestModule as HasProvider<(dyn Repository + 'static)>>
             <TestModule as HasProvider<<ServiceImpl as Provider<TestModule>>::Interface>>
             <TestModule as HasProvider<DbConnection>>
note: required by a bound in `HasProvider`
  --> shaku/tests/debug_rust_1_56.rs:1:1
   |
1  | trait HasProvider<T: ?Sized> {}
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `HasProvider`

error[E0277]: the trait bound `TestModule: HasProvider<(dyn Repository + 'static)>` is not satisfied
  --> shaku/tests/debug_rust_1_56.rs:27:6
   |
27 | impl HasProvider<<ServiceImpl as Provider<Self>>::Interface> for TestModule {}
   |      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `HasProvider<(dyn Repository + 'static)>` is not implemented for `TestModule`
   |
   = help: the following implementations were found:
             <TestModule as HasProvider<(dyn Repository + 'static)>>
             <TestModule as HasProvider<<ServiceImpl as Provider<TestModule>>::Interface>>
             <TestModule as HasProvider<DbConnection>>
note: required because of the requirements on the impl of `Provider<TestModule>` for `ServiceImpl`
  --> shaku/tests/debug_rust_1_56.rs:20:38
   |
20 | impl<M: HasProvider<dyn Repository>> Provider<M> for ServiceImpl {
   |                                      ^^^^^^^^^^^     ^^^^^^^^^^^

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0277`.

Note that it says HasProvider<(dyn Repository + 'static)> is not implemented for TestModule, but then lists it as an existing implementation.

Version it worked on

It most recently worked on: 1.55.0

Version with regression

rustc --version --verbose:

rustc 1.56.0 (09c42c458 2021-10-18)
binary: rustc
commit-hash: 09c42c45858d5f3aedfa670698275303a3d19afa
commit-date: 2021-10-18
host: x86_64-unknown-linux-gnu
release: 1.56.0
LLVM version: 13.0.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-trait-systemArea: Trait systemC-bugCategory: This is a bug.P-highHigh priorityregression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions