BinChengZhao / delay-timer

Time-manager of delayed tasks. Like crontab, but synchronous asynchronous tasks are possible scheduling, and dynamic add/cancel/remove is supported.
Apache License 2.0
315 stars 24 forks source link

cargo +nightly build error as unsatisfied trait bounds #48

Closed Curricane closed 10 months ago

Curricane commented 11 months ago

Describe the bug i can not run cargo +nightly build as unsatisfied trait bounds.

To Reproduce Steps to reproduce the behavior:

rustc version: rustc 1.76.0-nightly (a1a37735c 2023-11-23) delay_timer commit 69a3867c0981428810bace164159ff4619bcf755

  1. cd delay_timer
  2. cargo +nightly build

then error will show like:

error[E0277]: the trait bound `StrSearcher<'_, '_>: DoubleEndedSearcher<'_>` is not satisfied                                                                     [0/583]
    --> src/utils/parse.rs:371:83
     |
371  |         let mut sub_command_inner = command.trim().split_inclusive(angle_bracket).rev();
     |                                                                                   ^^^ the trait `DoubleEndedSearcher<'_>` is not implemented for `StrSearcher<'_, '_>`
     |
     = help: the following other types implement trait `DoubleEndedSearcher<'a>`:
               CharSearcher<'a>
               CharArraySearcher<'a, N>
               CharArrayRefSearcher<'a, 'b, N>
               CharSliceSearcher<'a, 'b>
               CharPredicateSearcher<'a, F>
     = note: required for `std::str::SplitInclusive<'_, &str>` to implement `DoubleEndedIterator`
note: required by a bound in `rev`
    --> /home/chenmc/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/iter/traits/iterator.rs:3399:23
     |
3397 |     fn rev(self) -> Rev<Self>
     |        --- required by a bound in this associated function
3398 |     where
3399 |         Self: Sized + DoubleEndedIterator,
     |                       ^^^^^^^^^^^^^^^^^^^ required by this bound in `Iterator::rev`

error[E0599]: the method `next` exists for struct `Rev<SplitInclusive<'_, &str>>`, but its trait bounds were not satisfied
    --> src/utils/parse.rs:374:14
     |
373  | /         sub_command_inner
374  | |             .next()
     | |             -^^^^ method cannot be called on `Rev<SplitInclusive<'_, &str>>` due to unsatisfied trait bounds
     | |_____________|
     |
     |
    ::: /home/chenmc/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/str/iter.rs:1216:1
     |
1216 |   pub struct SplitInclusive<'a, P: Pattern<'a>>(pub(super) SplitInternal<'a, P>);
     |   --------------------------------------------- doesn't satisfy `_: DoubleEndedIterator`
     |
    ::: /home/chenmc/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/iter/adapters/rev.rs:15:1
     |
15   |   pub struct Rev<T> {
     |   ----------------- doesn't satisfy `Rev<std::str::SplitInclusive<'_, &str>>: Iterator`
     |
     = note: the following trait bounds were not satisfied:
             `std::str::SplitInclusive<'_, &str>: DoubleEndedIterator`
             which is required by `Rev<std::str::SplitInclusive<'_, &str>>: Iterator`

Some errors have detailed explanations: E0277, E0599.
For more information about an error, try `rustc --explain E0277`.
error: could not compile `delay_timer` (lib) due to 2 previous errors

Expected behavior compile ok

Screenshots

Desktop (please complete the following information):

greenhat616 commented 11 months ago

It was a rust issue. ref: https://github.com/rust-lang/rust/pull/100806#issuecomment-1825585534

The only way, aka workaround, as far as I kown, is that use Rust stable channel or use a third-part lib to fix this boundary issue: just like what I have did here: https://github.com/greenhat616/clash-verge/tree/main/backend/delay_timer

DannyGoldberg commented 10 months ago

it looks like the issue has made it into rust stable -- https://github.com/rust-lang/rust/pull/100806#issuecomment-1871429789

I tried the same diff as you had in https://github.com/greenhat616/clash-verge/commit/dc81e1c0b527defc59ac0b84353977ade760ed52#diff-06f45ed9ebd95944143757cdbc32141be89dc35712bcb01cbf057085538917d4 and that would fix it, although it only works with cargo +nightly since str_splitter relies on nightly features

Diff enclosed here ```diff diff --git a/Cargo.toml b/Cargo.toml index 56d11f7..a2d32ac 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -42,6 +42,7 @@ log = "^0.4.14" tracing = "0.1.29" thiserror = "^1.0.24" +str_splitter = "0.1.1" tokio = { version = "^1.3.0", features = ["full"] } diff --git a/src/utils/parse.rs b/src/utils/parse.rs index 9de44d0..ae56dae 100644 --- a/src/utils/parse.rs +++ b/src/utils/parse.rs @@ -3,6 +3,8 @@ /// Collection of functions related to shell commands and processes. pub mod shell_command { + use str_splitter::combinators::SplitExt; + use crate::prelude::*; use anyhow::Error as AnyhowError; @@ -368,7 +370,9 @@ pub mod shell_command { return None; }; - let mut sub_command_inner = command.trim().split_inclusive(angle_bracket).rev(); + // TODO: waiting for rust team fix this issue since: https://github.com/rust-lang/rust/pull/100806 + // let mut sub_command_inner = command.trim().split_inclusive(angle_bracket).rev(); + let mut sub_command_inner = command.trim().splitter(angle_bracket).to_inclusive().to_reversed(); sub_command_inner .next() ```
BinChengZhao commented 10 months ago

Hi guys, the issue has been fixed in V0.11.5