Skip to content

Feature: add support for impl const Trait syntax#1974

Open
usmanovbf wants to merge 1 commit intodtolnay:masterfrom
usmanovbf:feat_impl_const
Open

Feature: add support for impl const Trait syntax#1974
usmanovbf wants to merge 1 commit intodtolnay:masterfrom
usmanovbf:feat_impl_const

Conversation

@usmanovbf
Copy link

This PR introduces support for parsing constant trait implementations, specifically the const impl and impl const syntaxes. This resolves the parsing error reported in issue #1972 and aligns syn with the experimental syntax introduced by RFC 2632 (Const Trait Impls).

Changes included in this PR:

  • AST Modification: Added a new constness: Option<Token![const]> field to the syn::ItemImpl struct.
  • Parsing Logic (Parse): Updated the parser in src/item.rs to correctly recognize and consume the const keyword. It handles both const impl Trait and impl const Trait variations to ensure robust compatibility with the experimental compiler features.
  • Token Serialization (ToTokens): Updated the implementation to assure the const token is properly preserved and written back into the token stream during code generation.
  • Auto-generated AST Traversal: Updated all generated visitor and folder modules (clone.rs, debug.rs, eq.rs, fold.rs, hash.rs, visit.rs, visit_mut.rs) to account for the new constness field.
  • Testing: Added comprehensive test coverage in tests/test_item.rs to verify successful parsing, token round-tripping, and correct behavior when combined with other modifiers like default and unsafe.

SemVer Note:
Please note that adding a public field to ItemImpl is a breaking change for users relying on exhaustive pattern matching. I defer to the maintainers on the appropriate milestone or breaking release batch for this PR.

@usmanovbf
Copy link
Author

There are failed tests in CI.
Do I need just to add them to EXCLUDE section in the tests/repo/mod.rs:

  "library/core/src/slice/index.rs",
  "library/core/src/str/traits.rs",

?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant