rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
96.73k stars 12.5k forks source link

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

Open matthiaskrgr opened 1 year ago

matthiaskrgr commented 1 year ago

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

KittyBorgX commented 1 year ago

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

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

clubby789 commented 1 year ago

You need to build with debug assertions, and invoke with -Wunused-lifetimes. I believe the bad span is created around https://github.com/rust-lang/rust/blob/e7eaed21d50d7bfb8d614d6ee7fcea940b39185d/compiler/rustc_resolve/src/late.rs#L739 I tried modifying that span to instead contain the generics, which fixes this case but regresses a few other cases

layerkugou commented 1 year ago

very good