-
Notifications
You must be signed in to change notification settings - Fork 18
Resolve conflicting implementations for two similarly named types #174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -25,7 +25,7 @@ macro_rules! call_template { | |||||||||||||||
| ($this:ident, $fn:ident, $tld:ident, $($args:expr),*) => { | ||||||||||||||||
| Ok($fn( | ||||||||||||||||
| $this.format_comments(&$tld.comments)?, | ||||||||||||||||
| $this.to_rust_const_case(&$tld.name), | ||||||||||||||||
| $this.to_rust_const_case_unique(&$tld.name), | ||||||||||||||||
| $($args),* | ||||||||||||||||
| )) | ||||||||||||||||
| }; | ||||||||||||||||
|
|
@@ -132,15 +132,15 @@ impl Rasn { | |||||||||||||||
| if integer_type.is_unbounded() { | ||||||||||||||||
| Ok(lazy_static_value_template( | ||||||||||||||||
| self.format_comments(&tld.comments)?, | ||||||||||||||||
| self.to_rust_const_case(&tld.name), | ||||||||||||||||
| self.to_rust_const_case_unique(&tld.name), | ||||||||||||||||
| ty, | ||||||||||||||||
| val, | ||||||||||||||||
| self.config.no_std_compliant_bindings, | ||||||||||||||||
| )) | ||||||||||||||||
| } else { | ||||||||||||||||
| Ok(integer_value_template( | ||||||||||||||||
| self.format_comments(&tld.comments)?, | ||||||||||||||||
| self.to_rust_const_case(&tld.name), | ||||||||||||||||
| self.to_rust_const_case_unique(&tld.name), | ||||||||||||||||
| ty, | ||||||||||||||||
| val, | ||||||||||||||||
| )) | ||||||||||||||||
|
|
@@ -502,9 +502,11 @@ impl Rasn { | |||||||||||||||
| &self, | ||||||||||||||||
| tld: ToplevelTypeDefinition, | ||||||||||||||||
| ) -> Result<TokenStream, GeneratorError> { | ||||||||||||||||
| let name = self.to_rust_title_case(&tld.name); | ||||||||||||||||
| let base_name = self.to_rust_title_case(&tld.name).to_string(); | ||||||||||||||||
| let name = self.to_rust_title_case_unique(&tld.name); | ||||||||||||||||
| let mut annotations = vec![quote!(delegate), self.format_tag(tld.tag.as_ref(), false)]; | ||||||||||||||||
| if name.to_string() != tld.name { | ||||||||||||||||
| let name_str = name.to_string(); | ||||||||||||||||
| if name_str != tld.name || name_str != base_name { | ||||||||||||||||
| annotations.push(self.format_identifier_annotation(&tld.name, &tld.comments, &tld.ty)); | ||||||||||||||||
| } | ||||||||||||||||
| Ok(any_template( | ||||||||||||||||
|
|
@@ -595,10 +597,11 @@ impl Rasn { | |||||||||||||||
| #[non_exhaustive]} | ||||||||||||||||
| }) | ||||||||||||||||
| .unwrap_or_default(); | ||||||||||||||||
| let name = self.to_rust_title_case(&tld.name); | ||||||||||||||||
| let name = self.to_rust_title_case_unique(&tld.name); | ||||||||||||||||
| let mut annotations = | ||||||||||||||||
| vec![quote!(enumerated), self.format_tag(tld.tag.as_ref(), false)]; | ||||||||||||||||
| if name.to_string() != tld.name { | ||||||||||||||||
| let name_str = name.to_string(); | ||||||||||||||||
| if name_str != tld.name || name_str != self.to_rust_title_case(&tld.name).to_string() { | ||||||||||||||||
| annotations.push(self.format_identifier_annotation( | ||||||||||||||||
| &tld.name, | ||||||||||||||||
| &tld.comments, | ||||||||||||||||
|
|
@@ -622,7 +625,7 @@ impl Rasn { | |||||||||||||||
| tld: ToplevelTypeDefinition, | ||||||||||||||||
| ) -> Result<TokenStream, GeneratorError> { | ||||||||||||||||
| if let ASN1Type::Choice(ref choice) = tld.ty { | ||||||||||||||||
| let name = self.to_rust_title_case(&tld.name); | ||||||||||||||||
| let name = self.to_rust_title_case_unique(&tld.name); | ||||||||||||||||
| let extensible = choice | ||||||||||||||||
| .extensible | ||||||||||||||||
| .or( | ||||||||||||||||
|
|
@@ -642,7 +645,8 @@ impl Rasn { | |||||||||||||||
| && !choice.options.iter().any(|o| o.tag.is_some()), | ||||||||||||||||
| ), | ||||||||||||||||
| ]; | ||||||||||||||||
| if name.to_string() != tld.name { | ||||||||||||||||
| let name_str = name.to_string(); | ||||||||||||||||
| if name_str != tld.name || name_str != self.to_rust_title_case(&tld.name).to_string() { | ||||||||||||||||
|
||||||||||||||||
| if name_str != tld.name || name_str != self.to_rust_title_case(&tld.name).to_string() { | |
| let base_name = self.to_rust_title_case(&tld.name).to_string(); | |
| if name_str != tld.name || name_str != base_name { |
Copilot
AI
Dec 4, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same issue as lines 604 and 649: the condition at line 784 is redundant. The check should compare name_str against the base name (before uniquification) to determine if a number was appended due to a name collision.
The correct pattern is:
let base_name = self.to_rust_title_case(&tld.name).to_string();
let name = self.to_rust_title_case_unique(&tld.name);
// ... later in the code
let name_str = name.to_string();
if name_str != tld.name || name_str != base_name {| let name_str = name.to_string(); | |
| if name_str != tld.name | |
| || name_str != self.to_rust_title_case(&tld.name).to_string() | |
| { | |
| let base_name = self.to_rust_title_case(&tld.name).to_string(); | |
| let name_str = name.to_string(); | |
| if name_str != base_name { |
Copilot
AI
Dec 4, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same issue as previous cases: the condition name_str != self.to_rust_title_case(&tld.name).to_string() is redundant. The check should compare name_str against the base name (before uniquification) to determine if a number was appended due to a name collision.
The correct pattern is:
let base_name = self.to_rust_title_case(&tld.name).to_string();
let name = self.to_rust_title_case_unique(&tld.name);
// ... later in the code
let name_str = name.to_string();
if name_str != tld.name || name_str != base_name {| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -514,11 +514,14 @@ impl Rasn { | |
| // ITU-T X.691 clause 30.1, 30.6: Known-multiplier character strings types | ||
| match c_string.ty { | ||
| // 30.1: Known-multiplier character string types | ||
| CharacterStringType::NumericString | CharacterStringType::PrintableString | | ||
| CharacterStringType::VisibleString | CharacterStringType::IA5String | | ||
| CharacterStringType::BMPString | CharacterStringType::UniversalString => { | ||
| CharacterStringType::NumericString | ||
| | CharacterStringType::PrintableString | ||
| | CharacterStringType::VisibleString | ||
| | CharacterStringType::IA5String | ||
| | CharacterStringType::BMPString | ||
| | CharacterStringType::UniversalString => { | ||
| self.format_range_annotations(false, &all_constraints)? | ||
| }, | ||
| } | ||
| // 30.6: Non-known-multiplier character string types | ||
| _ => TokenStream::new(), | ||
| } | ||
|
|
@@ -1271,6 +1274,12 @@ impl Rasn { | |
| ) | ||
| } | ||
|
|
||
| pub(crate) fn to_rust_const_case_unique(&self, input: &str) -> Ident { | ||
| let base_name = self.to_rust_const_case(input).to_string(); | ||
| let unique_name = self.get_unique_name(&base_name); | ||
| Ident::new(&unique_name, Span::call_site()) | ||
| } | ||
|
|
||
| pub(crate) fn to_rust_enum_identifier(&self, input: &str) -> Ident { | ||
| let mut formatted = format_ident!("{}", input.replace('-', "_")); | ||
| if Self::RUST_KEYWORDS.contains(&input) { | ||
|
|
@@ -1300,6 +1309,30 @@ impl Rasn { | |
| TokenStream::from_str(&name).unwrap() | ||
| } | ||
|
|
||
| pub(crate) fn to_rust_title_case_unique(&self, input: &str) -> TokenStream { | ||
| let base_name = self.to_rust_title_case(input).to_string(); | ||
| let unique_name = self.get_unique_name(&base_name); | ||
| TokenStream::from_str(&unique_name).unwrap() | ||
| } | ||
|
|
||
| fn get_unique_name(&self, base_name: &str) -> String { | ||
| let mut used_names = self.used_names.borrow_mut(); | ||
| if !used_names.contains(base_name) { | ||
| used_names.insert(base_name.to_string()); | ||
| return base_name.to_string(); | ||
| } | ||
|
|
||
| let mut counter = 2; | ||
| loop { | ||
| let candidate = format!("{base_name}{counter}"); | ||
| if !used_names.contains(&candidate) { | ||
| used_names.insert(candidate.clone()); | ||
| return candidate; | ||
| } | ||
| counter += 1; | ||
| } | ||
| } | ||
|
Comment on lines
+1318
to
+1334
|
||
|
|
||
| /// Generate a `TokenStream` containing a type identifier, optionally qualified by module. | ||
| /// | ||
| /// Module name is converted to snake case, and type name converted to title case. | ||
|
|
@@ -1319,10 +1352,12 @@ impl Rasn { | |
| &self, | ||
| tld: &ToplevelTypeDefinition, | ||
| ) -> Result<(TokenStream, Vec<TokenStream>), GeneratorError> { | ||
| let name = self.to_rust_title_case(&tld.name); | ||
| let base_name = self.to_rust_title_case(&tld.name).to_string(); | ||
| let name = self.to_rust_title_case_unique(&tld.name); | ||
| let mut annotations = vec![quote!(delegate), self.format_tag(tld.tag.as_ref(), false)]; | ||
|
|
||
| if name.to_string() != tld.name { | ||
| let name_str = name.to_string(); | ||
| if name_str != tld.name || name_str != base_name { | ||
| annotations.push(self.format_identifier_annotation(&tld.name, &tld.comments, &tld.ty)); | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The condition
name_str != self.to_rust_title_case(&tld.name).to_string()is redundant becausename_stris derived fromto_rust_title_case_unique(&tld.name), which internally callsto_rust_title_case(&tld.name). When there's no collision, both will be identical. The actual check needed is whether the name was modified due to a collision (i.e., whether a number was appended).Consider storing the base name (before uniquification) and comparing against it instead:
This pattern is correctly implemented in
format_name_and_common_annotationsat line 1355-1360 in utils.rs.