File: type-mismatch-same-crate-name.rs

package info (click to toggle)
rustc 1.88.0%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 934,128 kB
  • sloc: xml: 158,127; python: 36,062; javascript: 19,855; sh: 19,700; cpp: 18,947; ansic: 12,993; asm: 4,792; makefile: 690; lisp: 29; perl: 29; ruby: 19; sql: 11
file content (34 lines) | stat: -rw-r--r-- 1,767 bytes parent folder | download | duplicates (14)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
//@ aux-build:crate_a1.rs
//@ aux-build:crate_a2.rs

// This tests the extra note reported when a type error deals with
// seemingly identical types.
// The main use case of this error is when there are two crates imported
// with the same name, causing a type mismatch. Here, we simulate that error
// using block-scoped aliased `extern crate` declarations.
// This is *not* the same case as two different crate versions in the
// dependency tree. That is tested in `tests/run-make/crate-loading/`.

fn main() {
    let foo2 = {extern crate crate_a2 as a; a::Foo};
        //~^ NOTE one type comes from crate `crate_a2` used here, which is renamed locally to `a`
        //~| NOTE one trait comes from crate `crate_a2` used here, which is renamed locally to `a`
    let bar2 = {extern crate crate_a2 as a; a::bar()};
    {
        extern crate crate_a1 as a;
        //~^ NOTE one type comes from crate `crate_a1` used here, which is renamed locally to `a`
        //~| NOTE one trait comes from crate `crate_a1` used here, which is renamed locally to `a`
        a::try_foo(foo2);
        //~^ ERROR mismatched types
        //~| NOTE expected `main::a::Foo`, found a different `main::a::Foo`
        //~| NOTE arguments to this function are incorrect
        //~| NOTE two types coming from two different crates are different types even if they look the same
        //~| NOTE function defined here
        a::try_bar(bar2);
        //~^ ERROR mismatched types
        //~| NOTE expected trait `main::a::Bar`, found a different trait `main::a::Bar`
        //~| NOTE arguments to this function are incorrect
        //~| NOTE two types coming from two different crates are different types even if they look the same
        //~| NOTE function defined here
    }
}