You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Auto merge of #128849 - estebank:issue-89143, r=jackh726
Tweak detection of multiple crate versions to be more encompassing
Previously, we only emitted the additional context if the type was in the same crate as the trait that appeared multiple times in the dependency tree. Now, we look at all traits looking for two with the same name in different crates with the same crate number, and we are more flexible looking for the types involved. This will work even if the type that implements the wrong trait version is from a different crate entirely.
```
error[E0277]: the trait bound `CustomErrorHandler: ErrorHandler` is not satisfied because the trait comes from a different crate version
--> src/main.rs:5:17
|
5 | cnb_runtime(CustomErrorHandler {});
| ^^^^^^^^^^^^^^^^^^^^^ the trait `ErrorHandler` is not implemented for `CustomErrorHandler`
|
note: there are multiple different versions of crate `c` in the dependency graph
--> /home/gh-estebank/testcase-rustc-crate-version-mismatch/c-v0.2/src/lib.rs:1:1
|
1 | pub trait ErrorHandler {}
| ^^^^^^^^^^^^^^^^^^^^^^ this is the required trait
|
::: src/main.rs:1:5
|
1 | use b::CustomErrorHandler;
| - one version of crate `c` is used here, as a dependency of crate `b`
2 | use c::cnb_runtime;
| - one version of crate `c` is used here, as a direct dependency of the current crate
|
::: /home/gh-estebank/testcase-rustc-crate-version-mismatch/b/src/lib.rs:1:1
|
1 | pub struct CustomErrorHandler {}
| ----------------------------- this type doesn't implement the required trait
|
::: /home/gh-estebank/testcase-rustc-crate-version-mismatch/c-v0.1/src/lib.rs:1:1
|
1 | pub trait ErrorHandler {}
| ---------------------- 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
```
Fix#89143.
r#"error[E0277]: the trait bound `dep_2_reexport::Type: Trait` is not satisfied
23
-
--> multiple-dep-versions.rs:7:18
24
-
|
25
-
7 | do_something(Type);
26
-
| ------------ ^^^^ the trait `Trait` is not implemented for `dep_2_reexport::Type`
27
-
| |
28
-
| required by a bound introduced by this call
29
-
|
30
-
help: there are multiple different versions of crate `dependency` in the dependency graph
31
-
--> multiple-dep-versions.rs:1:1
32
-
|
33
-
1 | extern crate dep_2_reexport;
34
-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ one version of crate `dependency` is used here, as a dependency of crate `foo`
35
-
2 | extern crate dependency;
36
-
| ^^^^^^^^^^^^^^^^^^^^^^^^ one version of crate `dependency` is used here, as a direct dependency of the current crate"#,
37
-
)
38
-
.assert_stderr_contains(
39
-
r#"
40
-
3 | pub struct Type(pub i32);
41
-
| ^^^^^^^^^^^^^^^ this type implements the required trait
42
-
4 | pub trait Trait {
43
-
| --------------- this is the required trait"#,
44
-
)
45
-
.assert_stderr_contains(
46
-
r#"
47
-
3 | pub struct Type;
48
-
| ^^^^^^^^^^^^^^^ this type doesn't implement the required trait"#,
49
-
)
50
-
.assert_stderr_contains(
51
-
r#"
52
-
error[E0599]: no method named `foo` found for struct `dep_2_reexport::Type` in the current scope
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
+
|
27
+
note: there are multiple different versions of crate `dependency` in the dependency graph"#)
28
+
.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
33
+
"#)
34
+
.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"#)
39
+
.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"#)
46
+
.assert_stderr_contains(r#"error[E0599]: no method named `foo` found for struct `dep_2_reexport::Type` in the current scope
53
47
--> multiple-dep-versions.rs:8:10
54
48
|
55
49
8 | Type.foo();
56
50
| ^^^ method not found in `Type`
57
51
|
58
-
note: there are multiple different versions of crate `dependency` in the dependency graph"#,
59
-
)
60
-
.assert_stderr_contains(
61
-
r#"
52
+
note: there are multiple different versions of crate `dependency` in the dependency graph"#)
53
+
.assert_stderr_contains(r#"
62
54
4 | pub trait Trait {
63
55
| ^^^^^^^^^^^^^^^ this is the trait that is needed
64
56
5 | fn foo(&self);
@@ -67,25 +59,19 @@ note: there are multiple different versions of crate `dependency` in the depende
67
59
::: multiple-dep-versions.rs:4:18
68
60
|
69
61
4 | use dependency::{Trait, do_something};
70
-
| ----- `Trait` imported here doesn't correspond to the right version of crate `dependency`"#,
71
-
)
72
-
.assert_stderr_contains(
73
-
r#"
62
+
| ----- `Trait` imported here doesn't correspond to the right version of crate `dependency`"#)
63
+
.assert_stderr_contains(r#"
74
64
4 | pub trait Trait {
75
-
| --------------- this is the trait that was imported"#,
76
-
)
77
-
.assert_stderr_contains(
78
-
r#"
65
+
| --------------- this is the trait that was imported"#)
66
+
.assert_stderr_contains(r#"
79
67
error[E0599]: no function or associated item named `bar` found for struct `dep_2_reexport::Type` in the current scope
80
68
--> multiple-dep-versions.rs:9:11
81
69
|
82
70
9 | Type::bar();
83
71
| ^^^ function or associated item not found in `Type`
84
72
|
85
-
note: there are multiple different versions of crate `dependency` in the dependency graph"#,
86
-
)
87
-
.assert_stderr_contains(
88
-
r#"
73
+
note: there are multiple different versions of crate `dependency` in the dependency graph"#)
74
+
.assert_stderr_contains(r#"
89
75
4 | pub trait Trait {
90
76
| ^^^^^^^^^^^^^^^ this is the trait that is needed
91
77
5 | fn foo(&self);
@@ -95,6 +81,9 @@ note: there are multiple different versions of crate `dependency` in the depende
95
81
::: multiple-dep-versions.rs:4:18
96
82
|
97
83
4 | use dependency::{Trait, do_something};
98
-
| ----- `Trait` imported here doesn't correspond to the right version of crate `dependency`"#,
99
-
);
84
+
| ----- `Trait` imported here doesn't correspond to the right version of crate `dependency`"#)
85
+
.assert_stderr_contains(
86
+
r#"
87
+
6 | pub struct OtherType;
88
+
| -------------------- this type doesn't implement the required trait"#);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ one version of crate `foreign_struct_trait_unimplemented` is used here, as a direct dependency of the current crate
14
-
= help: you can use `cargo tree` to explore your dependency tree
0 commit comments