Skip to content

Commit 98f59bc

Browse files
authored
Rollup merge of #76515 - jumbatm:issue76496-reproducibility-regression, r=oli-obk
SessionDiagnostic: Fix non-determinism in generated format string. Fixes #76496. r? @oli-obk
2 parents c18fa46 + 8b39250 commit 98f59bc

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

compiler/rustc_macros/src/session_diagnostic.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
#![deny(unused_must_use)]
2-
use quote::format_ident;
3-
use quote::quote;
4-
52
use proc_macro::Diagnostic;
3+
use quote::{format_ident, quote};
64
use syn::spanned::Spanned;
75

8-
use std::collections::{HashMap, HashSet};
6+
use std::collections::{BTreeSet, HashMap};
97

108
/// Implements #[derive(SessionDiagnostic)], which allows for errors to be specified as a struct, independent
119
/// from the actual diagnostics emitting code.
@@ -577,7 +575,10 @@ impl<'a> SessionDiagnosticDeriveBuilder<'a> {
577575
/// ```
578576
/// This function builds the entire call to format!.
579577
fn build_format(&self, input: &String, span: proc_macro2::Span) -> proc_macro2::TokenStream {
580-
let mut referenced_fields: HashSet<String> = HashSet::new();
578+
// This set is used later to generate the final format string. To keep builds reproducible,
579+
// the iteration order needs to be deterministic, hence why we use a BTreeSet here instead
580+
// of a HashSet.
581+
let mut referenced_fields: BTreeSet<String> = BTreeSet::new();
581582

582583
// At this point, we can start parsing the format string.
583584
let mut it = input.chars().peekable();

0 commit comments

Comments
 (0)