File tree Expand file tree Collapse file tree 2 files changed +9
-8
lines changed
Expand file tree Collapse file tree 2 files changed +9
-8
lines changed Original file line number Diff line number Diff line change @@ -5,12 +5,7 @@ pub struct Ident(Cow<'static, str>);
55
66impl Ident {
77 pub fn new ( s : impl Into < Cow < ' static , str > > ) -> Self {
8- let s: Cow < ' static , str > = s. into ( ) ;
9- if is_keyword ( & s) {
10- Self ( Cow :: Owned ( format ! ( "%{}" , s) ) )
11- } else {
12- Self ( s)
13- }
8+ Self ( s. into ( ) )
149 }
1510}
1611
2520
2621impl fmt:: Display for Ident {
2722 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
23+ if is_keyword ( & self . 0 ) {
24+ write ! ( f, "%" ) ?;
25+ }
2826 self . 0 . fmt ( f)
2927 }
3028}
@@ -37,8 +35,8 @@ impl AsRef<str> for Ident {
3735
3836fn is_keyword ( name : & str ) -> bool {
3937 match name {
40- "u8" | "u16" | "u32" | "u64" | "s8" | "s16" | "s32" | "s64" | "float32 " | "float64 "
41- | "char" | " bool" | "string" | "tuple" | "list" | "option" | "result" | "use" | "type"
38+ "u8" | "u16" | "u32" | "u64" | "s8" | "s16" | "s32" | "s64" | "f32 " | "f64" | "char "
39+ | "bool" | "string" | "tuple" | "list" | "option" | "result" | "use" | "type"
4240 | "resource" | "func" | "record" | "enum" | "flags" | "variant" | "static"
4341 | "interface" | "world" | "import" | "export" | "package" | "own" | "borrow" => true ,
4442 _ => false ,
Original file line number Diff line number Diff line change @@ -103,6 +103,7 @@ const PACKAGE: &str = indoc::indoc! {"
103103 type t46 = t44;
104104 type foo = bar;
105105 type bar = u32;
106+ type %f64 = f64;
106107 resource t50 {
107108 }
108109 resource t51 {
@@ -211,6 +212,8 @@ fn types() {
211212 interface. type_def ( TypeDef :: type_ ( "foo" , Type :: named ( "bar" ) ) ) ;
212213 interface. type_def ( TypeDef :: type_ ( "bar" , Type :: U32 ) ) ;
213214
215+ interface. type_def ( TypeDef :: type_ ( "f64" , Type :: F64 ) ) ;
216+
214217 interface. type_def ( TypeDef :: resource ( "t50" , Vec :: < ResourceFunc > :: new ( ) ) ) ;
215218 interface. type_def ( TypeDef :: resource (
216219 "t51" ,
You can’t perform that action at this time.
0 commit comments