mirror of
https://github.com/allankoechke/rust.git
synced 2026-11-30 17:26:12 +00:00
Fix post-monomorphization error note race in the parallel frontend Fixes rust-lang/rust#154260. Part of https://github.com/rust-lang/rust/issues/154314. `collect_items_rec` decides whether to attach the note "the above error was encountered while instantiating `fn ...`" by snapshotting the error count before processing a mono item and comparing it afterwards. The mono item graph is walked in parallel (the `par_for_each_in` in `collect_crate_mono_items`), so the global error count can be bumped by an error emitted while collecting a different item on another thread between the two reads. That makes an unrelated item get blamed, which showed up as a spurious note when using parallel frontend: ``` note: the above error was encountered while instantiating `fn std::rt::lang_start::<()>` ``` This PR records the thread that emits each error alongside its `ErrorGuaranteed` in `err_guars`, `lint_err_guars`, and the stashed-diagnostics map, and add `err_count_on_current_thread`, which counts only the errors whose recorded thread is the calling thread. The collector uses it for the snapshot and comparison, so the delta is not affected by errors emitted on other threads. In serial compilation it is equivalent to a delta of `err_count`.