Closed
Description
Code
#!/usr/bin/env cargo
//! ```cargo
//! [dependencies]
//! chumsky = "1.0.0-alpha.7"
//! ```
use chumsky::{primitive::any, Parser};
pub(crate) trait CSTParser<'a, O = ()>: Parser<'a, &'a str, O> {}
impl<'a, O, T> CSTParser<'a, O> for T where T: Parser<'a, &'a str, O> {}
fn leaf<'a, O>(parser: impl CSTParser<'a, O>) -> impl CSTParser<'a, ()> {
let ws = any()
.filter(|c: &char| *c != '\n' && c.is_whitespace())
.ignored();
ws().then(parser.map(|_| ()))
}
fn main() {}
Current output
error[E0277]: the trait bound `Then<Ignored<chumsky::combinator::Filter<chumsky::primitive::Any<&str, chumsky::extra::Full<EmptyErr, (), ()>>, {closure@repro.rs:16:17: 16:27}>, char>, chumsky::combinator::Map<impl CSTParser<'a, O>, O, {closure@repro.rs:18:32: 18:35}>, (), (), chumsky::extra::Full<EmptyErr, (), ()>>: CSTParser<'a>` is not satisfied
--> repro.rs:14:50
|
14 | fn leaf<'a, O>(parser: impl CSTParser<'a, O>) -> impl CSTParser<'a, ()> {
| ^^^^^^^^^^^^^^^^^^^^^^ the trait `chumsky::private::ParserSealed<'_, &str, (), chumsky::extra::Full<EmptyErr, (), ()>>` is not implemented for `Then<Ignored<Filter<..., ...>, ...>, ..., ..., ..., ...>`, which is required by `Then<Ignored<chumsky::combinator::Filter<chumsky::primitive::Any<&str, chumsky::extra::Full<EmptyErr, (), ()>>, {closure@repro.rs:16:17: 16:27}>, char>, chumsky::combinator::Map<impl CSTParser<'a, O>, O, {closure@repro.rs:18:32: 18:35}>, (), (), chumsky::extra::Full<EmptyErr, (), ()>>: CSTParser<'a>`
|
= help: the trait `chumsky::private::ParserSealed<'_, &'a str, ((), ()), chumsky::extra::Full<EmptyErr, (), ()>>` is implemented for `Then<Ignored<chumsky::combinator::Filter<chumsky::primitive::Any<&str, chumsky::extra::Full<EmptyErr, (), ()>>, {closure@repro.rs:16:17: 16:27}>, char>, chumsky::combinator::Map<impl CSTParser<'a, O>, O, {closure@repro.rs:18:32: 18:35}>, (), (), chumsky::extra::Full<EmptyErr, (), ()>>`
= help: for that trait implementation, expected `((), ())`, found `()`
= note: required for `Then<Ignored<Filter<..., ...>, ...>, ..., ..., ..., ...>` to implement `Parser<'_, &str, ()>`
note: required for `Then<Ignored<Filter<..., ...>, ...>, ..., ..., ..., ...>` to implement `CSTParser<'a>`
--> repro.rs:12:16
|
12 | impl<'a, O, T> CSTParser<'a, O> for T where T: Parser<'a, &'a str, O> {}
| ^^^^^^^^^^^^^^^^ ^ ---------------------- unsatisfied trait bound introduced here
= note: the full name for the type has been written to '/home/jyn/.local/lib/cargo/target/debug/deps/foo-f0b1a0054d2a8996.long-type-7449552674356047294.txt'
= note: consider using `--verbose` to print the full type name to the console
= note: the full name for the type has been written to '/home/jyn/.local/lib/cargo/target/debug/deps/foo-f0b1a0054d2a8996.long-type-7449552674356047294.txt'
= note: consider using `--verbose` to print the full type name to the console
For more information about this error, try `rustc --explain E0277`.
Desired output
expected `((), ())`, found `()`
should be highlighted instead ofis implemented for `Then<...>`
- the difference between
ParserSealed<((), ())>
andParserSealed<()>
should be highlighted. - "the full name for the type has been written ..." should not be printed multiple times
- "trait is not implemented for T" followed by "trait is implemented for T" is really confusing. rustc shouldn't do that; or at least word it differently.
- especially since T is the same in both cases, it should not highlight T in purple.
- this should show the return value of the function somewhere; right now it's not even clear that the
ws().then()
line is related (from the spans, it looks like this is an error at the level of the function signature, not the function implementation)
Rationale and extra context
Other cases
No response
Rust Version
rustc 1.84.0-nightly (662180b 2024-10-20)
binary: rustc
commit-hash: 662180b
commit-date: 2024-10-20
host: x86_64-unknown-linux-gnu
release: 1.84.0-nightly
LLVM version: 19.1.1
Anything else?
No response