diff options
| author | jumbatm <30644300+jumbatm@users.noreply.github.com> | 2020-09-09 21:23:25 +1000 |
|---|---|---|
| committer | jumbatm <30644300+jumbatm@users.noreply.github.com> | 2020-09-09 21:23:25 +1000 |
| commit | 8b392505ae8e5645f3f254caa8aff2a932df4d72 (patch) | |
| tree | beef447d11d3059770b3723c6499ddd6d06a00d3 /compiler/rustc_macros/src/session_diagnostic.rs | |
| parent | 3f5e617e3630ad61aa35637bbe0ab704eada5974 (diff) | |
| download | rust-8b392505ae8e5645f3f254caa8aff2a932df4d72.tar.gz rust-8b392505ae8e5645f3f254caa8aff2a932df4d72.zip | |
Fix non-determinism in generated format string.
Diffstat (limited to 'compiler/rustc_macros/src/session_diagnostic.rs')
| -rw-r--r-- | compiler/rustc_macros/src/session_diagnostic.rs | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/compiler/rustc_macros/src/session_diagnostic.rs b/compiler/rustc_macros/src/session_diagnostic.rs index 396de77d5ee..610b9155cfc 100644 --- a/compiler/rustc_macros/src/session_diagnostic.rs +++ b/compiler/rustc_macros/src/session_diagnostic.rs @@ -1,11 +1,9 @@ #![deny(unused_must_use)] -use quote::format_ident; -use quote::quote; - use proc_macro::Diagnostic; +use quote::{format_ident, quote}; use syn::spanned::Spanned; -use std::collections::{HashMap, HashSet}; +use std::collections::{BTreeSet, HashMap}; /// Implements #[derive(SessionDiagnostic)], which allows for errors to be specified as a struct, independent /// from the actual diagnostics emitting code. @@ -577,7 +575,10 @@ impl<'a> SessionDiagnosticDeriveBuilder<'a> { /// ``` /// This function builds the entire call to format!. fn build_format(&self, input: &String, span: proc_macro2::Span) -> proc_macro2::TokenStream { - let mut referenced_fields: HashSet<String> = HashSet::new(); + // This set is used later to generate the final format string. To keep builds reproducible, + // the iteration order needs to be deterministic, hence why we use a BTreeSet here instead + // of a HashSet. + let mut referenced_fields: BTreeSet<String> = BTreeSet::new(); // At this point, we can start parsing the format string. let mut it = input.chars().peekable(); |
