kkawakam / rustyline

Readline Implementation in Rust
https://crates.io/crates/rustyline/
MIT License
1.52k stars 175 forks source link

`examples/diy_hints.rs` does not compile #716

Closed awwsmm closed 1 year ago

awwsmm commented 1 year ago

Fails for 12.0.0, 10.1.1, 9.1.2, and 8.2.0. Using 12.0.0, the following errors are printed

error: cannot find derive macro `Helper` in this scope
 --> src/main.rs:9:21
  |
9 | #[derive(Completer, Helper, Validator, Highlighter)]
  |                     ^^^^^^
  |
note: `Helper` is imported here, but it is only a trait, without a derive macro
 --> src/main.rs:6:28
  |
6 | use rustyline::{Completer, Helper, Highlighter, Validator};
  |                            ^^^^^^

error[E0603]: trait `Completer` is private
  --> src/main.rs:6:17
   |
6  | use rustyline::{Completer, Helper, Highlighter, Validator};
   |                 ^^^^^^^^^ private trait
   |
note: the trait `Completer` is defined here
  --> /Users/andrew/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rustyline-12.0.0/src/lib.rs:58:59
   |
58 | use crate::completion::{longest_common_prefix, Candidate, Completer};
   |                                                           ^^^^^^^^^

error[E0603]: trait `Highlighter` is private
  --> src/main.rs:6:36
   |
6  | use rustyline::{Completer, Helper, Highlighter, Validator};
   |                                    ^^^^^^^^^^^ private trait
   |
note: the trait `Highlighter` is defined here
  --> /Users/andrew/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rustyline-12.0.0/src/lib.rs:62:5
   |
62 | use crate::highlight::Highlighter;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0603]: trait `Validator` is private
  --> src/main.rs:6:49
   |
6  | use rustyline::{Completer, Helper, Highlighter, Validator};
   |                                                 ^^^^^^^^^ private trait
   |
note: the trait `Validator` is defined here
  --> /Users/andrew/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rustyline-12.0.0/src/lib.rs:71:5
   |
71 | use crate::validate::Validator;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0277]: the trait bound `DIYHinter: Helper` is not satisfied
   --> src/main.rs:89:17
    |
89  |     let mut rl: Editor<DIYHinter, DefaultHistory> = Editor::new()?;
    |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Helper` is not implemented for `DIYHinter`
    |
    = help: the following other types implement trait `Helper`:
              &'h H
              ()
note: required by a bound in `Editor`
   --> /Users/andrew/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rustyline-12.0.0/src/lib.rs:587:22
    |
587 | pub struct Editor<H: Helper, I: History> {
    |                      ^^^^^^ required by this bound in `Editor`

error[E0599]: the method `set_helper` exists for struct `Editor<DIYHinter, FileHistory>`, but its trait bounds were not satisfied
   --> src/main.rs:90:8
    |
10  | struct DIYHinter {
    | ----------------
    | |
    | doesn't satisfy `DIYHinter: Completer`
    | doesn't satisfy `DIYHinter: Helper`
    | doesn't satisfy `DIYHinter: Highlighter`
    | doesn't satisfy `DIYHinter: Validator`
...
90  |     rl.set_helper(Some(h));
    |        ^^^^^^^^^^ method cannot be called on `Editor<DIYHinter, FileHistory>` due to unsatisfied trait bounds
    |
    = note: the following trait bounds were not satisfied:
            `DIYHinter: Helper`
            `DIYHinter: Validator`
            which is required by `DIYHinter: Helper`
            `DIYHinter: Highlighter`
            which is required by `DIYHinter: Helper`
            `DIYHinter: Completer`
            which is required by `DIYHinter: Helper`
note: the traits `Completer`, `Highlighter`, `Validator`,  and `Helper` must be implemented
   --> /Users/andrew/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rustyline-12.0.0/src/lib.rs:546:1
    |
546 | pub trait Helper
    | ^^^^^^^^^^^^^^^^
    |
   ::: /Users/andrew/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rustyline-12.0.0/src/completion.rs:71:1
    |
71  | pub trait Completer {
    | ^^^^^^^^^^^^^^^^^^^
    |
   ::: /Users/andrew/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rustyline-12.0.0/src/highlight.rs:13:1
    |
13  | pub trait Highlighter {
    | ^^^^^^^^^^^^^^^^^^^^^
    |
   ::: /Users/andrew/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rustyline-12.0.0/src/validate.rs:58:1
    |
58  | pub trait Validator {
    | ^^^^^^^^^^^^^^^^^^^

error[E0277]: the trait bound `DIYHinter: Helper` is not satisfied
   --> src/main.rs:89:53
    |
89  |     let mut rl: Editor<DIYHinter, DefaultHistory> = Editor::new()?;
    |                                                     ^^^^^^^^^^^^^ the trait `Helper` is not implemented for `DIYHinter`
    |
    = help: the following other types implement trait `Helper`:
              &'h H
              ()
note: required by a bound in `Editor`
   --> /Users/andrew/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rustyline-12.0.0/src/lib.rs:587:22
    |
587 | pub struct Editor<H: Helper, I: History> {
    |                      ^^^^^^ required by this bound in `Editor`

error[E0277]: the trait bound `DIYHinter: Helper` is not satisfied
   --> src/main.rs:89:53
    |
89  |     let mut rl: Editor<DIYHinter, DefaultHistory> = Editor::new()?;
    |                                                     ^^^^^^^^^^^ the trait `Helper` is not implemented for `DIYHinter`
    |
    = help: the following other types implement trait `Helper`:
              &'h H
              ()
note: required by a bound in `Editor::<H, FileHistory>::new`
   --> /Users/andrew/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rustyline-12.0.0/src/lib.rs:600:9
    |
600 | impl<H: Helper> Editor<H, DefaultHistory> {
    |         ^^^^^^ required by this bound in `Editor::<H, FileHistory>::new`

error[E0277]: the trait bound `DIYHinter: Helper` is not satisfied
   --> src/main.rs:89:53
    |
89  |     let mut rl: Editor<DIYHinter, DefaultHistory> = Editor::new()?;
    |                                                     ^^^^^^ the trait `Helper` is not implemented for `DIYHinter`
    |
    = help: the following other types implement trait `Helper`:
              &'h H
              ()
note: required by a bound in `Editor`
   --> /Users/andrew/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rustyline-12.0.0/src/lib.rs:587:22
    |
587 | pub struct Editor<H: Helper, I: History> {
    |                      ^^^^^^ required by this bound in `Editor`

error[E0599]: the method `readline` exists for struct `Editor<DIYHinter, FileHistory>`, but its trait bounds were not satisfied
   --> src/main.rs:93:24
    |
10  | struct DIYHinter {
    | ----------------
    | |
    | doesn't satisfy `DIYHinter: Completer`
    | doesn't satisfy `DIYHinter: Helper`
    | doesn't satisfy `DIYHinter: Highlighter`
    | doesn't satisfy `DIYHinter: Validator`
...
93  |         let input = rl.readline("> ")?;
    |                        ^^^^^^^^ method cannot be called on `Editor<DIYHinter, FileHistory>` due to unsatisfied trait bounds
    |
    = note: the following trait bounds were not satisfied:
            `DIYHinter: Helper`
            `DIYHinter: Validator`
            which is required by `DIYHinter: Helper`
            `DIYHinter: Highlighter`
            which is required by `DIYHinter: Helper`
            `DIYHinter: Completer`
            which is required by `DIYHinter: Helper`
note: the traits `Completer`, `Highlighter`, `Validator`,  and `Helper` must be implemented
   --> /Users/andrew/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rustyline-12.0.0/src/lib.rs:546:1
    |
546 | pub trait Helper
    | ^^^^^^^^^^^^^^^^
    |
   ::: /Users/andrew/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rustyline-12.0.0/src/completion.rs:71:1
    |
71  | pub trait Completer {
    | ^^^^^^^^^^^^^^^^^^^
    |
   ::: /Users/andrew/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rustyline-12.0.0/src/highlight.rs:13:1
    |
13  | pub trait Highlighter {
    | ^^^^^^^^^^^^^^^^^^^^^
    |
   ::: /Users/andrew/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rustyline-12.0.0/src/validate.rs:58:1
    |
58  | pub trait Validator {
    | ^^^^^^^^^^^^^^^^^^^

Some errors have detailed explanations: E0277, E0599, E0603.
For more information about an error, try `rustc --explain E0277`.
error: could not compile `ngttglcli` (bin "ngttglcli") due to 10 previous errors
gwenn commented 1 year ago

Either you use rustyline from master and examples/diy_hints.rs from master with the features required. Or you use rustyline 12.0.0 and you checkout examples/diy_hints.rs v12.0.0. But most of the time, you cannot mix code associated to different versions.

awwsmm commented 1 year ago

The features was the thing I missed. Thanks, @gwenn

required-features = ["derive"]