These are chat archives for rust-lang/rust

20th
Aug 2016
Stewart Mackenzie
@sjmackenzie
Aug 20 2016 16:19

If someone could be so kind and take a look; I'm at trying to get this ABNF command ( "|" command )* which is used in shells for piping, i.e. : command1 | command2 | command3, this is what I currently have, when using Nom, a library implemented in Rust:

#[derive(Debug)]
enum Literal {
    Comment,
    Command(String),
}

use nom::{IResult, AsBytes};
use nom::{alphanumeric, begin, line_ending};

named!(command<&[u8],Literal>, chain!(
        command_list:
        preceded!(
          begin,
          terminated!(
            separated_list!(
              char!('|'),
              alphanumeric
            ),
            terminated!(
              opt!(char!('|')),
              line_ending
            )
          )
        ),
    || { Literal::Command(String::from_utf8(command_list.to_vec()).expect("not utf8")) }
));

my many lined error boils down to:

....
<nom macros>:148:48: 148:49 note: expected type `&[u8]`
<nom macros>:148:48: 148:49 note:    found type `()`
Jonas Platte
@jplatte
Aug 20 2016 17:24

Hi, I'm getting a linker error with the current nightly + conservative_impl_trait. I'm building a notes program split into a library and frontend in two different crates, and the library exports a function

pub fn root_notes<'a>(&'a self) -> impl Iterator<Item=&'a Note> {
    self.notes.iter().filter(|note| note.get_category().is_none())
}

(where self.notes is a Vec). It compiles just fine, but when I build my frontend and actually try to use this function I get a linker error:

/home/jplatte/Projekte/Γ cli/target/debug/Γ_cli.0.o: In function `{{inlined-root}}::next<core::slice::Iter<Γ_notes::note::Note>,closure>':
/buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/libcore/iter/mod.rs:953: undefined reference to `_$u393$_notes::app::App::root_notes::_$u7b$$u7b$closure$u7d$$u7d$::hd6e1f53d283a9ac3'

The slightly simpler pub fn all_notes(&self) -> slice::Iter<Note> that just returns a non-filtering iterator works fine. It looks like the closure I pass to filter isn't included in the library archive, right? Is that just a bug or do I need to do something more than add #![feature(conservative_impl_trait)] to my lib.rs to make this work? (I already tried adding the same to my frontends main.rs but that didn't help)