Compiler OOM when building in debug mode due to too many generics (with `type_alias_impl_trait`)
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.2k
- PR merge metrics
- PR metrics pending
Description
I recently updated a project of mine to avoid using dynamic dispatch in place of the static type for parser combinators, which ended up creating very, very long types (think hundreds of types nested together through generics).
The code itself is clean as I'm using type Alias = impl Trait and then static ...: Alias to reduce boilerplate, but the compiler does have to deal with very complex types.
The weird thing is, building in release mode works fine, and it completes pretty fast. Building in debug mode though is very long, consumes most of the available CPU, and ends up crashing after a few minutes.
The code can be found here. I tried building this crate outside of the workspace, and still got the same issue.
The project is pretty big (20k LoC) but the part that's relevant to the crash itself are located in this file.
I define a macro to generate statics with opaque impl types in order to not have to write these long types manually, and it seems to be the source of the crash.
For what it's worth, I'm building on a laptop with a decent processor, but with 16 GB RAM only. The RAM consumption from rustc varies wildly during the compilation, peaking at roughly 8 GB during the crash. Note that the RAM usage decreases and increases by several gigabytes at once, multiple times during the build.
Here are the logs from the compiler (running with RUST_BACKTRACE=1 did not produce any additional output):
(EDIT: see my update in the second comment for more infos after a successful build)
> cargo build
Compiling reshell-parser v0.1.0 (/home/clement/Projets/ReShell/crates/parser)
Compiling reshell-prettify v0.1.0 (/home/clement/Projets/ReShell/crates/prettify)
Compiling reshell-checker v0.1.0 (/home/clement/Projets/ReShell/crates/checker)
Compiling reshell-runtime v0.1.0 (/home/clement/Projets/ReShell/crates/runtime)
Compiling reshell-builtins v0.1.0 (/home/clement/Projets/ReShell/crates/builtins)
Compiling reshell-reports v0.1.0 (/home/clement/Projets/ReShell/crates/reports)
Compiling reshell-tests v0.0.0 (/home/clement/Projets/ReShell/crates/tests)
Compiling reshell-repl v0.1.0 (/home/clement/Projets/ReShell/crates/repl)
error: linking with `cc` failed: exit status: 1
|
= note: "cc" "-m64" "/home/clement/Projets/ReShell/target/debug/deps/rustceLP6tD/symbols.o" "<208 object files omitted>" "-Wl,--as-needed" "-Wl,-Bstatic" "/home/clement/Projets/ReShell/target/debug/deps/{libctrlc-c27023153c2e99b2,libnix-203fe451d82ed5cc,libdirs-75cf62dc641f7e28,libdirs_sys-1fbdcd182e449b2e,liboption_ext-a93c7cec780bc445,libreshell_syntax_highlighter-41dd858c8628d02b,libreshell_reports-9797096bf9f29c35,libannotate_snippets-3fb0067f50b1a161,libreedline-79c7e45de7a9a17e,libfd_lock-bba6c58b18c174e7,libstrip_ansi_escapes-fb93f92e8589710e,libvte-389aac9a1c7cd209,libstrum-b2d02edf2c4f2c9c,libunicase-8dd453ac80dfce3c,libchrono-9adf7cdd96385b61,libiana_time_zone-3ef1c2b2405156a9,libnum_traits-691f21aeab2a5193,libthiserror-eb91285c11e2750d,libunicode_width-a6375d3a2a26d1e5,libnu_ansi_term-fc893516ffb4beec,libcrossterm-fb91136a0705b524,libserde-763520412a812d2f,libparking_lot-254408b28a551bba,libparking_lot_core-f8e17da6ca8938b6,libsmallvec-83ffde712cc68410,liblock_api-9fd6913848ac39ce,libscopeguard-cfa69166bd4da734,libderive_more-27e9ae01a9728a9d,libsignal_hook_mio-5b1b63554b43727f,libsignal_hook-74645b2224b97401,libsignal_hook_registry-33f854ccc23e2200,libmio-2f22a67a47acfe8e,liblog-853433100b10785a,libunicode_segmentation-745c28ea3c19c6e9,libitertools-87da27f1d32eefe8,libreshell_builtins-4c11031beb300420,libdunce-dad757477a90192f,libtoml-2fdff3c1c0d88dce,libtoml_writer-7634cff7f7590d01,libtoml_parser-f51a97da0c1bc661,libwinnow-5a2f8bf7ed2cf838,libserde_spanned-aa488c3bd9c7f45a,libtoml_datetime-26b0b48f4a309bf3,librand-aadc7368e7618e0a,librand_chacha-bb44eda3a418a74d,libppv_lite86-f6aa0eb9b258f6ba,libzerocopy-baefa1f06abfd856,librand_core-1c0524bd52ecdfb3,libgetrandom-b653c4d05ae17b92,liblibc-869e22160f092ec5,libcfg_if-2262c59ed30cbfdf,libserde_json-71400ecc9e605a3d,libitoa-a586594d020aa48a,libzmij-c4f25045a497d348,libpomsky-06cdee15cf845799,libpomsky_syntax-79fddb70d6e32348,libglobby-e8e5786b079cf5d1,libparsy-6c5e79fc080801e6,libterminal_size-ee67100613cb74e3,librustix-aaa523b0bf2236f2,libbitflags-9b8f46c35869f106,libserde_core-b6276f2b9b173a57,liblinux_raw_sys-12d95df1e9fb328b,librayon-9edd9c9039b90399,librayon_core-0645cddf271abca5,libcrossbeam_deque-45c1181e7f67f75a,libcrossbeam_epoch-9699aac84ac5e5aa,libcrossbeam_utils-1ab00d54e6c79ffa,libeither-9a78d543324cf6ff,libreshell_runtime-0634ba5291a7141e,libregex-043d9c650d27547a,libregex_automata-d19cfc4f2260468d,libaho_corasick-25a35edbb23f5ce8,libmemchr-5860c3e5f17fe065,libregex_syntax-bc020d83057bca35,libjiff-29ee7088ef71c1eb,libreshell_checker-65534167096d9325,libreshell_prettify-0dc6c11bb54a4751,libreshell_parser-a946cfce3e52d74b,libindexmap-8d9678b95f34933b,libequivalent-3ff77df1ac69f53a,libhashbrown-b0e8b026c933dc04,libparsy-611749d21f42453f,libcolored-5b26b8bcd167138a,libclap-c18886c96631dc76,libclap_builder-237446ae40b03f21,libstrsim-5cdf9c8c121387d0,libanstream-ac99c5c12d3c7aee,libanstyle_query-73fe42fb77c51cb0,libis_terminal_polyfill-2a2616ab4e156c2c,libcolorchoice-e4a0c70eb199cf46,libanstyle_parse-926948edb075e3f4,libutf8parse-97e8d7c35760ee10,libclap_lex-ac15a2c28e689723,libanstyle-abcb25e3dde70769}.rlib" "<sysroot>/lib/rustlib/x86_64-unknown-linux-gnu/lib/{libstd-*,libpanic_unwind-*,libobject-*,libmemchr-*,libaddr2line-*,libgimli-*,libcfg_if-*,librustc_demangle-*,libstd_detect-*,libhashbrown-*,librustc_std_workspace_alloc-*,libminiz_oxide-*,libadler2-*,libunwind-*,liblibc-*,librustc_std_workspace_core-*,liballoc-*,libcore-*,libcompiler_builtins-*}.rlib" "-Wl,-Bdynamic" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-L" "/home/clement/Projets/ReShell/target/debug/deps/rustceLP6tD/raw-dylibs" "-B<sysroot>/lib/rustlib/x86_64-unknown-linux-gnu/bin/gcc-ld" "-fuse-ld=lld" "-Wl,--eh-frame-hdr" "-Wl,-z,noexecstack" "-L" "<sysroot>/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-o" "/home/clement/Projets/ReShell/target/debug/deps/reshell-115fd9f5b2bebebe" "-Wl,--gc-sections" "-pie" "-Wl,-z,relro,-z,now" "-nodefaultlibs"
= note: some arguments are omitted. use `--verbose` to show all linker arguments
= note: rust-lld: error: /home/clement/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-c648d4fae29b59eb.rlib(panic_unwind-c648d4fae29b59eb.panic_unwind.5e086d299a53f1ae-cgu.0.rcgu.o):(.debug_info+0x30): relocation R_X86_64_32 out of range: 7310088817 is not in [0, 4294967295]
>>> referenced by panic_unwind.5e086d299a53f1ae-cgu.0; consider recompiling with -fdebug-types-section to reduce size of debug sections
rust-lld: error: /home/clement/Projets/ReShell/target/debug/deps/libreshell_checker-65534167096d9325.rlib(reshell_checker-65534167096d9325.4473v52coquftormiushla5rc.1u3j2hm.rcgu.o):(.debug_info+0x1a): relocation R_X86_64_32 out of range: 6793932848 is not in [0, 4294967295]
>>> referenced by 4473v52coquftormiushla5rc; consider recompiling with -fdebug-types-section to reduce size of debug sections
rust-lld: error: /home/clement/Projets/ReShell/target/debug/deps/libreshell_parser-a946cfce3e52d74b.rlib(reshell_parser-a946cfce3e52d74b.93p902ub14tru05yp2epmkhyw.1l9n5kc.rcgu.o):(.debug_info+0x12): relocation R_X86_64_32 out of range: 5993113467 is not in [0, 4294967295]
>>> referenced by 93p902ub14tru05yp2epmkhyw; consider recompiling with -fdebug-types-section to reduce size of debug sections
rust-lld: error: /home/clement/Projets/ReShell/target/debug/deps/libsignal_hook_registry-33f854ccc23e2200.rlib(signal_hook_registry-33f854ccc23e2200.signal_hook_registry.77623f62d3d4b9e5-cgu.1.rcgu.o):(.debug_info+0x12): relocation R_X86_64_32 out of range: 6435518391 is not in [0, 4294967295]
>>> referenced by signal_hook_registry.77623f62d3d4b9e5-cgu.1; consider recompiling with -fdebug-types-section to reduce size of debug sections
rust-lld: error: /home/clement/Projets/ReShell/target/debug/deps/libreshell_runtime-0634ba5291a7141e.rlib(reshell_runtime-0634ba5291a7141e.891vfnipp4te54175h9feclx2.1t7yscu.rcgu.o):(.debug_info+0x1a): relocation R_X86_64_32 out of range: 6793932848 is not in [0, 4294967295]
>>> referenced by 891vfnipp4te54175h9feclx2; consider recompiling with -fdebug-types-section to reduce size of debug sections
rust-lld: error: /home/clement/Projets/ReShell/target/debug/deps/libpomsky_syntax-79fddb70d6e32348.rlib(pomsky_syntax-79fddb70d6e32348.pomsky_syntax.fb2f9bb5b127e39c-cgu.06.rcgu.o):(.debug_info+0x2b): relocation R_X86_64_32 out of range: 6435726163 is not in [0, 4294967295]
>>> referenced by pomsky_syntax.fb2f9bb5b127e39c-cgu.06; consider recompiling with -fdebug-types-section to reduce size of debug sections
rust-lld: error: /home/clement/Projets/ReShell/target/debug/deps/libaho_corasick-25a35edbb23f5ce8.rlib(aho_corasick-25a35edbb23f5ce8.aho_corasick.d4d3945652830f4e-cgu.00.rcgu.o):(.debug_info+0x12): relocation R_X86_64_32 out of range: 4857836986 is not in [0, 4294967295]
>>> referenced by aho_corasick.d4d3945652830f4e-cgu.00; consider recompiling with -fdebug-types-section to reduce size of debug sections
rust-lld: error: /home/clement/Projets/ReShell/target/debug/deps/libreshell_runtime-0634ba5291a7141e.rlib(reshell_runtime-0634ba5291a7141e.891vfnipp4te54175h9feclx2.1t7yscu.rcgu.o):(.debug_info+0x2b): relocation R_X86_64_32 out of range: 8604517144 is not in [0, 4294967295]
>>> referenced by 891vfnipp4te54175h9feclx2; consider recompiling with -fdebug-types-section to reduce size of debug sections
rust-lld: error: /home/clement/Projets/ReShell/target/debug/deps/libreshell_checker-65534167096d9325.rlib(reshell_checker-65534167096d9325.4473v52coquftormiushla5rc.1u3j2hm.rcgu.o):(.debug_info+0x30): relocation R_X86_64_32 out of range: 7310088817 is not in [0, 4294967295]
>>> referenced by 4473v52coquftormiushla5rc; consider recompiling with -fdebug-types-section to reduce size of debug sections
rust-lld: error: /home/clement/Projets/ReShell/target/debug/deps/libpomsky_syntax-79fddb70d6e32348.rlib(pomsky_syntax-79fddb70d6e32348.pomsky_syntax.fb2f9bb5b127e39c-cgu.06.rcgu.o):(.debug_info+0x35): relocation R_X86_64_32 out of range: 5541156237 is not in [0, 4294967295]
>>> referenced by pomsky_syntax.fb2f9bb5b127e39c-cgu.06; consider recompiling with -fdebug-types-section to reduce size of debug sections
rust-lld: error: /home/clement/Projets/ReShell/target/debug/deps/libreshell_parser-a946cfce3e52d74b.rlib(reshell_parser-a946cfce3e52d74b.93p902ub14tru05yp2epmkhyw.1l9n5kc.rcgu.o):(.debug_info+0x1a): relocation R_X86_64_32 out of range: 6793932848 is not in [0, 4294967295]
>>> referenced by 93p902ub14tru05yp2epmkhyw; consider recompiling with -fdebug-types-section to reduce size of debug sections
rust-lld: error: /home/clement/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-c648d4fae29b59eb.rlib(panic_unwind-c648d4fae29b59eb.panic_unwind.5e086d299a53f1ae-cgu.0.rcgu.o):(.debug_info+0x35): relocation R_X86_64_32 out of range: 4856969501 is not in [0, 4294967295]
>>> referenced by panic_unwind.5e086d299a53f1ae-cgu.0; consider recompiling with -fdebug-types-section to reduce size of debug sections
rust-lld: error: /home/clement/Projets/ReShell/target/debug/deps/libaho_corasick-25a35edbb23f5ce8.rlib(aho_corasick-25a35edbb23f5ce8.aho_corasick.d4d3945652830f4e-cgu.00.rcgu.o):(.debug_info+0x1a): relocation R_X86_64_32 out of range: 9217883706 is not in [0, 4294967295]
>>> referenced by aho_corasick.d4d3945652830f4e-cgu.00; consider recompiling with -fdebug-types-section to reduce size of debug sections
rust-lld: error: /home/clement/Projets/ReShell/target/debug/deps/libreshell_runtime-0634ba5291a7141e.rlib(reshell_runtime-0634ba5291a7141e.891vfnipp4te54175h9feclx2.1t7yscu.rcgu.o):(.debug_info+0x30): relocation R_X86_64_32 out of range: 8604517159 is not in [0, 4294967295]
>>> referenced by 891vfnipp4te54175h9feclx2; consider recompiling with -fdebug-types-section to reduce size of debug sections
rust-lld: error: /home/clement/Projets/ReShell/target/debug/deps/libsignal_hook_registry-33f854ccc23e2200.rlib(signal_hook_registry-33f854ccc23e2200.signal_hook_registry.77623f62d3d4b9e5-cgu.1.rcgu.o):(.debug_info+0x1a): relocation R_X86_64_32 out of range: 8825840504 is not in [0, 4294967295]
>>> referenced by signal_hook_registry.77623f62d3d4b9e5-cgu.1; consider recompiling with -fdebug-types-section to reduce size of debug sections
rust-lld: error: /home/clement/Projets/ReShell/target/debug/deps/libreshell_parser-a946cfce3e52d74b.rlib(reshell_parser-a946cfce3e52d74b.93p902ub14tru05yp2epmkhyw.1l9n5kc.rcgu.o):(.debug_info+0x3a): relocation R_X86_64_32 out of range: 7310103864 is not in [0, 4294967295]
>>> referenced by 93p902ub14tru05yp2epmkhyw; consider recompiling with -fdebug-types-section to reduce size of debug sections
rust-lld: error: /home/clement/Projets/ReShell/target/debug/deps/libsignal_hook_registry-33f854ccc23e2200.rlib(signal_hook_registry-33f854ccc23e2200.signal_hook_registry.77623f62d3d4b9e5-cgu.1.rcgu.o):(.debug_info+0x2b): relocation R_X86_64_32 out of range: 7080975366 is not in [0, 4294967295]
>>> referenced by signal_hook_registry.77623f62d3d4b9e5-cgu.1; consider recompiling with -fdebug-types-section to reduce size of debug sections
rust-lld: error: /home/clement/Projets/ReShell/target/debug/deps/libaho_corasick-25a35edbb23f5ce8.rlib(aho_corasick-25a35edbb23f5ce8.aho_corasick.d4d3945652830f4e-cgu.00.rcgu.o):(.debug_info+0x30): relocation R_X86_64_32 out of range: 7310088817 is not in [0, 4294967295]
>>> referenced by aho_corasick.d4d3945652830f4e-cgu.00; consider recompiling with -fdebug-types-section to reduce size of debug sections
rust-lld: error: /home/clement/Projets/ReShell/target/debug/deps/libsignal_hook_registry-33f854ccc23e2200.rlib(signal_hook_registry-33f854ccc23e2200.signal_hook_registry.77623f62d3d4b9e5-cgu.1.rcgu.o):(.debug_info+0x42): relocation R_X86_64_32 out of range: 7310334172 is not in [0, 4294967295]
>>> referenced by signal_hook_registry.77623f62d3d4b9e5-cgu.1; consider recompiling with -fdebug-types-section to reduce size of debug sections
rust-lld: error: /home/clement/Projets/ReShell/target/debug/deps/libpomsky_syntax-79fddb70d6e32348.rlib(pomsky_syntax-79fddb70d6e32348.pomsky_syntax.fb2f9bb5b127e39c-cgu.06.rcgu.o):(.debug_info+0x4b): relocation R_X86_64_32 out of range: 5541805389 is not in [0, 4294967295]
>>> referenced by pomsky_syntax.fb2f9bb5b127e39c-cgu.06; consider recompiling with -fdebug-types-section to reduce size of debug sections
rust-lld: error: too many errors emitted, stopping now (use --error-limit=0 to see all errors)
collect2: error: ld returned 1 exit status
error: could not compile `reshell-repl` (bin "reshell") due to 1 previous error
Meta
rustc --version --verbose:
rustc 1.94.0-nightly (86a49fd71 2026-01-14)
binary: rustc
commit-hash: 86a49fd71fecd25b0fd20247db0ba95eeceaba28
commit-date: 2026-01-14
host: x86_64-unknown-linux-gnu
release: 1.94.0-nightly
LLVM version: 21.1.8
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the failure with cargo build on the linked ReShell revision, comparing debug and release builds. Start with crates/parser/src/parsers/mod.rs, especially the macro generating static opaque types, and inspect the reported linker and memory behavior. Done means the cause of the debug-build failure is identified and the affected build no longer exhausts resources.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100