Repository navigation
fix(generator): reject type names that shadow build-in types - #327
Merged
Merged
Conversation
Unless `BUILD_IN_ABSOLUTE_PATHS` is set, the generated code refers to build-in types and traits like `String`, `Option` or `Result` by their bare name. A generated type with the same name shadows them, which results in code that does not compile, e.g. `pub type String = String;` for `xs:string` with an empty type postfix, or broken `Option<..>` fields for an element named `Option` (the element postfix is empty by default). Raise an error that names the type and points to the flag instead of silently generating broken code.
Bergmann89
force-pushed
the
fix/shadowed-build-in-types
branch
from
November 12, 2026 20:29
4b6720b to
d86223f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Unless
GeneratorFlags::BUILD_IN_ABSOLUTE_PATHSis set, the generated code refers to build-in types and traits likeString,OptionorResultby their bare name. A generated type with the same name shadows them and the generated code does not compile, e.g.:pub type String = String;(E0391, cycle detected) forxs:stringwhen the type postfix is empty, as reported in Please provide examples of how to resolve conflicts in type names #316Option<..>fields for an element namedOption, since the element postfix is empty by defaultThe generator now raises
GeneratorError::ShadowedBuildInfor these names, which names the affected type and points toBUILD_IN_ABSOLUTE_PATHS, instead of silently generating broken code.Changes
ShadowedBuildInin the generator error (additive).claim_path, next to the existingDuplicateTypeNamecheck, and is skipped whenBUILD_IN_ABSOLUTE_PATHSis set.shadowed_build_in: error for an element namedOption, error forxs:stringwith an empty type postfix, and a compiled quick-xml snapshot with the flag enabled.Schemas that generate one of these names without the flag now fail with an error instead of generating code that does not compile.
Checklist
update-expectationsand reviewedcargo fmt,cargo clippyandcargo testpass (see CONTRIBUTING.md)