Skip to content

Expand list of trait implementers in E0277 when calling rustc with --verbose #125984

Closed
@estebank

Description

@estebank

When emitting an error like the following

error[E0277]: the trait bound `MaybeMissing<std::string::String>: Reconcile` is not satisfied
   --> src/main.rs:3:19
    |
3   | #[derive(Hydrate, Reconcile)]
    |                   ^^^^^^^^^ the trait `Reconcile` is not implemented for `MaybeMissing<std::string::String>`, which is required by `&MaybeMissing<std::string::String>: Reconcile`
4   | struct S {
5   |     s: MaybeMissing<String>,
    |     - required by a bound introduced by this call
    |
    = help: the following other types implement trait `Reconcile`:
              bool
              i8
              i16
              i32
              i64
              u8
              u16
              u32
            and 17 others
    = note: required for `&MaybeMissing<std::string::String>` to implement `Reconcile`
note: required by a bound in `autosurgeon::reconcile::MapReconciler::put`
   --> /home/matt/.cargo/registry/src/index.crates.io-6f17d22bba15001f/autosurgeon-0.8.3/src/reconcile.rs:114:15
    |
114 |     fn put<R: Reconcile, P: AsRef<str>>(&mut self, prop: P, value: R) -> Result<(), Self::Error>;
    |               ^^^^^^^^^ required by this bound in `MapReconciler::put`

Allow the --verbose flag (self.tcx.sess.opts.verbose) to print the whole list by modifying

let end = if candidates.len() <= 9 { candidates.len() } else { 8 };
err.help(format!(
"the following {other}types implement trait `{}`:{}{}",
trait_ref.print_trait_sugared(),
candidates[..end].join(""),
if candidates.len() > 9 {
format!("\nand {} others", candidates.len() - 8)
} else {
String::new()
}
));

There are other places where we limit output where we don't currently listen to this flag to expand the output. For type name shortening I believe we already do, but we should look for all of them and make the appropriate change for them too.

Originally reported at https://users.rust-lang.org/t/how-can-i-get-a-list-of-the-and-17-others-types-in-this-compilation-error/112458

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsD-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.P-lowLow priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions