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>);
5
5
6
6
impl Ident {
7
7
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 ( ) )
14
9
}
15
10
}
16
11
25
20
26
21
impl fmt:: Display for Ident {
27
22
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
23
+ if is_keyword ( & self . 0 ) {
24
+ write ! ( f, "%" ) ?;
25
+ }
28
26
self . 0 . fmt ( f)
29
27
}
30
28
}
@@ -37,8 +35,8 @@ impl AsRef<str> for Ident {
37
35
38
36
fn is_keyword ( name : & str ) -> bool {
39
37
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"
42
40
| "resource" | "func" | "record" | "enum" | "flags" | "variant" | "static"
43
41
| "interface" | "world" | "import" | "export" | "package" | "own" | "borrow" => true ,
44
42
_ => false ,
Original file line number Diff line number Diff line change @@ -103,6 +103,7 @@ const PACKAGE: &str = indoc::indoc! {"
103
103
type t46 = t44;
104
104
type foo = bar;
105
105
type bar = u32;
106
+ type %f64 = f64;
106
107
resource t50 {
107
108
}
108
109
resource t51 {
@@ -211,6 +212,8 @@ fn types() {
211
212
interface. type_def ( TypeDef :: type_ ( "foo" , Type :: named ( "bar" ) ) ) ;
212
213
interface. type_def ( TypeDef :: type_ ( "bar" , Type :: U32 ) ) ;
213
214
215
+ interface. type_def ( TypeDef :: type_ ( "f64" , Type :: F64 ) ) ;
216
+
214
217
interface. type_def ( TypeDef :: resource ( "t50" , Vec :: < ResourceFunc > :: new ( ) ) ) ;
215
218
interface. type_def ( TypeDef :: resource (
216
219
"t51" ,
You can’t perform that action at this time.
0 commit comments