Repository: serde-rs/json (language: rust)

Issue:
`json!` unusable with `no_std` and feature `alloc`
When you use an array inside the `json!` macro, the expansion calls `vec!` unqualified. This is a problem in a `no_std` environment, because it requires the user to `use alloc::vec`. Which is weird and no expected from a macro.

Reproducer on rustexplorer: https://www.rustexplorer.com/b#LyoKW2RlcGVuZGVuY2llc10Kc2VyZGVfanNvbiA9IHsgdmVyc2lvbiA9ICIxLjAuMTIwIiwgZGVmYXVsdC1mZWF0dXJlcyA9IGZhbHNlLCBmZWF0dXJlcyA9IFsiYWxsb2MiXSB9CiovCgojIVtub19zdGRdCgpleHRlcm4gY3JhdGUgYWxsb2M7CgpmbiBtYWluKCkgewogICAgc2VyZGVfanNvbjo6anNvbiEoWyIiLCAiIl0pOwp9Cg==

Code: 
```rust
/*
[dependencies]
serde_json = { version = "1.0.120", default-features = false, features = ["alloc"] }
*/

#![no_std]

extern crate alloc;

fn main() {
    serde_json::json!(["", ""]);
}
```

I think this issue has a simple solution by changing `vec!` to `::alloc::vec!`, unless I'm missing something.


Discussion / hints:

Fix patch:
diff --git a/src/lib.rs b/src/lib.rs
index 3225e26f0..4ef91095f 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -373,6 +373,12 @@ extern crate alloc;
 #[cfg(feature = "std")]
 extern crate std;
 
+// Not public API. Used from macro-generated code.
+#[doc(hidden)]
+pub mod __private {
+    pub use alloc::vec;
+}
+
 #[cfg(feature = "std")]
 #[cfg_attr(docsrs, doc(cfg(feature = "std")))]
 #[doc(inline)]
diff --git a/src/macros.rs b/src/macros.rs
index 68e071026..c47bdf929 100644
--- a/src/macros.rs
+++ b/src/macros.rs
@@ -77,12 +77,12 @@ macro_rules! json_internal {
 
     // Done with trailing comma.
     (@array [$($elems:expr,)*]) => {
-        vec![$($elems,)*]
+        $crate::__private::vec![$($elems,)*]
     };
 
     // Done without trailing comma.
     (@array [$($elems:expr),*]) => {
-        vec![$($elems),*]
+        $crate::__private::vec![$($elems),*]
     };
 
     // Next element is `null`.
@@ -254,7 +254,7 @@ macro_rules! json_internal {
     };
 
     ([]) => {
-        $crate::Value::Array(vec![])
+        $crate::Value::Array($crate::__private::vec![])
     };
 
     ([ $($tt:tt)+ ]) => {


Test patch: