Skip to content
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

Stop implicitly adding &'input to input type #299

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kevinmehall
Copy link
Owner

Rust-peg currently adds &'input to the specified input type. The 'input lifetime violates macro hygiene and is confusing to use along with other explicitly-declared lifetimes used in the input type.

This change also allows Copy input wrapper types like SliceByRef to be zero-cost, instead of adding another layer of pointer indirection.

Breaking change

All grammars must add & to their input type, and if they use the 'input lifetime, must explicitly declare it.

Before:

grammar g() for str {

After:

grammar g() for &str {

or

grammar g<'input>() for &'input str {

Additionally, the signatures of the Parse, ParseElem, ParseLiteral, and ParseSlice traits have changed. If you implement these traits for custom input types, you'll need to make changes to implement these traits for &T rather than T, and take self rather than &self.

To Do

  • Detect unfixed str and [T] input types and either automatically do the right thing or give an error message that is more actionable than the one Rust gives.

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