diff options
| author | Dylan DPC <99973273+Dylan-DPC@users.noreply.github.com> | 2023-03-19 15:33:55 +0530 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-03-19 15:33:55 +0530 |
| commit | e9c25b4ad5a78e7a125efec5bc050abe1eff293e (patch) | |
| tree | 855c7fe74f2fa461ac372a448f4e7ee4c0e90ed1 /tests | |
| parent | 993b775849bdc75eac5cd3b7d459bcbaa9514ed8 (diff) | |
| parent | 97915ab943001b5a74df4b3e22e7c0a469433fb9 (diff) | |
| download | rust-e9c25b4ad5a78e7a125efec5bc050abe1eff293e.tar.gz rust-e9c25b4ad5a78e7a125efec5bc050abe1eff293e.zip | |
Rollup merge of #105793 - lukas-code:circular-deps, r=Mark-Simulacrum
Add note for mismatched types because of circular dependencies If you have crate A with a dependency on crate B, and crate B with a dev-dependency on A, then you might see "mismatched types" errors on types that seem to be equal. This PR adds a note that explains that the types are different, because crate B is compiled twice, one time with `cfg(test)` and one time without. I haven't found a good way to create circular dependencies in UI tests, so I abused the incremental tests instead. As a bonus, incremental tests support "cpass" now. related to https://github.com/rust-lang/rust/issues/22750
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/incremental/auxiliary/circular-dependencies-aux.rs | 10 | ||||
| -rw-r--r-- | tests/incremental/circular-dependencies.rs | 37 |
2 files changed, 47 insertions, 0 deletions
diff --git a/tests/incremental/auxiliary/circular-dependencies-aux.rs b/tests/incremental/auxiliary/circular-dependencies-aux.rs new file mode 100644 index 00000000000..0e74eb1b2f2 --- /dev/null +++ b/tests/incremental/auxiliary/circular-dependencies-aux.rs @@ -0,0 +1,10 @@ +// edition: 2021 +// compile-flags: --crate-type lib --extern circular_dependencies={{build-base}}/circular-dependencies/libcircular_dependencies.rmeta --emit dep-info,metadata + +use circular_dependencies::Foo; + +pub fn consume_foo(_: Foo) {} + +pub fn produce_foo() -> Foo { + Foo +} diff --git a/tests/incremental/circular-dependencies.rs b/tests/incremental/circular-dependencies.rs new file mode 100644 index 00000000000..10673066a9d --- /dev/null +++ b/tests/incremental/circular-dependencies.rs @@ -0,0 +1,37 @@ +// ignore-tidy-linelength +// revisions: cpass1 cfail2 +// edition: 2021 +// [cpass1] compile-flags: --crate-type lib --emit dep-info,metadata +// [cfail2] aux-build: circular-dependencies-aux.rs +// [cfail2] compile-flags: --test --extern aux={{build-base}}/circular-dependencies/auxiliary/libcircular_dependencies_aux.rmeta -L dependency={{build-base}}/circular-dependencies + +pub struct Foo; +//[cfail2]~^ NOTE `Foo` is defined in the current crate +//[cfail2]~| NOTE `Foo` is defined in the current crate +//[cfail2]~| NOTE `circular_dependencies::Foo` is defined in crate `circular_dependencies` +//[cfail2]~| NOTE `circular_dependencies::Foo` is defined in crate `circular_dependencies` + +pub fn consume_foo(_: Foo) {} +//[cfail2]~^ NOTE function defined here + +pub fn produce_foo() -> Foo { + Foo +} + +#[test] +fn test() { + aux::consume_foo(produce_foo()); + //[cfail2]~^ ERROR mismatched types [E0308] + //[cfail2]~| NOTE expected `circular_dependencies::Foo`, found `Foo` + //[cfail2]~| NOTE arguments to this function are incorrect + //[cfail2]~| NOTE `Foo` and `circular_dependencies::Foo` have similar names, but are actually distinct types + //[cfail2]~| NOTE the crate `circular_dependencies` is compiled multiple times, possibly with different configurations + //[cfail2]~| NOTE function defined here + + consume_foo(aux::produce_foo()); + //[cfail2]~^ ERROR mismatched types [E0308] + //[cfail2]~| NOTE expected `Foo`, found `circular_dependencies::Foo` + //[cfail2]~| NOTE arguments to this function are incorrect + //[cfail2]~| NOTE `circular_dependencies::Foo` and `Foo` have similar names, but are actually distinct types + //[cfail2]~| NOTE the crate `circular_dependencies` is compiled multiple times, possibly with different configurations +} |
