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

Invalid Rust Generation for Semantic actions #108

Open
UPWRD1 opened this issue Jun 17, 2024 · 1 comment
Open

Invalid Rust Generation for Semantic actions #108

UPWRD1 opened this issue Jun 17, 2024 · 1 comment

Comments

@UPWRD1
Copy link

UPWRD1 commented Jun 17, 2024

I have run into an issue regarding the Rust target.

himecc v4.3.0 generates invalid Rust code when attempting to use semantic actions.

In particular, rustc emits the following errors:
1:

E0106]: missing lifetime specifier
   --> ../lang.rs:429:78
    |
429 | fn parse_text(text: Text, actions: &mut dyn Actions) -> ParseResult<'static, '_, 'static> {
    |                     ----           ----------------                          ^^ expected named lifetime parameter

2:

error[E0308]: mismatched types
   --> src/root/passes/frontend/lang.rs:420:5
    |
418 | pub fn parse_utf8_stream(input: &mut dyn Read) -> Result<ParseResult<'static, 'static, 'static>, std::io::Error> {
    |                                                   -------------------------------------------------------------- expected `Result<ParseResult<'static, 'static, 'static>, std::io::Error>` because of return type
419 |     let text = Text::from_utf8_stream(input).unwrap();
420 |     parse_text(text, &mut NoActions {})
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Result<ParseResult<'_, '_, '_>, ...>`, found `ParseResult<'_, '_, '_>`
    |
    = note: expected enum `Result<ParseResult<'_, 'static, '_>, std::io::Error>`
             found struct `ParseResult<'_, '_, '_>`
help: try wrapping the expression in `Ok`
    |
420 |     Ok(parse_text(text, &mut NoActions {}))
    |     +++                                   +

3

error: lifetime may not live long enough
   --> src/root/passes/frontend/lang.rs:430:5
    |
429 | fn parse_text(text: Text, actions: &mut dyn Actions) -> ParseResult<'static, '_, 'static> {
    |               ---- has type `Text<'1>`
430 |     parse_text_with(text, TERMINALS, VARIABLES, VIRTUALS, actions)
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ returning this value requires that `'1` must outlive `'static`

These are quite easy to fix by simply wrapping error 2 in Ok(), and setting the faulty lifetimes to 'static. (Given my relative inexperience with complicated Rust development, these are most certianly the wrong approach.)

However, it's quite a pain to do this each time, as regenerating the files destroys previous changes, and it also creates a barrier of entry, for someone who is not as experienced with Rust.

Would it be possible to fix this in the generator?

Thank you.

@UPWRD1
Copy link
Author

UPWRD1 commented Jun 17, 2024

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

No branches or pull requests

1 participant