From e489fc09130262796744451b8675aa084696ac80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Rakic?= Date: Thu, 21 Nov 2024 16:59:40 +0000 Subject: [PATCH] Revert "Remove less relevant info from diagnostic" This reverts commit 8a568d9f15453cbfe5d6f45fa5f5bb32e58b93ed. (cherry picked from commit 764e3e264f69d8af9fa42d86ea36702584dcb36b) --- .../traits/fulfillment_errors.rs | 18 --------------- .../foo.stderr | 7 +++++- .../multiple-dep-versions.stderr | 22 +++++++++++++++---- 3 files changed, 24 insertions(+), 23 deletions(-) diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs index 20cef5e06a4c..307c1af41cc0 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs @@ -1808,24 +1808,6 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { StringPart::highlighted("cargo tree".to_string()), StringPart::normal("` to explore your dependency tree".to_string()), ]); - - // FIXME: this is a giant hack for the benefit of this specific diagnostic. Because - // we're so nested in method calls before the error gets emitted, bubbling a single bit - // flag informing the top level caller to stop adding extra detail to the diagnostic, - // would actually be harder to follow. So we do something naughty here: we consume the - // diagnostic, emit it and leave in its place a "delayed bug" that will continue being - // modified but won't actually be printed to end users. This *is not ideal*, but allows - // us to reduce the verbosity of an error that is already quite verbose and increase its - // specificity. Below we modify the main message as well, in a way that *could* break if - // the implementation of Diagnostics change significantly, but that would be caught with - // a make test failure when this diagnostic is tested. - err.primary_message(format!( - "{} because the trait comes from a different crate version", - err.messages[0].0.as_str().unwrap(), - )); - let diag = err.clone(); - err.downgrade_to_delayed_bug(); - self.tcx.dcx().emit_diagnostic(diag); return true; } diff --git a/tests/run-make/crate-loading-crate-depends-on-itself/foo.stderr b/tests/run-make/crate-loading-crate-depends-on-itself/foo.stderr index 9c2fcabe5ba8..36379429530b 100644 --- a/tests/run-make/crate-loading-crate-depends-on-itself/foo.stderr +++ b/tests/run-make/crate-loading-crate-depends-on-itself/foo.stderr @@ -1,4 +1,4 @@ -error[E0277]: the trait bound `foo::Struct: Trait` is not satisfied because the trait comes from a different crate version +error[E0277]: the trait bound `foo::Struct: Trait` is not satisfied --> foo-current.rs:13:19 | 13 | check_trait::(); @@ -23,6 +23,11 @@ note: there are multiple different versions of crate `foo` in the dependency gra | --------------- this is the found trait = note: two types coming from two different versions of the same crate are different types even if they look the same = help: you can use `cargo tree` to explore your dependency tree +note: required by a bound in `check_trait` + --> foo-current.rs:10:19 + | +10 | fn check_trait() {} + | ^^^^^ required by this bound in `check_trait` error: aborting due to 1 previous error diff --git a/tests/run-make/crate-loading/multiple-dep-versions.stderr b/tests/run-make/crate-loading/multiple-dep-versions.stderr index 7f04b2dd64ab..5888aad8f37b 100644 --- a/tests/run-make/crate-loading/multiple-dep-versions.stderr +++ b/tests/run-make/crate-loading/multiple-dep-versions.stderr @@ -1,8 +1,10 @@ -error[E0277]: the trait bound `dep_2_reexport::Type: Trait` is not satisfied because the trait comes from a different crate version +error[E0277]: the trait bound `dep_2_reexport::Type: Trait` is not satisfied --> replaced | LL | do_something(Type); - | ^^^^ the trait `Trait` is not implemented for `dep_2_reexport::Type` + | ------------ ^^^^ the trait `Trait` is not implemented for `dep_2_reexport::Type` + | | + | required by a bound introduced by this call | note: there are multiple different versions of crate `dependency` in the dependency graph --> replaced @@ -27,6 +29,11 @@ LL | pub trait Trait { | --------------- this is the found trait = note: two types coming from two different versions of the same crate are different types even if they look the same = help: you can use `cargo tree` to explore your dependency tree +note: required by a bound in `do_something` + --> replaced + | +LL | pub fn do_something(_: X) {} + | ^^^^^ required by this bound in `do_something` error[E0599]: no method named `foo` found for struct `dep_2_reexport::Type` in the current scope --> replaced @@ -77,11 +84,13 @@ LL | use dependency::{Trait, do_something}; LL | pub trait Trait { | --------------- this is the trait that was imported -error[E0277]: the trait bound `OtherType: Trait` is not satisfied because the trait comes from a different crate version +error[E0277]: the trait bound `OtherType: Trait` is not satisfied --> replaced | LL | do_something(OtherType); - | ^^^^^^^^^ the trait `Trait` is not implemented for `OtherType` + | ------------ ^^^^^^^^^ the trait `Trait` is not implemented for `OtherType` + | | + | required by a bound introduced by this call | note: there are multiple different versions of crate `dependency` in the dependency graph --> replaced @@ -106,6 +115,11 @@ LL | pub struct OtherType; LL | pub trait Trait { | --------------- this is the found trait = help: you can use `cargo tree` to explore your dependency tree +note: required by a bound in `do_something` + --> replaced + | +LL | pub fn do_something(_: X) {} + | ^^^^^ required by this bound in `do_something` error: aborting due to 4 previous errors