Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rust 2021 (1.56+) breaks shaku (fixed on 1.59) #30

Closed
elertan opened this issue Nov 3, 2021 · 12 comments
Closed

Rust 2021 (1.56+) breaks shaku (fixed on 1.59) #30

elertan opened this issue Nov 3, 2021 · 12 comments

Comments

@elertan
Copy link
Contributor

elertan commented Nov 3, 2021

Breaking changes introduced by the new version breaks HasComponent impls on the module using the shaku::module macro.
I will try to provide a poc as soon as possible.

https://doc.rust-lang.org/edition-guide/rust-2021/prelude.html
Maybe some documentation as to why this occurs is available.

@elertan
Copy link
Contributor Author

elertan commented Nov 3, 2021

Can't seem to replicate it using a simple poc..
Here's what I tried on Rust 1.56.1:

use shaku::{module, Component, Interface, HasComponent};

trait User {
    fn id(&self) -> u32;
}

trait Repository<T>: Interface where T: ?Sized {
    fn get_all(&self) -> Vec<Box<T>>;
}

#[derive(Component)]
#[shaku(interface = Repository<dyn User>)]
struct UserRepositoryImpl;

impl Repository<dyn User> for UserRepositoryImpl {
    fn get_all(&self) -> Vec<Box<dyn User>> {
        vec![]
    }
}

module! {
    MyModule {
        components = [UserRepositoryImpl],
        providers = []
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test() {
        let module = MyModule::builder()
            .build();

        let x: &dyn Repository<dyn User> = module.resolve_ref();
        x.get_all();
    }
}

Code above compiles fine.

In my actual codebase I get about 47 errors which all look similar to this:

error[E0277]: the trait bound `_Module: HasComponent<(dyn Repository<(dyn AccountBase + 'static), (dyn Account + 'static), AccountFields> + 'static)>` is not satisfied
  --> _/src/dependency_inversion.rs:9:1
   |
9  | / module! {
10 | |     pub _Module {
11 | |         components = [
12 | |             persistence::database::PoolProviderImpl,
...  |
45 | |     }
46 | | }
   | |_^ the trait `HasComponent<(dyn Repository<(dyn AccountBase + 'static), (dyn Account + 'static), AccountFields> + 'static)>` is not implemented for `_Module`
   |
   = help: the following implementations were found:
             <FuifModule as HasComponent<(dyn AutocompleteService + 'static)>>
             <FuifModule as HasComponent<(dyn ConfigProvider + 'static)>>
             <FuifModule as HasComponent<(dyn DateTimeService + 'static)>>
             <FuifModule as HasComponent<(dyn GoogleAuthService + 'static)>>
           and 24 others
   = note: required because of the requirements on the impl of `shaku::Component<_Module>` for `DefaultProfileService`
   = note: this error originates in the macro `module` (in Nightly builds, run with -Z macro-backtrace for more info)

Note: I removed keywords related to the project with _ as they are not publicly disclosable.
These errors do not occur when I build it with Rust on 1.55.0

Edit:
Realize I kept the name in anyways... 🤦‍♂️. Oh well.

@AzureMarker
Copy link
Owner

Thanks for opening this issue, I'll take a look soon!

@AzureMarker
Copy link
Owner

AzureMarker commented Nov 5, 2021

Weird, it shows an error for me in https://github.com/AzureMarker/shaku/blob/master/shaku/tests/repository_service_provider.rs even when still using Rust 2018.
(still investigating)

@elertan
Copy link
Contributor Author

elertan commented Nov 5, 2021

Weird, it shows an error for me in https://github.com/AzureMarker/shaku/blob/master/shaku/tests/repository_service_provider.rs even when still using Rust 2018.

(still investigating)

Are you using Rust 1.56+ with the 2018 edition or Rust 1.55.0 or lower?
The issue also occurred for me with Rust 1.56+ when using the 2018 edition.
(As in setting the edition to 2018 and compiling on 1.56.1 gives me the same errors)

@AzureMarker
Copy link
Owner

Yeah, 1.56.1 on 2018

@elertan
Copy link
Contributor Author

elertan commented Nov 6, 2021

Yeah, 1.56.1 on 2018

Well at least happy to see that it is reproducable. After digging through the release notes of Rust 1.56 nothing really seems like it should affect how this works.
Maybe it is caused by some undocumented change?

@AzureMarker
Copy link
Owner

Opened bug on rustc: rust-lang/rust#90662

@AzureMarker AzureMarker pinned this issue Nov 6, 2021
@AzureMarker
Copy link
Owner

The rustc issue has been closed with a fix, and it should release in 1.59.

@elertan
Copy link
Contributor Author

elertan commented Dec 20, 2021

Hope to see the Rust 1.59 soon then. Thanks for your involvement to help getting this fixed.
Still surprising to me though that the stable Rust release would introduce breaking changes.
I'll close the issue once 1.59 is released to see if everything works fine by then.

emilien-jegou pushed a commit to emilien-jegou/idie that referenced this issue Feb 22, 2022
Shaku can't compile in rust 1.56.+ ; track issue here:
AzureMarker/shaku#30
emilien-jegou pushed a commit to emilien-jegou/idie that referenced this issue Feb 22, 2022
Shaku can't compile in rust 1.56.+ ; track issue here:
AzureMarker/shaku#30
emilien-jegou pushed a commit to emilien-jegou/idie that referenced this issue Feb 22, 2022
Shaku can't compile in rust 1.56.+ ; track issue here:
AzureMarker/shaku#30
@elertan
Copy link
Contributor Author

elertan commented Feb 24, 2022

Seems like Rust 1.59 has been released today, I will attempt to build the project I had issues in previously to see if it has been resolved now. For now I had been using nightly to build the project which did not have any issues.

@elertan
Copy link
Contributor Author

elertan commented Feb 24, 2022

Fixed on 1.59 🎉

@elertan elertan closed this as completed Feb 24, 2022
@elertan elertan changed the title Rust 2021 (1.56+) breaks shaku Rust 2021 (1.56+) breaks shaku (fixed on 1.59) Feb 24, 2022
@AzureMarker
Copy link
Owner

Thanks for following up!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants