nom icon indicating copy to clipboard operation
nom copied to clipboard

nom is not compatible with pub(crate) and the `unreachable-pub` lint

Open marmistrz opened this issue 8 years ago • 3 comments

Prerequisites

Here are a few things you should provide to help me understand the issue:

  • Rust version : rustc -V: rustc 1.28.0-nightly (cd494c1f0 2018-06-27)
  • nom version : 4.0.0
  • nom compilation features used: default

Test case

This is the initial code. It triggers the rustc warning about unreachable-pub items. nom-incompat.zip

The compiler suggests to restrict its visibility, by using pub(crate). After changing the line

named!(pub par, tag!("xD"));

to

named!(pub(crate) par, tag!("xD"));

The example doesn't build anymore

error: no rules expected the token `par`
 --> src/protocol/parser.rs:3:19
  |
3 | named!(pub(crate) par, tag!("xD"));
  |                   ^^^

error: aborting due to previous error

marmistrz avatar Jun 28 '18 15:06 marmistrz

To me, this looks like an issue with the way named! parses function names. It's probably not capable of handling pub(crate). However, since you're on 1.28 nightly, I think you can instead use the 'crate' access modifier - it's equivalent.

Perhaps Geal has more insight, however.

Zarenor avatar Jun 28 '18 17:06 Zarenor

The 'crate' access modifier doesn't work either. These two snippets produce the same error (on a current nightly rustc):

named!(pub(crate) par, tag!("xD"));

named!(crate par, tag!("xD"));

agentsim avatar Aug 16 '18 19:08 agentsim

#566 was merged, this will be available in the next nom version

Geal avatar Oct 06 '18 13:10 Geal