Skip to content

Commit 764e3e2

Browse files
committed
Revert "Remove less relevant info from diagnostic"
This reverts commit 8a568d9.
1 parent 9148660 commit 764e3e2

File tree

2 files changed

+26
-38
lines changed

2 files changed

+26
-38
lines changed

compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs

-18
Original file line numberDiff line numberDiff line change
@@ -1804,24 +1804,6 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
18041804
StringPart::highlighted("cargo tree".to_string()),
18051805
StringPart::normal("` to explore your dependency tree".to_string()),
18061806
]);
1807-
1808-
// FIXME: this is a giant hack for the benefit of this specific diagnostic. Because
1809-
// we're so nested in method calls before the error gets emitted, bubbling a single bit
1810-
// flag informing the top level caller to stop adding extra detail to the diagnostic,
1811-
// would actually be harder to follow. So we do something naughty here: we consume the
1812-
// diagnostic, emit it and leave in its place a "delayed bug" that will continue being
1813-
// modified but won't actually be printed to end users. This *is not ideal*, but allows
1814-
// us to reduce the verbosity of an error that is already quite verbose and increase its
1815-
// specificity. Below we modify the main message as well, in a way that *could* break if
1816-
// the implementation of Diagnostics change significantly, but that would be caught with
1817-
// a make test failure when this diagnostic is tested.
1818-
err.primary_message(format!(
1819-
"{} because the trait comes from a different crate version",
1820-
err.messages[0].0.as_str().unwrap(),
1821-
));
1822-
let diag = err.clone();
1823-
err.downgrade_to_delayed_bug();
1824-
self.tcx.dcx().emit_diagnostic(diag);
18251807
return true;
18261808
}
18271809

tests/run-make/crate-loading/rmake.rs

+26-20
Original file line numberDiff line numberDiff line change
@@ -18,31 +18,37 @@ fn main() {
1818
.extern_("dependency", rust_lib_name("dependency"))
1919
.extern_("dep_2_reexport", rust_lib_name("foo"))
2020
.run_fail()
21-
.assert_stderr_contains(r#"error[E0277]: the trait bound `dep_2_reexport::Type: Trait` is not satisfied because the trait comes from a different crate version
22-
--> multiple-dep-versions.rs:7:18
23-
|
24-
7 | do_something(Type);
25-
| ^^^^ the trait `Trait` is not implemented for `dep_2_reexport::Type`
26-
|
21+
.assert_stderr_contains(r#"error[E0277]: the trait bound `dep_2_reexport::Type: Trait` is not satisfied
22+
--> multiple-dep-versions.rs:7:18
23+
|
24+
7 | do_something(Type);
25+
| ------------ ^^^^ the trait `Trait` is not implemented for `dep_2_reexport::Type`
26+
| |
27+
| required by a bound introduced by this call
28+
|
2729
note: there are multiple different versions of crate `dependency` in the dependency graph"#)
2830
.assert_stderr_contains(r#"
29-
3 | pub struct Type(pub i32);
30-
| --------------- this type implements the required trait
31-
4 | pub trait Trait {
32-
| ^^^^^^^^^^^^^^^ this is the required trait
31+
3 | pub struct Type(pub i32);
32+
| --------------- this type implements the required trait
33+
4 | pub trait Trait {
34+
| ^^^^^^^^^^^^^^^ this is the required trait
3335
"#)
3436
.assert_stderr_contains(r#"
35-
1 | extern crate dep_2_reexport;
36-
| ---------------------------- one version of crate `dependency` is used here, as a dependency of crate `foo`
37-
2 | extern crate dependency;
38-
| ------------------------ one version of crate `dependency` is used here, as a direct dependency of the current crate"#)
37+
1 | extern crate dep_2_reexport;
38+
| ---------------------------- one version of crate `dependency` is used here, as a dependency of crate `foo`
39+
2 | extern crate dependency;
40+
| ------------------------ one version of crate `dependency` is used here, as a direct dependency of the current crate"#)
3941
.assert_stderr_contains(r#"
40-
3 | pub struct Type;
41-
| --------------- this type doesn't implement the required trait
42-
4 | pub trait Trait {
43-
| --------------- this is the found trait
44-
= note: two types coming from two different versions of the same crate are different types even if they look the same
45-
= help: you can use `cargo tree` to explore your dependency tree"#)
42+
3 | pub struct Type;
43+
| --------------- this type doesn't implement the required trait
44+
4 | pub trait Trait {
45+
| --------------- this is the found trait
46+
= note: two types coming from two different versions of the same crate are different types even if they look the same
47+
= help: you can use `cargo tree` to explore your dependency tree"#)
48+
.assert_stderr_contains(r#"note: required by a bound in `do_something`"#)
49+
.assert_stderr_contains(r#"
50+
12 | pub fn do_something<X: Trait>(_: X) {}
51+
| ^^^^^ required by this bound in `do_something`"#)
4652
.assert_stderr_contains(r#"error[E0599]: no method named `foo` found for struct `dep_2_reexport::Type` in the current scope
4753
--> multiple-dep-versions.rs:8:10
4854
|

0 commit comments

Comments
 (0)