From 9cc9dacc080e918c70c81ab4b31baad427d0e16d Mon Sep 17 00:00:00 2001 From: Jakub Konka Date: Fri, 28 Feb 2020 21:06:12 +0100 Subject: [PATCH] Escape reserved keywords in generate This commit escapes certain (hopefully all keywords present in snapshot1!) reserved keywords in Rust that are autogenerated by wiggle. --- crates/generate/src/names.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/crates/generate/src/names.rs b/crates/generate/src/names.rs index f268514c1d..1167d25a60 100644 --- a/crates/generate/src/names.rs +++ b/crates/generate/src/names.rs @@ -77,6 +77,8 @@ impl Names { // FIXME this is a hack - just a proof of concept. if id.as_str().starts_with('2') { format_ident!("TooBig") + } else if id.as_str() == "type" { + format_ident!("Type") } else { format_ident!("{}", id.as_str().to_camel_case()) } @@ -91,7 +93,12 @@ impl Names { } pub fn struct_member(&self, id: &Id) -> Ident { - format_ident!("{}", id.as_str().to_snake_case()) + // FIXME this is a hack - just a proof of concept. + if id.as_str() == "type" { + format_ident!("type_") + } else { + format_ident!("{}", id.as_str().to_snake_case()) + } } pub fn module(&self, id: &Id) -> Ident { @@ -107,7 +114,12 @@ impl Names { } pub fn func_param(&self, id: &Id) -> Ident { - format_ident!("{}", id.as_str().to_snake_case()) + // FIXME this is a hack - just a proof of concept. + if id.as_str() == "in" { + format_ident!("in_") + } else { + format_ident!("{}", id.as_str().to_snake_case()) + } } /// For when you need a {name}_ptr binding for passing a value by reference: