rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
97.88k stars 12.67k forks source link

E0277 highlights really long types for no reason, and doesn't highlight useful help #132013

Open jyn514 opened 5 hours ago

jyn514 commented 5 hours ago

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

Image

``` error[E0277]: the trait bound `Then>, {closure@repro.rs:16:17: 16:27}>, char>, chumsky::combinator::Map, O, {closure@repro.rs:18:32: 18:35}>, (), (), chumsky::extra::Full>: 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>` is not implemented for `Then, ...>, ..., ..., ..., ...>`, which is required by `Then>, {closure@repro.rs:16:17: 16:27}>, char>, chumsky::combinator::Map, O, {closure@repro.rs:18:32: 18:35}>, (), (), chumsky::extra::Full>: CSTParser<'a>` | = help: the trait `chumsky::private::ParserSealed<'_, &'a str, ((), ()), chumsky::extra::Full>` is implemented for `Then>, {closure@repro.rs:16:17: 16:27}>, char>, chumsky::combinator::Map, O, {closure@repro.rs:18:32: 18:35}>, (), (), chumsky::extra::Full>` = help: for that trait implementation, expected `((), ())`, found `()` = note: required for `Then, ...>, ..., ..., ..., ...>` to implement `Parser<'_, &str, ()>` note: required for `Then, ...>, ..., ..., ..., ...>` 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

Rationale and extra context

Other cases

No response

Rust Version

rustc 1.84.0-nightly (662180b34 2024-10-20) binary: rustc commit-hash: 662180b34d95f72d05b7c467b0baf4d23d36b1e1 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

jyn514 commented 5 hours ago

also this is a bit of a larger change, but it would be nice if rustc never broke up a diagnostic across a type name. it means that it's harder to visually parse, it has bad degenerate behavior when the types are long, and it doesn't really seem more clear than, e.g., "a trait bound was not satisfied: Then<...>: CSTParser"

jyn514 commented 5 hours ago

i think the the whole ", which is required by ..." clause shouldn't be there either tbh - it's already in a note below, and it's right in the middle of the span making it harder to see the rest of the diagnostic.