syn icon indicating copy to clipboard operation
syn copied to clipboard

Very misleading docs: docs say "impl Parse for ExprMatch" available in feature "parsing", but it is not

Open safinaskar opened this issue 3 years ago • 0 comments

Here is my full journey to this absolutely strange bug.

I have a pretty recent rustc (rustc 1.64.0-nightly (f8588549c 2022-07-18)). Right now I created empty proc macro lib. I typed the following code: lib.rs:

#[proc_macro]
pub fn match_deref(tokens: proc_macro::TokenStream) -> proc_macro::TokenStream {
    let _m = syn::parse_macro_input!(tokens as syn::ExprMatch);
    todo!();
}

Cargo.toml:

[package]
name = "my-proc-macro"
version = "0.1.0"
edition = "2021"

[lib]
proc-macro = true

Then I typed cargo add syn. This gave me this output:

    Updating crates.io index
      Adding syn v1.0.98 to dependencies.
             Features:
             + clone-impls
             + derive
             + parsing
             + printing
             + proc-macro
             + quote
             - extra-traits
             - fold
             - full
             - test
             - visit
             - visit-mut

Then I run cargo build. Surprisingly I got this error message: "the trait bound ExprMatch: Parse is not satisfied". This was very strange. I checked cargo add output. It included parsing feature. I checked docs ( https://docs.rs/syn/1.0.98/syn/struct.ExprMatch.html#impl-Parse ), they said that ExprMatch implements Parse trait when parsing is enabled. I checked whether my installed syn version corresponds to syn version in docs URL. It matched. Then I added this code:

fn fff() where syn::ExprMatch: syn::parse::Parse {}

But I still got same error message.

Then I clicked "source" link on docs page and surprisingly saw this:

    #[cfg(feature = "full")]
    #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
    impl Parse for ExprMatch {

?!?!??!!?! So it seems this code is written intentionally cryptic. It deliberately hides cfg(feature = "full") and shows cfg(feature = "parsing") in docs. ?!?!??!?!?! How I should know this? Please, fix misleading docs.

(Then, of course, I added feature = ["full"] and everything started to work.)

safinaskar avatar Jul 24 '22 21:07 safinaskar