You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm not sure whether this is serde_json's issue or rustc's. If you think this is not related tho this repo, but rather a bug in rustc, file it to them or tell me and I'll do this.
OK, now the issue. This code does not compile unless the first line is removed:
use serde_json;#[cfg(test)]mod test {#[test]fninto_iter(){assert_eq!(10, vec![1, 2, 3, 4].iter().sum());}}
The problem is that compiler cannot infer types for sum(). However, removing or putting the use serde_json; into a comment makes it compile.
The problem is even more strange as it brakes similar code in other modules of the same package.
I made a demo repo that shows the problem.
It brakes only with_serde json. At least importing serde and failure does not brake it.
The text was updated successfully, but these errors were encountered:
acanthite1855
changed the title
use serde_json breaks type inference in some cases
serde_json breaks type inference of user code in some cases
Apr 6, 2020
I found the issue in serde_json. This macro expansion causes it: src/value/partial_eq.rs#L90.
Without this macro expansion inference works.
If I understand correctly, rustc cannot figure what I want to compare in the assert_eq, because the partialeq_numeric makes primitives equatable to Value.
I can see that the macro is used only in tests, because the main library compiles fine without this macro.
But it cannot be moved into tests because of the rust's orphan rules for trait implementations. Neither #[cfg(test)] will work. Because the tests module implemented as a separate crate (very strange as for me, why not in the same carte?), and uses serde_json as a regular dependency. Which builds as regular depndency and throws all of the #[cfg(test)] code, if understand it correctly.
I'm not sure whether this is serde_json's issue or rustc's. If you think this is not related tho this repo, but rather a bug in rustc, file it to them or tell me and I'll do this.
OK, now the issue. This code does not compile unless the first line is removed:
The problem is that compiler cannot infer types for
sum()
. However, removing or putting theuse serde_json;
into a comment makes it compile.The problem is even more strange as it brakes similar code in other modules of the same package.
I made a demo repo that shows the problem.
It brakes only with_serde json. At least importing
serde
andfailure
does not brake it.The text was updated successfully, but these errors were encountered: