Skip to content

False Negative error with rust-peg macros #13013

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

Closed
linkdd opened this issue Aug 13, 2022 · 3 comments
Closed

False Negative error with rust-peg macros #13013

linkdd opened this issue Aug 13, 2022 · 3 comments
Labels
A-ty type system / type inference / traits / method resolution C-bug Category: bug

Comments

@linkdd
Copy link

linkdd commented Aug 13, 2022

rust-analyzer version: v0.3.1162

rustc version: rustc 1.61.0 (fe5b13d68 2022-05-18)

relevant settings:


When using the crate rust-peg to define a grammar, if I use their precedence!{} macro, rust-analyzer reports the following error:

expected &dyn Fn(usize, &mut ParseState, &mut ErrorState, &dyn Fn(usize, i32, &mut ParseState, &mut ErrorState)),
found
&|usize, &mut ParseState, {unknown}, {unknown}| -> RuleResult<Node<TypeRef>>

But the compiler manages to compile the code just fine.

See related (now closed) issue: kevinmehall/rust-peg#316 (comment)

@flodiebold
Copy link
Member

Can you provide a simple example to reproduce the problem?

@flodiebold flodiebold added A-ty type system / type inference / traits / method resolution C-bug Category: bug labels Aug 13, 2022
@lowr
Copy link
Contributor

lowr commented Aug 17, 2022

Looks like the same issue as #13031. I've tested the following (incomplete) code and the error seems to go away with #13049 (peg does use bare dyn types).

@linkdd Would you test if #13049 fixes the issue?

code
enum Token { Comma, OperatorBinAnd, OperatorBinOr, ParenthesisBegin, ParenthesisEnd }
pub type LocationInfo = (usize, usize);

#[derive(Clone, Debug, PartialEq)]
pub struct Node<T> {
  pub location: LocationInfo,
  pub data: Box<T>,
}

peg::parser!{
    grammar list_parser() for str {
        rule type_refs() -> Vec<Node<ast::types::TypeRef>>
  = type_ref() ++ [Token::Comma]

rule type_ref() -> Node<ast::types::TypeRef>
  = precedence!{
    l:position!() data:@ r:position!() {
      Node::new((l, r), data)
    }
    --
    lhs:(@) [Token::OperatorBinOr] rhs:@ {
      ast::types::TypeRef::one_of(vec![lhs, rhs])
    }
    --
    lhs:(@) [Token::OperatorBinAnd] rhs:@ {
      ast::types::TypeRef::all_of(vec![lhs, rhs])
    }
    --
    [Token::Negation] t:(@) {
      ast::types::TypeRef::not(t)
    }
    --
    t:type_ref_term() { t }
    [Token::ParenthesisBegin] t:type_ref() [Token::ParenthesisEnd] { t.data }
  }

rule type_ref_term() -> Box<ast::types::TypeRef>
  = type_ref_term_generic_symbol()
  / type_ref_term_concrete_symbol()
  / type_ref_term_struct_def()
  / type_ref_term_tuple_def()
  / type_ref_term_function_signature()
  / type_ref_term_literal()
    }
}

@linkdd
Copy link
Author

linkdd commented Aug 17, 2022

@flodiebold Hi, sorry I was a bit sick the past few days.

@lowr Yes thank you, it works as well for me here. I'm closing this issue since it's a duplicate

@linkdd linkdd closed this as completed Aug 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ty type system / type inference / traits / method resolution C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

3 participants