diff --git a/crates/wit-parser/src/lib.rs b/crates/wit-parser/src/lib.rs index 9d78dda286..696a8c19c3 100644 --- a/crates/wit-parser/src/lib.rs +++ b/crates/wit-parser/src/lib.rs @@ -19,7 +19,8 @@ mod live; pub use live::LiveTypes; mod serde_; use serde_::{ - serialize_anon_result, serialize_id, serialize_id_map, serialize_optional_id, serialize_params, + serialize_anon_result, serialize_id, serialize_id_map, serialize_none, serialize_optional_id, + serialize_params, }; /// Checks if the given string is a legal identifier in wit. @@ -427,6 +428,7 @@ pub enum TypeOwner { Interface(InterfaceId), /// This type wasn't inherently defined anywhere, such as a `list`, which /// doesn't need an owner. + #[serde(untagged, serialize_with = "serialize_none")] None, } diff --git a/crates/wit-parser/src/serde_.rs b/crates/wit-parser/src/serde_.rs index 64497b3c96..c31eda8420 100644 --- a/crates/wit-parser/src/serde_.rs +++ b/crates/wit-parser/src/serde_.rs @@ -4,6 +4,13 @@ use indexmap::IndexMap; use serde::ser::{SerializeMap, SerializeSeq, Serializer}; use serde::Serialize; +pub fn serialize_none(serializer: S) -> Result +where + S: Serializer, +{ + serializer.serialize_none() +} + pub fn serialize_arena(arena: &Arena, serializer: S) -> Result where T: Serialize, diff --git a/crates/wit-parser/tests/ui/functions.wit.json b/crates/wit-parser/tests/ui/functions.wit.json index cac2adb53a..bb2867cde4 100644 --- a/crates/wit-parser/tests/ui/functions.wit.json +++ b/crates/wit-parser/tests/ui/functions.wit.json @@ -134,14 +134,14 @@ ] } }, - "owner": "none" + "owner": null }, { "name": null, "kind": { "option": "u32" }, - "owner": "none" + "owner": null }, { "name": null, @@ -151,7 +151,7 @@ "err": "float32" } }, - "owner": "none" + "owner": null } ], "packages": [ diff --git a/crates/wit-parser/tests/ui/random.wit.json b/crates/wit-parser/tests/ui/random.wit.json index 970e8067f2..5d46664671 100644 --- a/crates/wit-parser/tests/ui/random.wit.json +++ b/crates/wit-parser/tests/ui/random.wit.json @@ -49,7 +49,7 @@ "kind": { "list": "u8" }, - "owner": "none" + "owner": null } ], "packages": [ diff --git a/crates/wit-parser/tests/ui/resources-empty.wit.json b/crates/wit-parser/tests/ui/resources-empty.wit.json index 5ec2d76de7..6c40c61dfc 100644 --- a/crates/wit-parser/tests/ui/resources-empty.wit.json +++ b/crates/wit-parser/tests/ui/resources-empty.wit.json @@ -48,7 +48,7 @@ "borrow": 0 } }, - "owner": "none" + "owner": null }, { "name": null, @@ -57,7 +57,7 @@ "own": 0 } }, - "owner": "none" + "owner": null } ], "packages": [ diff --git a/crates/wit-parser/tests/ui/resources-multiple-returns-borrow.wit.json b/crates/wit-parser/tests/ui/resources-multiple-returns-borrow.wit.json index 21ed3b10ad..d5fbf02a2c 100644 --- a/crates/wit-parser/tests/ui/resources-multiple-returns-borrow.wit.json +++ b/crates/wit-parser/tests/ui/resources-multiple-returns-borrow.wit.json @@ -59,7 +59,7 @@ "borrow": 0 } }, - "owner": "none" + "owner": null } ], "packages": [ diff --git a/crates/wit-parser/tests/ui/resources-multiple-returns-own.wit.json b/crates/wit-parser/tests/ui/resources-multiple-returns-own.wit.json index 83ca7fd8b4..e7234f7ed8 100644 --- a/crates/wit-parser/tests/ui/resources-multiple-returns-own.wit.json +++ b/crates/wit-parser/tests/ui/resources-multiple-returns-own.wit.json @@ -59,7 +59,7 @@ "borrow": 0 } }, - "owner": "none" + "owner": null }, { "name": null, @@ -68,7 +68,7 @@ "own": 0 } }, - "owner": "none" + "owner": null } ], "packages": [ diff --git a/crates/wit-parser/tests/ui/resources-multiple.wit.json b/crates/wit-parser/tests/ui/resources-multiple.wit.json index f76eb0bccb..b77d35f867 100644 --- a/crates/wit-parser/tests/ui/resources-multiple.wit.json +++ b/crates/wit-parser/tests/ui/resources-multiple.wit.json @@ -228,7 +228,7 @@ "borrow": 0 } }, - "owner": "none" + "owner": null }, { "name": null, @@ -240,14 +240,14 @@ ] } }, - "owner": "none" + "owner": null }, { "name": null, "kind": { "option": "u32" }, - "owner": "none" + "owner": null }, { "name": null, @@ -257,7 +257,7 @@ "err": "float32" } }, - "owner": "none" + "owner": null }, { "name": null, @@ -266,7 +266,7 @@ "own": 0 } }, - "owner": "none" + "owner": null } ], "packages": [ diff --git a/crates/wit-parser/tests/ui/resources-return-borrow.wit.json b/crates/wit-parser/tests/ui/resources-return-borrow.wit.json index 85bd1f04fb..c48dd35167 100644 --- a/crates/wit-parser/tests/ui/resources-return-borrow.wit.json +++ b/crates/wit-parser/tests/ui/resources-return-borrow.wit.json @@ -54,7 +54,7 @@ "borrow": 0 } }, - "owner": "none" + "owner": null } ], "packages": [ diff --git a/crates/wit-parser/tests/ui/resources-return-own.wit.json b/crates/wit-parser/tests/ui/resources-return-own.wit.json index bc3f273263..3e44fc106c 100644 --- a/crates/wit-parser/tests/ui/resources-return-own.wit.json +++ b/crates/wit-parser/tests/ui/resources-return-own.wit.json @@ -54,7 +54,7 @@ "borrow": 0 } }, - "owner": "none" + "owner": null }, { "name": null, @@ -63,7 +63,7 @@ "own": 0 } }, - "owner": "none" + "owner": null } ], "packages": [ diff --git a/crates/wit-parser/tests/ui/resources.wit.json b/crates/wit-parser/tests/ui/resources.wit.json index ad368e0679..169fb02110 100644 --- a/crates/wit-parser/tests/ui/resources.wit.json +++ b/crates/wit-parser/tests/ui/resources.wit.json @@ -209,7 +209,7 @@ "borrow": 3 } }, - "owner": "none" + "owner": null }, { "name": null, @@ -218,7 +218,7 @@ "borrow": 4 } }, - "owner": "none" + "owner": null }, { "name": "a", @@ -286,7 +286,7 @@ "own": 1 } }, - "owner": "none" + "owner": null }, { "name": null, @@ -295,7 +295,7 @@ "own": 2 } }, - "owner": "none" + "owner": null }, { "name": null, @@ -304,7 +304,7 @@ "own": 3 } }, - "owner": "none" + "owner": null }, { "name": null, @@ -313,7 +313,7 @@ "own": 4 } }, - "owner": "none" + "owner": null }, { "name": null, @@ -322,7 +322,7 @@ "own": 13 } }, - "owner": "none" + "owner": null } ], "packages": [ diff --git a/crates/wit-parser/tests/ui/resources1.wit.json b/crates/wit-parser/tests/ui/resources1.wit.json index e04fa4019d..447e5ec2b9 100644 --- a/crates/wit-parser/tests/ui/resources1.wit.json +++ b/crates/wit-parser/tests/ui/resources1.wit.json @@ -72,7 +72,7 @@ "borrow": 0 } }, - "owner": "none" + "owner": null }, { "name": null, @@ -81,7 +81,7 @@ "own": 0 } }, - "owner": "none" + "owner": null } ], "packages": [ diff --git a/crates/wit-parser/tests/ui/shared-types.wit.json b/crates/wit-parser/tests/ui/shared-types.wit.json index ba3a90c804..d0dba6598c 100644 --- a/crates/wit-parser/tests/ui/shared-types.wit.json +++ b/crates/wit-parser/tests/ui/shared-types.wit.json @@ -57,7 +57,7 @@ "kind": { "list": "u8" }, - "owner": "none" + "owner": null }, { "name": null, @@ -68,7 +68,7 @@ ] } }, - "owner": "none" + "owner": null } ], "packages": [ diff --git a/crates/wit-parser/tests/ui/types.wit.json b/crates/wit-parser/tests/ui/types.wit.json index f805f579db..2839365bc8 100644 --- a/crates/wit-parser/tests/ui/types.wit.json +++ b/crates/wit-parser/tests/ui/types.wit.json @@ -531,7 +531,7 @@ "kind": { "option": "u32" }, - "owner": "none" + "owner": null }, { "name": "t37", @@ -618,14 +618,14 @@ "kind": { "list": 31 }, - "owner": "none" + "owner": null }, { "name": null, "kind": { "list": 42 }, - "owner": "none" + "owner": null }, { "name": "t45", diff --git a/crates/wit-parser/tests/ui/world-top-level-funcs.wit.json b/crates/wit-parser/tests/ui/world-top-level-funcs.wit.json index 7a802a66b3..b7866aa12d 100644 --- a/crates/wit-parser/tests/ui/world-top-level-funcs.wit.json +++ b/crates/wit-parser/tests/ui/world-top-level-funcs.wit.json @@ -57,21 +57,21 @@ "kind": { "list": "u32" }, - "owner": "none" + "owner": null }, { "name": null, "kind": { "option": "u32" }, - "owner": "none" + "owner": null }, { "name": null, "kind": { "list": 1 }, - "owner": "none" + "owner": null } ], "packages": [ diff --git a/crates/wit-parser/tests/ui/world-top-level-resources.wit.json b/crates/wit-parser/tests/ui/world-top-level-resources.wit.json index f3e2ff0363..ee1fd2c6f6 100644 --- a/crates/wit-parser/tests/ui/world-top-level-resources.wit.json +++ b/crates/wit-parser/tests/ui/world-top-level-resources.wit.json @@ -152,14 +152,14 @@ "borrow": 0 } }, - "owner": "none" + "owner": null }, { "name": null, "kind": { "list": "u32" }, - "owner": "none" + "owner": null }, { "name": null, @@ -168,7 +168,7 @@ "borrow": 1 } }, - "owner": "none" + "owner": null }, { "name": "request", @@ -195,7 +195,7 @@ "borrow": 5 } }, - "owner": "none" + "owner": null }, { "name": null, @@ -204,7 +204,7 @@ "borrow": 6 } }, - "owner": "none" + "owner": null }, { "name": null, @@ -213,7 +213,7 @@ "own": 5 } }, - "owner": "none" + "owner": null }, { "name": null, @@ -222,7 +222,7 @@ "own": 6 } }, - "owner": "none" + "owner": null } ], "packages": [