16bf7223ea
When encountering a type or trait mismatch for two types coming from two different crates with the same name, detect if it is either mixing two types/traits from the same crate on different versions: ``` error[E0308]: mismatched types --> replaced | LL | do_something_type(Type); | ----------------- ^^^^ expected `dependency::Type`, found `dep_2_reexport::Type` | | | arguments to this function are incorrect | note: two different versions of crate `dependency` are being used; two types coming from two different versions of the same crate are different types even if they look the same --> replaced | LL | pub struct Type(pub i32); | ^^^^^^^^^^^^^^^ this is the expected type `dependency::Type` | ::: replaced | LL | pub struct Type; | ^^^^^^^^^^^^^^^ this is the found type `dep_2_reexport::Type` | ::: replaced | LL | extern crate dep_2_reexport; | ---------------------------- one version of crate `dependency` is used here, as a dependency of crate `foo` LL | extern crate dependency; | ------------------------ one version of crate `dependency` is used here, as a direct dependency of the current crate = help: you can use `cargo tree` to explore your dependency tree note: function defined here --> replaced | LL | pub fn do_something_type(_: Type) {} | ^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types --> replaced | LL | do_something_trait(Box::new(Type) as Box<dyn Trait2>); | ------------------ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected trait `dependency::Trait2`, found trait `dep_2_reexport::Trait2` | | | arguments to this function are incorrect | note: two different versions of crate `dependency` are being used; two types coming from two different versions of the same crate are different types even if they look the same --> replaced | LL | pub trait Trait2 {} | ^^^^^^^^^^^^^^^^ this is the expected trait `dependency::Trait2` | ::: replaced | LL | pub trait Trait2 {} | ^^^^^^^^^^^^^^^^ this is the found trait `dep_2_reexport::Trait2` | ::: replaced | LL | extern crate dep_2_reexport; | ---------------------------- one version of crate `dependency` is used here, as a dependency of crate `foo` LL | extern crate dependency; | ------------------------ one version of crate `dependency` is used here, as a direct dependency of the current crate = help: you can use `cargo tree` to explore your dependency tree note: function defined here --> replaced | LL | pub fn do_something_trait(_: Box<dyn Trait2>) {} | ^^^^^^^^^^^^^^^^^^ ``` or if it is different crates that were renamed to the same name: ``` error[E0308]: mismatched types --> $DIR/type-mismatch-same-crate-name.rs:21:20 | LL | a::try_foo(foo2); | ---------- ^^^^ expected `main:🅰️:Foo`, found a different `main:🅰️:Foo` | | | arguments to this function are incorrect | note: two types coming from two different crates are different types even if they look the same --> $DIR/auxiliary/crate_a2.rs:1:1 | LL | pub struct Foo; | ^^^^^^^^^^^^^^ this is the found type `crate_a2::Foo` | ::: $DIR/auxiliary/crate_a1.rs:1:1 | LL | pub struct Foo; | ^^^^^^^^^^^^^^ this is the expected type `crate_a1::Foo` | ::: $DIR/type-mismatch-same-crate-name.rs:13:17 | LL | let foo2 = {extern crate crate_a2 as a; a::Foo}; | --------------------------- one type comes from crate `crate_a2` is used here, which is renamed locally to `a` ... LL | extern crate crate_a1 as a; | --------------------------- one type comes from crate `crate_a1` is used here, which is renamed locally to `a` note: function defined here --> $DIR/auxiliary/crate_a1.rs:10:8 | LL | pub fn try_foo(x: Foo){} | ^^^^^^^ error[E0308]: mismatched types --> $DIR/type-mismatch-same-crate-name.rs:27:20 | LL | a::try_bar(bar2); | ---------- ^^^^ expected trait `main:🅰️:Bar`, found a different trait `main:🅰️:Bar` | | | arguments to this function are incorrect | note: two types coming from two different crates are different types even if they look the same --> $DIR/auxiliary/crate_a2.rs:3:1 | LL | pub trait Bar {} | ^^^^^^^^^^^^^ this is the found trait `crate_a2::Bar` | ::: $DIR/auxiliary/crate_a1.rs:3:1 | LL | pub trait Bar {} | ^^^^^^^^^^^^^ this is the expected trait `crate_a1::Bar` | ::: $DIR/type-mismatch-same-crate-name.rs:13:17 | LL | let foo2 = {extern crate crate_a2 as a; a::Foo}; | --------------------------- one trait comes from crate `crate_a2` is used here, which is renamed locally to `a` ... LL | extern crate crate_a1 as a; | --------------------------- one trait comes from crate `crate_a1` is used here, which is renamed locally to `a` note: function defined here --> $DIR/auxiliary/crate_a1.rs:11:8 | LL | pub fn try_bar(x: Box<Bar>){} | ^^^^^^^ ``` This new output unifies the E0308 errors detail with the pre-existing E0277 errors, and better differentiates the "`extern crate` renamed" and "same crate, different versions" cases. |
||
---|---|---|
.. | ||
add_private_fn_at_krate_root_cc | ||
auxiliary | ||
callee_caller_cross_crate | ||
change_add_field | ||
change_crate_order | ||
change_implementation_cross_crate | ||
change_private_fn | ||
change_private_fn_cc | ||
change_private_impl_method | ||
change_private_impl_method_cc | ||
change_pub_inherent_method_body | ||
change_pub_inherent_method_sig | ||
const-generics | ||
extern_static | ||
hashes | ||
hygiene | ||
inlined_hir_34991 | ||
issue-39828 | ||
issue-49595 | ||
issue-85197-invalid-span | ||
issue-92163-missing-sourcefile | ||
issue-110457-same-span-closures | ||
krate_reassign_34991 | ||
link_order | ||
remapped_paths_cc | ||
remove-private-item-cross-crate | ||
remove_crate | ||
remove_source_file | ||
rlib_cross_crate | ||
span_hash_stable | ||
static_cycle | ||
static_refering_to_other_static | ||
static_refering_to_other_static2 | ||
static_refering_to_other_static3 | ||
static_stable_hash | ||
struct_change_field_type_cross_crate | ||
thinlto | ||
type_alias_cross_crate | ||
async-lifetimes.rs | ||
cache_file_headers.rs | ||
change_crate_dep_kind.rs | ||
change_name_of_static_in_fn.rs | ||
change_symbol_export_status.rs | ||
circular-dependencies.rs | ||
commandline-args.rs | ||
const-generic-type-cycle.rs | ||
crate_hash_reorder.rs | ||
cyclic-trait-hierarchy.rs | ||
decl_macro.rs | ||
delayed_span_bug.rs | ||
dirty_clean.rs | ||
feature_gate.rs | ||
foreign.rs | ||
hash-module-order.rs | ||
hello_world.rs | ||
ich_method_call_trait_scope.rs | ||
ich_nested_items.rs | ||
ich_resolve_results.rs | ||
incremental_proc_macro.rs | ||
issue-35593.rs | ||
issue-38222.rs | ||
issue-39569.rs | ||
issue-42602.rs | ||
issue-49043.rs | ||
issue-49482.rs | ||
issue-51409.rs | ||
issue-54059.rs | ||
issue-54242.rs | ||
issue-59523-on-implemented-is-not-unused.rs | ||
issue-59524-layout-scalar-valid-range-is-not-unused.rs | ||
issue-60629.rs | ||
issue-61323.rs | ||
issue-61530.rs | ||
issue-62649-path-collisions-happen.rs | ||
issue-69596.rs | ||
issue-72386.rs | ||
issue-79661-missing-def-path-hash.rs | ||
issue-79890-imported-crates-changed.rs | ||
issue-80336-invalid-span.rs | ||
issue-80691-bad-eval-cache.rs | ||
issue-82920-predicate-order-miscompile.rs | ||
issue-84252-global-alloc.rs | ||
issue-85360-eval-obligation-ice.rs | ||
issue-86753.rs | ||
issue-92987-provisional-dep-node.rs | ||
issue-96319-coinductive-cycle.rs | ||
issue-100521-change-struct-name-assocty.rs | ||
issue-101518.rs | ||
issue-108481-feed-eval-always.rs | ||
krate-inherent.rs | ||
krate-inlined.rs | ||
lto-in-linker.rs | ||
lto.rs | ||
macro_export.rs | ||
mir-opt.rs | ||
no_mangle.rs | ||
reorder_vtable.rs | ||
rlib-lto.rs | ||
rustc-rust-log.rs | ||
slice-pattern-const-ice-83085.rs | ||
source_loc_macros.rs | ||
spans_in_type_debuginfo.rs | ||
spans_significant_w_debuginfo.rs | ||
spans_significant_w_panic.rs | ||
spike-neg1.rs | ||
spike-neg2.rs | ||
spike.rs | ||
split_debuginfo_cached.rs | ||
split_debuginfo_mode.rs | ||
string_constant.rs | ||
struct_add_field.rs | ||
struct_change_field_name.rs | ||
struct_change_field_type.rs | ||
struct_change_nothing.rs | ||
struct_remove_field.rs | ||
track-deps-in-new-solver.rs | ||
unchecked_dirty_clean.rs | ||
unrecoverable_query.rs | ||
warnings-reemitted.rs |