Description
I tried this code:
use core::future;
fn func<T>() -> impl Sized {}
trait Trait<'a> {
type Assoc;
fn call() {
let _ = async {
let _value = func::<Self::Assoc>();
future::ready(()).await
};
}
}
impl Trait<'static> for () {
type Assoc = ();
}
fn main() {
<()>::call();
}
I expected to see this happen: The code would compile and link normally, and run
Instead, this happened: Compilation failed with the following linker error:
/playground/src/main.rs:9: undefined reference to `core::future::identity_future'
/usr/bin/ld: /playground/target/debug/deps/playground-2814c18f3846befb: hidden symbol `_ZN4core6future15identity_future17h32aefcac7c273f09E' isn't defined
/usr/bin/ld: final link failed: bad value
collect2: error: ld returned 1 exit status
= note: some `extern` functions couldn't be found; some native libraries may need to be installed or have their path specified
= note: use the `-l` flag to specify native libraries to link
= note: use the `cargo:rustc-link-lib` directive to specify the native libraries to link with Cargo (see https://doc.rust-lang.org/cargo/reference/build-scripts.html#cargorustc-link-libkindname)
This failure seems to only occurs if the fn call
is defined in the trait, and the trait must have a lifetime parameter.
The above is a minimum reproducing case that LegionMammal978 managed to produce on the forums, based of a more convoluted reproducing case I originally had (playground link). They also produced a version that uses a generator to cause a similar linker failure (in nightly), with very similar setup (playground link) and pointed to PR 89285 as a possible suspect (based on bisecting the issue).
Let me know if any more information is needed, thanks!
Meta
rustc --version --verbose
:
rustc 1.67.0 (fc594f156 2023-01-24)
binary: rustc
commit-hash: fc594f15669680fa70d255faec3ca3fb507c3405
commit-date: 2023-01-24
host: x86_64-unknown-linux-gnu
release: 1.67.0
LLVM version: 15.0.6
Also failed with nightly:
rustc 1.69.0-nightly (001a77fac 2023-01-30)
binary: rustc
commit-hash: 001a77fac33f6560ff361ff38f661ff5f1c6bf85
commit-date: 2023-01-30
host: x86_64-unknown-linux-gnu
release: 1.69.0-nightly
LLVM version: 15.0.7