Repository: rust
Issue: Linking a bin crate against a dylib crate from within the same workspace will fail if built from workspace root
Labels: A-linkage,T-compiler,C-bug,E-needs-mcve

The repo is set up like so:
<details><summary>Workspace Setup</summary>
<details><summary>Cargo.toml</summary>

```toml
[workspace]

members = [
	"bin",
	"first_lib"
]
```
</details>
<details><summary>first_lib/Cargo.toml</summary>

```toml
[package]
name = "first_lib"
version = "0.1.0"
edition = "2021"

[lib]
crate-type = ["dylib"]

[dependencies]
tokio = { version = "1.23.0", features = ["full"] }
```
</details>
<details><summary>first_lib/src/lib.rs</summary>

```rust
pub use tokio;
```
</details>
<details><summary>bin/Cargo.toml</summary>

```toml
[package]
name = "bin"
version = "0.1.0"
edition = "2021"

[dependencies]
first_lib = { path = "../first_lib" }
```
</details>
<details><summary>bin/src/main.rs</summary>

```rust
use first_lib::tokio::runtime::Builder;

fn main() {
    Builder::new_multi_thread()
        .enable_all()
        .build()
        .unwrap()
        .block_on(async {
            println!("Hello, world!");
        })
}

```
</details>
</details>

When performing `cargo run` directly against the `bin` crate either via being inside the `bin` directory or via calling `cargo run --bin bin`, the build and run was successful.
```
   Compiling first_lib v0.1.0 (/home/silvea/multi_test/first_lib)
   Compiling bin v0.1.0 (/home/silvea/multi_test/bin)
    Finished dev [unoptimized + debuginfo] target(s) in 10.29s
     Running `target/debug/bin`
Hello, world!
```

However, when performing `cargo run` on its own from the workspace root, instead I get
```
   Compiling first_lib v0.1.0 (/home/silvea/multi_test/first_lib)
   Compiling bin v0.1.0 (/home/silvea/multi_test/bin)
error: cannot satisfy dependencies so `std` only shows up once
  |
  = help: having upstream crates all available in one format will likely make this go away

error: could not compile `bin` due to previous error
```

Checking between the builds, the `libfirst_lib.so` lib is always the same from clean builds between runs of any given method, but it builds differently across the different methods (i.e. MD5 sum mismatch between working and failed method, but match between runs of the same method).

In my mind these should build the same? Not sure what's going on here, but it feels like a compiler bug.

### Meta
<!--
If you're using the stable version of the compiler, you should also check if the
bug also exists in the beta or nightly versions.
-->

`rustc --version --verbose`:
```
rustc 1.66.0 (69f9c33d7 2022-12-12)
binary: rustc
commit-hash: 69f9c33d71c871fc16ac445211281c6e7a340943
commit-date: 2022-12-12
host: x86_64-unknown-linux-gnu
release: 1.66.0
LLVM version: 15.0.2
```

<!--
Include a backtrace in the code block by setting `RUST_BACKTRACE=1` in your
environment. E.g. `RUST_BACKTRACE=1 cargo build`.
-->
<details><summary>Backtrace</summary>
<p>

```
❯ RUST_BACKTRACE=1 cargo run 
   Compiling libc v0.2.138
   Compiling autocfg v1.1.0
   Compiling proc-macro2 v1.0.49
   Compiling cfg-if v1.0.0
   Compiling quote v1.0.23
   Compiling unicode-ident v1.0.6
   Compiling syn v1.0.107
   Compiling log v0.4.17
   Compiling parking_lot_core v0.9.5
   Compiling smallvec v1.10.0
   Compiling scopeguard v1.1.0
   Compiling memchr v2.5.0
   Compiling bytes v1.3.0
   Compiling pin-project-lite v0.2.9
   Compiling lock_api v0.4.9
   Compiling tokio v1.23.0
   Compiling mio v0.8.5
   Compiling socket2 v0.4.7
   Compiling num_cpus v1.15.0
   Compiling signal-hook-registry v1.4.0
   Compiling parking_lot v0.12.1
   Compiling tokio-macros v1.8.2
   Compiling first_lib v0.1.0 (/home/silvea/multi_test/first_lib)
   Compiling bin v0.1.0 (/home/silvea/multi_test/bin)
error: cannot satisfy dependencies so `std` only shows up once
  |
  = help: having upstream crates all available in one format will likely make this go away

error: could not compile `bin` due to previous error
```

</p>
</details>