Rust: ICE involving missing const lifetime

Created on 31 Jan 2020  路  4Comments  路  Source: rust-lang/rust

Hi Rustaceans! :wave: Thanks for rust!

I forgot a lifetime parameter in a const in a struct's impl and somehow got the compiler to panic. I tried to create an extracted reproducible example, but outside of my application, I just get the expected E106. When I add the 'static in, my app builds successfully, and when I remove it the compiler panics consistently.

 26 |     const DIVIDER: &str = "\n";
    |                    ^ expected lifetime parameter

This is the compiler panic:

thread 'rustc' panicked at 'called `Result::unwrap()` on an `Err` value: DistinctSources(DistinctSources { begin: (Real("src/bin.rs"), BytePos(0)), end: (Real("src/state_machine.rs"), BytePos(29998)) })', src/librustc_errors/lib.rs:197:29
stack backtrace:
   0:        0x10665b675 - <unknown>
... 52 lines removed, please let me know if these <unknown> addresses are useful ...
  54:     0x7fff72bf1e65 - <unknown>

error: internal compiler error: unexpected panic

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.42.0-nightly (d1e594f40 2020-01-22) running on x86_64-apple-darwin

note: compiler flags: -C panic=abort -C debuginfo=2 -C incremental --crate-type bin

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [resolve_lifetimes] resolving lifetimes
#1 [generics_of] processing `default_config`
#2 [collect_mod_item_types] collecting item types in top-level module
#3 [analysis] running analysis passes on this crate
end of query stack

Is there additional debug information I can provide, since I can reproduce this consistently locally?

Thanks again!

E-needs-mcve I-ICE I-nominated T-compiler

Most helpful comment

Here's an mcve, it ended up being quite minimal and having nothing to do with macros: https://github.com/jbr/missing-const-lifetime-rust-compiler-error

All 4 comments

Please provide the full source code needed to reproduce this, otherwise it's unlikely that there's much we can do about this. Is the code inside a macro? If so then this is likely to be a duplicate of the other DistinctSources ICEs.

The struct does have #[derive(Default, Debug, Serialize, Deserialize)] on it (from serde 1.0.104, features=["derive"]), but it seems like there's some sort of interaction with something else, since I can't reproduce it in a standalone example. I'll try commenting things out of the main app and see if I can get to a mcve that still fails.

Here's an mcve, it ended up being quite minimal and having nothing to do with macros: https://github.com/jbr/missing-const-lifetime-rust-compiler-error

Fixed in beta and nightly.

Was this page helpful?
0 / 5 - 0 ratings