From 468bf58fa24d78bef8d0d017dcacb7da4c031c12 Mon Sep 17 00:00:00 2001 From: Taylor Yu Date: Fri, 15 Jun 2018 17:27:19 -0500 Subject: [PATCH 1/3] Make Rust warnings conditionally fatal Set rustc flags to treat warnings as fatal if configured with --enable-warnings. --- configure.ac | 6 ++++++ src/rust/.cargo/config.in | 3 +++ 2 files changed, 9 insertions(+) diff --git a/configure.ac b/configure.ac index d554ba8e55..5269d9c42e 100644 --- a/configure.ac +++ b/configure.ac @@ -462,6 +462,11 @@ if test "x$enable_rust" = "xyes"; then fi AC_DEFINE([HAVE_RUST], 1, [have Rust]) + if test "x$enable_fatal_warnings" = "xyes"; then + RUST_WARN= + else + RUST_WARN=# + fi if test "x$enable_cargo_online_mode" = "xyes"; then CARGO_ONLINE= RUST_DL=# @@ -515,6 +520,7 @@ if test "x$enable_rust" = "xyes"; then AC_SUBST(TOR_RUST_STATIC_NAME) AC_SUBST(CARGO_ONLINE) + AC_SUBST(RUST_WARN) AC_SUBST(RUST_DL) dnl Let's check the rustc version, too diff --git a/src/rust/.cargo/config.in b/src/rust/.cargo/config.in index 301e7fdbe7..70481bbcbe 100644 --- a/src/rust/.cargo/config.in +++ b/src/rust/.cargo/config.in @@ -6,3 +6,6 @@ @RUST_DL@ [source.vendored-sources] @RUST_DL@ directory = '@TOR_RUST_DEPENDENCIES@' + +@RUST_WARN@ [build] +@RUST_WARN@ rustflags = [ "-D", "warnings" ] \ No newline at end of file From d5a9b77a2892f195d391376f98287714d455ce5b Mon Sep 17 00:00:00 2001 From: Isis Lovecruft Date: Fri, 15 Jun 2018 22:49:05 +0000 Subject: [PATCH 2/3] rust: Add comment and pragma on "unused" smartlist_t type. * FIXES part of #26245: https://bugs.torproject.org/26245 --- src/rust/external/crypto_digest.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/rust/external/crypto_digest.rs b/src/rust/external/crypto_digest.rs index bc49e6124c..b55389ac51 100644 --- a/src/rust/external/crypto_digest.rs +++ b/src/rust/external/crypto_digest.rs @@ -117,6 +117,9 @@ struct common_digests_t { /// A `smartlist_t` is just an alias for the `#[repr(C)]` type `Stringlist`, to /// make it more clear that we're working with a smartlist which is owned by C. #[allow(non_camel_case_types)] +// BINDGEN_GENERATED: This type isn't actually bindgen generated, but the code +// below it which uses it is. As such, this comes up as "dead code" as well. +#[allow(dead_code)] type smartlist_t = Stringlist; /// All of the external functions from `src/common/crypto_digest.h`. From 748a0c7d0b7ed4657703371428aa2392d1383fe9 Mon Sep 17 00:00:00 2001 From: Isis Lovecruft Date: Fri, 15 Jun 2018 23:22:43 +0000 Subject: [PATCH 3/3] rust: Remove unused N_DIGEST_ALGORITHMS constant from crypto_digest.rs. In the C code, this constant is only ever used in src/test/bench.c. * FIXES part of #26245: https://bugs.torproject.org/26245 --- src/rust/external/crypto_digest.rs | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/rust/external/crypto_digest.rs b/src/rust/external/crypto_digest.rs index b55389ac51..4eae1550a2 100644 --- a/src/rust/external/crypto_digest.rs +++ b/src/rust/external/crypto_digest.rs @@ -66,13 +66,6 @@ const DIGEST_SHA512: digest_algorithm_t = 2; const DIGEST_SHA3_256: digest_algorithm_t = 3; const DIGEST_SHA3_512: digest_algorithm_t = 4; -/// The total number of digest algorithms we currently support. -/// -/// We can't access these from Rust, because their definitions in C require -/// introspecting the `digest_algorithm_t` typedef, which is an enum, so we have -/// to redefine them here. -const N_DIGEST_ALGORITHMS: usize = DIGEST_SHA3_512 as usize + 1; - /// The number of hash digests we produce for a `common_digests_t`. /// /// We can't access these from Rust, because their definitions in C require