From 8121958fda43759fa94e3f74f7cdbb595ddcc0e5 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Mon, 3 Mar 2025 18:59:30 +1100 Subject: Use `-Wunused_crate_dependencies` for compiler crates. It's very useful. There are some false positives involving integration tests in `rustc_pattern_analysis` and `rustc_serialize`. There is also a false positive involving `rustc_driver_impl`'s `rustc_randomized_layouts` feature. And I removed a `rustc_span` mention in a doc comment in `rustc_log` because it wasn't integral to the comment but caused a dev-dependency. --- Cargo.lock | 19 ------------------- compiler/rustc_ast_ir/Cargo.toml | 2 -- compiler/rustc_ast_lowering/Cargo.toml | 1 - compiler/rustc_ast_pretty/Cargo.toml | 5 ++++- compiler/rustc_attr_parsing/Cargo.toml | 3 --- compiler/rustc_codegen_ssa/Cargo.toml | 2 -- compiler/rustc_driver_impl/Cargo.toml | 2 +- compiler/rustc_driver_impl/src/lib.rs | 8 ++++++++ compiler/rustc_interface/Cargo.toml | 7 +++++-- compiler/rustc_log/Cargo.toml | 5 ----- compiler/rustc_log/src/lib.rs | 7 +------ compiler/rustc_metadata/Cargo.toml | 6 +++++- compiler/rustc_mir_build/Cargo.toml | 2 -- compiler/rustc_parse_format/Cargo.toml | 4 +++- compiler/rustc_pattern_analysis/src/lib.rs | 1 + compiler/rustc_pattern_analysis/tests/complexity.rs | 2 ++ .../rustc_pattern_analysis/tests/exhaustiveness.rs | 2 ++ compiler/rustc_pattern_analysis/tests/intersection.rs | 2 ++ compiler/rustc_query_impl/Cargo.toml | 2 -- compiler/rustc_query_system/Cargo.toml | 1 - compiler/rustc_sanitizers/Cargo.toml | 1 - compiler/rustc_serialize/src/lib.rs | 2 ++ compiler/rustc_serialize/tests/leb128.rs | 3 +++ compiler/rustc_serialize/tests/opaque.rs | 2 ++ compiler/rustc_smir/Cargo.toml | 1 - compiler/rustc_symbol_mangling/Cargo.toml | 1 - compiler/rustc_ty_utils/Cargo.toml | 1 - src/bootstrap/src/core/builder/cargo.rs | 1 + 28 files changed, 42 insertions(+), 53 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e91116ade9e..1a8dea0b105 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3206,7 +3206,6 @@ dependencies = [ "rustc_data_structures", "rustc_macros", "rustc_serialize", - "rustc_span", ] [[package]] @@ -3225,7 +3224,6 @@ dependencies = [ "rustc_index", "rustc_macros", "rustc_middle", - "rustc_parse", "rustc_session", "rustc_span", "rustc_target", @@ -3260,7 +3258,6 @@ version = "0.0.0" dependencies = [ "itertools", "rustc_ast", - "rustc_data_structures", "rustc_lexer", "rustc_span", "thin-vec", @@ -3288,15 +3285,12 @@ dependencies = [ "rustc_ast", "rustc_ast_pretty", "rustc_attr_data_structures", - "rustc_data_structures", "rustc_errors", "rustc_feature", "rustc_fluent_macro", "rustc_hir", "rustc_lexer", "rustc_macros", - "rustc_middle", - "rustc_serialize", "rustc_session", "rustc_span", "thin-vec", @@ -3423,7 +3417,6 @@ dependencies = [ "rustc_abi", "rustc_arena", "rustc_ast", - "rustc_ast_pretty", "rustc_attr_parsing", "rustc_data_structures", "rustc_errors", @@ -3431,7 +3424,6 @@ dependencies = [ "rustc_fs_util", "rustc_hashes", "rustc_hir", - "rustc_hir_pretty", "rustc_incremental", "rustc_index", "rustc_macros", @@ -3879,7 +3871,6 @@ dependencies = [ "rustc_query_impl", "rustc_query_system", "rustc_resolve", - "rustc_serialize", "rustc_session", "rustc_span", "rustc_symbol_mangling", @@ -3954,7 +3945,6 @@ dependencies = [ name = "rustc_log" version = "0.0.0" dependencies = [ - "rustc_span", "tracing", "tracing-core", "tracing-subscriber", @@ -4043,13 +4033,11 @@ dependencies = [ name = "rustc_mir_build" version = "0.0.0" dependencies = [ - "either", "itertools", "rustc_abi", "rustc_apfloat", "rustc_arena", "rustc_ast", - "rustc_attr_parsing", "rustc_data_structures", "rustc_errors", "rustc_fluent_macro", @@ -4256,7 +4244,6 @@ version = "0.0.0" dependencies = [ "measureme 12.0.1", "rustc_data_structures", - "rustc_errors", "rustc_hashes", "rustc_hir", "rustc_index", @@ -4265,7 +4252,6 @@ dependencies = [ "rustc_serialize", "rustc_session", "rustc_span", - "thin-vec", "tracing", ] @@ -4290,7 +4276,6 @@ dependencies = [ "rustc_session", "rustc_span", "smallvec", - "thin-vec", "tracing", ] @@ -4328,7 +4313,6 @@ version = "0.0.0" dependencies = [ "bitflags", "rustc_abi", - "rustc_ast", "rustc_data_structures", "rustc_hir", "rustc_middle", @@ -4383,7 +4367,6 @@ name = "rustc_smir" version = "0.0.0" dependencies = [ "rustc_abi", - "rustc_ast", "rustc_data_structures", "rustc_hir", "rustc_hir_pretty", @@ -4425,7 +4408,6 @@ dependencies = [ "punycode", "rustc-demangle", "rustc_abi", - "rustc_ast", "rustc_data_structures", "rustc_errors", "rustc_hashes", @@ -4520,7 +4502,6 @@ version = "0.0.0" dependencies = [ "itertools", "rustc_abi", - "rustc_attr_parsing", "rustc_data_structures", "rustc_errors", "rustc_fluent_macro", diff --git a/compiler/rustc_ast_ir/Cargo.toml b/compiler/rustc_ast_ir/Cargo.toml index f54e9687d8c..76bdd9f7eb6 100644 --- a/compiler/rustc_ast_ir/Cargo.toml +++ b/compiler/rustc_ast_ir/Cargo.toml @@ -8,7 +8,6 @@ edition = "2024" rustc_data_structures = { path = "../rustc_data_structures", optional = true } rustc_macros = { path = "../rustc_macros", optional = true } rustc_serialize = { path = "../rustc_serialize", optional = true } -rustc_span = { path = "../rustc_span", optional = true } # tidy-alphabetical-end [features] @@ -17,5 +16,4 @@ nightly = [ "dep:rustc_serialize", "dep:rustc_data_structures", "dep:rustc_macros", - "dep:rustc_span", ] diff --git a/compiler/rustc_ast_lowering/Cargo.toml b/compiler/rustc_ast_lowering/Cargo.toml index 2ec4f4b0555..6ac258155fe 100644 --- a/compiler/rustc_ast_lowering/Cargo.toml +++ b/compiler/rustc_ast_lowering/Cargo.toml @@ -20,7 +20,6 @@ rustc_hir = { path = "../rustc_hir" } rustc_index = { path = "../rustc_index" } rustc_macros = { path = "../rustc_macros" } rustc_middle = { path = "../rustc_middle" } -rustc_parse = { path = "../rustc_parse" } rustc_session = { path = "../rustc_session" } rustc_span = { path = "../rustc_span" } rustc_target = { path = "../rustc_target" } diff --git a/compiler/rustc_ast_pretty/Cargo.toml b/compiler/rustc_ast_pretty/Cargo.toml index 2634dd1fdf9..b704040be96 100644 --- a/compiler/rustc_ast_pretty/Cargo.toml +++ b/compiler/rustc_ast_pretty/Cargo.toml @@ -7,8 +7,11 @@ edition = "2024" # tidy-alphabetical-start itertools = "0.12" rustc_ast = { path = "../rustc_ast" } -rustc_data_structures = { path = "../rustc_data_structures" } rustc_lexer = { path = "../rustc_lexer" } rustc_span = { path = "../rustc_span" } +# tidy-alphabetical-end + +[dev-dependencies] +# tidy-alphabetical-start thin-vec = "0.2.12" # tidy-alphabetical-end diff --git a/compiler/rustc_attr_parsing/Cargo.toml b/compiler/rustc_attr_parsing/Cargo.toml index 6b4ce957630..32029137268 100644 --- a/compiler/rustc_attr_parsing/Cargo.toml +++ b/compiler/rustc_attr_parsing/Cargo.toml @@ -9,15 +9,12 @@ rustc_abi = { path = "../rustc_abi" } rustc_ast = { path = "../rustc_ast" } rustc_ast_pretty = { path = "../rustc_ast_pretty" } rustc_attr_data_structures = { path = "../rustc_attr_data_structures" } -rustc_data_structures = { path = "../rustc_data_structures" } rustc_errors = { path = "../rustc_errors" } rustc_feature = { path = "../rustc_feature" } rustc_fluent_macro = { path = "../rustc_fluent_macro" } rustc_hir = { path = "../rustc_hir" } rustc_lexer = { path = "../rustc_lexer" } rustc_macros = { path = "../rustc_macros" } -rustc_middle = { path = "../rustc_middle" } -rustc_serialize = { path = "../rustc_serialize" } rustc_session = { path = "../rustc_session" } rustc_span = { path = "../rustc_span" } thin-vec = "0.2.12" diff --git a/compiler/rustc_codegen_ssa/Cargo.toml b/compiler/rustc_codegen_ssa/Cargo.toml index caa1db8274d..0a2f1d5bb67 100644 --- a/compiler/rustc_codegen_ssa/Cargo.toml +++ b/compiler/rustc_codegen_ssa/Cargo.toml @@ -19,7 +19,6 @@ regex = "1.4" rustc_abi = { path = "../rustc_abi" } rustc_arena = { path = "../rustc_arena" } rustc_ast = { path = "../rustc_ast" } -rustc_ast_pretty = { path = "../rustc_ast_pretty" } rustc_attr_parsing = { path = "../rustc_attr_parsing" } rustc_data_structures = { path = "../rustc_data_structures" } rustc_errors = { path = "../rustc_errors" } @@ -27,7 +26,6 @@ rustc_fluent_macro = { path = "../rustc_fluent_macro" } rustc_fs_util = { path = "../rustc_fs_util" } rustc_hashes = { path = "../rustc_hashes" } rustc_hir = { path = "../rustc_hir" } -rustc_hir_pretty = { path = "../rustc_hir_pretty" } rustc_incremental = { path = "../rustc_incremental" } rustc_index = { path = "../rustc_index" } rustc_macros = { path = "../rustc_macros" } diff --git a/compiler/rustc_driver_impl/Cargo.toml b/compiler/rustc_driver_impl/Cargo.toml index 8593d1faba2..de643355f5f 100644 --- a/compiler/rustc_driver_impl/Cargo.toml +++ b/compiler/rustc_driver_impl/Cargo.toml @@ -54,7 +54,7 @@ time = { version = "0.3.36", default-features = false, features = ["alloc", "for tracing = { version = "0.1.35" } # tidy-alphabetical-end -[target.'cfg(unix)'.dependencies] +[target.'cfg(all(unix, any(target_env = "gnu", target_os = "macos")))'.dependencies] # tidy-alphabetical-start libc = "0.2" # tidy-alphabetical-end diff --git a/compiler/rustc_driver_impl/src/lib.rs b/compiler/rustc_driver_impl/src/lib.rs index 43dc2e3cf9e..8ede6e41336 100644 --- a/compiler/rustc_driver_impl/src/lib.rs +++ b/compiler/rustc_driver_impl/src/lib.rs @@ -44,6 +44,10 @@ use rustc_errors::emitter::stderr_destination; use rustc_errors::registry::Registry; use rustc_errors::{ColorConfig, DiagCtxt, ErrCode, FatalError, PResult, markdown}; use rustc_feature::find_gated_cfg; +// This avoids a false positive with `-Wunused_crate_dependencies`. +// `rust_index` isn't used in this crate's code, but it must be named in the +// `Cargo.toml` for the `rustc_randomized_layouts` feature. +use rustc_index as _; use rustc_interface::util::{self, get_codegen_backend}; use rustc_interface::{Linker, create_and_enter_global_ctxt, interface, passes}; use rustc_lint::unerased_lint_store; @@ -89,6 +93,10 @@ pub mod pretty; #[macro_use] mod print; mod session_diagnostics; + +// Keep the OS parts of this `cfg` in sync with the `cfg` on the `libc` +// dependency in `compiler/rustc_driver/Cargo.toml`, to keep +// `-Wunused-crated-dependencies` satisfied. #[cfg(all(not(miri), unix, any(target_env = "gnu", target_os = "macos")))] mod signal_handler; diff --git a/compiler/rustc_interface/Cargo.toml b/compiler/rustc_interface/Cargo.toml index 9c9660cf504..e3673935664 100644 --- a/compiler/rustc_interface/Cargo.toml +++ b/compiler/rustc_interface/Cargo.toml @@ -7,7 +7,6 @@ edition = "2024" # tidy-alphabetical-start rustc-rayon = { version = "0.5.0" } rustc-rayon-core = { version = "0.5.0" } -rustc_abi = { path = "../rustc_abi" } rustc_ast = { path = "../rustc_ast" } rustc_ast_lowering = { path = "../rustc_ast_lowering" } rustc_ast_passes = { path = "../rustc_ast_passes" } @@ -41,7 +40,6 @@ rustc_privacy = { path = "../rustc_privacy" } rustc_query_impl = { path = "../rustc_query_impl" } rustc_query_system = { path = "../rustc_query_system" } rustc_resolve = { path = "../rustc_resolve" } -rustc_serialize = { path = "../rustc_serialize" } rustc_session = { path = "../rustc_session" } rustc_span = { path = "../rustc_span" } rustc_symbol_mangling = { path = "../rustc_symbol_mangling" } @@ -52,6 +50,11 @@ rustc_ty_utils = { path = "../rustc_ty_utils" } tracing = "0.1" # tidy-alphabetical-end +[dev-dependencies] +# tidy-alphabetical-start +rustc_abi = { path = "../rustc_abi" } +# tidy-alphabetical-end + [features] # tidy-alphabetical-start llvm = ['dep:rustc_codegen_llvm'] diff --git a/compiler/rustc_log/Cargo.toml b/compiler/rustc_log/Cargo.toml index 30f6e9ba805..c673d51a1d4 100644 --- a/compiler/rustc_log/Cargo.toml +++ b/compiler/rustc_log/Cargo.toml @@ -11,11 +11,6 @@ tracing-subscriber = { version = "0.3.3", default-features = false, features = [ tracing-tree = "0.3.1" # tidy-alphabetical-end -[dev-dependencies] -# tidy-alphabetical-start -rustc_span = { path = "../rustc_span" } -# tidy-alphabetical-end - [features] # tidy-alphabetical-start max_level_info = ['tracing/max_level_info'] diff --git a/compiler/rustc_log/src/lib.rs b/compiler/rustc_log/src/lib.rs index d0ef82f4a6c..49dd388f14c 100644 --- a/compiler/rustc_log/src/lib.rs +++ b/compiler/rustc_log/src/lib.rs @@ -9,17 +9,12 @@ //! [dependencies] //! rustc_ast = { path = "../rust/compiler/rustc_ast" } //! rustc_log = { path = "../rust/compiler/rustc_log" } -//! rustc_span = { path = "../rust/compiler/rustc_span" } //! ``` //! //! ``` //! fn main() { //! rustc_log::init_logger(rustc_log::LoggerConfig::from_env("LOG")).unwrap(); -//! -//! let edition = rustc_span::edition::Edition::Edition2021; -//! rustc_span::create_session_globals_then(edition, None, || { -//! /* ... */ -//! }); +//! /* ... */ //! } //! ``` //! diff --git a/compiler/rustc_metadata/Cargo.toml b/compiler/rustc_metadata/Cargo.toml index 1f5d41014d4..08dcc3d519a 100644 --- a/compiler/rustc_metadata/Cargo.toml +++ b/compiler/rustc_metadata/Cargo.toml @@ -6,7 +6,6 @@ edition = "2024" [dependencies] # tidy-alphabetical-start bitflags = "2.4.1" -libc = "0.2" libloading = "0.8.0" odht = { version = "0.3.1", features = ["nightly"] } rustc_abi = { path = "../rustc_abi" } @@ -30,3 +29,8 @@ rustc_target = { path = "../rustc_target" } tempfile = "3.2" tracing = "0.1" # tidy-alphabetical-end + +[target.'cfg(target_os = "aix")'.dependencies] +# tidy-alphabetical-start +libc = "0.2" +# tidy-alphabetical-end diff --git a/compiler/rustc_mir_build/Cargo.toml b/compiler/rustc_mir_build/Cargo.toml index d70d70a31a4..1534865cdd3 100644 --- a/compiler/rustc_mir_build/Cargo.toml +++ b/compiler/rustc_mir_build/Cargo.toml @@ -5,14 +5,12 @@ edition = "2024" [dependencies] # tidy-alphabetical-start -either = "1.5.0" itertools = "0.12" rustc_abi = { path = "../rustc_abi" } rustc_apfloat = "0.2.0" rustc_arena = { path = "../rustc_arena" } rustc_ast = { path = "../rustc_ast" } -rustc_attr_parsing = { path = "../rustc_attr_parsing" } rustc_data_structures = { path = "../rustc_data_structures" } rustc_errors = { path = "../rustc_errors" } rustc_fluent_macro = { path = "../rustc_fluent_macro" } diff --git a/compiler/rustc_parse_format/Cargo.toml b/compiler/rustc_parse_format/Cargo.toml index a39cca716d2..d6c3bd9877c 100644 --- a/compiler/rustc_parse_format/Cargo.toml +++ b/compiler/rustc_parse_format/Cargo.toml @@ -5,6 +5,8 @@ edition = "2024" [dependencies] # tidy-alphabetical-start -rustc_index = { path = "../rustc_index", default-features = false } rustc_lexer = { path = "../rustc_lexer" } # tidy-alphabetical-end + +[target.'cfg(target_pointer_width = "64")'.dependencies] +rustc_index = { path = "../rustc_index", default-features = false } diff --git a/compiler/rustc_pattern_analysis/src/lib.rs b/compiler/rustc_pattern_analysis/src/lib.rs index eeea724a29b..176dcbf6da4 100644 --- a/compiler/rustc_pattern_analysis/src/lib.rs +++ b/compiler/rustc_pattern_analysis/src/lib.rs @@ -5,6 +5,7 @@ // tidy-alphabetical-start #![allow(rustc::diagnostic_outside_of_impl)] #![allow(rustc::untranslatable_diagnostic)] +#![allow(unused_crate_dependencies)] #![cfg_attr(feature = "rustc", feature(let_chains))] // tidy-alphabetical-end diff --git a/compiler/rustc_pattern_analysis/tests/complexity.rs b/compiler/rustc_pattern_analysis/tests/complexity.rs index abd1ec24d93..93aecafe48d 100644 --- a/compiler/rustc_pattern_analysis/tests/complexity.rs +++ b/compiler/rustc_pattern_analysis/tests/complexity.rs @@ -1,5 +1,7 @@ //! Test the pattern complexity limit. +#![allow(unused_crate_dependencies)] + use common::*; use rustc_pattern_analysis::MatchArm; use rustc_pattern_analysis::pat::DeconstructedPat; diff --git a/compiler/rustc_pattern_analysis/tests/exhaustiveness.rs b/compiler/rustc_pattern_analysis/tests/exhaustiveness.rs index 61ce0fd11e7..3b8f346ef19 100644 --- a/compiler/rustc_pattern_analysis/tests/exhaustiveness.rs +++ b/compiler/rustc_pattern_analysis/tests/exhaustiveness.rs @@ -1,5 +1,7 @@ //! Test exhaustiveness checking. +#![allow(unused_crate_dependencies)] + use common::*; use rustc_pattern_analysis::MatchArm; use rustc_pattern_analysis::pat::{DeconstructedPat, WitnessPat}; diff --git a/compiler/rustc_pattern_analysis/tests/intersection.rs b/compiler/rustc_pattern_analysis/tests/intersection.rs index 45674338efd..8e6f84dcbc8 100644 --- a/compiler/rustc_pattern_analysis/tests/intersection.rs +++ b/compiler/rustc_pattern_analysis/tests/intersection.rs @@ -1,5 +1,7 @@ //! Test the computation of arm intersections. +#![allow(unused_crate_dependencies)] + use common::*; use rustc_pattern_analysis::MatchArm; use rustc_pattern_analysis::pat::DeconstructedPat; diff --git a/compiler/rustc_query_impl/Cargo.toml b/compiler/rustc_query_impl/Cargo.toml index b6773fb460f..e5cceacf15d 100644 --- a/compiler/rustc_query_impl/Cargo.toml +++ b/compiler/rustc_query_impl/Cargo.toml @@ -7,7 +7,6 @@ edition = "2024" # tidy-alphabetical-start measureme = "12.0.1" rustc_data_structures = { path = "../rustc_data_structures" } -rustc_errors = { path = "../rustc_errors" } rustc_hashes = { path = "../rustc_hashes" } rustc_hir = { path = "../rustc_hir" } rustc_index = { path = "../rustc_index" } @@ -16,6 +15,5 @@ rustc_query_system = { path = "../rustc_query_system" } rustc_serialize = { path = "../rustc_serialize" } rustc_session = { path = "../rustc_session" } rustc_span = { path = "../rustc_span" } -thin-vec = "0.2.12" tracing = "0.1" # tidy-alphabetical-end diff --git a/compiler/rustc_query_system/Cargo.toml b/compiler/rustc_query_system/Cargo.toml index 3e8ccb51021..78710efb7a9 100644 --- a/compiler/rustc_query_system/Cargo.toml +++ b/compiler/rustc_query_system/Cargo.toml @@ -22,6 +22,5 @@ rustc_serialize = { path = "../rustc_serialize" } rustc_session = { path = "../rustc_session" } rustc_span = { path = "../rustc_span" } smallvec = { version = "1.8.1", features = ["union", "may_dangle"] } -thin-vec = "0.2.12" tracing = "0.1" # tidy-alphabetical-end diff --git a/compiler/rustc_sanitizers/Cargo.toml b/compiler/rustc_sanitizers/Cargo.toml index 900cd4243b1..66488bc9625 100644 --- a/compiler/rustc_sanitizers/Cargo.toml +++ b/compiler/rustc_sanitizers/Cargo.toml @@ -8,7 +8,6 @@ bitflags = "2.5.0" tracing = "0.1" twox-hash = "1.6.3" rustc_abi = { path = "../rustc_abi" } -rustc_ast = { path = "../rustc_ast" } rustc_data_structures = { path = "../rustc_data_structures" } rustc_hir = { path = "../rustc_hir" } rustc_middle = { path = "../rustc_middle" } diff --git a/compiler/rustc_serialize/src/lib.rs b/compiler/rustc_serialize/src/lib.rs index 13c1a273eb8..8672278d0f1 100644 --- a/compiler/rustc_serialize/src/lib.rs +++ b/compiler/rustc_serialize/src/lib.rs @@ -3,6 +3,8 @@ // tidy-alphabetical-start #![allow(internal_features)] #![allow(rustc::internal)] +// FIXME +#![allow(unused_crate_dependencies)] #![cfg_attr(test, feature(test))] #![doc( html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/", diff --git a/compiler/rustc_serialize/tests/leb128.rs b/compiler/rustc_serialize/tests/leb128.rs index aef55d15e60..11402cbbf3b 100644 --- a/compiler/rustc_serialize/tests/leb128.rs +++ b/compiler/rustc_serialize/tests/leb128.rs @@ -1,3 +1,6 @@ +// FIXME +#![allow(unused_crate_dependencies)] + use rustc_serialize::Decoder; use rustc_serialize::leb128::*; use rustc_serialize::opaque::{MAGIC_END_BYTES, MemDecoder}; diff --git a/compiler/rustc_serialize/tests/opaque.rs b/compiler/rustc_serialize/tests/opaque.rs index 5aeedbdcd4e..418c8ede50b 100644 --- a/compiler/rustc_serialize/tests/opaque.rs +++ b/compiler/rustc_serialize/tests/opaque.rs @@ -1,4 +1,6 @@ #![allow(rustc::internal)] +// FIXME +#![allow(unused_crate_dependencies)] use std::fmt::Debug; use std::fs; diff --git a/compiler/rustc_smir/Cargo.toml b/compiler/rustc_smir/Cargo.toml index a11df9a9c9b..b2149a03a8e 100644 --- a/compiler/rustc_smir/Cargo.toml +++ b/compiler/rustc_smir/Cargo.toml @@ -6,7 +6,6 @@ edition = "2024" [dependencies] # tidy-alphabetical-start rustc_abi = { path = "../rustc_abi" } -rustc_ast = { path = "../rustc_ast" } rustc_data_structures = { path = "../rustc_data_structures" } rustc_hir = { path = "../rustc_hir" } rustc_hir_pretty = { path = "../rustc_hir_pretty" } diff --git a/compiler/rustc_symbol_mangling/Cargo.toml b/compiler/rustc_symbol_mangling/Cargo.toml index 90ddf4c8a04..12fe6b719f9 100644 --- a/compiler/rustc_symbol_mangling/Cargo.toml +++ b/compiler/rustc_symbol_mangling/Cargo.toml @@ -9,7 +9,6 @@ punycode = "0.4.0" rustc-demangle = "0.1.21" rustc_abi = { path = "../rustc_abi" } -rustc_ast = { path = "../rustc_ast" } rustc_data_structures = { path = "../rustc_data_structures" } rustc_errors = { path = "../rustc_errors" } rustc_hashes = { path = "../rustc_hashes" } diff --git a/compiler/rustc_ty_utils/Cargo.toml b/compiler/rustc_ty_utils/Cargo.toml index b14ce8a7f21..ce08b300cc8 100644 --- a/compiler/rustc_ty_utils/Cargo.toml +++ b/compiler/rustc_ty_utils/Cargo.toml @@ -7,7 +7,6 @@ edition = "2024" # tidy-alphabetical-start itertools = "0.12" rustc_abi = { path = "../rustc_abi" } -rustc_attr_parsing = { path = "../rustc_attr_parsing" } rustc_data_structures = { path = "../rustc_data_structures" } rustc_errors = { path = "../rustc_errors" } rustc_fluent_macro = { path = "../rustc_fluent_macro" } diff --git a/src/bootstrap/src/core/builder/cargo.rs b/src/bootstrap/src/core/builder/cargo.rs index efb1b8b25b7..a96ccdd12c2 100644 --- a/src/bootstrap/src/core/builder/cargo.rs +++ b/src/bootstrap/src/core/builder/cargo.rs @@ -1073,6 +1073,7 @@ impl Builder<'_> { lint_flags.push("-Wkeyword_idents_2024"); lint_flags.push("-Wunreachable_pub"); lint_flags.push("-Wunsafe_op_in_unsafe_fn"); + lint_flags.push("-Wunused_crate_dependencies"); } // This does not use RUSTFLAGS for two reasons. -- cgit 1.4.1-3-g733a5 From e2320b32c5268913349549fc59972443975ceec4 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Mon, 3 Mar 2025 19:40:00 +1100 Subject: Convert `rustc_serialize` integration tests to unit tests. Because (a) the vast majority of compiler tests are unit tests, and (b) this works better with `unused_crate_dependencies`. --- compiler/rustc_serialize/src/leb128.rs | 3 + compiler/rustc_serialize/src/leb128/tests.rs | 95 +++++++++ compiler/rustc_serialize/src/lib.rs | 6 +- compiler/rustc_serialize/src/opaque.rs | 3 + compiler/rustc_serialize/src/opaque/tests.rs | 295 ++++++++++++++++++++++++++ compiler/rustc_serialize/tests/leb128.rs | 98 --------- compiler/rustc_serialize/tests/opaque.rs | 298 --------------------------- 7 files changed, 400 insertions(+), 398 deletions(-) create mode 100644 compiler/rustc_serialize/src/leb128/tests.rs create mode 100644 compiler/rustc_serialize/src/opaque/tests.rs delete mode 100644 compiler/rustc_serialize/tests/leb128.rs delete mode 100644 compiler/rustc_serialize/tests/opaque.rs diff --git a/compiler/rustc_serialize/src/leb128.rs b/compiler/rustc_serialize/src/leb128.rs index 4a475805697..954c1f728f2 100644 --- a/compiler/rustc_serialize/src/leb128.rs +++ b/compiler/rustc_serialize/src/leb128.rs @@ -155,3 +155,6 @@ impl_read_signed_leb128!(read_i32_leb128, i32); impl_read_signed_leb128!(read_i64_leb128, i64); impl_read_signed_leb128!(read_i128_leb128, i128); impl_read_signed_leb128!(read_isize_leb128, isize); + +#[cfg(test)] +mod tests; diff --git a/compiler/rustc_serialize/src/leb128/tests.rs b/compiler/rustc_serialize/src/leb128/tests.rs new file mode 100644 index 00000000000..8434cd1e2e1 --- /dev/null +++ b/compiler/rustc_serialize/src/leb128/tests.rs @@ -0,0 +1,95 @@ +use super::*; +use crate::Decoder; +use crate::opaque::{MAGIC_END_BYTES, MemDecoder}; + +macro_rules! impl_test_unsigned_leb128 { + ($test_name:ident, $write_fn_name:ident, $read_fn_name:ident, $int_ty:ident) => { + #[test] + fn $test_name() { + // Test 256 evenly spaced values of integer range, + // integer max value, and some "random" numbers. + let mut values = Vec::new(); + + let increment = (1 as $int_ty) << ($int_ty::BITS - 8); + values.extend((0..256).map(|i| $int_ty::MIN + i * increment)); + + values.push($int_ty::MAX); + + values.extend( + (-500..500).map(|i| (i as $int_ty).wrapping_mul(0x12345789ABCDEFu64 as $int_ty)), + ); + + let mut stream = Vec::new(); + + let mut buf = Default::default(); + for &x in &values { + let n = $write_fn_name(&mut buf, x); + stream.extend(&buf[..n]); + } + let stream_end = stream.len(); + stream.extend(MAGIC_END_BYTES); + + let mut decoder = MemDecoder::new(&stream, 0).unwrap(); + for &expected in &values { + let actual = $read_fn_name(&mut decoder); + assert_eq!(expected, actual); + } + assert_eq!(stream_end, decoder.position()); + } + }; +} + +impl_test_unsigned_leb128!(test_u16_leb128, write_u16_leb128, read_u16_leb128, u16); +impl_test_unsigned_leb128!(test_u32_leb128, write_u32_leb128, read_u32_leb128, u32); +impl_test_unsigned_leb128!(test_u64_leb128, write_u64_leb128, read_u64_leb128, u64); +impl_test_unsigned_leb128!(test_u128_leb128, write_u128_leb128, read_u128_leb128, u128); +impl_test_unsigned_leb128!(test_usize_leb128, write_usize_leb128, read_usize_leb128, usize); + +macro_rules! impl_test_signed_leb128 { + ($test_name:ident, $write_fn_name:ident, $read_fn_name:ident, $int_ty:ident) => { + #[test] + fn $test_name() { + // Test 256 evenly spaced values of integer range, + // integer max value, and some "random" numbers. + let mut values = Vec::new(); + + let mut value = $int_ty::MIN; + let increment = (1 as $int_ty) << ($int_ty::BITS - 8); + + for _ in 0..256 { + values.push(value); + // The addition in the last loop iteration overflows. + value = value.wrapping_add(increment); + } + + values.push($int_ty::MAX); + + values.extend( + (-500..500).map(|i| (i as $int_ty).wrapping_mul(0x12345789ABCDEFi64 as $int_ty)), + ); + + let mut stream = Vec::new(); + + let mut buf = Default::default(); + for &x in &values { + let n = $write_fn_name(&mut buf, x); + stream.extend(&buf[..n]); + } + let stream_end = stream.len(); + stream.extend(MAGIC_END_BYTES); + + let mut decoder = MemDecoder::new(&stream, 0).unwrap(); + for &expected in &values { + let actual = $read_fn_name(&mut decoder); + assert_eq!(expected, actual); + } + assert_eq!(stream_end, decoder.position()); + } + }; +} + +impl_test_signed_leb128!(test_i16_leb128, write_i16_leb128, read_i16_leb128, i16); +impl_test_signed_leb128!(test_i32_leb128, write_i32_leb128, read_i32_leb128, i32); +impl_test_signed_leb128!(test_i64_leb128, write_i64_leb128, read_i64_leb128, i64); +impl_test_signed_leb128!(test_i128_leb128, write_i128_leb128, read_i128_leb128, i128); +impl_test_signed_leb128!(test_isize_leb128, write_isize_leb128, read_isize_leb128, isize); diff --git a/compiler/rustc_serialize/src/lib.rs b/compiler/rustc_serialize/src/lib.rs index 8672278d0f1..34be35e36ac 100644 --- a/compiler/rustc_serialize/src/lib.rs +++ b/compiler/rustc_serialize/src/lib.rs @@ -3,8 +3,6 @@ // tidy-alphabetical-start #![allow(internal_features)] #![allow(rustc::internal)] -// FIXME -#![allow(unused_crate_dependencies)] #![cfg_attr(test, feature(test))] #![doc( html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/", @@ -18,6 +16,10 @@ #![feature(rustdoc_internals)] // tidy-alphabetical-end +// Allows macros to refer to this crate as `::rustc_serialize`. +#[cfg(test)] +extern crate self as rustc_serialize; + pub use self::serialize::{Decodable, Decoder, Encodable, Encoder}; mod serialize; diff --git a/compiler/rustc_serialize/src/opaque.rs b/compiler/rustc_serialize/src/opaque.rs index d4907b69b72..81f6266f8d1 100644 --- a/compiler/rustc_serialize/src/opaque.rs +++ b/compiler/rustc_serialize/src/opaque.rs @@ -451,3 +451,6 @@ impl<'a> Decodable> for IntEncodedWithFixedSize { IntEncodedWithFixedSize(u64::from_le_bytes(bytes)) } } + +#[cfg(test)] +mod tests; diff --git a/compiler/rustc_serialize/src/opaque/tests.rs b/compiler/rustc_serialize/src/opaque/tests.rs new file mode 100644 index 00000000000..11401d24595 --- /dev/null +++ b/compiler/rustc_serialize/src/opaque/tests.rs @@ -0,0 +1,295 @@ +use std::fmt::Debug; +use std::fs; + +use rustc_macros::{Decodable_NoContext, Encodable_NoContext}; + +use crate::opaque::{FileEncoder, MemDecoder}; +use crate::{Decodable, Encodable}; + +#[derive(PartialEq, Clone, Debug, Encodable_NoContext, Decodable_NoContext)] +struct Struct { + a: (), + b: u8, + c: u16, + d: u32, + e: u64, + f: usize, + + g: i8, + h: i16, + i: i32, + j: i64, + k: isize, + + l: char, + m: String, + p: bool, + q: Option, +} + +fn check_round_trip< + T: Encodable + for<'a> Decodable> + PartialEq + Debug, +>( + values: Vec, +) { + let tmpfile = tempfile::NamedTempFile::new().unwrap(); + let tmpfile = tmpfile.path(); + + let mut encoder = FileEncoder::new(&tmpfile).unwrap(); + for value in &values { + Encodable::encode(value, &mut encoder); + } + encoder.finish().unwrap(); + + let data = fs::read(&tmpfile).unwrap(); + let mut decoder = MemDecoder::new(&data[..], 0).unwrap(); + for value in values { + let decoded = Decodable::decode(&mut decoder); + assert_eq!(value, decoded); + } +} + +#[test] +fn test_unit() { + check_round_trip(vec![(), (), (), ()]); +} + +#[test] +fn test_u8() { + let mut vec = vec![]; + for i in u8::MIN..u8::MAX { + vec.push(i); + } + check_round_trip(vec); +} + +#[test] +fn test_u16() { + for i in [u16::MIN, 111, 3333, 55555, u16::MAX] { + check_round_trip(vec![1, 2, 3, i, i, i]); + } +} + +#[test] +fn test_u32() { + check_round_trip(vec![1, 2, 3, u32::MIN, 0, 1, u32::MAX, 2, 1]); +} + +#[test] +fn test_u64() { + check_round_trip(vec![1, 2, 3, u64::MIN, 0, 1, u64::MAX, 2, 1]); +} + +#[test] +fn test_usize() { + check_round_trip(vec![1, 2, 3, usize::MIN, 0, 1, usize::MAX, 2, 1]); +} + +#[test] +fn test_i8() { + let mut vec = vec![]; + for i in i8::MIN..i8::MAX { + vec.push(i); + } + check_round_trip(vec); +} + +#[test] +fn test_i16() { + for i in [i16::MIN, -100, 0, 101, i16::MAX] { + check_round_trip(vec![-1, 2, -3, i, i, i, 2]); + } +} + +#[test] +fn test_i32() { + check_round_trip(vec![-1, 2, -3, i32::MIN, 0, 1, i32::MAX, 2, 1]); +} + +#[test] +fn test_i64() { + check_round_trip(vec![-1, 2, -3, i64::MIN, 0, 1, i64::MAX, 2, 1]); +} + +#[test] +fn test_isize() { + check_round_trip(vec![-1, 2, -3, isize::MIN, 0, 1, isize::MAX, 2, 1]); +} + +#[test] +fn test_bool() { + check_round_trip(vec![false, true, true, false, false]); +} + +#[test] +fn test_char() { + let vec = vec!['a', 'b', 'c', 'd', 'A', 'X', ' ', '#', 'Ö', 'Ä', 'µ', '€']; + check_round_trip(vec); +} + +#[test] +fn test_string() { + let vec = vec![ + "abcbuÖeiovÄnameÜavmpßvmea€µsbpnvapeapmaebn".to_string(), + "abcbuÖganeiovÄnameÜavmpßvmea€µsbpnvapeapmaebn".to_string(), + "abcbuÖganeiovÄnameÜavmpßvmea€µsbpapmaebn".to_string(), + "abcbuÖganeiovÄnameÜavmpßvmeabpnvapeapmaebn".to_string(), + "abcbuÖganeiÄnameÜavmpßvmea€µsbpnvapeapmaebn".to_string(), + "abcbuÖganeiovÄnameÜavmpßvmea€µsbpmaebn".to_string(), + "abcbuÖganeiovÄnameÜavmpßvmea€µnvapeapmaebn".to_string(), + ]; + + check_round_trip(vec); +} + +#[test] +fn test_option() { + check_round_trip(vec![Some(-1i8)]); + check_round_trip(vec![Some(-2i16)]); + check_round_trip(vec![Some(-3i32)]); + check_round_trip(vec![Some(-4i64)]); + check_round_trip(vec![Some(-5isize)]); + + let none_i8: Option = None; + check_round_trip(vec![none_i8]); + + let none_i16: Option = None; + check_round_trip(vec![none_i16]); + + let none_i32: Option = None; + check_round_trip(vec![none_i32]); + + let none_i64: Option = None; + check_round_trip(vec![none_i64]); + + let none_isize: Option = None; + check_round_trip(vec![none_isize]); +} + +#[test] +fn test_struct() { + check_round_trip(vec![Struct { + a: (), + b: 10, + c: 11, + d: 12, + e: 13, + f: 14, + + g: 15, + h: 16, + i: 17, + j: 18, + k: 19, + + l: 'x', + m: "abc".to_string(), + p: false, + q: None, + }]); + + check_round_trip(vec![Struct { + a: (), + b: 101, + c: 111, + d: 121, + e: 131, + f: 141, + + g: -15, + h: -16, + i: -17, + j: -18, + k: -19, + + l: 'y', + m: "def".to_string(), + p: true, + q: Some(1234567), + }]); +} + +#[derive(PartialEq, Clone, Debug, Encodable_NoContext, Decodable_NoContext)] +enum Enum { + Variant1, + Variant2(usize, u32), + Variant3 { a: i32, b: char, c: bool }, +} + +#[test] +fn test_enum() { + check_round_trip(vec![ + Enum::Variant1, + Enum::Variant2(1, 25), + Enum::Variant3 { a: 3, b: 'b', c: false }, + Enum::Variant3 { a: -4, b: 'f', c: true }, + ]); +} + +#[test] +fn test_sequence() { + let mut vec = vec![]; + for i in -100i64..100i64 { + vec.push(i * 100000); + } + + check_round_trip(vec![vec]); +} + +#[test] +fn test_hash_map() { + use std::collections::HashMap; + let mut map = HashMap::new(); + for i in -100i64..100i64 { + map.insert(i * 100000, i * 10000); + } + + check_round_trip(vec![map]); +} + +#[test] +fn test_tuples() { + check_round_trip(vec![('x', (), false, 5u32)]); + check_round_trip(vec![(9i8, 10u16, 15i64)]); + check_round_trip(vec![(-12i16, 11u8, 12usize)]); + check_round_trip(vec![(1234567isize, 100000000000000u64, 99999999999999i64)]); + check_round_trip(vec![(String::new(), "some string".to_string())]); +} + +#[test] +fn test_unit_like_struct() { + #[derive(Encodable_NoContext, Decodable_NoContext, PartialEq, Debug)] + struct UnitLikeStruct; + + check_round_trip(vec![UnitLikeStruct]); +} + +#[test] +fn test_box() { + #[derive(Encodable_NoContext, Decodable_NoContext, PartialEq, Debug)] + struct A { + foo: Box<[bool]>, + } + + let obj = A { foo: Box::new([true, false]) }; + check_round_trip(vec![obj]); +} + +#[test] +fn test_cell() { + use std::cell::{Cell, RefCell}; + + #[derive(Encodable_NoContext, Decodable_NoContext, PartialEq, Debug)] + struct A { + baz: isize, + } + + #[derive(Encodable_NoContext, Decodable_NoContext, PartialEq, Debug)] + struct B { + foo: Cell, + bar: RefCell, + } + + let obj = B { foo: Cell::new(true), bar: RefCell::new(A { baz: 2 }) }; + check_round_trip(vec![obj]); +} diff --git a/compiler/rustc_serialize/tests/leb128.rs b/compiler/rustc_serialize/tests/leb128.rs deleted file mode 100644 index 11402cbbf3b..00000000000 --- a/compiler/rustc_serialize/tests/leb128.rs +++ /dev/null @@ -1,98 +0,0 @@ -// FIXME -#![allow(unused_crate_dependencies)] - -use rustc_serialize::Decoder; -use rustc_serialize::leb128::*; -use rustc_serialize::opaque::{MAGIC_END_BYTES, MemDecoder}; - -macro_rules! impl_test_unsigned_leb128 { - ($test_name:ident, $write_fn_name:ident, $read_fn_name:ident, $int_ty:ident) => { - #[test] - fn $test_name() { - // Test 256 evenly spaced values of integer range, - // integer max value, and some "random" numbers. - let mut values = Vec::new(); - - let increment = (1 as $int_ty) << ($int_ty::BITS - 8); - values.extend((0..256).map(|i| $int_ty::MIN + i * increment)); - - values.push($int_ty::MAX); - - values.extend( - (-500..500).map(|i| (i as $int_ty).wrapping_mul(0x12345789ABCDEFu64 as $int_ty)), - ); - - let mut stream = Vec::new(); - - let mut buf = Default::default(); - for &x in &values { - let n = $write_fn_name(&mut buf, x); - stream.extend(&buf[..n]); - } - let stream_end = stream.len(); - stream.extend(MAGIC_END_BYTES); - - let mut decoder = MemDecoder::new(&stream, 0).unwrap(); - for &expected in &values { - let actual = $read_fn_name(&mut decoder); - assert_eq!(expected, actual); - } - assert_eq!(stream_end, decoder.position()); - } - }; -} - -impl_test_unsigned_leb128!(test_u16_leb128, write_u16_leb128, read_u16_leb128, u16); -impl_test_unsigned_leb128!(test_u32_leb128, write_u32_leb128, read_u32_leb128, u32); -impl_test_unsigned_leb128!(test_u64_leb128, write_u64_leb128, read_u64_leb128, u64); -impl_test_unsigned_leb128!(test_u128_leb128, write_u128_leb128, read_u128_leb128, u128); -impl_test_unsigned_leb128!(test_usize_leb128, write_usize_leb128, read_usize_leb128, usize); - -macro_rules! impl_test_signed_leb128 { - ($test_name:ident, $write_fn_name:ident, $read_fn_name:ident, $int_ty:ident) => { - #[test] - fn $test_name() { - // Test 256 evenly spaced values of integer range, - // integer max value, and some "random" numbers. - let mut values = Vec::new(); - - let mut value = $int_ty::MIN; - let increment = (1 as $int_ty) << ($int_ty::BITS - 8); - - for _ in 0..256 { - values.push(value); - // The addition in the last loop iteration overflows. - value = value.wrapping_add(increment); - } - - values.push($int_ty::MAX); - - values.extend( - (-500..500).map(|i| (i as $int_ty).wrapping_mul(0x12345789ABCDEFi64 as $int_ty)), - ); - - let mut stream = Vec::new(); - - let mut buf = Default::default(); - for &x in &values { - let n = $write_fn_name(&mut buf, x); - stream.extend(&buf[..n]); - } - let stream_end = stream.len(); - stream.extend(MAGIC_END_BYTES); - - let mut decoder = MemDecoder::new(&stream, 0).unwrap(); - for &expected in &values { - let actual = $read_fn_name(&mut decoder); - assert_eq!(expected, actual); - } - assert_eq!(stream_end, decoder.position()); - } - }; -} - -impl_test_signed_leb128!(test_i16_leb128, write_i16_leb128, read_i16_leb128, i16); -impl_test_signed_leb128!(test_i32_leb128, write_i32_leb128, read_i32_leb128, i32); -impl_test_signed_leb128!(test_i64_leb128, write_i64_leb128, read_i64_leb128, i64); -impl_test_signed_leb128!(test_i128_leb128, write_i128_leb128, read_i128_leb128, i128); -impl_test_signed_leb128!(test_isize_leb128, write_isize_leb128, read_isize_leb128, isize); diff --git a/compiler/rustc_serialize/tests/opaque.rs b/compiler/rustc_serialize/tests/opaque.rs deleted file mode 100644 index 418c8ede50b..00000000000 --- a/compiler/rustc_serialize/tests/opaque.rs +++ /dev/null @@ -1,298 +0,0 @@ -#![allow(rustc::internal)] -// FIXME -#![allow(unused_crate_dependencies)] - -use std::fmt::Debug; -use std::fs; - -use rustc_macros::{Decodable_NoContext, Encodable_NoContext}; -use rustc_serialize::opaque::{FileEncoder, MemDecoder}; -use rustc_serialize::{Decodable, Encodable}; - -#[derive(PartialEq, Clone, Debug, Encodable_NoContext, Decodable_NoContext)] -struct Struct { - a: (), - b: u8, - c: u16, - d: u32, - e: u64, - f: usize, - - g: i8, - h: i16, - i: i32, - j: i64, - k: isize, - - l: char, - m: String, - p: bool, - q: Option, -} - -fn check_round_trip< - T: Encodable + for<'a> Decodable> + PartialEq + Debug, ->( - values: Vec, -) { - let tmpfile = tempfile::NamedTempFile::new().unwrap(); - let tmpfile = tmpfile.path(); - - let mut encoder = FileEncoder::new(&tmpfile).unwrap(); - for value in &values { - Encodable::encode(value, &mut encoder); - } - encoder.finish().unwrap(); - - let data = fs::read(&tmpfile).unwrap(); - let mut decoder = MemDecoder::new(&data[..], 0).unwrap(); - for value in values { - let decoded = Decodable::decode(&mut decoder); - assert_eq!(value, decoded); - } -} - -#[test] -fn test_unit() { - check_round_trip(vec![(), (), (), ()]); -} - -#[test] -fn test_u8() { - let mut vec = vec![]; - for i in u8::MIN..u8::MAX { - vec.push(i); - } - check_round_trip(vec); -} - -#[test] -fn test_u16() { - for i in [u16::MIN, 111, 3333, 55555, u16::MAX] { - check_round_trip(vec![1, 2, 3, i, i, i]); - } -} - -#[test] -fn test_u32() { - check_round_trip(vec![1, 2, 3, u32::MIN, 0, 1, u32::MAX, 2, 1]); -} - -#[test] -fn test_u64() { - check_round_trip(vec![1, 2, 3, u64::MIN, 0, 1, u64::MAX, 2, 1]); -} - -#[test] -fn test_usize() { - check_round_trip(vec![1, 2, 3, usize::MIN, 0, 1, usize::MAX, 2, 1]); -} - -#[test] -fn test_i8() { - let mut vec = vec![]; - for i in i8::MIN..i8::MAX { - vec.push(i); - } - check_round_trip(vec); -} - -#[test] -fn test_i16() { - for i in [i16::MIN, -100, 0, 101, i16::MAX] { - check_round_trip(vec![-1, 2, -3, i, i, i, 2]); - } -} - -#[test] -fn test_i32() { - check_round_trip(vec![-1, 2, -3, i32::MIN, 0, 1, i32::MAX, 2, 1]); -} - -#[test] -fn test_i64() { - check_round_trip(vec![-1, 2, -3, i64::MIN, 0, 1, i64::MAX, 2, 1]); -} - -#[test] -fn test_isize() { - check_round_trip(vec![-1, 2, -3, isize::MIN, 0, 1, isize::MAX, 2, 1]); -} - -#[test] -fn test_bool() { - check_round_trip(vec![false, true, true, false, false]); -} - -#[test] -fn test_char() { - let vec = vec!['a', 'b', 'c', 'd', 'A', 'X', ' ', '#', 'Ö', 'Ä', 'µ', '€']; - check_round_trip(vec); -} - -#[test] -fn test_string() { - let vec = vec![ - "abcbuÖeiovÄnameÜavmpßvmea€µsbpnvapeapmaebn".to_string(), - "abcbuÖganeiovÄnameÜavmpßvmea€µsbpnvapeapmaebn".to_string(), - "abcbuÖganeiovÄnameÜavmpßvmea€µsbpapmaebn".to_string(), - "abcbuÖganeiovÄnameÜavmpßvmeabpnvapeapmaebn".to_string(), - "abcbuÖganeiÄnameÜavmpßvmea€µsbpnvapeapmaebn".to_string(), - "abcbuÖganeiovÄnameÜavmpßvmea€µsbpmaebn".to_string(), - "abcbuÖganeiovÄnameÜavmpßvmea€µnvapeapmaebn".to_string(), - ]; - - check_round_trip(vec); -} - -#[test] -fn test_option() { - check_round_trip(vec![Some(-1i8)]); - check_round_trip(vec![Some(-2i16)]); - check_round_trip(vec![Some(-3i32)]); - check_round_trip(vec![Some(-4i64)]); - check_round_trip(vec![Some(-5isize)]); - - let none_i8: Option = None; - check_round_trip(vec![none_i8]); - - let none_i16: Option = None; - check_round_trip(vec![none_i16]); - - let none_i32: Option = None; - check_round_trip(vec![none_i32]); - - let none_i64: Option = None; - check_round_trip(vec![none_i64]); - - let none_isize: Option = None; - check_round_trip(vec![none_isize]); -} - -#[test] -fn test_struct() { - check_round_trip(vec![Struct { - a: (), - b: 10, - c: 11, - d: 12, - e: 13, - f: 14, - - g: 15, - h: 16, - i: 17, - j: 18, - k: 19, - - l: 'x', - m: "abc".to_string(), - p: false, - q: None, - }]); - - check_round_trip(vec![Struct { - a: (), - b: 101, - c: 111, - d: 121, - e: 131, - f: 141, - - g: -15, - h: -16, - i: -17, - j: -18, - k: -19, - - l: 'y', - m: "def".to_string(), - p: true, - q: Some(1234567), - }]); -} - -#[derive(PartialEq, Clone, Debug, Encodable_NoContext, Decodable_NoContext)] -enum Enum { - Variant1, - Variant2(usize, u32), - Variant3 { a: i32, b: char, c: bool }, -} - -#[test] -fn test_enum() { - check_round_trip(vec![ - Enum::Variant1, - Enum::Variant2(1, 25), - Enum::Variant3 { a: 3, b: 'b', c: false }, - Enum::Variant3 { a: -4, b: 'f', c: true }, - ]); -} - -#[test] -fn test_sequence() { - let mut vec = vec![]; - for i in -100i64..100i64 { - vec.push(i * 100000); - } - - check_round_trip(vec![vec]); -} - -#[test] -fn test_hash_map() { - use std::collections::HashMap; - let mut map = HashMap::new(); - for i in -100i64..100i64 { - map.insert(i * 100000, i * 10000); - } - - check_round_trip(vec![map]); -} - -#[test] -fn test_tuples() { - check_round_trip(vec![('x', (), false, 5u32)]); - check_round_trip(vec![(9i8, 10u16, 15i64)]); - check_round_trip(vec![(-12i16, 11u8, 12usize)]); - check_round_trip(vec![(1234567isize, 100000000000000u64, 99999999999999i64)]); - check_round_trip(vec![(String::new(), "some string".to_string())]); -} - -#[test] -fn test_unit_like_struct() { - #[derive(Encodable_NoContext, Decodable_NoContext, PartialEq, Debug)] - struct UnitLikeStruct; - - check_round_trip(vec![UnitLikeStruct]); -} - -#[test] -fn test_box() { - #[derive(Encodable_NoContext, Decodable_NoContext, PartialEq, Debug)] - struct A { - foo: Box<[bool]>, - } - - let obj = A { foo: Box::new([true, false]) }; - check_round_trip(vec![obj]); -} - -#[test] -fn test_cell() { - use std::cell::{Cell, RefCell}; - - #[derive(Encodable_NoContext, Decodable_NoContext, PartialEq, Debug)] - struct A { - baz: isize, - } - - #[derive(Encodable_NoContext, Decodable_NoContext, PartialEq, Debug)] - struct B { - foo: Cell, - bar: RefCell, - } - - let obj = B { foo: Cell::new(true), bar: RefCell::new(A { baz: 2 }) }; - check_round_trip(vec![obj]); -} -- cgit 1.4.1-3-g733a5