Skip to content

Hitting “undefined reference to `core::future::identity_future’” when working with associated types and async #107557

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
oliverbrowneprima opened this issue Feb 1, 2023 · 9 comments · Fixed by #113108
Assignees
Labels
C-bug Category: This is a bug. P-high High priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@oliverbrowneprima
Copy link

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
@oliverbrowneprima oliverbrowneprima added C-bug Category: This is a bug. regression-untriaged Untriaged performance or correctness regression. labels Feb 1, 2023
@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Feb 1, 2023
@steffahn
Copy link
Member

steffahn commented Feb 1, 2023

@rustbot label T-compiler -regression-untriaged +regression-from-stable-to-stable

For clarification (for prioritization): This regression happens between 1.55 and 1.56, so it’s not a very recent regression.

Of course, hitting such a linking error is a serious bug either way. Bisection looks like

searched toolchains nightly-2021-09-27 through nightly-2021-09-30


********************************************************************************
Regression in nightly-2021-09-28
********************************************************************************

fetching https://static.rust-lang.org/dist/2021-09-27/channel-rust-nightly-git-commit-hash.txt
nightly manifest 2021-09-27: 40 B / 40 B [=========================================================================================================================] 100.00 % 344.14 KB/s converted 2021-09-27 to 05044c2e6c043929a11537d7f6169eb3a2397bb8
fetching https://static.rust-lang.org/dist/2021-09-28/channel-rust-nightly-git-commit-hash.txt
nightly manifest 2021-09-28: 40 B / 40 B [=========================================================================================================================] 100.00 % 396.34 KB/s converted 2021-09-28 to 98c8619502093f34ca82f8f26ccf32e753924440
looking for regression commit between 2021-09-27 and 2021-09-28
fetching (via remote github) commits from max(05044c2e6c043929a11537d7f6169eb3a2397bb8, 2021-09-25) to 98c8619502093f34ca82f8f26ccf32e753924440
ending github query because we found starting sha: 05044c2e6c043929a11537d7f6169eb3a2397bb8
get_commits_between returning commits, len: 8
  commit[0] 2021-09-26UTC: Auto merge of #89144 - sexxi-goose:insig_stdlib, r=nikomatsakis
  commit[1] 2021-09-26UTC: Auto merge of #89092 - bjorn3:sync_cg_clif-2021-09-19, r=bjorn3
  commit[2] 2021-09-27UTC: Auto merge of #89145 - rusticstuff:bump_stdarch, r=kennytm
  commit[3] 2021-09-27UTC: Auto merge of #89182 - GuillaumeGomez:boostrap-explicit-request, r=Mark-Simulacrum
  commit[4] 2021-09-27UTC: Auto merge of #89203 - GuillaumeGomez:cleanup-rustdoc-types, r=camelid
  commit[5] 2021-09-27UTC: Auto merge of #89263 - TaKO8Ki:suggest-both-immutable-and-mutable-trait-implementations, r=estebank
  commit[6] 2021-09-27UTC: Auto merge of #89285 - jackh726:issue-88862, r=nikomatsakis
  commit[7] 2021-09-27UTC: Auto merge of #89214 - smoelius:register_tool, r=petrochenkov
ERROR: no CI builds available between 05044c2e6c043929a11537d7f6169eb3a2397bb8 and 98c8619502093f34ca82f8f26ccf32e753924440 within last 167 day

@rustbot rustbot added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. regression-from-stable-to-stable Performance or correctness regression from one stable version to another. and removed regression-untriaged Untriaged performance or correctness regression. labels Feb 1, 2023
@compiler-errors
Copy link
Member

Hm, I bet it's #89285

@LegionMammal978
Copy link
Contributor

Given that #89285 was a revert of #85499, and that it was un-reverted by #100980, I wonder if #89285 simply unmasked a regression that occurred between #85499 and #89285.

@apiraino
Copy link
Contributor

apiraino commented Feb 2, 2023

WG-prioritization assigning priority (Zulip discussion).

@rustbot label -I-prioritize +P-high

@rustbot rustbot added P-high High priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Feb 2, 2023
@compiler-errors compiler-errors self-assigned this Feb 2, 2023
@compiler-errors
Copy link
Member

I wonder if #89285 simply unmasked a regression that occurred between #85499 and #89285.

I don't think this is the case. This is definitely caused by #89285, which was fixed by #100980, and then un-fixed by #103509. I'm gonna try to look into fixing this behavior for real in #107620.

@megakorre
Copy link
Contributor

seems the symbol names get normalized correctly with -C symbol-mangling-version=v0
https://rust.godbolt.org/z/59YqG3nrn

@oliverbrowneprima
Copy link
Author

Hey folks, really appreciate you all looking at this. Is there any update? Anything I can do to assist?

I'll admit the technical details of the failure here are beyond me though 😆

@Swatinem
Copy link
Contributor

Out of curiosity, how does this look like today on nightly, now that identity_future is gone completely?
This might also be related / a duplicate of #107513, as that describes a similar linker error.

@LegionMammal978
Copy link
Contributor

LegionMammal978 commented Mar 29, 2023

This linker error happens with any generic function that takes the generator type. See, e.g., my minimized example:

#![feature(generators)]

fn wrapper<T>(value: T) -> T {
    value
}

fn func<T>() -> impl Sized {}

trait Trait<'a> {
    type Assoc;

    fn call() {
        let _ = wrapper(|()| {
            let _value = func::<Self::Assoc>();
            yield;
        });
    }
}

impl Trait<'static> for () {
    type Assoc = ();
}

fn main() {
    <()>::call();
}

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
C-bug Category: This is a bug. P-high High priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
8 participants