Revert "Remove less relevant info from diagnostic"

This reverts commit 8a568d9f15.

(cherry picked from commit 764e3e264f)
This commit is contained in:
Rémy Rakic 2024-11-21 16:59:40 +00:00 committed by Josh Stone
parent bdaaaf3ec3
commit e489fc0913
3 changed files with 24 additions and 23 deletions

View file

@ -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;
}

View file

@ -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

View file

@ -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