Skip to content

main() returning a type that implements Termination with an unsatisfied lifetime bound gives a linker error #148421

@theemathas

Description

@theemathas

I tried this code:

use std::process::ExitCode;
use std::process::Termination;

trait IsStatic {}
impl<'a: 'static> IsStatic for &'a () {}

struct Thing;
impl Termination for Thing where for<'a> &'a (): IsStatic {
    fn report(self) -> ExitCode { panic!() }
}

fn main() -> Thing { Thing }

I expected a normal compiler error. Instead, I got the following:

error: linking with `cc` failed: exit status: 1
  |
  = note:  "cc" ....... <arguments omitted for brevity of this issue>
  = note: some arguments are omitted. use `--verbose` to show all linker arguments
  = note: rust-lld: error: undefined hidden symbol: std::rt::lang_start::h005004333204f9e0
          >>> referenced by playground.b3525d8026055c0f-cgu.0
          >>>               /playground/target/debug/deps/playground-65a1e30147052435.playground.b3525d8026055c0f-cgu.0.rcgu.o:(main)
          collect2: error: ld returned 1 exit status

Meta

Reproducible on the playground with version 1.93.0-nightly (2025-11-01 bd3ac0330018c23b111b)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-borrow-checkerArea: The borrow checkerA-lifetimesArea: Lifetimes / regionsA-linkersArea: linkers... you gotta love linkersA-runtimeArea: std's runtime and "pre-main" init for handling backtraces, unwinds, stack overflowsC-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-typesRelevant to the types team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions