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 when neither std nor alloc is enabled #643

Merged
merged 1 commit into from
Mar 28, 2020
Merged

Conversation

dtolnay
Copy link
Member

@dtolnay dtolnay commented Mar 28, 2020

Some tweaks to make the following produce a more compact error.

[dependencies]
serde_json = { version = "1.0", default-features = false }

After:

error: expected item, found `"serde_json requires that either `std` (default) or `alloc` feature is enabled"`
 --> src/features_check/error.rs:1:1
  |
1 | "serde_json requires that either `std` (default) or `alloc` feature is enabled"
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected item

Before:

error: expected item, found `"serde_json requires that either `std` (default) or `alloc` feature is enabled"`
 --> src/features_check/error.rs:1:1
  |
1 | "serde_json requires that either `std` (default) or `alloc` feature is enabled"
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected item

error[E0407]: method `visit_string` is not a member of trait `Visitor`
  --> src/value/de.rs:60:13
   |
60 | /             fn visit_string<E>(self, value: String) -> Result<Value, E> {
61 | |                 Ok(Value::String(value))
62 | |             }
   | |_____________^ not a member of trait `Visitor`

error[E0407]: method `visit_string` is not a member of trait `Visitor`
    --> src/value/de.rs:1340:5
     |
1340 | /     fn visit_string<E>(self, s: String) -> Result<Self::Value, E>
1341 | |     where
1342 | |         E: de::Error,
1343 | |     {
...    |
1350 | |         }
1351 | |     }
     | |_____^ not a member of trait `Visitor`

error[E0277]: the trait bound `alloc::string::String: serde::ser::Serialize` is not satisfied
   --> src/map.rs:301:22
    |
301 |             tri!(map.serialize_entry(k, v));
    |                      ^^^^^^^^^^^^^^^ the trait `serde::ser::Serialize` is not implemented for `alloc::string::String`

error[E0277]: the trait bound `alloc::string::String: serde::de::Deserialize<'de>` is not satisfied
   --> src/map.rs:337:61
    |
337 |                 while let Some((key, value)) = tri!(visitor.next_entry()) {
    |                                                             ^^^^^^^^^^ the trait `serde::de::Deserialize<'de>` is not implemented for `alloc::string::String`

error[E0599]: no method named `visit_string` found for struct `value::de::<impl serde::de::Deserialize<'de> for value::Value>::deserialize::ValueVisitor` in the current scope
  --> src/value/de.rs:56:22
   |
22 |         struct ValueVisitor;
   |         -------------------- method `visit_string` not found for this
...
56 |                 self.visit_string(String::from(value))
   |                      ^^^^^^^^^^^^ method not found in `value::de::<impl serde::de::Deserialize<'de> for value::Value>::deserialize::ValueVisitor`

error[E0277]: the trait bound `alloc::string::String: serde::de::Deserialize<'de>` is not satisfied
   --> src/value/de.rs:115:69
    |
115 |                         while let Some((key, value)) = tri!(visitor.next_entry()) {
    |                                                                     ^^^^^^^^^^ the trait `serde::de::Deserialize<'de>` is not implemented for `alloc::string::String`

error[E0599]: no method named `visit_string` found for type parameter `V` in the current scope
   --> src/value/de.rs:211:41
    |
211 |             Value::String(v) => visitor.visit_string(v),
    |                                         ^^^^^^^^^^^^ help: there is an associated function with a similar name: `visit_str`

error[E0599]: no method named `visit_string` found for type parameter `V` in the current scope
   --> src/value/de.rs:341:41
    |
341 |             Value::String(v) => visitor.visit_string(v),
    |                                         ^^^^^^^^^^^^ help: there is an associated function with a similar name: `visit_str`

error[E0599]: no method named `visit_string` found for type parameter `V` in the current scope
   --> src/value/de.rs:358:41
    |
358 |             Value::String(v) => visitor.visit_string(v),
    |                                         ^^^^^^^^^^^^ help: there is an associated function with a similar name: `visit_str`

error[E0599]: no method named `visit_string` found for type parameter `V` in the current scope
    --> src/value/de.rs:1228:52
     |
1228 |                 (Err(_), Cow::Owned(s)) => visitor.visit_string(s),
     |                                                    ^^^^^^^^^^^^ help: there is an associated function with a similar name: `visit_str`
...
1244 |     deserialize_integer_key!(deserialize_i8 => visit_i8);
     |     ----------------------------------------------------- in this macro invocation
     |
     = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0599]: no method named `visit_string` found for type parameter `V` in the current scope
    --> src/value/de.rs:1228:52
     |
1228 |                 (Err(_), Cow::Owned(s)) => visitor.visit_string(s),
     |                                                    ^^^^^^^^^^^^ help: there is an associated function with a similar name: `visit_str`
...
1245 |     deserialize_integer_key!(deserialize_i16 => visit_i16);
     |     ------------------------------------------------------- in this macro invocation
     |
     = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0599]: no method named `visit_string` found for type parameter `V` in the current scope
    --> src/value/de.rs:1228:52
     |
1228 |                 (Err(_), Cow::Owned(s)) => visitor.visit_string(s),
     |                                                    ^^^^^^^^^^^^ help: there is an associated function with a similar name: `visit_str`
...
1246 |     deserialize_integer_key!(deserialize_i32 => visit_i32);
     |     ------------------------------------------------------- in this macro invocation
     |
     = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0599]: no method named `visit_string` found for type parameter `V` in the current scope
    --> src/value/de.rs:1228:52
     |
1228 |                 (Err(_), Cow::Owned(s)) => visitor.visit_string(s),
     |                                                    ^^^^^^^^^^^^ help: there is an associated function with a similar name: `visit_str`
...
1247 |     deserialize_integer_key!(deserialize_i64 => visit_i64);
     |     ------------------------------------------------------- in this macro invocation
     |
     = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0599]: no method named `visit_string` found for type parameter `V` in the current scope
    --> src/value/de.rs:1228:52
     |
1228 |                 (Err(_), Cow::Owned(s)) => visitor.visit_string(s),
     |                                                    ^^^^^^^^^^^^ help: there is an associated function with a similar name: `visit_str`
...
1248 |     deserialize_integer_key!(deserialize_u8 => visit_u8);
     |     ----------------------------------------------------- in this macro invocation
     |
     = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0599]: no method named `visit_string` found for type parameter `V` in the current scope
    --> src/value/de.rs:1228:52
     |
1228 |                 (Err(_), Cow::Owned(s)) => visitor.visit_string(s),
     |                                                    ^^^^^^^^^^^^ help: there is an associated function with a similar name: `visit_str`
...
1249 |     deserialize_integer_key!(deserialize_u16 => visit_u16);
     |     ------------------------------------------------------- in this macro invocation
     |
     = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0599]: no method named `visit_string` found for type parameter `V` in the current scope
    --> src/value/de.rs:1228:52
     |
1228 |                 (Err(_), Cow::Owned(s)) => visitor.visit_string(s),
     |                                                    ^^^^^^^^^^^^ help: there is an associated function with a similar name: `visit_str`
...
1250 |     deserialize_integer_key!(deserialize_u32 => visit_u32);
     |     ------------------------------------------------------- in this macro invocation
     |
     = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0599]: no method named `visit_string` found for type parameter `V` in the current scope
    --> src/value/de.rs:1228:52
     |
1228 |                 (Err(_), Cow::Owned(s)) => visitor.visit_string(s),
     |                                                    ^^^^^^^^^^^^ help: there is an associated function with a similar name: `visit_str`
...
1251 |     deserialize_integer_key!(deserialize_u64 => visit_u64);
     |     ------------------------------------------------------- in this macro invocation
     |
     = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0599]: no method named `visit_string` found for type parameter `V` in the current scope
    --> src/value/de.rs:1228:52
     |
1228 |                 (Err(_), Cow::Owned(s)) => visitor.visit_string(s),
     |                                                    ^^^^^^^^^^^^ help: there is an associated function with a similar name: `visit_str`
...
1254 |         deserialize_integer_key!(deserialize_i128 => visit_i128);
     |         --------------------------------------------------------- in this macro invocation
     |
     = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0599]: no method named `visit_string` found for type parameter `V` in the current scope
    --> src/value/de.rs:1228:52
     |
1228 |                 (Err(_), Cow::Owned(s)) => visitor.visit_string(s),
     |                                                    ^^^^^^^^^^^^ help: there is an associated function with a similar name: `visit_str`
...
1255 |         deserialize_integer_key!(deserialize_u128 => visit_u128);
     |         --------------------------------------------------------- in this macro invocation
     |
     = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0599]: no method named `visit_string` found for type parameter `V` in the current scope
    --> src/value/de.rs:1395:43
     |
1395 |             Cow::Owned(string) => visitor.visit_string(string),
     |                                           ^^^^^^^^^^^^ help: there is an associated function with a similar name: `visit_str`

error[E0277]: the trait bound `alloc::string::String: serde::ser::Serialize` is not satisfied
  --> src/value/ser.rs:27:30
   |
27 |                     tri!(map.serialize_entry(k, v));
   |                              ^^^^^^^^^^^^^^^ the trait `serde::ser::Serialize` is not implemented for `alloc::string::String`

error: aborting due to 22 previous errors

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.

None yet

1 participant