Skip to content

Make adding an existing MultiProgress member a no-op - #854

Merged
chris-laplante merged 1 commit into
console-rs:mainfrom
NgoQuocViet2001:fix-multi-double-add
Nov 5, 2026
Merged

chris-laplante merged 1 commit into
console-rs:mainfrom
NgoQuocViet2001:fix-multi-double-add

Conversation

@NgoQuocViet2001

Copy link
Copy Markdown
Contributor

The docs on MultiProgress::add and the insert* methods say that adding a bar that is already a member has no effect (#503), but internalize() always allocates a new slot, so the bar moves and its old slot is never freed. If that slot is first in the ordering, finished bars are never pruned and a dropped bar keeps being redrawn (two spinners with a {msg} template):

let pb1 = mp.add(spinner("pb1").with_finish(ProgressFinish::AndLeave));
let pb1 = mp.add(pb1); // documented as having no effect
let pb2 = mp.add(spinner("pb2"));
pb1.tick(); pb2.tick();
pb1.finish_with_message("done"); drop(pb1);
mp.clear().unwrap(); pb2.tick();
// screen before: "done\npb2", after: "pb2"

This returns early from internalize() when the bar already belongs to this MultiProgress, using the same Arc::ptr_eq check as remove(). So insert(0, pb) on an existing member no longer moves it, which matches the docs.

The new mp_double_add_is_noop test fails on main (5 members instead of 2). Tests pass with all, default and no default features; fmt, clippy and doc are clean.

@djc djc left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me -- @chris-laplante thoughts?

@chris-laplante

Copy link
Copy Markdown
Collaborator

Makes sense to me -- @chris-laplante thoughts?

Yes, agreed! Sorry for the delay, I was on vacation.

@chris-laplante
chris-laplante merged commit bd7a6b6 into console-rs:main Nov 5, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants