From e843ccdb9064b9b753da5b839363b3ebb371f383 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Tue, 9 Mar 2021 19:58:36 +0100 Subject: [PATCH] ruma-api: Force client and server Cargo features to always be on --- ruma-api/Cargo.toml | 5 +++-- ruma-api/src/lib.rs | 3 +++ ruma-api/tests/conversions.rs | 1 - ruma-api/tests/header_override.rs | 2 -- ruma-api/tests/no_fields.rs | 2 -- 5 files changed, 6 insertions(+), 7 deletions(-) diff --git a/ruma-api/Cargo.toml b/ruma-api/Cargo.toml index 11087bee..f978eec6 100644 --- a/ruma-api/Cargo.toml +++ b/ruma-api/Cargo.toml @@ -32,8 +32,9 @@ thiserror = "1.0.23" ruma-events = { version = "=0.22.0-alpha.2", path = "../ruma-events" } trybuild = "1.0.38" -# These feature gates exist as a workaround to pass tests. -# Any crate that invokes the `ruma-api!` macro should include these features. +# These feature gates exist only for the tests. Disabling them results in a +# compile error. [features] +default = ["client", "server"] client = [] server = [] diff --git a/ruma-api/src/lib.rs b/ruma-api/src/lib.rs index 4abd2e05..64d7f5e7 100644 --- a/ruma-api/src/lib.rs +++ b/ruma-api/src/lib.rs @@ -14,6 +14,9 @@ #![warn(rust_2018_idioms)] #![deny(missing_copy_implementations, missing_debug_implementations, missing_docs)] +#[cfg(not(all(feature = "client", feature = "server")))] +compile_error!("ruma_api's Cargo features only exist as a workaround are not meant to be disabled"); + use std::{ convert::{TryFrom, TryInto}, error::Error as StdError, diff --git a/ruma-api/tests/conversions.rs b/ruma-api/tests/conversions.rs index da4ae27b..69e6307f 100644 --- a/ruma-api/tests/conversions.rs +++ b/ruma-api/tests/conversions.rs @@ -34,7 +34,6 @@ ruma_api! { } } -#[cfg(all(feature = "client", feature = "server"))] #[test] fn request_serde() -> Result<(), Box> { let req = Request { diff --git a/ruma-api/tests/header_override.rs b/ruma-api/tests/header_override.rs index d55b4efa..b96b8a07 100644 --- a/ruma-api/tests/header_override.rs +++ b/ruma-api/tests/header_override.rs @@ -27,7 +27,6 @@ ruma_api! { } } -#[cfg(all(feature = "client", feature = "server"))] #[test] fn response_content_type_override() { let res = Response { stuff: "magic".into() }; @@ -45,7 +44,6 @@ fn response_content_type_override() { assert_eq!(http_res.headers().get("content-type").unwrap(), "magic"); } -#[cfg(feature = "client")] #[test] fn request_content_type_override() { let req = Request { location: None, stuff: "magic".into() }; diff --git a/ruma-api/tests/no_fields.rs b/ruma-api/tests/no_fields.rs index fd9b831c..f09a85bb 100644 --- a/ruma-api/tests/no_fields.rs +++ b/ruma-api/tests/no_fields.rs @@ -16,7 +16,6 @@ ruma_api! { response: {} } -#[cfg(feature = "client")] #[test] fn empty_request_http_repr() { let req = Request {}; @@ -25,7 +24,6 @@ fn empty_request_http_repr() { assert!(http_req.body().is_empty()); } -#[cfg(feature = "server")] #[test] fn empty_response_http_repr() { let res = Response {};