diff --git a/Cargo.toml b/Cargo.toml index 77ed145ef..89012be02 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,6 +14,7 @@ categories = ["development-tools::debugging"] keywords = ["logging"] exclude = ["rfcs/**/*"] rust-version = "1.60.0" +edition = "2021" [package.metadata.docs.rs] features = ["std", "serde", "kv_unstable_std", "kv_unstable_sval", "kv_unstable_serde"] diff --git a/benches/value.rs b/benches/value.rs index 4e6960e80..70d466f1c 100644 --- a/benches/value.rs +++ b/benches/value.rs @@ -1,9 +1,6 @@ #![cfg(feature = "kv_unstable")] #![feature(test)] -extern crate log; -extern crate test; - use log::kv::Value; #[bench] diff --git a/src/kv/key.rs b/src/kv/key.rs index 4f9a506ec..971c866b9 100644 --- a/src/kv/key.rs +++ b/src/kv/key.rs @@ -103,11 +103,8 @@ mod std_support { mod sval_support { use super::*; - extern crate sval; - extern crate sval_ref; - - use self::sval::Value; - use self::sval_ref::ValueRef; + use sval::Value; + use sval_ref::ValueRef; impl<'a> Value for Key<'a> { fn stream<'sval, S: sval::Stream<'sval> + ?Sized>( @@ -119,10 +116,7 @@ mod sval_support { } impl<'a> ValueRef<'a> for Key<'a> { - fn stream_ref + ?Sized>( - &self, - stream: &mut S, - ) -> self::sval::Result { + fn stream_ref + ?Sized>(&self, stream: &mut S) -> sval::Result { self.key.stream(stream) } } @@ -132,9 +126,7 @@ mod sval_support { mod serde_support { use super::*; - extern crate serde; - - use self::serde::{Serialize, Serializer}; + use serde::{Serialize, Serializer}; impl<'a> Serialize for Key<'a> { fn serialize(&self, serializer: S) -> Result diff --git a/src/kv/source.rs b/src/kv/source.rs index 45fc6dce4..eb5e4a484 100644 --- a/src/kv/source.rs +++ b/src/kv/source.rs @@ -1,14 +1,6 @@ //! Sources for key-value pairs. -#[cfg(feature = "kv_unstable_sval")] -extern crate sval; -#[cfg(feature = "kv_unstable_sval")] -extern crate sval_ref; - -#[cfg(feature = "kv_unstable_serde")] -extern crate serde; - -use kv::{Error, Key, ToKey, ToValue, Value}; +use crate::kv::{Error, Key, ToKey, ToValue, Value}; use std::fmt; /// A source of key-value pairs. @@ -64,7 +56,7 @@ pub trait Source { fn count(&self) -> usize; } -/// The default implemention of `Source::get` +/// The default implementation of `Source::get` pub(crate) fn get_default<'v>(source: &'v (impl Source + ?Sized), key: Key) -> Option> { struct Get<'k, 'v> { key: Key<'k>, @@ -319,7 +311,7 @@ mod std_support { Ok(()) } - fn get<'v>(&'v self, key: Key) -> Option> { + fn get(&self, key: Key) -> Option> { BTreeMap::get(self, key.as_str()).map(|v| v.to_value()) } @@ -330,10 +322,12 @@ mod std_support { #[cfg(test)] mod tests { - use super::*; - use kv::value::tests::Token; use std::collections::{BTreeMap, HashMap}; + use crate::kv::value::tests::Token; + + use super::*; + #[test] fn count() { assert_eq!(1, Source::count(&Box::new(("a", 1)))); @@ -462,17 +456,17 @@ where mod sval_support { use super::*; - impl self::sval::Value for AsMap + impl sval::Value for AsMap where S: Source, { - fn stream<'sval, SV: self::sval::Stream<'sval> + ?Sized>( + fn stream<'sval, SV: sval::Stream<'sval> + ?Sized>( &'sval self, stream: &mut SV, - ) -> self::sval::Result { + ) -> sval::Result { struct StreamVisitor<'a, V: ?Sized>(&'a mut V); - impl<'a, 'kvs, V: self::sval::Stream<'kvs> + ?Sized> Visitor<'kvs> for StreamVisitor<'a, V> { + impl<'a, 'kvs, V: sval::Stream<'kvs> + ?Sized> Visitor<'kvs> for StreamVisitor<'a, V> { fn visit_pair(&mut self, key: Key<'kvs>, value: Value<'kvs>) -> Result<(), Error> { self.0 .map_key_begin() @@ -498,31 +492,31 @@ mod sval_support { stream .map_begin(Some(self.count())) - .map_err(|_| self::sval::Error::new())?; + .map_err(|_| sval::Error::new())?; self.visit(&mut StreamVisitor(stream)) - .map_err(|_| self::sval::Error::new())?; + .map_err(|_| sval::Error::new())?; - stream.map_end().map_err(|_| self::sval::Error::new()) + stream.map_end().map_err(|_| sval::Error::new()) } } - impl self::sval::Value for AsList + impl sval::Value for AsList where S: Source, { - fn stream<'sval, SV: self::sval::Stream<'sval> + ?Sized>( + fn stream<'sval, SV: sval::Stream<'sval> + ?Sized>( &'sval self, stream: &mut SV, - ) -> self::sval::Result { + ) -> sval::Result { struct StreamVisitor<'a, V: ?Sized>(&'a mut V); - impl<'a, 'kvs, V: self::sval::Stream<'kvs> + ?Sized> Visitor<'kvs> for StreamVisitor<'a, V> { + impl<'a, 'kvs, V: sval::Stream<'kvs> + ?Sized> Visitor<'kvs> for StreamVisitor<'a, V> { fn visit_pair(&mut self, key: Key<'kvs>, value: Value<'kvs>) -> Result<(), Error> { self.0 .seq_value_begin() .map_err(|_| Error::msg("failed to stream seq value"))?; - self::sval_ref::stream_ref(self.0, (key, value)) + sval_ref::stream_ref(self.0, (key, value)) .map_err(|_| Error::msg("failed to stream seq value"))?; self.0 .seq_value_end() @@ -534,24 +528,20 @@ mod sval_support { stream .seq_begin(Some(self.count())) - .map_err(|_| self::sval::Error::new())?; + .map_err(|_| sval::Error::new())?; self.visit(&mut StreamVisitor(stream)) - .map_err(|_| self::sval::Error::new())?; + .map_err(|_| sval::Error::new())?; - stream.seq_end().map_err(|_| self::sval::Error::new()) + stream.seq_end().map_err(|_| sval::Error::new()) } } #[cfg(test)] mod tests { - extern crate sval_derive; - use super::*; - - use self::sval_derive::Value; - use crate::kv::source; + use sval_derive::Value; #[test] fn derive_stream() { @@ -575,8 +565,7 @@ pub mod as_map { //! `serde` adapters for serializing a `Source` as a map. use super::*; - - use self::serde::{Serialize, Serializer}; + use serde::{Serialize, Serializer}; /// Serialize a `Source` as a map. pub fn serialize(source: &T, serializer: S) -> Result @@ -593,8 +582,7 @@ pub mod as_list { //! `serde` adapters for serializing a `Source` as a list. use super::*; - - use self::serde::{Serialize, Serializer}; + use serde::{Serialize, Serializer}; /// Serialize a `Source` as a list. pub fn serialize(source: &T, serializer: S) -> Result @@ -609,8 +597,7 @@ pub mod as_list { #[cfg(feature = "kv_unstable_serde")] mod serde_support { use super::*; - - use self::serde::ser::{Error as SerError, Serialize, SerializeMap, SerializeSeq, Serializer}; + use serde::ser::{Error as SerError, Serialize, SerializeMap, SerializeSeq, Serializer}; impl Serialize for AsMap where @@ -677,10 +664,8 @@ mod serde_support { #[cfg(test)] mod tests { use super::*; - - use self::serde::Serialize; - use crate::kv::source; + use serde::Serialize; #[test] fn derive_serialize() { @@ -705,8 +690,9 @@ mod serde_support { #[cfg(test)] mod tests { + use crate::kv::value::tests::Token; + use super::*; - use kv::value::tests::Token; #[test] fn source_is_object_safe() { diff --git a/src/kv/value.rs b/src/kv/value.rs index 9485d485b..ee40eaf62 100644 --- a/src/kv/value.rs +++ b/src/kv/value.rs @@ -2,19 +2,9 @@ use std::fmt; -extern crate value_bag; +pub use crate::kv::Error; -#[cfg(feature = "kv_unstable_sval")] -extern crate sval; -#[cfg(feature = "kv_unstable_sval")] -extern crate sval_ref; - -#[cfg(feature = "kv_unstable_serde")] -extern crate serde; - -use self::value_bag::ValueBag; - -pub use kv::Error; +use value_bag::ValueBag; /// A type that can be converted into a [`Value`](struct.Value.html). pub trait ToValue { @@ -199,7 +189,7 @@ impl<'v> Value<'v> { /// Get a value from a type implementing `serde::Serialize`. pub fn capture_serde(value: &'v T) -> Self where - T: self::serde::Serialize + 'static, + T: serde::Serialize + 'static, { Value { inner: ValueBag::capture_serde1(value), @@ -210,7 +200,7 @@ impl<'v> Value<'v> { #[cfg(feature = "kv_unstable_sval")] pub fn capture_sval(value: &'v T) -> Self where - T: self::sval::Value + 'static, + T: sval::Value + 'static, { Value { inner: ValueBag::capture_sval2(value), @@ -241,7 +231,7 @@ impl<'v> Value<'v> { #[cfg(feature = "kv_unstable_serde")] pub fn from_serde(value: &'v T) -> Self where - T: self::serde::Serialize, + T: serde::Serialize, { Value { inner: ValueBag::from_serde1(value), @@ -252,7 +242,7 @@ impl<'v> Value<'v> { #[cfg(feature = "kv_unstable_sval")] pub fn from_sval(value: &'v T) -> Self where - T: self::sval::Value, + T: sval::Value, { Value { inner: ValueBag::from_sval2(value), @@ -406,29 +396,26 @@ impl ToValue for dyn std::error::Error + 'static { } #[cfg(feature = "kv_unstable_serde")] -impl<'v> self::serde::Serialize for Value<'v> { +impl<'v> serde::Serialize for Value<'v> { fn serialize(&self, s: S) -> Result where - S: self::serde::Serializer, + S: serde::Serializer, { self.inner.serialize(s) } } #[cfg(feature = "kv_unstable_sval")] -impl<'v> self::sval::Value for Value<'v> { - fn stream<'sval, S: self::sval::Stream<'sval> + ?Sized>( - &'sval self, - stream: &mut S, - ) -> self::sval::Result { - self::sval::Value::stream(&self.inner, stream) +impl<'v> sval::Value for Value<'v> { + fn stream<'sval, S: sval::Stream<'sval> + ?Sized>(&'sval self, stream: &mut S) -> sval::Result { + sval::Value::stream(&self.inner, stream) } } #[cfg(feature = "kv_unstable_sval")] -impl<'v> self::sval_ref::ValueRef<'v> for Value<'v> { - fn stream_ref + ?Sized>(&self, stream: &mut S) -> self::sval::Result { - self::sval_ref::ValueRef::stream_ref(&self.inner, stream) +impl<'v> sval_ref::ValueRef<'v> for Value<'v> { + fn stream_ref + ?Sized>(&self, stream: &mut S) -> sval::Result { + sval_ref::ValueRef::stream_ref(&self.inner, stream) } } @@ -601,10 +588,10 @@ impl<'v> Value<'v> { #[cfg(feature = "kv_unstable_std")] mod std_support { - use super::*; - use std::borrow::Cow; + use super::*; + impl ToValue for Box where T: ToValue + ?Sized, @@ -773,8 +760,7 @@ where #[cfg(test)] pub(crate) mod tests { use super::*; - - pub(crate) use super::value_bag::test::TestToken as Token; + pub(crate) use value_bag::test::TestToken as Token; impl<'v> Value<'v> { pub(crate) fn to_token(&self) -> Token { diff --git a/src/lib.rs b/src/lib.rs index ab5cdfa4a..0e2622cd0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -334,12 +334,10 @@ #[cfg(all(not(feature = "std"), not(test)))] extern crate core as std; -use std::cmp; #[cfg(feature = "std")] use std::error; -use std::fmt; -use std::mem; use std::str::FromStr; +use std::{cmp, fmt, mem}; #[macro_use] mod macros; @@ -1537,9 +1535,7 @@ const fn get_max_level_inner() -> LevelFilter { #[cfg(test)] mod tests { - extern crate std; use super::{Level, LevelFilter, ParseLevelError}; - use tests::std::string::ToString; #[test] fn test_levelfilter_from_str() { @@ -1748,7 +1744,7 @@ mod tests { #[cfg(feature = "kv_unstable")] fn test_record_key_values_builder() { use super::Record; - use kv::{self, Visitor}; + use crate::kv::{self, Visitor}; struct TestVisitor { seen_pairs: usize, diff --git a/src/serde.rs b/src/serde.rs index 50128330f..e0ed8c219 100644 --- a/src/serde.rs +++ b/src/serde.rs @@ -1,13 +1,12 @@ #![cfg(feature = "serde")] -extern crate serde; -use self::serde::de::{ +use serde::de::{ Deserialize, DeserializeSeed, Deserializer, EnumAccess, Error, Unexpected, VariantAccess, Visitor, }; -use self::serde::ser::{Serialize, Serializer}; +use serde::ser::{Serialize, Serializer}; -use {Level, LevelFilter, LOG_LEVEL_NAMES}; +use crate::{Level, LevelFilter, LOG_LEVEL_NAMES}; use std::fmt; use std::str::{self, FromStr}; @@ -205,10 +204,8 @@ impl<'de> Deserialize<'de> for LevelFilter { #[cfg(test)] mod tests { - extern crate serde_test; - use self::serde_test::{assert_de_tokens, assert_de_tokens_error, assert_tokens, Token}; - - use {Level, LevelFilter}; + use crate::{Level, LevelFilter}; + use serde_test::{assert_de_tokens, assert_de_tokens_error, assert_tokens, Token}; fn level_token(variant: &'static str) -> Token { Token::UnitVariant { @@ -262,7 +259,7 @@ mod tests { #[test] fn test_level_ser_de() { - let cases = [ + let cases = &[ (Level::Error, [level_token("ERROR")]), (Level::Warn, [level_token("WARN")]), (Level::Info, [level_token("INFO")]), @@ -270,14 +267,14 @@ mod tests { (Level::Trace, [level_token("TRACE")]), ]; - for &(s, expected) in &cases { - assert_tokens(&s, &expected); + for (s, expected) in cases { + assert_tokens(s, expected); } } #[test] fn test_level_case_insensitive() { - let cases = [ + let cases = &[ (Level::Error, [level_token("error")]), (Level::Warn, [level_token("warn")]), (Level::Info, [level_token("info")]), @@ -285,14 +282,14 @@ mod tests { (Level::Trace, [level_token("trace")]), ]; - for &(s, expected) in &cases { - assert_de_tokens(&s, &expected); + for (s, expected) in cases { + assert_de_tokens(s, expected); } } #[test] fn test_level_de_bytes() { - let cases = [ + let cases = &[ (Level::Error, level_bytes_tokens(b"ERROR")), (Level::Warn, level_bytes_tokens(b"WARN")), (Level::Info, level_bytes_tokens(b"INFO")), @@ -300,14 +297,14 @@ mod tests { (Level::Trace, level_bytes_tokens(b"TRACE")), ]; - for &(value, tokens) in &cases { - assert_de_tokens(&value, &tokens); + for (value, tokens) in cases { + assert_de_tokens(value, tokens); } } #[test] fn test_level_de_variant_index() { - let cases = [ + let cases = &[ (Level::Error, level_variant_tokens(0)), (Level::Warn, level_variant_tokens(1)), (Level::Info, level_variant_tokens(2)), @@ -315,8 +312,8 @@ mod tests { (Level::Trace, level_variant_tokens(4)), ]; - for &(value, tokens) in &cases { - assert_de_tokens(&value, &tokens); + for (value, tokens) in cases { + assert_de_tokens(value, tokens); } } @@ -329,7 +326,7 @@ mod tests { #[test] fn test_level_filter_ser_de() { - let cases = [ + let cases = &[ (LevelFilter::Off, [level_filter_token("OFF")]), (LevelFilter::Error, [level_filter_token("ERROR")]), (LevelFilter::Warn, [level_filter_token("WARN")]), @@ -338,14 +335,14 @@ mod tests { (LevelFilter::Trace, [level_filter_token("TRACE")]), ]; - for &(s, expected) in &cases { - assert_tokens(&s, &expected); + for (s, expected) in cases { + assert_tokens(s, expected); } } #[test] fn test_level_filter_case_insensitive() { - let cases = [ + let cases = &[ (LevelFilter::Off, [level_filter_token("off")]), (LevelFilter::Error, [level_filter_token("error")]), (LevelFilter::Warn, [level_filter_token("warn")]), @@ -354,14 +351,14 @@ mod tests { (LevelFilter::Trace, [level_filter_token("trace")]), ]; - for &(s, expected) in &cases { - assert_de_tokens(&s, &expected); + for (s, expected) in cases { + assert_de_tokens(s, expected); } } #[test] fn test_level_filter_de_bytes() { - let cases = [ + let cases = &[ (LevelFilter::Off, level_filter_bytes_tokens(b"OFF")), (LevelFilter::Error, level_filter_bytes_tokens(b"ERROR")), (LevelFilter::Warn, level_filter_bytes_tokens(b"WARN")), @@ -370,14 +367,14 @@ mod tests { (LevelFilter::Trace, level_filter_bytes_tokens(b"TRACE")), ]; - for &(value, tokens) in &cases { - assert_de_tokens(&value, &tokens); + for (value, tokens) in cases { + assert_de_tokens(value, tokens); } } #[test] fn test_level_filter_de_variant_index() { - let cases = [ + let cases = &[ (LevelFilter::Off, level_filter_variant_tokens(0)), (LevelFilter::Error, level_filter_variant_tokens(1)), (LevelFilter::Warn, level_filter_variant_tokens(2)), @@ -386,8 +383,8 @@ mod tests { (LevelFilter::Trace, level_filter_variant_tokens(5)), ]; - for &(value, tokens) in &cases { - assert_de_tokens(&value, &tokens); + for (value, tokens) in cases { + assert_de_tokens(value, tokens); } } diff --git a/test_max_level_features/Cargo.toml b/test_max_level_features/Cargo.toml index 9d0b9759b..ae23058f9 100644 --- a/test_max_level_features/Cargo.toml +++ b/test_max_level_features/Cargo.toml @@ -1,6 +1,7 @@ [package] name = "optimized" version = "0.1.0" +edition = "2021" publish = false [[bin]] diff --git a/test_max_level_features/main.rs b/test_max_level_features/main.rs index bfbf2b247..1c894ad21 100644 --- a/test_max_level_features/main.rs +++ b/test_max_level_features/main.rs @@ -7,7 +7,7 @@ use log::{Level, LevelFilter, Log, Record, Metadata}; #[cfg(feature = "std")] use log::set_boxed_logger; #[cfg(not(feature = "std"))] -fn set_boxed_logger(logger: Box) -> Result<(), log::SetLoggerError> { +fn set_boxed_logger(logger: Box) -> Result<(), log::SetLoggerError> { log::set_logger(Box::leak(logger)) } diff --git a/tests/Cargo.toml b/tests/Cargo.toml index 25ac12bec..88f37b5d4 100644 --- a/tests/Cargo.toml +++ b/tests/Cargo.toml @@ -1,6 +1,7 @@ [package] name = "integration" version = "0.1.0" +edition = "2021" publish = false build = "src/build.rs"