Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

auto-generated rust code fails to compile #6616

Open
CrepeGoat opened this issue Oct 22, 2024 · 0 comments
Open

auto-generated rust code fails to compile #6616

CrepeGoat opened this issue Oct 22, 2024 · 0 comments
Labels
a:language-rust Rust API and codegen (mO,mS) bug Something isn't working

Comments

@CrepeGoat
Copy link

CrepeGoat commented Oct 22, 2024

system

  • macbook air M1 2020
  • macOS 14.5 Sonoma
  • cargo --version -> cargo 1.81.0 (2dbb1af80 2024-08-20)
  • rustup --version -> rustc 1.81.0 (eeb90cda1 2024-09-04)
  • slint = "1.8.0"

code

build.rs

fn main() {
    slint_build::compile("ui/app-window.slint").expect("Slint build failed");
}

src/main.rs

// Prevent console window in addition to Slint window in Windows release builds when, e.g., starting the app via file manager. Ignored on other platforms.
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]

slint::include_modules!();

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let ui = AppWindow::new()?;

    ui.run()?;

    Ok(())
}

ui/app-window.slint

import {  HorizontalBox } from "std-widgets.slint";

component DeltasList {
    in property <string> delta;
}

component Changelog inherits Rectangle {
    in-out property <int> count-files-changed;
    in-out property <[string]> changes_log: [];
    in-out property <int> selected: -2;
    callback selection-changed(/*new selection*/ int);
}

export component AppWindow inherits Window {
    in-out property <[string]> changes_log <=> log.changes_log;
    in-out property <int> count-files-changed <=> log.count-files-changed;
    in-out property <string> delta <=> deltas.delta;
    callback request-change-delta(string);
    callback request-diff-delta(string);

    function fill-diff-view() {
        if log.selected >= 0 && log.selected < changes_log.length {
            root.request-change-delta(changes_log[log.selected])
        } else if log.selected == -1 {
            root.request-diff-delta("channel name")
        } else {
            delta = "";
        }
    }

    HorizontalBox {
        log := Changelog {
            horizontal-stretch: 2;
            selection-changed => {
                fill-diff-view();
            }
        }

        deltas := DeltasList {
            horizontal-stretch: 3;
        }
    }
}

problem

running cargo build generates the error:

error[E0425]: cannot find value `tmp_root_1_changes_log` in this scope
   --> /.../target/debug/build/project-3091f44e836850bc/out/app-window.rs:711:66
    |
711 | ... (match & r#tmp_root_1_changes_log . clone () {
    |              ^^^^^^^^^^^^^^^^^^^^^^^^ not found in this scope

error[E0425]: cannot find value `tmp_log_3_selected` in this scope
   --> /.../target/debug/build/project-3091f44e836850bc/out/app-window.rs:713:47
    |
713 | ...   let index = (r#tmp_log_3_selected . clone ()) as usize ;
    |                    ^^^^^^^^^^^^^^^^^^^^ not found in this scope

For more information about this error, try `rustc --explain E0425`.
error: could not compile `project` (bin "project") due to 2 previous errors

this error seems to take place in the generated rust code.

working alternatives

  • replace
    root.request-change-delta(changes_log[log.selected])
    with
    root.request-change-delta("")
  • replace
    if log.selected >= 0 && log.selected < changes_log.length {
        root.request-change-delta(changes_log[log.selected])
    } else if log.selected == -1 {
        root.request-diff-delta("channel name")
    } else {
        delta = "";
    }
    with
    if log.selected >= 0 && log.selected < changes_log.length {
        root.request-change-delta(changes_log[log.selected])
    } else {
        root.request-diff-delta("channel name")
    }

expected behavior

either:

  • compile, or
  • emit a slint-contexted error referencing the slint user code, instead of a rust-contexted error referencing the auto-generated rust code
@ogoffart ogoffart added need triaging Issue that the owner of the area still need to triage bug Something isn't working a:language-rust Rust API and codegen (mO,mS) and removed need triaging Issue that the owner of the area still need to triage labels Oct 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:language-rust Rust API and codegen (mO,mS) bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants