Closed
Description
I'm seeing error: can't find crate for
..., can't find crate
errors when trying to use crate::foo::Bar
-style items in enum newtype variants and newtype structs. It works as expected for both normal structs and enum struct variants.
From my small amount of digging, it looks as though field.ty
is missing the leading crate
element when deserialize_externally_tagged_newtype_variant gets called, e.g. crate::foo::Bar
becomes just ::foo::Bar
.
Since absolute paths starting with ::
were valid in rust 2015, I assumed that they would be valid in the 2018 edition as well, which would make the absence of the crate
element a non-issue, but maybe not?
// Opt in to unstable features expected for Rust 2018
#![feature(rust_2018_preview, use_extern_macros)]
// Opt in to warnings about new 2018 idioms
#![warn(rust_2018_idioms)]
use serde_derive::Deserialize;
#[derive(Deserialize)]
struct Foo;
// These three work as expected:
#[derive(Deserialize)]
enum ThingOne {
Foo(self::Foo),
}
#[derive(Deserialize)]
enum ThingTwo {
Foo(Foo),
}
enum ThingThree {
Foo(crate::Foo),
}
// The next three don't work and all give the same error:
// error: can't find crate for `Foo`, can't find crate
// #[derive(Deserialize)]
// enum ThingFour {
// Foo(crate::Foo),
// }
// #[derive(Deserialize)]
// enum ThingFive {
// Foo(::Foo),
// }
// enum ThingSix {
// Foo(::Foo),
// }