Skip to content

debug assertion ice: bad spans: -Wunused-lifetimes #108248

Open

Description

@matthiaskrgr

Code

fn main() {
    let _: extern fn<'a: 'static>();
}

The problem is this first garbage span:

warning: lifetime parameter `'a` never used
 --> recover-fn-ptr-with-generics.rs:2:22
  |
2 |     let _: extern fn<'a: 'static>();
  |            -         ^^
  |            |
  |            help: elide the unused lifetime
  |
  = note: requested on the command line with `-W unused-lifetimes`

Meta

rustc --version --verbose:

eebdfb55fce148676c24555505aebf648123b2de

Error output

<output>

unused_lifetime.txt

Activity

  1. added
    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.
    I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    C-bugCategory: This is a bug.
    S-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issue
    requires-debug-assertionsThis issue requires a build of rustc or tooling with debug-assertions in some way
    on Feb 19, 2023
  2. KittyBorgX commented on Feb 20, 2023

    @KittyBorgX
    Contributor

    @matthiaskrgr I think I can take this up.
    Before I do, just some questions:

    • What's the expected output which I can use to verify?
    • I can't reproduce the help: elide the unused lifetime part:
      image
      and there's no ICE for me.

    rustc --version --verbose for me:

    rustc 1.69.0-nightly (7aa413d59 2023-02-19)
    binary: rustc
    commit-hash: 7aa413d59206fd511137728df3d9e0fd377429bd
    commit-date: 2023-02-19
    host: aarch64-apple-darwin
    release: 1.69.0-nightly
    LLVM version: 15.0.7
    

    Edit : I'm on the latest nightly

  3. clubby789 commented on Feb 20, 2023

    @clubby789
    Contributor

    You need to build with debug assertions, and invoke with -Wunused-lifetimes. I believe the bad span is created around

    let span = ty.span.shrink_to_lo().to(bare_fn.decl_span.shrink_to_lo());

    I tried modifying that span to instead contain the generics, which fixes this case but regresses a few other cases

  4. layerkugou commented on Feb 21, 2023

    @layerkugou

    very good

  5. added a commit that references this issue on Jan 27, 2025
  6. added a commit that references this issue on Jan 27, 2025
  7. cyrgani commented on Jan 27, 2025

    @cyrgani
    Contributor

    @rustbot label S-bug-has-test

  8. added
    S-bug-has-testStatus: This bug is tracked inside the repo by a `known-bug` test.
    on Jan 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️L-unused_lifetimesLint: unused_lifetimesS-bug-has-testStatus: This bug is tracked inside the repo by a `known-bug` test.S-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.requires-debug-assertionsThis issue requires a build of rustc or tooling with debug-assertions in some way

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions