summary refs log tree commit diff
diff options
context:
space:
mode:
authorRémy Rakic <remy.rakic+github@gmail.com>2024-11-21 16:59:40 +0000
committerJosh Stone <jistone@redhat.com>2025-01-23 11:32:32 -0800
commite489fc09130262796744451b8675aa084696ac80 (patch)
tree01ad1474cdcc875061dce5ac57eb0374c2808436
parentbdaaaf3ec37201271d509858432b7afcb263dae6 (diff)
downloadrust-e489fc09130262796744451b8675aa084696ac80.tar.gz
rust-e489fc09130262796744451b8675aa084696ac80.zip
Revert "Remove less relevant info from diagnostic"
This reverts commit 8a568d9f15453cbfe5d6f45fa5f5bb32e58b93ed.

(cherry picked from commit 764e3e264f69d8af9fa42d86ea36702584dcb36b)
-rw-r--r--compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs18
-rw-r--r--tests/run-make/crate-loading-crate-depends-on-itself/foo.stderr7
-rw-r--r--tests/run-make/crate-loading/multiple-dep-versions.stderr22
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 20cef5e06a4..307c1af41cc 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 9c2fcabe5ba..36379429530 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::<foo::Struct>();
@@ -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<T: 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 7f04b2dd64a..5888aad8f37 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: Trait>(_: 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: Trait>(_: X) {}
+   |                        ^^^^^ required by this bound in `do_something`
 
 error: aborting due to 4 previous errors