diff --git a/ast/asdl_rs.py b/ast/asdl_rs.py index ed5800f..a18ec65 100755 --- a/ast/asdl_rs.py +++ b/ast/asdl_rs.py @@ -227,12 +227,12 @@ class StructVisitor(TypeInfoEmitVisitor): if cons.fields: self.emit(f"{cons.name} {{", depth) for f in cons.fields: - self.visit(f, parent, "", depth + 1) + self.visit(f, parent, "", depth + 1, cons.name) self.emit("},", depth) else: self.emit(f"{cons.name},", depth) - def visitField(self, field, parent, vis, depth): + def visitField(self, field, parent, vis, depth, constructor=None): typ = get_rust_type(field.type) fieldtype = self.typeinfo.get(field.type) if fieldtype and fieldtype.has_userdata: @@ -240,7 +240,11 @@ class StructVisitor(TypeInfoEmitVisitor): # don't box if we're doing Vec, but do box if we're doing Vec>> if fieldtype and fieldtype.boxed and (not (parent.product or field.seq) or field.opt): typ = f"Box<{typ}>" - if field.opt: + if field.opt or ( + # Add `Option` to allow `Dict.keys` to contain `None` for dictionary unpacking + # in a dict literal. + constructor == "Dict" and field.name == "keys" + ): typ = f"Option<{typ}>" if field.seq: typ = f"Vec<{typ}>"