chfi / rs-gfa

GFA parser in Rust

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Build error `&[u8]::trim` not found

RagnarGrootKoerkamp opened this issue · comments

Compiling version 0.10.0 with the latest rustc version gives the following error:

   Compiling gfa v0.10.0
error[E0599]: no method named `trim` found for reference `&[u8]` in the current scope
   --> src/parser.rs:150:33
    |
150 |         let line: &BStr = bytes.trim().as_ref();
    |                                 ^^^^ method not found in `&[u8]`

error[E0599]: no method named `trim` found for reference `&[u8]` in the current scope
   --> src/parser.rs:175:33
    |
175 |         let line: &[u8] = bytes.trim().as_ref();
    |                                 ^^^^ method not found in `&[u8]`
    ```
    
Maybe `trim` should be replaced by the [unstable `trim_ascii`](https://doc.rust-lang.org/std/primitive.slice.html#method.trim_ascii)? (Actually I'm curious how this ever worked before now, as I cannot find a mention of `trim` on `&[u8]` anywhere.)

trim is from bstr's ByteSlice trait: https://docs.rs/bstr/0.2.0/bstr/trait.ByteSlice.html#method.trim, and it builds for me on the latest rustc.

It seems like it's not finding ByteSlice::trim, despite the trait being imported in the file. I suspect cargo might have messed something up, but I've never seen anything quite like it.

Thanks for the quick reply! I did a cargo clean and cargo +stable build, and now cargo +nightly build also works again. No idea why it failed before 🤷.

Never had random bulid errors in dependencies before though. Also, thanks for this crate; saves me a lot of time on quickly coding up a proof of concept! 😄

Ah, the error disappeared because I added bstr to the dependencies of my own project. Not sure what's going on but it works now.

@RagnarGrootKoerkamp Shall we reopen this issue? I have encountered the same error: error[E0599]: no method named `trim` found for reference `&[u8]` in the current scope.

@chfi You can cargo init a blank package, and add gfa = "0.10.0" to Cargo.toml to reproduce this error.

It seems like it's not finding ByteSlice::trim, despite the trait being imported in the file. I suspect cargo might have messed something up, but I've never seen anything quite like it.

It's caused by disabling the unicode feature of bstr in the latest (>=0.9.0) Cargo.toml. FYI, fn trim is actually under the unicode feature, source code.

There are two solutions:

  1. Change trim to trim_with (I will make a pull request).
  2. Reuse the unicode feature.