Skip to content

On recursive requirements, elide repeating output #47720

Closed
@estebank

Description

@estebank

When encountering recursive requirements, elide some of the repeating output instead of having the following wall of text detailing every recursive step the compiler takes:

error[E0275]: overflow evaluating the requirement `Foo: std::marker::Sync`
 --> src/main.rs:5:1
  |
5 | / lazy_static! {
6 | |     static ref CHAR: Foo = unimplemented!();
7 | | }
  | |_^
  |
  = help: consider adding a `#![recursion_limit="128"]` attribute to your crate
  = note: required because it appears within the type `std::marker::PhantomData<Foo>`
  = note: required because it appears within the type `Bar`
  = note: required because it appears within the type `std::marker::PhantomData<Bar>`
  = note: required because it appears within the type `Foo`
  = note: required because it appears within the type `std::marker::PhantomData<Foo>`
  = note: required because it appears within the type `Bar`
  = note: required because it appears within the type `std::marker::PhantomData<Bar>`
  = note: required because it appears within the type `Foo`
  = note: required because it appears within the type `std::marker::PhantomData<Foo>`
  = note: required because it appears within the type `Bar`
8<8<8<8<8<8<8<
  = note: required by `lazy_static::lazy::Lazy`
  = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

The following code

ObligationCauseCode::BuiltinDerivedObligation(ref data) => {
let parent_trait_ref = self.resolve_type_vars_if_possible(&data.parent_trait_ref);
err.note(&format!("required because it appears within the type `{}`",
parent_trait_ref.0.self_ty()));
let parent_predicate = parent_trait_ref.to_predicate();
self.note_obligation_cause_code(err,
&parent_predicate,
&data.parent_code);
}

needs to be modified to pass down a vector of the Tys note_obligation_cause_code has encountered on previous runs. I feel it is reasonable to delay the notes from being produced until the bottom has been reached, and prune the list then. The output should be something along the lines of

error[E0275]: overflow evaluating the requirement `Foo: std::marker::Sync`
 --> src/main.rs:5:1
  |
5 | / lazy_static! {
6 | |     static ref CHAR: Foo = unimplemented!();
7 | | }
  | |_^
  |
  = help: consider adding a `#![recursion_limit="128"]` attribute to your crate
  = note: required because it appears within the type `std::marker::PhantomData<Foo>`
  = note: required because it appears within the type `Bar`
  = note: required because it appears within the type `std::marker::PhantomData<Bar>`
  = note: required because it appears within the type `Foo`
  = note: required because it appears within the type `std::marker::PhantomData<Foo>`
  = note: ...and so on, these requirements repeat until reaching the recursion limit
  = note: required by `lazy_static::lazy::Lazy`
  = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.D-verboseDiagnostics: Too much output caused by a single piece of incorrect code.T-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