weiznich / rust-foundation-community-grant

20 stars 6 forks source link

Added chumsky example #1

Closed zesterer closed 2 years ago

zesterer commented 2 years ago

Rust infamously generates absurd error messages and suggestions when compiling code that uses chumsky, my parser combinator crate. I figured it would be a good addition to this collection!

Example error ``` error[E0271]: type mismatch resolving ') -> String as FnOnce<(Vec,)>>::Output == Json' --> tests/chumsky/json.rs:92:17 | 92 | .or(string) | -- ^^^^^^ expected enum 'Json', found struct 'String' | | | required by a bound introduced by this call | = note: required because of the requirements on the impl of 'chumsky::Parser' for 'chumsky::combinator::Map>, Repeated>, chumsky::combinator::Map>, Or>, Just>>, Just>>, To>, char, char>>, To>, char, char>>, To>, char, char>>, To>, char, char>>, To>, char, char>>, chumsky::combinator::Map>, Validate>>, fn(Vec) -> String, Vec>, String, [closure@$DIR/tests/chumsky/json.rs:48:35: 54:26]>>, fn((char, char)) -> char, (char, char)>>>, fn((char, char)) -> char, (char, char)>>>>, fn((char, Vec)) -> Vec, (char, Vec)>, Just>>, fn((Vec, char)) -> Vec, (Vec, char)>, fn(Vec) -> String, Vec>' = note: 1 redundant requirement hidden = note: required because of the requirements on the impl of 'chumsky::Parser' for 'Label>, Repeated>, chumsky::combinator::Map>, Or>, Just>>, Just>>, To>, char, char>>, To>, char, char>>, To>, char, char>>, To>, char, char>>, To>, char, char>>, chumsky::combinator::Map>, Validate>>, fn(Vec) -> String, Vec>, String, [closure@$DIR/tests/chumsky/json.rs:48:35: 54:26]>>, fn((char, char)) -> char, (char, char)>>>, fn((char, char)) -> char, (char, char)>>>>, fn((char, Vec)) -> Vec, (char, Vec)>, Just>>, fn((Vec, char)) -> Vec, (Vec, char)>, fn(Vec) -> String, Vec>, &str>' note: required by a bound in 'or' --> $CARGO/chumsky-0.8.0/src/lib.rs | | P: Parser, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in 'or' error[E0599]: the method 'or' exists for struct 'Or>, &str, Json>, &str>, Label>, &str, Json>, &str>>, Label>, &str, Json>, &str>>, chumsky::combinator::Map>>, impl chumsky::Parser::Collection, Error = chumsky::error::Simple> + Copy + Clone>, fn((Option, String)) -> Vec, (Option, String)>, chumsky::combinator::Map>, impl chumsky::Parser::Collection, Error = chumsky::error::Simple> + Copy + Clone>, fn((char, String)) -> Vec, (char, String)>>, fn(Option>) -> Vec, Option>>>, fn((Vec, Vec)) -> Vec, (Vec, Vec)>, chumsky::combinator::Map>, Just>>, OrNot>, Just>>>>, fn((char, Option)) -> Vec, (char, Option)>, impl chumsky::Parser::Collection, Error = chumsky::error::Simple> + Copy + Clone>, fn((Vec, String)) -> Vec, (Vec, String)>>, fn(Option>) -> Vec, Option>>>, fn((Vec, Vec)) -> Vec, (Vec, Vec)>, fn(Vec) -> String, Vec>, fn(String) -> Result, String>, fn(Result) -> f64, Result>, &str>, fn(f64) -> Json {Json::Num}, f64>>, Label>, Repeated>, chumsky::combinator::Map>, Or>, Just>>, Just>>, To>, char, char>>, To>, char, char>>, To>, char, char>>, To>, char, char>>, To>, char, char>>, chumsky::combinator::Map>, Validate>>, fn(Vec) -> String, Vec>, String, [closure@$DIR/tests/chumsky/json.rs:48:35: 54:26]>>, fn((char, char)) -> char, (char, char)>>>, fn((char, char)) -> char, (char, char)>>>>, fn((char, Vec)) -> Vec, (char, Vec)>, Just>>, fn((Vec, char)) -> Vec, (Vec, char)>, fn(Vec) -> String, Vec>, &str>>', but its trait bounds were not satisfied --> tests/chumsky/json.rs:94:14 | 94 | .or(array) | ^^ method cannot be called on 'Or>, &str, Json>, &str>, Label>, &str, Json>, &str>>, Label>, &str, Json>, &str>>, chumsky::combinator::Map>>, impl chumsky::Parser::Collection, Error = chumsky::error::Simple> + Copy + Clone>, fn((Option, String)) -> Vec, (Option, String)>, chumsky::combinator::Map>, impl chumsky::Parser::Collection, Error = chumsky::error::Simple> + Copy + Clone>, fn((char, String)) -> Vec, (char, String)>>, fn(Option>) -> Vec, Option>>>, fn((Vec, Vec)) -> Vec, (Vec, Vec)>, chumsky::combinator::Map>, Just>>, OrNot>, Just>>>>, fn((char, Option)) -> Vec, (char, Option)>, impl chumsky::Parser::Collection, Error = chumsky::error::Simple> + Copy + Clone>, fn((Vec, String)) -> Vec, (Vec, String)>>, fn(Option>) -> Vec, Option>>>, fn((Vec, Vec)) -> Vec, (Vec, Vec)>, fn(Vec) -> String, Vec>, fn(String) -> Result, String>, fn(Result) -> f64, Result>, &str>, fn(f64) -> Json {Json::Num}, f64>>, Label>, Repeated>, chumsky::combinator::Map>, Or>, Just>>, Just>>, To>, char, char>>, To>, char, char>>, To>, char, char>>, To>, char, char>>, To>, char, char>>, chumsky::combinator::Map>, Validate>>, fn(Vec) -> String, Vec>, String, [closure@$DIR/tests/chumsky/json.rs:48:35: 54:26]>>, fn((char, char)) -> char, (char, char)>>>, fn((char, char)) -> char, (char, char)>>>>, fn((char, Vec)) -> Vec, (char, Vec)>, Just>>, fn((Vec, char)) -> Vec, (Vec, char)>, fn(Vec) -> String, Vec>, &str>>' due to unsatisfied trait bounds | ::: $CARGO/chumsky-0.8.0/src/combinator.rs | | pub struct Or(pub(crate) A, pub(crate) B); | ------------------- doesn't satisfy '_: chumsky::Parser<_, _>' | = note: the following trait bounds were not satisfied: 'Or>, &str, Json>, &str>, Label>, &str, Json>, &str>>, Label>, &str, Json>, &str>>, chumsky::combinator::Map>>, impl chumsky::Parser::Collection, Error = chumsky::error::Simple> + Copy + Clone>, fn((Option, String)) -> Vec, (Option, String)>, chumsky::combinator::Map>, impl chumsky::Parser::Collection, Error = chumsky::error::Simple> + Copy + Clone>, fn((char, String)) -> Vec, (char, String)>>, fn(Option>) -> Vec, Option>>>, fn((Vec, Vec)) -> Vec, (Vec, Vec)>, chumsky::combinator::Map>, Just>>, OrNot>, Just>>>>, fn((char, Option)) -> Vec, (char, Option)>, impl chumsky::Parser::Collection, Error = chumsky::error::Simple> + Copy + Clone>, fn((Vec, String)) -> Vec, (Vec, String)>>, fn(Option>) -> Vec, Option>>>, fn((Vec, Vec)) -> Vec, (Vec, Vec)>, fn(Vec) -> String, Vec>, fn(String) -> Result, String>, fn(Result) -> f64, Result>, &str>, fn(f64) -> Json {Json::Num}, f64>>, Label>, Repeated>, chumsky::combinator::Map>, Or>, Just>>, Just>>, To>, char, char>>, To>, char, char>>, To>, char, char>>, To>, char, char>>, To>, char, char>>, chumsky::combinator::Map>, Validate>>, fn(Vec) -> String, Vec>, String, [closure@$DIR/tests/chumsky/json.rs:48:35: 54:26]>>, fn((char, char)) -> char, (char, char)>>>, fn((char, char)) -> char, (char, char)>>>>, fn((char, Vec)) -> Vec, (char, Vec)>, Just>>, fn((Vec, char)) -> Vec, (Vec, char)>, fn(Vec) -> String, Vec>, &str>>: chumsky::Parser<_, _>' which is required by '&Or>, &str, Json>, &str>, Label>, &str, Json>, &str>>, Label>, &str, Json>, &str>>, chumsky::combinator::Map>>, impl chumsky::Parser::Collection, Error = chumsky::error::Simple> + Copy + Clone>, fn((Option, String)) -> Vec, (Option, String)>, chumsky::combinator::Map>, impl chumsky::Parser::Collection, Error = chumsky::error::Simple> + Copy + Clone>, fn((char, String)) -> Vec, (char, String)>>, fn(Option>) -> Vec, Option>>>, fn((Vec, Vec)) -> Vec, (Vec, Vec)>, chumsky::combinator::Map>, Just>>, OrNot>, Just>>>>, fn((char, Option)) -> Vec, (char, Option)>, impl chumsky::Parser::Collection, Error = chumsky::error::Simple> + Copy + Clone>, fn((Vec, String)) -> Vec, (Vec, String)>>, fn(Option>) -> Vec, Option>>>, fn((Vec, Vec)) -> Vec, (Vec, Vec)>, fn(Vec) -> String, Vec>, fn(String) -> Result, String>, fn(Result) -> f64, Result>, &str>, fn(f64) -> Json {Json::Num}, f64>>, Label>, Repeated>, chumsky::combinator::Map>, Or>, Just>>, Just>>, To>, char, char>>, To>, char, char>>, To>, char, char>>, To>, char, char>>, To>, char, char>>, chumsky::combinator::Map>, Validate>>, fn(Vec) -> String, Vec>, String, [closure@$DIR/tests/chumsky/json.rs:48:35: 54:26]>>, fn((char, char)) -> char, (char, char)>>>, fn((char, char)) -> char, (char, char)>>>>, fn((char, Vec)) -> Vec, (char, Vec)>, Just>>, fn((Vec, char)) -> Vec, (Vec, char)>, fn(Vec) -> String, Vec>, &str>>: chumsky::Parser<_, _>' ```
weiznich commented 2 years ago

Thanks :heart: