Skip to content

Commit 191e2f3

Browse files
committed
Make derive order stable
1 parent 3b3e1c0 commit 191e2f3

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

c2rust-transpile/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ pub struct TranspilerConfig {
8383
pub disable_refactoring: bool,
8484
pub preserve_unused_functions: bool,
8585
pub log_level: log::LevelFilter,
86-
pub derives: HashSet<Derive>,
86+
pub derives: Vec<Derive>,
8787

8888
// Options that control build files
8989
/// Emit `Cargo.toml` and `lib.rs`
@@ -93,7 +93,7 @@ pub struct TranspilerConfig {
9393
pub binaries: Vec<String>,
9494
}
9595

96-
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Display)]
96+
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Display, PartialOrd, Ord)]
9797
pub enum Derive {
9898
Clone,
9999
Copy,

c2rust/src/bin/c2rust-transpile.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use clap::{Parser, ValueEnum};
22
use log::LevelFilter;
33
use regex::Regex;
4-
use std::{fs, path::PathBuf};
4+
use std::{fs, path::PathBuf, collections::HashSet};
55

66
use c2rust_transpile::{Derive, Diagnostic, ReplaceMode, TranspilerConfig};
77

@@ -194,12 +194,6 @@ impl ExtraDerive {
194194
fn main() {
195195
let args = Args::parse();
196196

197-
let derives = DEFAULT_DERIVES
198-
.iter()
199-
.cloned()
200-
.chain(args.extra_derives.iter().map(|d| d.to_transpiler_derive()))
201-
.collect();
202-
203197
// Build a TranspilerConfig from the command line
204198
let mut tcfg = TranspilerConfig {
205199
dump_untyped_context: args.dump_untyped_clang_ast,
@@ -249,7 +243,7 @@ fn main() {
249243
emit_no_std: args.emit_no_std,
250244
enabled_warnings: args.warn.into_iter().collect(),
251245
log_level: args.log_level,
252-
derives,
246+
derives: get_derives(&args.extra_derives),
253247
};
254248
// binaries imply emit-build-files
255249
if !tcfg.binaries.is_empty() {
@@ -295,3 +289,15 @@ fn main() {
295289
.expect("Failed to remove temporary compile_commands.json");
296290
}
297291
}
292+
293+
fn get_derives(extra_derives: &[ExtraDerive]) -> Vec<Derive> {
294+
// Make sure there are no dupes and sort so the derives are always in the same order
295+
let derives_set: HashSet<_> = DEFAULT_DERIVES
296+
.iter()
297+
.cloned()
298+
.chain(extra_derives.iter().map(|d| d.to_transpiler_derive()))
299+
.collect();
300+
let mut derives: Vec<Derive> = derives_set.into_iter().collect();
301+
derives.sort();
302+
derives
303+
}

0 commit comments

Comments
 (0)