iced-rs/iced · error
Editor cannot have multiple strong references
Error message
Editor cannot have multiple strong references
What it means
Editor::highlight needs exclusive mutable access: it Arc::try_unwraps the internal Arc<Internal> (editor.rs:842, same pattern as with_internal_mut at editor.rs:67). If any other strong reference exists, try_unwrap returns Err and expect("Editor cannot have multiple strong references") panics. Editor is cheap to clone precisely because it wraps an Arc, and every surviving clone blocks highlighting and mutation.
Solutions
- Keep exactly one strong owner: never clone() the Editor; move or borrow it instead
- For read-only sharing use editor.downgrade() (a Weak reference), which does not block Arc::try_unwrap
- Drop cached/cloned editors before driving update/highlight
- Give each widget its own editor state instead of sharing one instance
Example fix
// before let editor_copy = editor.clone(); // kept in a cache editor.highlight(font, &mut hl, fmt); // panics: clone still alive // after - share read access via Weak debug_snapshot(editor); // reads bounds only let weak = editor.downgrade(); // Weak does not block try_unwrap drop(editor_copy); // if a clone existed, release it first editor.highlight(font, &mut hl, fmt);
Defensive patterns
Strategy: validation
Validate before calling
// keep exactly one strong reference alive when mutating/highlighting // drop any cached clones before the update/highlight cycle drop(cached_editors.values()); // if you keep a map of clones, clear it first editor.update(bounds, font, size, line_height, wrapping, alignment, hint, &mut highlighter);
Prevention
- Never clone() an Editor you intend to mutate or highlight; move or borrow it
- Use editor.downgrade() (Weak) for read-only sharing; Weak does not block Arc::try_unwrap
- Give each widget its own editor state instead of sharing one instance
- Audit caches that outlive the widget tree for stashed editor clones
When it happens
Trigger: Cloning the Editor (or the widget/tree holding it) and keeping the twin alive while the original is mutated/highlighted; caching editors in a map while also using them in the tree; two widgets sharing one editor instance.
Common situations: Stashing a copy of the editor for background measurement or persistence; splitting view/state ownership by cloning; reusing one editor across multiple text_editor-like widgets.
Related errors
- Editor should always be initialized
- Line layout should be cached
- Write font system
- Caches must not be empty
- Create color
AI-assisted analysis of iced-rs/iced@3de451447b (2026-08-17).
Data as JSON: /api/errors/c733a0d879f62f42.
Report an issue: GitHub.
Appendix: source
Thrown at graphics/src/text/editor.rs:842
if window > visible_lines {
window -= visible_lines;
None
} else {
Some(scroll.line + i)
}
})
.unwrap_or(buffer.lines.len().saturating_sub(1));
let current_line = highlighter.current_line();
if current_line > last_visible_line {
return;
}
let editor = self.0.take().expect("Editor should always be initialized");
let mut internal =
Arc::try_unwrap(editor).expect("Editor cannot have multiple strong references");
let mut font_system = text::font_system().write().expect("Write font system");
let attributes = text::to_attributes(font);
for line in &mut buffer_mut_from_editor(&mut internal.editor).lines
[current_line..=last_visible_line]
{
let mut list = cosmic_text::AttrsList::new(&attributes);
for (range, highlight) in highlighter.highlight_line(line.text()) {
let format = format_highlight(&highlight);
if format.color.is_some() || format.font.is_some() {
list.add_span(
range,
&cosmic_text::Attrs {
color_opt: format.color.map(text::to_color),View on GitHub (pinned to 3de451447b)