-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Adding serde_json as an unused external crate causes a compiler error in unrelated code #46257
Comments
I guess that kind of makes sense, though, doesn't it? Importing |
It was a bad idea to have those impls (serde-rs/json#380) but while they exist, it would be nice if the compiler could resolve this case better. #46206 may fix this. |
Wow, just stumbled upon this. Had to search quite a bit until I figured out that serde / its usage is the cause. The compiler message isn't helpful at all extern crate serde_json; // 1.0.41
pub enum MyEnum {
Variant,
}
impl Into<u16> for MyEnum {
fn into(self) -> u16 {
0
}
}
fn blubb() {
// for as long as serde_json is mentioned in this file:
// type annotations required: cannot resolve `MyEnum: std::convert::Into<_>`
assert_eq!(0u16, MyEnum::Variant.into());
// fine
// assert_eq!(0u16, <MyEnum as Into<u16>>::into(MyEnum::Variant));
// in case of no "extern crate"
// serde_json::to_string_pretty(&"");
} Remove the Compiling playground v0.0.1 (/playground)
error[E0283]: type annotations required: cannot resolve `MyEnum: std::convert::Into<_>`
--> src/lib.rs:16:38
|
16 | assert_eq!(0u16, MyEnum::Variant.into());
| ^^^^
error: aborting due to previous error @dtolnay Will there be any kind of quick fix available / possible? (except of using <... as Into>) |
See rust-lang/rust#46257 This just requires us to be a little more explicit about types in a couple places
See rust-lang/rust#46257 This just requires us to be a little more explicit about types in a couple places
See rust-lang/rust#46257 This just requires us to be a little more explicit about types in a couple places
See rust-lang/rust#46257 This just requires us to be a little more explicit about types in a couple places
See rust-lang/rust#46257 This just requires us to be a little more explicit about types in a couple places
See rust-lang/rust#46257 This just requires us to be a little more explicit about types in a couple places
It is slightly different from the above question. If A depends on B, B depends on serde_json. Then serde_json would cause type inference in A to fail. Here is a example repo: https://github.com/cathaysia/rust_46257 |
The problem is easy to spot on the latest version of rust's compiler. But it would be better if there is no problem |
Someone on the Rust community discord stumbled into this, and I made a super minimal repro, I figured I'd post it just in case. #![no_implicit_prelude]
use ::core::todo;
enum Foo {}
impl ::core::cmp::PartialEq<Foo> for u32 {
fn eq(&self, other: &Foo) -> bool {
todo!()
}
}
fn main() {
0u32 == 0u64 as _;
}
|
This code compiles:
This code does not:
The text was updated successfully, but these errors were encountered: