Repository: Stebalien/tempfile
Pull request #101 (2019-07-01 03:16:14)

Transit to 2018 edition
Block on #99 


Patch:
diff --git a/Cargo.toml b/Cargo.toml
index 3f0efff..3b61aea 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -7,27 +7,30 @@ authors = [
   "Ashley Mannix <ashleymannix@live.com.au>",
   "Jason White <jasonaw0@gmail.com>",
 ]
-description = """
-A library for managing temporary files and directories.
-"""
-
 documentation = "https://docs.rs/tempfile"
-repository = "https://github.com/Stebalien/tempfile"
+edition = "2018"
+exclude = ["/.travis.yml", "/appveyor.yml"]
 homepage = "http://stebalien.com/projects/tempfile-rs"
 keywords = ["tempfile", "tmpfile", "filesystem"]
-license = "MIT/Apache-2.0"
-exclude = ["/.travis.yml", "/appveyor.yml"]
+license = "MIT OR Apache-2.0"
+repository = "https://github.com/Stebalien/tempfile"
+description = "A library for managing temporary files and directories."
 
 [dependencies]
+cfg-if = "0.1"
 rand = "0.7"
 remove_dir_all = "0.5"
-cfg-if = "0.1"
 
 [target.'cfg(unix)'.dependencies]
 libc = "0.2.27"
 
-[target.'cfg(windows)'.dependencies]
-winapi = { version = "0.3", features = ["fileapi", "winbase", "handleapi"] }
+[target.'cfg(windows)'.dependencies.winapi]
+version = "0.3"
+features = [
+    "fileapi",
+    "handleapi",
+    "winbase",
+]
 
 [target.'cfg(target_os = "redox")'.dependencies]
 redox_syscall = "0.1"
diff --git a/README.md b/README.md
index 7ac920d..6a9c06b 100644
--- a/README.md
+++ b/README.md
@@ -23,16 +23,10 @@ Add this to your `Cargo.toml`:
 tempfile = "3"
 ```
 
-...and this to your crate root:
-```rust
-extern crate tempfile;
-```
-
 Example
 -------
 
 ```rust
-extern crate tempfile;
 use std::fs::File;
 use std::io::{Write, Read, Seek, SeekFrom};
 
diff --git a/src/dir.rs b/src/dir.rs
index 90507a7..ae8a637 100644
--- a/src/dir.rs
+++ b/src/dir.rs
@@ -12,8 +12,8 @@ use remove_dir_all::remove_dir_all;
 use std::path::{self, Path, PathBuf};
 use std::{fmt, fs, io};
 
-use error::IoResultExt;
-use Builder;
+use crate::error::IoResultExt;
+use crate::Builder;
 
 /// Create a new temporary directory.
 ///
@@ -33,7 +33,6 @@ use Builder;
 /// # Examples
 ///
 /// ```
-/// # extern crate tempfile;
 /// use tempfile::tempdir;
 /// use std::fs::File;
 /// use std::io::{self, Write};
@@ -83,7 +82,6 @@ pub fn tempdir() -> io::Result<TempDir> {
 /// # Examples
 ///
 /// ```
-/// # extern crate tempfile;
 /// use tempfile::tempdir;
 /// use std::fs::File;
 /// use std::io::{self, Write};
@@ -385,7 +383,7 @@ impl AsRef<Path> for TempDir {
 }
 
 impl fmt::Debug for TempDir {
-    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         f.debug_struct("TempDir")
             .field("path", &self.path())
             .finish()
diff --git a/src/error.rs b/src/error.rs
index 43a1253..ed6b6cc 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -8,7 +8,7 @@ struct PathError {
 }
 
 impl fmt::Display for PathError {
-    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         write!(f, "{} at path {:?}", self.err, self.path)
     }
 }
diff --git a/src/file/imp/unix.rs b/src/file/imp/unix.rs
index eec6320..35b1ddb 100644
--- a/src/file/imp/unix.rs
+++ b/src/file/imp/unix.rs
@@ -5,7 +5,7 @@ use std::io;
 use std::os::unix::ffi::OsStrExt;
 use std::os::unix::fs::{MetadataExt, OpenOptionsExt};
 use std::path::Path;
-use util;
+use crate::util;
 
 #[cfg(not(target_os = "redox"))]
 use libc::{c_char, c_int, link, rename, unlink};
@@ -85,7 +85,7 @@ fn create_unix(dir: &Path) -> io::Result<File> {
         dir,
         OsStr::new(".tmp"),
         OsStr::new(""),
-        ::NUM_RAND_CHARS,
+        crate::NUM_RAND_CHARS,
         |path| create_unlinked(&path),
     )
 }
diff --git a/src/file/imp/windows.rs b/src/file/imp/windows.rs
index 529eb60..71b4748 100644
--- a/src/file/imp/windows.rs
+++ b/src/file/imp/windows.rs
@@ -14,7 +14,7 @@ use winapi::um::winnt::{FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_TEMPORARY};
 use winapi::um::winnt::{FILE_GENERIC_READ, FILE_GENERIC_WRITE, HANDLE};
 use winapi::um::winnt::{FILE_SHARE_DELETE, FILE_SHARE_READ, FILE_SHARE_WRITE};
 
-use util;
+use crate::util;
 
 fn to_utf16(s: &Path) -> Vec<u16> {
     s.as_os_str().encode_wide().chain(iter::once(0)).collect()
@@ -34,7 +34,7 @@ pub fn create(dir: &Path) -> io::Result<File> {
         dir,
         OsStr::new(".tmp"),
         OsStr::new(""),
-        ::NUM_RAND_CHARS,
+        crate::NUM_RAND_CHARS,
         |path| {
             OpenOptions::new()
                 .create_new(true)
diff --git a/src/file/mod.rs b/src/file/mod.rs
index 9173e86..ce70cac 100644
--- a/src/file/mod.rs
+++ b/src/file/mod.rs
@@ -9,8 +9,8 @@ use std::mem;
 use std::ops::Deref;
 use std::path::{Path, PathBuf};
 
-use error::IoResultExt;
-use Builder;
+use crate::error::IoResultExt;
+use crate::Builder;
 
 mod imp;
 
@@ -34,7 +34,6 @@ mod imp;
 /// # Examples
 ///
 /// ```
-/// # extern crate tempfile;
 /// use tempfile::tempfile;
 /// use std::io::{self, Write};
 ///
@@ -76,7 +75,6 @@ pub fn tempfile() -> io::Result<File> {
 /// # Examples
 ///
 /// ```
-/// # extern crate tempfile;
 /// use tempfile::tempfile_in;
 /// use std::io::{self, Write};
 ///
@@ -123,7 +121,7 @@ impl From<PathPersistError> for TempPath {
 }
 
 impl fmt::Display for PathPersistError {
-    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         write!(f, "failed to persist temporary file path: {}", self.error)
     }
 }
@@ -156,7 +154,6 @@ impl TempPath {
     /// # Examples
     ///
     /// ```no_run
-    /// # extern crate tempfile;
     /// # use std::io;
     /// use tempfile::NamedTempFile;
     ///
@@ -208,7 +205,6 @@ impl TempPath {
     ///
     /// ```no_run
     /// # use std::io::{self, Write};
-    /// # extern crate tempfile;
     /// use tempfile::NamedTempFile;
     ///
     /// # fn main() {
@@ -268,7 +264,6 @@ impl TempPath {
     ///
     /// ```no_run
     /// # use std::io::{self, Write};
-    /// # extern crate tempfile;
     /// use tempfile::NamedTempFile;
     ///
     /// # fn main() {
@@ -320,7 +315,6 @@ impl TempPath {
     ///
     /// ```no_run
     /// # use std::io::{self, Write};
-    /// # extern crate tempfile;
     /// use tempfile::NamedTempFile;
     ///
     /// # fn main() {
@@ -359,7 +353,7 @@ impl TempPath {
 }
 
 impl fmt::Debug for TempPath {
-    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         self.path.fmt(f)
     }
 }
@@ -477,7 +471,7 @@ pub struct NamedTempFile {
 }
 
 impl fmt::Debug for NamedTempFile {
-    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         write!(f, "NamedTempFile({:?})", self.path)
     }
 }
@@ -513,7 +507,7 @@ impl From<PersistError> for NamedTempFile {
 }
 
 impl fmt::Display for PersistError {
-    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         write!(f, "failed to persist temporary file: {}", self.error)
     }
 }
@@ -566,7 +560,6 @@ impl NamedTempFile {
     ///
     /// ```no_run
     /// # use std::io::{self, Write};
-    /// # extern crate tempfile;
     /// use tempfile::NamedTempFile;
     ///
     /// # fn main() {
@@ -608,7 +601,6 @@ impl NamedTempFile {
     ///
     /// ```no_run
     /// # use std::io::{self, Write};
-    /// # extern crate tempfile;
     /// use tempfile::NamedTempFile;
     ///
     /// # fn main() {
@@ -639,7 +631,6 @@ impl NamedTempFile {
     /// # Examples
     ///
     /// ```no_run
-    /// # extern crate tempfile;
     /// # use std::io;
     /// use tempfile::NamedTempFile;
     ///
@@ -687,7 +678,6 @@ impl NamedTempFile {
     ///
     /// ```no_run
     /// # use std::io::{self, Write};
-    /// # extern crate tempfile;
     /// use tempfile::NamedTempFile;
     ///
     /// # fn main() {
@@ -743,7 +733,6 @@ impl NamedTempFile {
     ///
     /// ```no_run
     /// # use std::io::{self, Write};
-    /// # extern crate tempfile;
     /// use tempfile::NamedTempFile;
     ///
     /// # fn main() {
@@ -786,7 +775,6 @@ impl NamedTempFile {
     ///
     /// ```no_run
     /// # use std::io::{self, Write};
-    /// # extern crate tempfile;
     /// use tempfile::NamedTempFile;
     ///
     /// # fn main() {
@@ -836,7 +824,6 @@ impl NamedTempFile {
     ///
     /// ```no_run
     /// # use std::io;
-    /// # extern crate tempfile;
     /// use tempfile::NamedTempFile;
     ///
     /// # fn main() {
diff --git a/src/lib.rs b/src/lib.rs
index 1a0affd..a4cb574 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -32,7 +32,6 @@
 //! Create a temporary file and write some data into it:
 //!
 //! ```
-//! # extern crate tempfile;
 //! use tempfile::tempfile;
 //! use std::io::{self, Write};
 //!
@@ -53,7 +52,6 @@
 //! Create a named temporary file and open an independent file handle:
 //!
 //! ```
-//! # extern crate tempfile;
 //! use tempfile::NamedTempFile;
 //! use std::io::{self, Write, Read};
 //!
@@ -85,7 +83,6 @@
 //! Create a temporary directory and add a file to it:
 //!
 //! ```
-//! # extern crate tempfile;
 //! use tempfile::tempdir;
 //! use std::fs::File;
 //! use std::io::{self, Write};
@@ -126,20 +123,10 @@
     html_root_url = "https://docs.rs/tempfile/3.1.0"
 )]
 #![cfg_attr(test, deny(warnings))]
+#![deny(rust_2018_idioms)]
 
 #[macro_use]
 extern crate cfg_if;
-extern crate rand;
-extern crate remove_dir_all;
-
-#[cfg(unix)]
-extern crate libc;
-
-#[cfg(windows)]
-extern crate winapi;
-
-#[cfg(target_os = "redox")]
-extern crate syscall;
 
 const NUM_RETRIES: u32 = 1 << 31;
 const NUM_RAND_CHARS: usize = 6;
@@ -155,9 +142,9 @@ mod file;
 mod spooled;
 mod util;
 
-pub use dir::{tempdir, tempdir_in, TempDir};
-pub use file::{tempfile, tempfile_in, NamedTempFile, PathPersistError, PersistError, TempPath};
-pub use spooled::{spooled_tempfile, SpooledTempFile};
+pub use crate::dir::{tempdir, tempdir_in, TempDir};
+pub use crate::file::{tempfile, tempfile_in, NamedTempFile, PathPersistError, PersistError, TempPath};
+pub use crate::spooled::{spooled_tempfile, SpooledTempFile};
 
 /// Create a new temporary file or directory with custom parameters.
 #[derive(Debug, Clone, Eq, PartialEq)]
@@ -171,7 +158,7 @@ pub struct Builder<'a, 'b> {
 impl<'a, 'b> Default for Builder<'a, 'b> {
     fn default() -> Self {
         Builder {
-            random_len: ::NUM_RAND_CHARS,
+            random_len: crate::NUM_RAND_CHARS,
             prefix: OsStr::new(".tmp"),
             suffix: OsStr::new(""),
             append: false,
@@ -187,7 +174,6 @@ impl<'a, 'b> Builder<'a, 'b> {
     /// Create a named temporary file and write some data into it:
     ///
     /// ```
-    /// # extern crate tempfile;
     /// # use std::io;
     /// # use std::ffi::OsStr;
     /// # fn main() {
@@ -220,7 +206,6 @@ impl<'a, 'b> Builder<'a, 'b> {
     /// Create a temporary directory and add a file to it:
     ///
     /// ```
-    /// # extern crate tempfile;
     /// # use std::io::{self, Write};
     /// # use std::fs::File;
     /// # use std::ffi::OsStr;
@@ -263,7 +248,6 @@ impl<'a, 'b> Builder<'a, 'b> {
     /// # Examples
     ///
     /// ```
-    /// # extern crate tempfile;
     /// # use std::io;
     /// # fn main() {
     /// #     if let Err(_) = run() {
@@ -291,7 +275,6 @@ impl<'a, 'b> Builder<'a, 'b> {
     /// # Examples
     ///
     /// ```
-    /// # extern crate tempfile;
     /// # use std::io;
     /// # fn main() {
     /// #     if let Err(_) = run() {
@@ -318,7 +301,6 @@ impl<'a, 'b> Builder<'a, 'b> {
     /// # Examples
     ///
     /// ```
-    /// # extern crate tempfile;
     /// # use std::io;
     /// # fn main() {
     /// #     if let Err(_) = run() {
@@ -345,7 +327,6 @@ impl<'a, 'b> Builder<'a, 'b> {
     /// # Examples
     ///
     /// ```
-    /// # extern crate tempfile;
     /// # use std::io;
     /// # fn main() {
     /// #     if let Err(_) = run() {
@@ -382,7 +363,6 @@ impl<'a, 'b> Builder<'a, 'b> {
     /// # Examples
     ///
     /// ```
-    /// # extern crate tempfile;
     /// # use std::io;
     /// # fn main() {
     /// #     if let Err(_) = run() {
@@ -419,7 +399,6 @@ impl<'a, 'b> Builder<'a, 'b> {
     /// # Examples
     ///
     /// ```
-    /// # extern crate tempfile;
     /// # use std::io;
     /// # fn main() {
     /// #     if let Err(_) = run() {
diff --git a/src/spooled.rs b/src/spooled.rs
index 093477b..e6f750e 100644
--- a/src/spooled.rs
+++ b/src/spooled.rs
@@ -1,4 +1,4 @@
-use file::tempfile;
+use crate::file::tempfile;
 use std::fs::File;
 use std::io::{self, Cursor, Read, Seek, SeekFrom, Write};
 
@@ -34,7 +34,6 @@ pub struct SpooledTempFile {
 /// # Examples
 ///
 /// ```
-/// # extern crate tempfile;
 /// use tempfile::spooled_tempfile;
 /// use std::io::{self, Write};
 ///
diff --git a/src/util.rs b/src/util.rs
index 42d1eed..36c9a78 100644
--- a/src/util.rs
+++ b/src/util.rs
@@ -4,7 +4,7 @@ use std::ffi::{OsStr, OsString};
 use std::path::{Path, PathBuf};
 use std::{io, str};
 
-use error::IoResultExt;
+use crate::error::IoResultExt;
 
 fn tmpname(prefix: &OsStr, suffix: &OsStr, rand_len: usize) -> OsString {
     let mut buf = OsString::with_capacity(prefix.len() + suffix.len() + rand_len);
@@ -33,7 +33,7 @@ pub fn create_helper<F, R>(
 where
     F: Fn(PathBuf) -> io::Result<R>,
 {
-    let num_retries = if random_len != 0 { ::NUM_RETRIES } else { 1 };
+    let num_retries = if random_len != 0 { crate::NUM_RETRIES } else { 1 };
 
     for _ in 0..num_retries {
         let path = base.join(tmpname(prefix, suffix, random_len));


Test patch:
diff --git a/tests/namedtempfile.rs b/tests/namedtempfile.rs
index e7ea8de..a489d56 100644
--- a/tests/namedtempfile.rs
+++ b/tests/namedtempfile.rs
@@ -1,4 +1,5 @@
-extern crate tempfile;
+#![deny(rust_2018_idioms)]
+
 use std::env;
 use std::fs::File;
 use std::io::{Read, Seek, SeekFrom, Write};
diff --git a/tests/spooled.rs b/tests/spooled.rs
index 8481936..288d1e6 100644
--- a/tests/spooled.rs
+++ b/tests/spooled.rs
@@ -1,4 +1,4 @@
-extern crate tempfile;
+#![deny(rust_2018_idioms)]
 
 use std::io::{Read, Seek, SeekFrom, Write};
 
diff --git a/tests/tempdir.rs b/tests/tempdir.rs
index 9baccdc..746fe47 100644
--- a/tests/tempdir.rs
+++ b/tests/tempdir.rs
@@ -8,7 +8,7 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-extern crate tempfile;
+#![deny(rust_2018_idioms)]
 
 use std::env;
 use std::fs;
diff --git a/tests/tempfile.rs b/tests/tempfile.rs
index 4a19b29..065dccb 100644
--- a/tests/tempfile.rs
+++ b/tests/tempfile.rs
@@ -1,4 +1,5 @@
-extern crate tempfile;
+#![deny(rust_2018_idioms)]
+
 use std::fs;
 use std::io::{Read, Seek, SeekFrom, Write};
 use std::sync::mpsc::{sync_channel, TryRecvError};