sunng87 / handlebars-iron

Handlebars middleware for Iron web framework
MIT License
119 stars 20 forks source link

Compilation error with `serde_type` #47

Closed azerupi closed 7 years ago

azerupi commented 8 years ago

So when using the serde_type feature I get a compilation error. The compilation error actually originates in the handlebars crate but since I do not depend on it directly I was not sure where I should submit the issue.

Compiling handlebars v0.18.1
error: a type named `Json` has already been imported in this module [--explain E0252]
  --> /home/azerupi/.cargo/registry/src/github.com-1ecc6299db9ec823/handlebars-0.18.1/src/template.rs:11:5
   |>
9  |> use serialize::json::Json;
   |>     --------------------- previous import of `Json` here
10 |> #[cfg(feature = "serde_type")]
11 |> use serde_json::value::Value as Json;
   |>     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: a trait named `ToJson` has already been imported in this module [--explain E0252]
 --> /home/azerupi/.cargo/registry/src/github.com-1ecc6299db9ec823/handlebars-0.18.1/src/registry.rs:9:5
  |>
7 |> use serialize::json::ToJson;
  |>     ----------------------- previous import of `ToJson` here
8 |> #[cfg(feature = "serde_type")]
9 |> use serde::ser::Serialize as ToJson;
  |>     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: a type named `Json` has already been imported in this module [--explain E0252]
  --> /home/azerupi/.cargo/registry/src/github.com-1ecc6299db9ec823/handlebars-0.18.1/src/render.rs:10:5
   |>
8  |> use serialize::json::Json;
   |>     --------------------- previous import of `Json` here
9  |> #[cfg(feature = "serde_type")]
10 |> use serde_json::value::Value as Json;
   |>     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: a type named `Json` has already been imported in this module [--explain E0252]
 --> /home/azerupi/.cargo/registry/src/github.com-1ecc6299db9ec823/handlebars-0.18.1/src/helpers/helper_each.rs:4:31
  |>
2 |> use serialize::json::{Json, ToJson};
  |>                       ---- previous import of `Json` here
3 |> #[cfg(feature = "serde_type")]
4 |> use serde_json::value::{self, Value as Json};
  |>                               ^^^^^^^^^^^^^

error: a type named `Json` has already been imported in this module [--explain E0252]
 --> /home/azerupi/.cargo/registry/src/github.com-1ecc6299db9ec823/handlebars-0.18.1/src/helpers/helper_lookup.rs:4:5
  |>
2 |> use serialize::json::Json;
  |>     --------------------- previous import of `Json` here
3 |> #[cfg(feature = "serde_type")]
4 |> use serde_json::value::Value as Json;
  |>     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: a type named `Json` has already been imported in this module [--explain E0252]
   --> /home/azerupi/.cargo/registry/src/github.com-1ecc6299db9ec823/handlebars-0.18.1/src/context.rs:7:31
    |>
2   |> use serialize::json::{Json, ToJson};
    |>                       ---- previous import of `Json` here
...
7   |> use serde_json::value::{self, Value as Json};
    |>                               ^^^^^^^^^^^^^

error: duplicate definitions with name `call`: [--explain E0201]
  --> /home/azerupi/.cargo/registry/src/github.com-1ecc6299db9ec823/handlebars-0.18.1/src/helpers/helper_each.rs:87:5
   |>
87 |>     fn call(&self,
   |>     ^
note: previous definition of `call` here
  --> /home/azerupi/.cargo/registry/src/github.com-1ecc6299db9ec823/handlebars-0.18.1/src/helpers/helper_each.rs:17:5
   |>
17 |>     fn call(&self,
   |>     ^

error: duplicate definitions with name `wraps`: [--explain E0201]
  --> /home/azerupi/.cargo/registry/src/github.com-1ecc6299db9ec823/handlebars-0.18.1/src/context.rs:79:5
   |>
79 |>     pub fn wraps<T: Serialize>(e: &T) -> Context {
   |>     ^
note: previous definition of `wraps` here
  --> /home/azerupi/.cargo/registry/src/github.com-1ecc6299db9ec823/handlebars-0.18.1/src/context.rs:73:5
   |>
73 |>     pub fn wraps<T: ToJson>(e: &T) -> Context {
   |>     ^

error: aborting due to 2 previous errors
error: Could not compile `handlebars`.

At first sight, it seems as enabling serde_type does not disable rustc-serialize causing the double definitions.

EDIT: It seems to compile fine with default-features = false but intuitively I would have assumed that just enabling serde_type would take care of this. Would it be possible disable rustc-serialize when serde_type is enabled?

sunng87 commented 7 years ago

It's because I made rustc_serialize the default feature for convenience and backward compatibility. In order to use serde_type, you will need to disable it via --no-default-features.

azerupi commented 7 years ago

Is there a way to leave it as default feature but still disable it when serde_type is enabled?

azerupi commented 7 years ago

I think you could use something like below to only compile rustc-serialize code when serde_type isn't enabled

#[cfg(all(rustc-serialize, not(serde_type)))]
azerupi commented 7 years ago

By the way, I am busy at the moment but I am willing to test this and make a PR later today if you agree :)

sunng87 commented 7 years ago

Nice! Thank you!