slint-ui/slint · error

Rust code generation failed

Error message

Rust code generation failed

What it means

The `compile_to_rust` benchmark helper compiles a parsed .slint syntax tree and generates Rust code via `i_slint_compiler::generator::rust::generate`. Code generation is expected to succeed for valid benchmarks; if it returns `None`, generation failed and the benchmark panics.

Solutions

  1. Run the snippet through the slint compiler (slint-viewer or a test) and print `diag` to find the actual generation failure
  2. Simplify or update the benchmark fixture to use fully supported language features
  3. Rebuild after `cargo build` to rule out a stale mixed compiler build; update to latest compiler if the feature is newly unsupported

Example fix

// before
let rust_code = generate(&doc, &config).expect("Rust code generation failed");
// after
let rust_code = generate(&doc, &config)
    .unwrap_or_else(|| panic!("codegen failed: {:#?}", diagnostics)); // surface real diagnostics
Defensive patterns

Strategy: validation

Validate before calling

// validate the fixture compiles before benchmarking
let mut diags = Default::default();
let (doc, diag, loader) = spin_on::spin_on(compile_syntax_node(node, &mut diags, config));
assert!(diag.is_empty(), "fixture has errors: {:#?}", diag);

Try / catch

generate(&doc, &config).unwrap_or_else(|| {
    panic!("Rust codegen failed for benchmark fixture: {:#?}", diag)
})

Prevention

When it happens

Trigger: Benchmarking a .slint snippet that fails Rust code generation: unsupported language features in the benchmark source, type errors not caught by the earlier diagnostics check, or an internal compiler limitation triggered by the fixture.

Common situations: Editing benchmark fixtures with new syntax the generator does not support; running benches on a compiler in a partially-broken state; fixture drift after compiler changes.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


AI-assisted analysis of slint-ui/slint@bb937076de (2026-09-16). Data as JSON: /api/errors/59355c422d31c421. Report an issue: GitHub.

Appendix: source

Thrown at internal/compiler/benches/semantic_analysis.rs:370

/// Benchmark simulating the proc-macro pipeline (compile + Rust code generation).
///
/// This module measures the full cost of processing a slint! macro invocation,
/// providing a baseline for tracking down slow proc-macro expansion in rust-analyzer.
mod proc_macro_simulation {
    use super::*;

    /// Compile and generate Rust code (simulates what the slint! proc-macro does)
    fn compile_to_rust(source: &str) -> (proc_macro2::TokenStream, BuildDiagnostics) {
        let diagnostics = BuildDiagnostics::default();
        let node = parse_source(source);

        let config = CompilerConfiguration::new(i_slint_compiler::generator::OutputFormat::Rust);

        let (doc, diag, loader) =
            spin_on::spin_on(i_slint_compiler::compile_syntax_node(node, diagnostics, config));

        let rust_code = i_slint_compiler::generator::rust::generate(&doc, &loader.compiler_config)
            .expect("Rust code generation failed");

        (rust_code, diag)
    }

    /// Baseline benchmark: empty component through full proc-macro pipeline.
    /// This measures the minimum overhead of proc-macro expansion.
    #[divan::bench]
    fn empty_component() {
        divan::black_box(compile_to_rust(EMPTY_COMPONENT));
    }
}

/// Detailed phase benchmarks to identify hotspots in compilation.
mod phase_breakdown {
    use super::*;
    use std::cell::RefCell;
    use std::rc::Rc;

View on GitHub (pinned to bb937076de)