Skip to content

Commit 836059d

Browse files
committed
feat: Fixing parallel targets in the same pass
1 parent c7b0e1c commit 836059d

File tree

1 file changed

+27
-21
lines changed

1 file changed

+27
-21
lines changed

src/ops/fixit.rs

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ fn exec(args: FixitArgs) -> CargoResult<()> {
6969
let mut iteration = 0;
7070

7171
let mut last_errors = IndexMap::new();
72-
let mut current_target: Option<BuildUnit> = None;
72+
let mut current_target: IndexSet<BuildUnit> = IndexSet::new();
7373
let mut seen = HashSet::new();
7474

7575
loop {
@@ -80,7 +80,7 @@ fn exec(args: FixitArgs) -> CargoResult<()> {
8080
if !args.broken_code && exit_code != Some(0) {
8181
let mut out = String::new();
8282

83-
if current_target.is_some() {
83+
if !current_target.is_empty() {
8484
out.push_str(
8585
"failed to automatically apply fixes suggested by rustc\n\n\
8686
after fixes were automatically applied the \
@@ -150,7 +150,10 @@ fn exec(args: FixitArgs) -> CargoResult<()> {
150150
let (mut errors, build_unit_map) = collect_errors(messages, &seen);
151151

152152
if iteration >= max_iterations {
153-
if let Some(target) = current_target {
153+
if current_target.is_empty() {
154+
break;
155+
}
156+
for target in &current_target {
154157
if seen.iter().all(|b| b.package_id != target.package_id) {
155158
shell::status("Checking", format_package_id(&target.package_id)?)?;
156159
}
@@ -160,9 +163,9 @@ fn exec(args: FixitArgs) -> CargoResult<()> {
160163
}
161164
files = IndexMap::new();
162165

163-
let mut errors = errors.shift_remove(&target).unwrap_or_else(IndexSet::new);
166+
let mut errors = errors.shift_remove(target).unwrap_or_else(IndexSet::new);
164167

165-
if let Some(e) = build_unit_map.get(&target) {
168+
if let Some(e) = build_unit_map.get(target) {
166169
for (_, e) in e.iter().flat_map(|(_, s)| s) {
167170
let Some(e) = e else {
168171
continue;
@@ -174,26 +177,26 @@ fn exec(args: FixitArgs) -> CargoResult<()> {
174177
shell::print_ansi_stderr(format!("{}\n\n", e.trim_end()).as_bytes())?;
175178
}
176179

177-
seen.insert(target);
178-
current_target = None;
179-
iteration = 0;
180-
} else {
181-
break;
180+
seen.insert(target.clone());
182181
}
182+
iteration = 0;
183+
current_target = IndexSet::new();
183184
}
184185

185-
let mut made_changes = false;
186+
let mut made_changes = HashSet::new();
186187

187188
for (build_unit, file_map) in build_unit_map {
188189
if seen.contains(&build_unit) {
189190
continue;
190191
}
191192

193+
let same = current_target.iter().any(|b| b == &build_unit);
194+
192195
let build_unit_errors = errors
193196
.entry(build_unit.clone())
194197
.or_insert_with(IndexSet::new);
195198

196-
if current_target.is_none() && file_map.is_empty() {
199+
if current_target.is_empty() && file_map.is_empty() {
197200
if seen.iter().all(|b| b.package_id != build_unit.package_id) {
198201
shell::status("Checking", format_package_id(&build_unit.package_id)?)?;
199202
}
@@ -204,11 +207,11 @@ fn exec(args: FixitArgs) -> CargoResult<()> {
204207

205208
seen.insert(build_unit);
206209
} else if !file_map.is_empty()
207-
&& current_target.get_or_insert(build_unit.clone()) == &build_unit
210+
&& (same || current_target.is_empty())
208211
&& fix_errors(&mut files, file_map, build_unit_errors)?
209212
{
210-
made_changes = true;
211-
break;
213+
current_target.insert(build_unit.clone());
214+
made_changes.insert(build_unit);
212215
}
213216
}
214217

@@ -218,8 +221,12 @@ fn exec(args: FixitArgs) -> CargoResult<()> {
218221
last_errors = errors;
219222
iteration += 1;
220223

221-
if !made_changes {
222-
if let Some(pkg) = current_target {
224+
if made_changes.is_empty() {
225+
if current_target.is_empty() {
226+
break;
227+
}
228+
229+
for pkg in current_target.clone() {
223230
if seen.iter().all(|b| b.package_id != pkg.package_id) {
224231
shell::status("Checking", format_package_id(&pkg.package_id)?)?;
225232
}
@@ -234,12 +241,11 @@ fn exec(args: FixitArgs) -> CargoResult<()> {
234241
shell::print_ansi_stderr(format!("{}\n\n", e.trim_end()).as_bytes())?;
235242
}
236243

244+
current_target.shift_remove(&pkg);
237245
seen.insert(pkg);
238-
current_target = None;
239-
iteration = 0;
240-
} else {
241-
break;
242246
}
247+
iteration = 0;
248+
current_target = IndexSet::new();
243249
}
244250
}
245251

0 commit comments

Comments
 (0)