slint-ui/slint · error

field is not a string

Error message

{} field is not a string

What it means

check_and_fix_package_string_field throws this when the [package] field exists in Cargo.toml but its parsed value is not a TOML string (e.g. an inline table, array, or other type). The check only knows how to compare/fix string fields.

Solutions

  1. Edit the Cargo.toml so the field is a plain string, e.g. `license = "MIT OR Apache-2.0"` instead of `license = { file = "..." }`
  2. Re-run `cargo xtask check` to confirm the field passes
  3. Use `cargo metadata`/`cargo package --list` to spot malformed package fields

Example fix

// before
license = { file = "LICENSE" }
// after
license = "MIT OR Apache-2.0"
Defensive patterns

Strategy: validation

Validate before calling

let t: toml::Value = toml::from_str(&std::fs::read_to_string("Cargo.toml")?)?;
if !t["package"]["license"].is_str() {
    panic!("license must be a plain SPDX string");
}

Type guard

fn package_field_is_str(doc: &toml::Value, field: &str) -> bool {
    doc["package"][field].is_str()
}

Prevention

When it happens

Trigger: A Cargo.toml [package] field that should be a string is written as another TOML type, e.g. `license = { file = "LICENSE" }` or `homepage = true` — then `item.as_str()` returns None and the None branch errors.

Common situations: Copy-pasting metadata syntax (license as table instead of SPDX string); a TOML merge or automated edit replaced the string with a table; typos such as `repository = ["url"]`.

Related errors


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

Appendix: source

Thrown at xtask/src/license_headers_check.rs:901

                            if text != expected_str {
                                if fix_it {
                                    eprintln!(
                                        "Fixing up {:?} as instructed. It has unexpected data in {field}.",
                                        self.path
                                    );
                                    self.doc["package"][field] = toml_edit::value(expected_str);
                                    self.edited = true;
                                } else {
                                    return Err(anyhow!(
                                        "Incorrect {}. Found {} expected {}",
                                        field,
                                        text,
                                        expected_str
                                    ));
                                }
                            }
                        }
                        None => return Err(anyhow!("{} field is not a string", field)),
                    },
                };
            }
            None => {
                if fix_it {
                    eprintln!("Fixing up {:?} as instructed. It has no {field}.", self.path);
                    self.doc["package"][field] = toml_edit::value(expected_str);
                    self.edited = true;
                } else {
                    return Err(anyhow!("Missing {} field", field));
                }
            }
        };
        Ok(())
    }

    fn published(&self) -> Result<bool> {
        Ok(self.package()?.get("publish").map(|v| v.as_bool().unwrap()).unwrap_or(true))

View on GitHub (pinned to 3a7e700487)