mondeja / leptos-fluent

Internationalization framework for Leptos using Fluent
https://mondeja.github.io/leptos-fluent/
MIT License
38 stars 10 forks source link

[Bug] StaticLoader name collision compilation error #230

Closed SleeplessOne1917 closed 3 months ago

SleeplessOne1917 commented 3 months ago

I updated my project to use leptos-fluent v0.1.17 and fluent-templates v0.10.0. When I try to compile my project, I get this error:

error[E0308]: mismatched types
  --> src/lib.rs:50:3
   |
50 | /   leptos_fluent! {{
51 | |     translations: [TRANSLATIONS],
52 | |     locales: "./locales",
53 | |     check_translations: "./src/**/*.rs",
...  |
59 | |     initial_language_from_navigator: true
60 | |   }};
   | |____^ expected `StaticLoader`, found a different `StaticLoader`
   |
   = note: `StaticLoader` and `StaticLoader` have similar names, but are actually distinct types
note: `StaticLoader` is defined in crate `fluent_templates`
  --> /home/insomnia/.cargo/registry/src/index.crates.io-6f17d22bba15001f/fluent-templates-0.10.0/src/loader/static_loader.rs:12:1
   |
12 | pub struct StaticLoader {
   | ^^^^^^^^^^^^^^^^^^^^^^^
note: `StaticLoader` is defined in crate `fluent_templates`
  --> /home/insomnia/.cargo/registry/src/index.crates.io-6f17d22bba15001f/fluent-templates-0.9.4/src/loader/static_loader.rs:12:1
   |
12 | pub struct StaticLoader {
   | ^^^^^^^^^^^^^^^^^^^^^^^
   = note: perhaps two different versions of crate `fluent_templates` are being used?
   = note: this error originates in the macro `leptos_fluent` (in Nightly builds, run with -Z macro-backtrace for more info)

For more information about this error, try `rustc --explain E0308`.
warning: `lemmy-ui-leptos` (lib) generated 14 warnings
error: could not compile `lemmy-ui-leptos` (lib) due to 1 previous error; 14 warnings emitted
Error: Failed to build lemmy-ui-leptos

The collision appears to be happening because it's trying to look both for the fluent-templates 0.9.4 StaticLoader and 0.10.0 StaticLoader. A look through my Cargo.lock file reveals the following:

...
[[package]]
name = "fluent-template-macros"
version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77d2bcae1f3ec390c50161fcf130d3228750e9ecf965618584e046d884199b83"
dependencies = [
 "flume",
 "ignore",
 "once_cell",
 "proc-macro2",
 "quote",
 "syn 2.0.75",
 "unic-langid",
]
...
[[package]]
name = "fluent-templates"
version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "197feb1e37209c6b3d29f0754b11fc070890efb2b1d761caac4e5287a200e9db"
dependencies = [
 "arc-swap",
 "fluent",
 "fluent-bundle",
 "fluent-langneg",
 "fluent-syntax",
 "fluent-template-macros 0.9.4",
 "flume",
 "heck",
 "ignore",
 "intl-memoizer",
 "log",
 "once_cell",
 "serde_json",
 "thiserror",
 "unic-langid",
]
...
[[package]]
name = "leptos-fluent"
version = "0.1.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ed6f0c7684f034decab4bfe92291c57e82ab27dd5aa3beef325c8d5f3ce42e63"
dependencies = [
 "fluent-templates 0.9.4",
 "leptos",
 "leptos-fluent-macros",
 "leptos_meta",
 "web-sys",
]

[[package]]
name = "leptos-fluent-macros"
version = "0.1.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "347676182d2064b95924f063a31ffac63ab3836e8d619adc722ea9bff367a37b"
dependencies = [
 "cfg-expr",
 "current_platform",
 "fluent-syntax",
 "fluent-templates 0.9.4",
 "globwalk",
 "pathdiff",
 "proc-macro2",
 "quote",
 "serde",
 "serde_json",
 "syn 2.0.75",
 "walkdir",
]

An examination of leptos-fluent's codebase doesn't show any use of v0.9.4 anywhere - all of the uses are for v0.10.0. I am fortunately able to get my project to compile if I knock my fluent-template version down to 0.9.4, but I imagine you want to have users of this library use the latest version of fluent-templates when possible. To this end, it may be worth re-exporting the fluent-templates crate from this crate so users don't have to add the dependencies separately and so it's easier to guarantee that dependents use compatible versions.

mondeja commented 3 months ago

I'm pretty sure that you're using both versions for some reason, I've experienced this on the past. Perhaps is a rustc bug, do you've run cargo update? Please, try to run cargo update, ensure that fluent-templates v0.10.0 is used and, remove the target/ folder and recompile, that worked for me.

I don't want to reexport fluent-templates to allow users to change their fluent-templates version when they want without depending on leptos fluent. For example, to use it on the server.

SleeplessOne1917 commented 3 months ago

I ran cargo clean to delete the target folder and cargo update to update all deps and still have the issue. I even deleted everything under ~/.cargo/registry/src, ~/.cargo/registry/index, and ~/.cargo/registry/cache and I'm still getting the issue.

SleeplessOne1917 commented 3 months ago

I also tried making a fresh project with cargo leptos new -g leptos-rs/start and added the leptos-fluent and fluent-templates dependencies to it. I ran into the same issue of the project using both v0.10.0 and v0.9.4 of fluent-templates.

SleeplessOne1917 commented 3 months ago

I think I found the issue: the commit on the master branch of this repo that updated the fluent-templates dependency isn't in v0.1.17. I was able to get my project to compile fine when I used a local copy of this repo with the master branch, and the 0.1.17 release in github's release list says "1 commit to master since release".

image

The most recent commit to master was bumping the fluent-templates dep to use v0.10.0. Therefore, 0.1.17 must not include the fluent-templates 0.10.0.

mondeja commented 3 months ago

Thanks for investigate it. I'll relax the dependency and release a patch ASAP. Apoligies for my confusion here.