From 0d29ec1cb91e2c7ef97004aa1c558212b372201e Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Fri, 29 May 2020 21:38:14 -0700 Subject: [PATCH 1/7] Update to 2018 edition --- Cargo.toml | 1 + src/buffer/mod.rs | 2 +- src/d2s.rs | 8 ++++---- src/d2s_small_table.rs | 4 ++-- src/f2s.rs | 2 +- src/lib.rs | 4 ++-- src/pretty/exponent.rs | 2 +- src/pretty/mantissa.rs | 2 +- src/pretty/mod.rs | 8 ++++---- 9 files changed, 17 insertions(+), 16 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8af8867..856fe8c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,6 +8,7 @@ repository = "https://github.com/dtolnay/ryu" documentation = "https://docs.rs/ryu" readme = "README.md" build = "build.rs" +edition = "2018" [features] # Use smaller lookup tables. Instead of storing every required power of diff --git a/src/buffer/mod.rs b/src/buffer/mod.rs index d524de6..bfc0ebe 100644 --- a/src/buffer/mod.rs +++ b/src/buffer/mod.rs @@ -3,7 +3,7 @@ use core::{mem, slice, str}; #[cfg(maybe_uninit)] use core::mem::MaybeUninit; -use raw; +use crate::raw; #[cfg(feature = "no-panic")] use no_panic::no_panic; diff --git a/src/d2s.rs b/src/d2s.rs index cebef96..9137b35 100644 --- a/src/d2s.rs +++ b/src/d2s.rs @@ -26,12 +26,12 @@ use core::mem::MaybeUninit; #[cfg(not(maybe_uninit))] use core::mem; -use common::*; +use crate::common::*; #[cfg(not(feature = "small"))] -use d2s_full_table::*; -use d2s_intrinsics::*; +use crate::d2s_full_table::*; +use crate::d2s_intrinsics::*; #[cfg(feature = "small")] -use d2s_small_table::*; +use crate::d2s_small_table::*; pub const DOUBLE_MANTISSA_BITS: u32 = 52; pub const DOUBLE_EXPONENT_BITS: u32 = 11; diff --git a/src/d2s_small_table.rs b/src/d2s_small_table.rs index fc4a1a2..c6f0973 100644 --- a/src/d2s_small_table.rs +++ b/src/d2s_small_table.rs @@ -18,9 +18,9 @@ // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. -use common::*; +use crate::common::*; #[cfg(not(integer128))] -use d2s_intrinsics::*; +use crate::d2s_intrinsics::*; pub static DOUBLE_POW5_TABLE: [u64; 26] = [ 1, diff --git a/src/f2s.rs b/src/f2s.rs index 4ad50a1..0633e8e 100644 --- a/src/f2s.rs +++ b/src/f2s.rs @@ -18,7 +18,7 @@ // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. -use common::*; +use crate::common::*; pub const FLOAT_MANTISSA_BITS: u32 = 23; pub const FLOAT_EXPONENT_BITS: u32 = 8; diff --git a/src/lib.rs b/src/lib.rs index f7fddb2..1b0fce7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -103,9 +103,9 @@ mod digit_table; mod f2s; mod pretty; -pub use buffer::{Buffer, Float}; +pub use crate::buffer::{Buffer, Float}; /// Unsafe functions that mirror the API of the C implementation of Ryū. pub mod raw { - pub use pretty::{format32, format64}; + pub use crate::pretty::{format32, format64}; } diff --git a/src/pretty/exponent.rs b/src/pretty/exponent.rs index f10643f..9d52f40 100644 --- a/src/pretty/exponent.rs +++ b/src/pretty/exponent.rs @@ -1,6 +1,6 @@ use core::ptr; -use digit_table::*; +use crate::digit_table::*; #[cfg_attr(feature = "no-panic", inline)] pub unsafe fn write_exponent3(mut k: isize, mut result: *mut u8) -> usize { diff --git a/src/pretty/mantissa.rs b/src/pretty/mantissa.rs index 4280232..186afa0 100644 --- a/src/pretty/mantissa.rs +++ b/src/pretty/mantissa.rs @@ -1,6 +1,6 @@ use core::ptr; -use digit_table::*; +use crate::digit_table::*; #[cfg_attr(feature = "no-panic", inline)] pub unsafe fn write_mantissa_long(mut output: u64, mut result: *mut u8) { diff --git a/src/pretty/mod.rs b/src/pretty/mod.rs index 1e51343..530d8c6 100644 --- a/src/pretty/mod.rs +++ b/src/pretty/mod.rs @@ -5,10 +5,10 @@ use core::{mem, ptr}; use self::exponent::*; use self::mantissa::*; -use common; -use d2s; -use d2s::*; -use f2s::*; +use crate::common; +use crate::d2s; +use crate::d2s::*; +use crate::f2s::*; #[cfg(feature = "no-panic")] use no_panic::no_panic; From b77ef45497f297a3dcbb2ae199df1e491620697c Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Fri, 29 May 2020 21:44:08 -0700 Subject: [PATCH 2/7] Organize imports --- src/buffer/mod.rs | 7 ++----- src/d2s.rs | 13 +++++-------- src/pretty/exponent.rs | 3 +-- src/pretty/mantissa.rs | 3 +-- src/pretty/mod.rs | 7 ++----- 5 files changed, 11 insertions(+), 22 deletions(-) diff --git a/src/buffer/mod.rs b/src/buffer/mod.rs index bfc0ebe..550bf35 100644 --- a/src/buffer/mod.rs +++ b/src/buffer/mod.rs @@ -1,10 +1,7 @@ -use core::{mem, slice, str}; - +use crate::raw; #[cfg(maybe_uninit)] use core::mem::MaybeUninit; - -use crate::raw; - +use core::{mem, slice, str}; #[cfg(feature = "no-panic")] use no_panic::no_panic; diff --git a/src/d2s.rs b/src/d2s.rs index 9137b35..213860f 100644 --- a/src/d2s.rs +++ b/src/d2s.rs @@ -18,20 +18,17 @@ // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. -use core::ptr; - -#[cfg(maybe_uninit)] -use core::mem::MaybeUninit; - -#[cfg(not(maybe_uninit))] -use core::mem; - use crate::common::*; #[cfg(not(feature = "small"))] use crate::d2s_full_table::*; use crate::d2s_intrinsics::*; #[cfg(feature = "small")] use crate::d2s_small_table::*; +#[cfg(not(maybe_uninit))] +use core::mem; +#[cfg(maybe_uninit)] +use core::mem::MaybeUninit; +use core::ptr; pub const DOUBLE_MANTISSA_BITS: u32 = 52; pub const DOUBLE_EXPONENT_BITS: u32 = 11; diff --git a/src/pretty/exponent.rs b/src/pretty/exponent.rs index 9d52f40..84053d5 100644 --- a/src/pretty/exponent.rs +++ b/src/pretty/exponent.rs @@ -1,6 +1,5 @@ -use core::ptr; - use crate::digit_table::*; +use core::ptr; #[cfg_attr(feature = "no-panic", inline)] pub unsafe fn write_exponent3(mut k: isize, mut result: *mut u8) -> usize { diff --git a/src/pretty/mantissa.rs b/src/pretty/mantissa.rs index 186afa0..e5fc202 100644 --- a/src/pretty/mantissa.rs +++ b/src/pretty/mantissa.rs @@ -1,6 +1,5 @@ -use core::ptr; - use crate::digit_table::*; +use core::ptr; #[cfg_attr(feature = "no-panic", inline)] pub unsafe fn write_mantissa_long(mut output: u64, mut result: *mut u8) { diff --git a/src/pretty/mod.rs b/src/pretty/mod.rs index 530d8c6..930025d 100644 --- a/src/pretty/mod.rs +++ b/src/pretty/mod.rs @@ -1,15 +1,12 @@ mod exponent; mod mantissa; -use core::{mem, ptr}; - use self::exponent::*; use self::mantissa::*; use crate::common; -use crate::d2s; -use crate::d2s::*; +use crate::d2s::{self, *}; use crate::f2s::*; - +use core::{mem, ptr}; #[cfg(feature = "no-panic")] use no_panic::no_panic; From ebc78a39ab433580f503b12c79816082b4ba5e9d Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Fri, 29 May 2020 21:46:03 -0700 Subject: [PATCH 3/7] Raise minimum supported compiler to 1.31 --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 93896e7..ea91ef1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,11 +23,11 @@ jobs: if: matrix.rust == 'nightly' msrv: - name: Rust 1.15.0 + name: Rust 1.31.0 runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - uses: dtolnay/rust-toolchain@1.15.0 + - uses: dtolnay/rust-toolchain@1.31.0 - run: cargo build - run: cargo build --features small From b721d7e834de29888d36caf6bc3f5e25cb7edef2 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Fri, 29 May 2020 21:46:17 -0700 Subject: [PATCH 4/7] Document compiler version support --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e990313..44ec366 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ [![Build Status](https://img.shields.io/github/workflow/status/dtolnay/ryu/CI/master)](https://github.com/dtolnay/ryu/actions?query=branch%3Amaster) [![Latest Version](https://img.shields.io/crates/v/ryu.svg)](https://crates.io/crates/ryu) [![Rust Documentation](https://img.shields.io/badge/api-rustdoc-blue.svg)](https://docs.rs/ryu) -[![Rustc Version 1.15+](https://img.shields.io/badge/rustc-1.15+-lightgray.svg)](https://blog.rust-lang.org/2017/02/02/Rust-1.15.html) +[![Rustc Version 1.31+](https://img.shields.io/badge/rustc-1.31+-lightgray.svg)](https://blog.rust-lang.org/2018/12/06/Rust-1.31-and-rust-2018.html) Pure Rust implementation of Ryū, an algorithm to quickly convert floating point numbers to decimal strings. @@ -15,7 +15,7 @@ under the creative commons CC-BY-SA license. This Rust implementation is a line-by-line port of Ulf Adams' implementation in C, [https://github.com/ulfjack/ryu][upstream]. -*Requirements: this crate supports any compiler version back to rustc 1.15; it +*Requirements: this crate supports any compiler version back to rustc 1.31; it uses nothing from the Rust standard library so is usable from no_std crates.* [paper]: https://dl.acm.org/citation.cfm?id=3192369 From 59383f3e2de969e532e53e04dac35b6ce46e0e55 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Fri, 29 May 2020 21:46:55 -0700 Subject: [PATCH 5/7] Remove edition override from doc tests --- src/buffer/mod.rs | 2 +- src/lib.rs | 2 +- src/pretty/mod.rs | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/buffer/mod.rs b/src/buffer/mod.rs index 550bf35..df21fe0 100644 --- a/src/buffer/mod.rs +++ b/src/buffer/mod.rs @@ -13,7 +13,7 @@ const NEG_INFINITY: &'static str = "-inf"; /// /// ## Example /// -/// ```edition2018 +/// ``` /// let mut buffer = ryu::Buffer::new(); /// let printed = buffer.format_finite(1.234); /// assert_eq!(printed, "1.234"); diff --git a/src/lib.rs b/src/lib.rs index 1b0fce7..ec49ae0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -13,7 +13,7 @@ //! //! # Example //! -//! ```edition2018 +//! ``` //! fn main() { //! let mut buffer = ryu::Buffer::new(); //! let printed = buffer.format(1.234); diff --git a/src/pretty/mod.rs b/src/pretty/mod.rs index 930025d..5eed13c 100644 --- a/src/pretty/mod.rs +++ b/src/pretty/mod.rs @@ -34,7 +34,7 @@ use no_panic::no_panic; /// /// ## Example /// -/// ```edition2018 +/// ``` /// use std::{mem::MaybeUninit, slice, str}; /// /// let f = 1.234f64; @@ -141,7 +141,7 @@ pub unsafe fn format64(f: f64, result: *mut u8) -> usize { /// /// ## Example /// -/// ```edition2018 +/// ``` /// use std::{mem::MaybeUninit, slice, str}; /// /// let f = 1.234f32; From 2cfbf40a869dbdb7acb3daa3d2f731581e2cb13d Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Fri, 29 May 2020 21:49:21 -0700 Subject: [PATCH 6/7] Remove use of 'extern crate' --- benches/bench.rs | 1 - examples/upstream_benchmark.rs | 3 --- src/lib.rs | 3 --- tests/d2s_table_test.rs | 2 -- tests/d2s_test.rs | 3 --- tests/exhaustive.rs | 3 --- tests/f2s_test.rs | 3 --- 7 files changed, 18 deletions(-) diff --git a/benches/bench.rs b/benches/bench.rs index 04d9bee..89a3ee6 100644 --- a/benches/bench.rs +++ b/benches/bench.rs @@ -2,7 +2,6 @@ #![feature(test)] -extern crate ryu; extern crate test; macro_rules! benches { diff --git a/examples/upstream_benchmark.rs b/examples/upstream_benchmark.rs index 7b91265..437855b 100644 --- a/examples/upstream_benchmark.rs +++ b/examples/upstream_benchmark.rs @@ -1,8 +1,5 @@ // cargo run --example upstream_benchmark --release -extern crate rand; -extern crate ryu; - use rand::{Rng, SeedableRng}; const SAMPLES: usize = 10000; diff --git a/src/lib.rs b/src/lib.rs index ec49ae0..8974ed7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -88,9 +88,6 @@ allow(cast_lossless, many_single_char_names, unreadable_literal,) )] -#[cfg(feature = "no-panic")] -extern crate no_panic; - mod buffer; mod common; mod d2s; diff --git a/tests/d2s_table_test.rs b/tests/d2s_table_test.rs index 8f27726..9e30e71 100644 --- a/tests/d2s_table_test.rs +++ b/tests/d2s_table_test.rs @@ -20,8 +20,6 @@ #![allow(dead_code)] -extern crate core; - #[path = "../src/common.rs"] mod common; diff --git a/tests/d2s_test.rs b/tests/d2s_test.rs index a4118be..32a7821 100644 --- a/tests/d2s_test.rs +++ b/tests/d2s_test.rs @@ -18,9 +18,6 @@ // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. -extern crate rand; -extern crate ryu; - #[macro_use] mod macros; diff --git a/tests/exhaustive.rs b/tests/exhaustive.rs index 5c36969..e97045e 100644 --- a/tests/exhaustive.rs +++ b/tests/exhaustive.rs @@ -1,8 +1,5 @@ #![cfg(exhaustive)] -extern crate num_cpus; -extern crate ryu; - use std::str; use std::sync::atomic::{AtomicUsize, Ordering}; use std::sync::Arc; diff --git a/tests/f2s_test.rs b/tests/f2s_test.rs index e6aaf5b..57eba43 100644 --- a/tests/f2s_test.rs +++ b/tests/f2s_test.rs @@ -18,9 +18,6 @@ // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. -extern crate rand; -extern crate ryu; - #[macro_use] mod macros; From ddc3cebe67d380e896691b7eb20805846d0996d2 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Fri, 29 May 2020 21:50:08 -0700 Subject: [PATCH 7/7] Remove obsolete crate use from benchmark --- benches/bench.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/benches/bench.rs b/benches/bench.rs index 89a3ee6..f7a0d90 100644 --- a/benches/bench.rs +++ b/benches/bench.rs @@ -11,8 +11,6 @@ macro_rules! benches { $( #[bench] fn $name(b: &mut Bencher) { - use ryu; - let mut buf = ryu::Buffer::new(); b.iter(move || {