Skip to content
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

Improve error message for using tag with alloc disabled #2742

Closed
wants to merge 1 commit into from

Conversation

dtolnay
Copy link
Member

@dtolnay dtolnay commented May 15, 2024

Closes #2668.

// [dependencies]
// serde = { version = "1", default-features = false }
// serde_derive = "1"

#[derive(serde_derive::Deserialize)]
#[serde(tag = "type")]
pub enum MyEnum {
    MyVariant
}

Error message before:

error[E0433]: failed to resolve: could not find `TaggedContentVisitor` in `de`
  --> src/main.rs:5:10
   |
5  | #[derive(serde_derive::Deserialize)]
   |          ^^^^^^^^^^^^^^^^^^^^^^^^^ could not find `TaggedContentVisitor` in `de`
   |
note: found an item that was configured out
  --> serde/src/private/de.rs:16:50
   |
16 |     TagOrContentField, TagOrContentFieldVisitor, TaggedContentVisitor, UntaggedUnitVisitor,
   |                                                  ^^^^^^^^^^^^^^^^^^^^
   = note: this error originates in the derive macro `serde_derive::Deserialize` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0433]: failed to resolve: could not find `ContentDeserializer` in `de`
  --> src/main.rs:5:10
   |
5  | #[derive(serde_derive::Deserialize)]
   |          ^^^^^^^^^^^^^^^^^^^^^^^^^ could not find `ContentDeserializer` in `de`
   |
note: found an item that was configured out
  --> serde/src/private/de.rs:14:14
   |
14 |     Content, ContentDeserializer, ContentRefDeserializer, EnumDeserializer,
   |              ^^^^^^^^^^^^^^^^^^^
   = note: this error originates in the derive macro `serde_derive::Deserialize` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0433]: failed to resolve: could not find `InternallyTaggedUnitVisitor` in `de`
  --> src/main.rs:5:10
   |
5  | #[derive(serde_derive::Deserialize)]
   |          ^^^^^^^^^^^^^^^^^^^^^^^^^ could not find `InternallyTaggedUnitVisitor` in `de`
   |
note: found an item that was configured out
  --> serde/src/private/de.rs:15:5
   |
15 |     InternallyTaggedUnitVisitor, TagContentOtherField, TagContentOtherFieldVisitor,
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^
   = note: this error originates in the derive macro `serde_derive::Deserialize` (in Nightly builds, run with -Z macro-backtrace for more info)

After:

error: Serde's `tag` attribute requires either "alloc" or "std" feature to be enabled on the serde crate
 --> src/main.rs:5:10
  |
5 | #[derive(serde_derive::Deserialize)]
  |          ^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: this error originates in the macro `_serde::__require_alloc_or_std` which comes from the expansion of the derive macro `serde_derive::Deserialize` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0433]: failed to resolve: could not find `TaggedContentVisitor` in `de`
  --> src/main.rs:5:10
   |
5  | #[derive(serde_derive::Deserialize)]
   |          ^^^^^^^^^^^^^^^^^^^^^^^^^ could not find `TaggedContentVisitor` in `de`
   |
note: found an item that was configured out
  --> serde/src/private/de.rs:16:50
   |
16 |     TagOrContentField, TagOrContentFieldVisitor, TaggedContentVisitor, UntaggedUnitVisitor,
   |                                                  ^^^^^^^^^^^^^^^^^^^^
   = note: this error originates in the derive macro `serde_derive::Deserialize` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0433]: failed to resolve: could not find `ContentDeserializer` in `de`
  --> src/main.rs:5:10
   |
5  | #[derive(serde_derive::Deserialize)]
   |          ^^^^^^^^^^^^^^^^^^^^^^^^^ could not find `ContentDeserializer` in `de`
   |
note: found an item that was configured out
  --> serde/src/private/de.rs:14:14
   |
14 |     Content, ContentDeserializer, ContentRefDeserializer, EnumDeserializer,
   |              ^^^^^^^^^^^^^^^^^^^
   = note: this error originates in the derive macro `serde_derive::Deserialize` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0433]: failed to resolve: could not find `InternallyTaggedUnitVisitor` in `de`
  --> src/main.rs:5:10
   |
5  | #[derive(serde_derive::Deserialize)]
   |          ^^^^^^^^^^^^^^^^^^^^^^^^^ could not find `InternallyTaggedUnitVisitor` in `de`
   |
note: found an item that was configured out
  --> serde/src/private/de.rs:15:5
   |
15 |     InternallyTaggedUnitVisitor, TagContentOtherField, TagContentOtherFieldVisitor,
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^
   = note: this error originates in the derive macro `serde_derive::Deserialize` (in Nightly builds, run with -Z macro-backtrace for more info)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Enum with tag does not work in #[no_std] environment
1 participant