From ea72066f5c0cc93ea7efe73396eb691724fccaaf Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Lauren=C8=9Biu=20Nicola?= <lnicola@dend.ro>
Date: Sun, 3 Feb 2019 18:24:05 +0200
Subject: [PATCH 01/24] Avoid some bounds checks in binary_heap::{PeekMut,Hole}

---
 src/liballoc/collections/binary_heap.rs | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/src/liballoc/collections/binary_heap.rs b/src/liballoc/collections/binary_heap.rs
index ad544e6015e4a..473f7aee5c76b 100644
--- a/src/liballoc/collections/binary_heap.rs
+++ b/src/liballoc/collections/binary_heap.rs
@@ -248,14 +248,18 @@ impl<'a, T: Ord> Drop for PeekMut<'a, T> {
 impl<'a, T: Ord> Deref for PeekMut<'a, T> {
     type Target = T;
     fn deref(&self) -> &T {
-        &self.heap.data[0]
+        debug_assert!(!self.heap.is_empty());
+        // SAFE: PeekMut is only instantiated for non-empty heaps
+        unsafe { self.heap.data.get_unchecked(0) }
     }
 }
 
 #[stable(feature = "binary_heap_peek_mut", since = "1.12.0")]
 impl<'a, T: Ord> DerefMut for PeekMut<'a, T> {
     fn deref_mut(&mut self) -> &mut T {
-        &mut self.heap.data[0]
+        debug_assert!(!self.heap.is_empty());
+        // SAFE: PeekMut is only instantiated for non-empty heaps
+        unsafe { self.heap.data.get_unchecked_mut(0) }
     }
 }
 
@@ -865,7 +869,8 @@ impl<'a, T> Hole<'a, T> {
     #[inline]
     unsafe fn new(data: &'a mut [T], pos: usize) -> Self {
         debug_assert!(pos < data.len());
-        let elt = ptr::read(&data[pos]);
+        // SAFE: pos should be inside the slice
+        let elt = ptr::read(data.get_unchecked(pos));
         Hole {
             data,
             elt: ManuallyDrop::new(elt),

From 6413480adf6bc788e515a9746cf382e1ceb153fe Mon Sep 17 00:00:00 2001
From: Taiki Endo <te316e89@gmail.com>
Date: Mon, 4 Feb 2019 03:42:27 +0900
Subject: [PATCH 02/24] libsyntax_pos => 2018

---
 src/libsyntax_pos/Cargo.toml             |  1 +
 src/libsyntax_pos/analyze_source_file.rs |  2 +-
 src/libsyntax_pos/edition.rs             |  2 +-
 src/libsyntax_pos/hygiene.rs             | 10 ++---
 src/libsyntax_pos/lib.rs                 | 41 ++++++++------------
 src/libsyntax_pos/span_encoding.rs       |  6 +--
 src/libsyntax_pos/symbol.rs              | 49 ++++++++++++------------
 7 files changed, 51 insertions(+), 60 deletions(-)

diff --git a/src/libsyntax_pos/Cargo.toml b/src/libsyntax_pos/Cargo.toml
index 08ee2e0f37626..5658451c54f71 100644
--- a/src/libsyntax_pos/Cargo.toml
+++ b/src/libsyntax_pos/Cargo.toml
@@ -2,6 +2,7 @@
 authors = ["The Rust Project Developers"]
 name = "syntax_pos"
 version = "0.0.0"
+edition = "2018"
 
 [lib]
 name = "syntax_pos"
diff --git a/src/libsyntax_pos/analyze_source_file.rs b/src/libsyntax_pos/analyze_source_file.rs
index 3abd260ac6f8f..18387bd5a091a 100644
--- a/src/libsyntax_pos/analyze_source_file.rs
+++ b/src/libsyntax_pos/analyze_source_file.rs
@@ -36,7 +36,7 @@ pub fn analyze_source_file(
     (lines, multi_byte_chars, non_narrow_chars)
 }
 
-cfg_if! {
+cfg_if::cfg_if! {
     if #[cfg(all(any(target_arch = "x86", target_arch = "x86_64")))] {
         fn analyze_source_file_dispatch(src: &str,
                                     source_file_start_pos: BytePos,
diff --git a/src/libsyntax_pos/edition.rs b/src/libsyntax_pos/edition.rs
index f5a745a9cd501..a0b0052f26dab 100644
--- a/src/libsyntax_pos/edition.rs
+++ b/src/libsyntax_pos/edition.rs
@@ -27,7 +27,7 @@ pub const EDITION_NAME_LIST: &str = "2015|2018";
 pub const DEFAULT_EDITION: Edition = Edition::Edition2015;
 
 impl fmt::Display for Edition {
-    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         let s = match *self {
             Edition::Edition2015 => "2015",
             Edition::Edition2018 => "2018",
diff --git a/src/libsyntax_pos/hygiene.rs b/src/libsyntax_pos/hygiene.rs
index 6e32a05dee361..0c645fc678caf 100644
--- a/src/libsyntax_pos/hygiene.rs
+++ b/src/libsyntax_pos/hygiene.rs
@@ -5,10 +5,10 @@
 //! and definition contexts*. J. Funct. Program. 22, 2 (March 2012), 181-216.
 //! DOI=10.1017/S0956796812000093 <https://doi.org/10.1017/S0956796812000093>
 
-use GLOBALS;
-use Span;
-use edition::{Edition, DEFAULT_EDITION};
-use symbol::{keywords, Symbol};
+use crate::GLOBALS;
+use crate::Span;
+use crate::edition::{Edition, DEFAULT_EDITION};
+use crate::symbol::{keywords, Symbol};
 
 use serialize::{Encodable, Decodable, Encoder, Decoder};
 use rustc_data_structures::fx::{FxHashMap, FxHashSet};
@@ -525,7 +525,7 @@ impl SyntaxContext {
 }
 
 impl fmt::Debug for SyntaxContext {
-    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         write!(f, "#{}", self.0)
     }
 }
diff --git a/src/libsyntax_pos/lib.rs b/src/libsyntax_pos/lib.rs
index 2a85779239689..13e7307570a4f 100644
--- a/src/libsyntax_pos/lib.rs
+++ b/src/libsyntax_pos/lib.rs
@@ -8,10 +8,11 @@
       html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
       html_root_url = "https://doc.rust-lang.org/nightly/")]
 
+#![deny(rust_2018_idioms)]
+
 #![feature(const_fn)]
 #![feature(crate_visibility_modifier)]
 #![feature(custom_attribute)]
-#![feature(nll)]
 #![feature(non_exhaustive)]
 #![feature(optin_builtin_traits)]
 #![feature(rustc_attrs)]
@@ -19,23 +20,11 @@
 #![feature(step_trait)]
 #![cfg_attr(not(stage0), feature(stdsimd))]
 
-extern crate arena;
-#[macro_use]
-extern crate rustc_data_structures;
-
-#[macro_use]
-extern crate scoped_tls;
-
 use serialize::{Encodable, Decodable, Encoder, Decoder};
 
-extern crate serialize;
+#[allow(unused_extern_crates)]
 extern crate serialize as rustc_serialize; // used by deriving
 
-#[macro_use]
-extern crate cfg_if;
-
-extern crate unicode_width;
-
 pub mod edition;
 pub mod hygiene;
 pub use hygiene::{Mark, SyntaxContext, ExpnInfo, ExpnFormat, CompilerDesugaringKind};
@@ -74,7 +63,7 @@ impl Globals {
     }
 }
 
-scoped_thread_local!(pub static GLOBALS: Globals);
+scoped_tls::scoped_thread_local!(pub static GLOBALS: Globals);
 
 /// Differentiates between real files and common virtual files.
 #[derive(Debug, Eq, PartialEq, Clone, Ord, PartialOrd, Hash, RustcDecodable, RustcEncodable)]
@@ -100,8 +89,8 @@ pub enum FileName {
 }
 
 impl std::fmt::Display for FileName {
-    fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::fmt::Result {
-        use self::FileName::*;
+    fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+        use FileName::*;
         match *self {
             Real(ref path) => write!(fmt, "{}", path.display()),
             Macros(ref name) => write!(fmt, "<{} macros>", name),
@@ -127,7 +116,7 @@ impl From<PathBuf> for FileName {
 
 impl FileName {
     pub fn is_real(&self) -> bool {
-        use self::FileName::*;
+        use FileName::*;
         match *self {
             Real(_) => true,
             Macros(_) |
@@ -143,7 +132,7 @@ impl FileName {
     }
 
     pub fn is_macros(&self) -> bool {
-        use self::FileName::*;
+        use FileName::*;
         match *self {
             Real(_) |
             Anon(_) |
@@ -611,7 +600,7 @@ impl serialize::UseSpecializedDecodable for Span {
     }
 }
 
-pub fn default_span_debug(span: Span, f: &mut fmt::Formatter) -> fmt::Result {
+pub fn default_span_debug(span: Span, f: &mut fmt::Formatter<'_>) -> fmt::Result {
     f.debug_struct("Span")
         .field("lo", &span.lo())
         .field("hi", &span.hi())
@@ -620,13 +609,13 @@ pub fn default_span_debug(span: Span, f: &mut fmt::Formatter) -> fmt::Result {
 }
 
 impl fmt::Debug for Span {
-    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         SPAN_DEBUG.with(|span_debug| span_debug.get()(*self, f))
     }
 }
 
 impl fmt::Debug for SpanData {
-    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         SPAN_DEBUG.with(|span_debug| span_debug.get()(Span::new(self.lo, self.hi, self.ctxt), f))
     }
 }
@@ -1009,7 +998,7 @@ impl Decodable for SourceFile {
                 // `crate_of_origin` has to be set by the importer.
                 // This value matches up with rustc::hir::def_id::INVALID_CRATE.
                 // That constant is not available here unfortunately :(
-                crate_of_origin: ::std::u32::MAX - 1,
+                crate_of_origin: std::u32::MAX - 1,
                 start_pos,
                 end_pos,
                 src: None,
@@ -1025,7 +1014,7 @@ impl Decodable for SourceFile {
 }
 
 impl fmt::Debug for SourceFile {
-    fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
+    fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
         write!(fmt, "SourceFile({})", self.name)
     }
 }
@@ -1111,7 +1100,7 @@ impl SourceFile {
 
     /// Get a line from the list of pre-computed line-beginnings.
     /// The line number here is 0-based.
-    pub fn get_line(&self, line_number: usize) -> Option<Cow<str>> {
+    pub fn get_line(&self, line_number: usize) -> Option<Cow<'_, str>> {
         fn get_until_newline(src: &str, begin: usize) -> &str {
             // We can't use `lines.get(line_number+1)` because we might
             // be parsing when we call this function and thus the current
@@ -1353,7 +1342,7 @@ pub struct FileLines {
     pub lines: Vec<LineInfo>
 }
 
-thread_local!(pub static SPAN_DEBUG: Cell<fn(Span, &mut fmt::Formatter) -> fmt::Result> =
+thread_local!(pub static SPAN_DEBUG: Cell<fn(Span, &mut fmt::Formatter<'_>) -> fmt::Result> =
                 Cell::new(default_span_debug));
 
 #[derive(Debug)]
diff --git a/src/libsyntax_pos/span_encoding.rs b/src/libsyntax_pos/span_encoding.rs
index 8cb3bc2144da1..03d7a9eb74238 100644
--- a/src/libsyntax_pos/span_encoding.rs
+++ b/src/libsyntax_pos/span_encoding.rs
@@ -4,9 +4,9 @@
 // The encoding format for inline spans were obtained by optimizing over crates in rustc/libstd.
 // See https://internals.rust-lang.org/t/rfc-compiler-refactoring-spans/1357/28
 
-use GLOBALS;
-use {BytePos, SpanData};
-use hygiene::SyntaxContext;
+use crate::GLOBALS;
+use crate::{BytePos, SpanData};
+use crate::hygiene::SyntaxContext;
 
 use rustc_data_structures::fx::FxHashMap;
 use std::hash::{Hash, Hasher};
diff --git a/src/libsyntax_pos/symbol.rs b/src/libsyntax_pos/symbol.rs
index 7097f332b8b8f..0eecdbfa97634 100644
--- a/src/libsyntax_pos/symbol.rs
+++ b/src/libsyntax_pos/symbol.rs
@@ -5,6 +5,7 @@
 use arena::DroplessArena;
 use rustc_data_structures::fx::FxHashMap;
 use rustc_data_structures::indexed_vec::Idx;
+use rustc_data_structures::newtype_index;
 use serialize::{Decodable, Decoder, Encodable, Encoder};
 
 use std::fmt;
@@ -12,8 +13,8 @@ use std::str;
 use std::cmp::{PartialEq, Ordering, PartialOrd, Ord};
 use std::hash::{Hash, Hasher};
 
-use hygiene::SyntaxContext;
-use {Span, DUMMY_SP, GLOBALS};
+use crate::hygiene::SyntaxContext;
+use crate::{Span, DUMMY_SP, GLOBALS};
 
 #[derive(Copy, Clone, Eq)]
 pub struct Ident {
@@ -100,13 +101,13 @@ impl Hash for Ident {
 }
 
 impl fmt::Debug for Ident {
-    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         write!(f, "{}{:?}", self.name, self.span.ctxt())
     }
 }
 
 impl fmt::Display for Ident {
-    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         fmt::Display::fmt(&self.name, f)
     }
 }
@@ -181,7 +182,7 @@ impl Symbol {
     pub fn as_str(self) -> LocalInternedString {
         with_interner(|interner| unsafe {
             LocalInternedString {
-                string: ::std::mem::transmute::<&str, &str>(interner.get(self))
+                string: std::mem::transmute::<&str, &str>(interner.get(self))
             }
         })
     }
@@ -198,7 +199,7 @@ impl Symbol {
 }
 
 impl fmt::Debug for Symbol {
-    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         let is_gensymed = with_interner(|interner| interner.is_gensymed(*self));
         if is_gensymed {
             write!(f, "{}({:?})", self, self.0)
@@ -209,7 +210,7 @@ impl fmt::Debug for Symbol {
 }
 
 impl fmt::Display for Symbol {
-    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         fmt::Display::fmt(&self.as_str(), f)
     }
 }
@@ -226,7 +227,7 @@ impl Decodable for Symbol {
     }
 }
 
-impl<T: ::std::ops::Deref<Target=str>> PartialEq<T> for Symbol {
+impl<T: std::ops::Deref<Target=str>> PartialEq<T> for Symbol {
     fn eq(&self, other: &T) -> bool {
         self.as_str() == other.deref()
     }
@@ -335,7 +336,7 @@ macro_rules! declare_keywords {(
             };
         )*
 
-        impl ::std::str::FromStr for Keyword {
+        impl std::str::FromStr for Keyword {
             type Err = ();
 
             fn from_str(s: &str) -> Result<Self, ()> {
@@ -519,40 +520,40 @@ impl LocalInternedString {
     }
 }
 
-impl<U: ?Sized> ::std::convert::AsRef<U> for LocalInternedString
+impl<U: ?Sized> std::convert::AsRef<U> for LocalInternedString
 where
-    str: ::std::convert::AsRef<U>
+    str: std::convert::AsRef<U>
 {
     fn as_ref(&self) -> &U {
         self.string.as_ref()
     }
 }
 
-impl<T: ::std::ops::Deref<Target = str>> ::std::cmp::PartialEq<T> for LocalInternedString {
+impl<T: std::ops::Deref<Target = str>> std::cmp::PartialEq<T> for LocalInternedString {
     fn eq(&self, other: &T) -> bool {
         self.string == other.deref()
     }
 }
 
-impl ::std::cmp::PartialEq<LocalInternedString> for str {
+impl std::cmp::PartialEq<LocalInternedString> for str {
     fn eq(&self, other: &LocalInternedString) -> bool {
         self == other.string
     }
 }
 
-impl<'a> ::std::cmp::PartialEq<LocalInternedString> for &'a str {
+impl<'a> std::cmp::PartialEq<LocalInternedString> for &'a str {
     fn eq(&self, other: &LocalInternedString) -> bool {
         *self == other.string
     }
 }
 
-impl ::std::cmp::PartialEq<LocalInternedString> for String {
+impl std::cmp::PartialEq<LocalInternedString> for String {
     fn eq(&self, other: &LocalInternedString) -> bool {
         self == other.string
     }
 }
 
-impl<'a> ::std::cmp::PartialEq<LocalInternedString> for &'a String {
+impl<'a> std::cmp::PartialEq<LocalInternedString> for &'a String {
     fn eq(&self, other: &LocalInternedString) -> bool {
         *self == other.string
     }
@@ -561,19 +562,19 @@ impl<'a> ::std::cmp::PartialEq<LocalInternedString> for &'a String {
 impl !Send for LocalInternedString {}
 impl !Sync for LocalInternedString {}
 
-impl ::std::ops::Deref for LocalInternedString {
+impl std::ops::Deref for LocalInternedString {
     type Target = str;
     fn deref(&self) -> &str { self.string }
 }
 
 impl fmt::Debug for LocalInternedString {
-    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         fmt::Debug::fmt(self.string, f)
     }
 }
 
 impl fmt::Display for LocalInternedString {
-    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         fmt::Display::fmt(self.string, f)
     }
 }
@@ -640,7 +641,7 @@ impl Ord for InternedString {
     }
 }
 
-impl<T: ::std::ops::Deref<Target = str>> PartialEq<T> for InternedString {
+impl<T: std::ops::Deref<Target = str>> PartialEq<T> for InternedString {
     fn eq(&self, other: &T) -> bool {
         self.with(|string| string == other.deref())
     }
@@ -676,20 +677,20 @@ impl<'a> PartialEq<InternedString> for &'a String {
     }
 }
 
-impl ::std::convert::From<InternedString> for String {
+impl std::convert::From<InternedString> for String {
     fn from(val: InternedString) -> String {
         val.as_symbol().to_string()
     }
 }
 
 impl fmt::Debug for InternedString {
-    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         self.with(|str| fmt::Debug::fmt(&str, f))
     }
 }
 
 impl fmt::Display for InternedString {
-    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         self.with(|str| fmt::Display::fmt(&str, f))
     }
 }
@@ -709,7 +710,7 @@ impl Encodable for InternedString {
 #[cfg(test)]
 mod tests {
     use super::*;
-    use Globals;
+    use crate::Globals;
 
     #[test]
     fn interner_tests() {

From 18da195bab0d64680d42ae141e09cbde5514a371 Mon Sep 17 00:00:00 2001
From: Taiki Endo <te316e89@gmail.com>
Date: Mon, 4 Feb 2019 03:55:40 +0900
Subject: [PATCH 03/24] libproc_macro => 2018

---
 src/libproc_macro/Cargo.toml       |  1 +
 src/libproc_macro/bridge/buffer.rs |  6 +--
 src/libproc_macro/bridge/client.rs | 62 +++++++++++++++++-------------
 src/libproc_macro/bridge/mod.rs    |  8 ++--
 src/libproc_macro/bridge/rpc.rs    | 18 ++++-----
 src/libproc_macro/bridge/server.rs | 14 +++----
 src/libproc_macro/diagnostic.rs    | 12 +++---
 src/libproc_macro/lib.rs           | 33 ++++++++--------
 src/libproc_macro/quote.rs         | 36 ++++++++---------
 9 files changed, 100 insertions(+), 90 deletions(-)

diff --git a/src/libproc_macro/Cargo.toml b/src/libproc_macro/Cargo.toml
index f903f79f9afc0..b3d0ee94f0e12 100644
--- a/src/libproc_macro/Cargo.toml
+++ b/src/libproc_macro/Cargo.toml
@@ -2,6 +2,7 @@
 authors = ["The Rust Project Developers"]
 name = "proc_macro"
 version = "0.0.0"
+edition = "2018"
 
 [lib]
 path = "lib.rs"
diff --git a/src/libproc_macro/bridge/buffer.rs b/src/libproc_macro/bridge/buffer.rs
index 8bc4f0fec85a8..0d8cc552d61ab 100644
--- a/src/libproc_macro/bridge/buffer.rs
+++ b/src/libproc_macro/bridge/buffer.rs
@@ -6,7 +6,7 @@ use std::ops::{Deref, DerefMut};
 use std::slice;
 
 #[repr(C)]
-struct Slice<'a, T: 'a> {
+struct Slice<'a, T> {
     data: &'a [T; 0],
     len: usize,
 }
@@ -42,7 +42,7 @@ pub struct Buffer<T: Copy> {
     data: *mut T,
     len: usize,
     capacity: usize,
-    extend_from_slice: extern "C" fn(Buffer<T>, Slice<T>) -> Buffer<T>,
+    extend_from_slice: extern "C" fn(Buffer<T>, Slice<'_, T>) -> Buffer<T>,
     drop: extern "C" fn(Buffer<T>),
 }
 
@@ -139,7 +139,7 @@ impl<T: Copy> From<Vec<T>> for Buffer<T> {
             }
         }
 
-        extern "C" fn extend_from_slice<T: Copy>(b: Buffer<T>, xs: Slice<T>) -> Buffer<T> {
+        extern "C" fn extend_from_slice<T: Copy>(b: Buffer<T>, xs: Slice<'_, T>) -> Buffer<T> {
             let mut v = to_vec(b);
             v.extend_from_slice(&xs);
             Buffer::from(v)
diff --git a/src/libproc_macro/bridge/client.rs b/src/libproc_macro/bridge/client.rs
index 3095c8041f2c1..b198bdb144699 100644
--- a/src/libproc_macro/bridge/client.rs
+++ b/src/libproc_macro/bridge/client.rs
@@ -66,7 +66,7 @@ macro_rules! define_handles {
             impl<S: server::Types> DecodeMut<'_, '_, HandleStore<server::MarkedTypes<S>>>
                 for Marked<S::$oty, $oty>
             {
-                fn decode(r: &mut Reader, s: &mut HandleStore<server::MarkedTypes<S>>) -> Self {
+                fn decode(r: &mut Reader<'_>, s: &mut HandleStore<server::MarkedTypes<S>>) -> Self {
                     s.$oty.take(handle::Handle::decode(r, &mut ()))
                 }
             }
@@ -80,7 +80,7 @@ macro_rules! define_handles {
             impl<S: server::Types> Decode<'_, 's, HandleStore<server::MarkedTypes<S>>>
                 for &'s Marked<S::$oty, $oty>
             {
-                fn decode(r: &mut Reader, s: &'s HandleStore<server::MarkedTypes<S>>) -> Self {
+                fn decode(r: &mut Reader<'_>, s: &'s HandleStore<server::MarkedTypes<S>>) -> Self {
                     &s.$oty[handle::Handle::decode(r, &mut ())]
                 }
             }
@@ -94,7 +94,10 @@ macro_rules! define_handles {
             impl<S: server::Types> DecodeMut<'_, 's, HandleStore<server::MarkedTypes<S>>>
                 for &'s mut Marked<S::$oty, $oty>
             {
-                fn decode(r: &mut Reader, s: &'s mut HandleStore<server::MarkedTypes<S>>) -> Self {
+                fn decode(
+                    r: &mut Reader<'_>,
+                    s: &'s mut HandleStore<server::MarkedTypes<S>>
+                ) -> Self {
                     &mut s.$oty[handle::Handle::decode(r, &mut ())]
                 }
             }
@@ -108,7 +111,7 @@ macro_rules! define_handles {
             }
 
             impl<S> DecodeMut<'_, '_, S> for $oty {
-                fn decode(r: &mut Reader, s: &mut S) -> Self {
+                fn decode(r: &mut Reader<'_>, s: &mut S) -> Self {
                     $oty(handle::Handle::decode(r, s))
                 }
             }
@@ -130,7 +133,7 @@ macro_rules! define_handles {
             impl<S: server::Types> DecodeMut<'_, '_, HandleStore<server::MarkedTypes<S>>>
                 for Marked<S::$ity, $ity>
             {
-                fn decode(r: &mut Reader, s: &mut HandleStore<server::MarkedTypes<S>>) -> Self {
+                fn decode(r: &mut Reader<'_>, s: &mut HandleStore<server::MarkedTypes<S>>) -> Self {
                     s.$ity.copy(handle::Handle::decode(r, &mut ()))
                 }
             }
@@ -144,7 +147,7 @@ macro_rules! define_handles {
             }
 
             impl<S> DecodeMut<'_, '_, S> for $ity {
-                fn decode(r: &mut Reader, s: &mut S) -> Self {
+                fn decode(r: &mut Reader<'_>, s: &mut S) -> Self {
                     $ity(handle::Handle::decode(r, s))
                 }
             }
@@ -200,7 +203,7 @@ impl Clone for Literal {
 
 // FIXME(eddyb) `Literal` should not expose internal `Debug` impls.
 impl fmt::Debug for Literal {
-    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         f.write_str(&self.debug())
     }
 }
@@ -212,7 +215,7 @@ impl Clone for SourceFile {
 }
 
 impl fmt::Debug for Span {
-    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         f.write_str(&self.debug())
     }
 }
@@ -275,7 +278,7 @@ impl BridgeState<'_> {
     ///
     /// N.B., while `f` is running, the thread-local state
     /// is `BridgeState::InUse`.
-    fn with<R>(f: impl FnOnce(&mut BridgeState) -> R) -> R {
+    fn with<R>(f: impl FnOnce(&mut BridgeState<'_>) -> R) -> R {
         BRIDGE_STATE.with(|state| {
             state.replace(BridgeState::InUse, |mut state| {
                 // FIXME(#52812) pass `f` directly to `replace` when `RefMutL` is gone
@@ -306,7 +309,7 @@ impl Bridge<'_> {
         BRIDGE_STATE.with(|state| state.set(BridgeState::Connected(self), f))
     }
 
-    fn with<R>(f: impl FnOnce(&mut Bridge) -> R) -> R {
+    fn with<R>(f: impl FnOnce(&mut Bridge<'_>) -> R) -> R {
         BridgeState::with(|state| match state {
             BridgeState::NotConnected => {
                 panic!("procedural macro API is used outside of a procedural macro");
@@ -331,15 +334,15 @@ impl Bridge<'_> {
 #[derive(Copy, Clone)]
 pub struct Client<F> {
     pub(super) get_handle_counters: extern "C" fn() -> &'static HandleCounters,
-    pub(super) run: extern "C" fn(Bridge, F) -> Buffer<u8>,
+    pub(super) run: extern "C" fn(Bridge<'_>, F) -> Buffer<u8>,
     pub(super) f: F,
 }
 
 // FIXME(#53451) public to work around `Cannot create local mono-item` ICE,
 // affecting not only the function itself, but also the `BridgeState` `thread_local!`.
 pub extern "C" fn __run_expand1(
-    mut bridge: Bridge,
-    f: fn(::TokenStream) -> ::TokenStream,
+    mut bridge: Bridge<'_>,
+    f: fn(crate::TokenStream) -> crate::TokenStream,
 ) -> Buffer<u8> {
     // The initial `cached_buffer` contains the input.
     let mut b = bridge.cached_buffer.take();
@@ -352,7 +355,7 @@ pub extern "C" fn __run_expand1(
             // Put the `cached_buffer` back in the `Bridge`, for requests.
             Bridge::with(|bridge| bridge.cached_buffer = b.take());
 
-            let output = f(::TokenStream(input)).0;
+            let output = f(crate::TokenStream(input)).0;
 
             // Take the `cached_buffer` back out, for the output value.
             b = Bridge::with(|bridge| bridge.cached_buffer.take());
@@ -378,8 +381,8 @@ pub extern "C" fn __run_expand1(
     b
 }
 
-impl Client<fn(::TokenStream) -> ::TokenStream> {
-    pub const fn expand1(f: fn(::TokenStream) -> ::TokenStream) -> Self {
+impl Client<fn(crate::TokenStream) -> crate::TokenStream> {
+    pub const fn expand1(f: fn(crate::TokenStream) -> crate::TokenStream) -> Self {
         Client {
             get_handle_counters: HandleCounters::get,
             run: __run_expand1,
@@ -391,8 +394,8 @@ impl Client<fn(::TokenStream) -> ::TokenStream> {
 // FIXME(#53451) public to work around `Cannot create local mono-item` ICE,
 // affecting not only the function itself, but also the `BridgeState` `thread_local!`.
 pub extern "C" fn __run_expand2(
-    mut bridge: Bridge,
-    f: fn(::TokenStream, ::TokenStream) -> ::TokenStream,
+    mut bridge: Bridge<'_>,
+    f: fn(crate::TokenStream, crate::TokenStream) -> crate::TokenStream,
 ) -> Buffer<u8> {
     // The initial `cached_buffer` contains the input.
     let mut b = bridge.cached_buffer.take();
@@ -406,7 +409,7 @@ pub extern "C" fn __run_expand2(
             // Put the `cached_buffer` back in the `Bridge`, for requests.
             Bridge::with(|bridge| bridge.cached_buffer = b.take());
 
-            let output = f(::TokenStream(input), ::TokenStream(input2)).0;
+            let output = f(crate::TokenStream(input), crate::TokenStream(input2)).0;
 
             // Take the `cached_buffer` back out, for the output value.
             b = Bridge::with(|bridge| bridge.cached_buffer.take());
@@ -432,8 +435,10 @@ pub extern "C" fn __run_expand2(
     b
 }
 
-impl Client<fn(::TokenStream, ::TokenStream) -> ::TokenStream> {
-    pub const fn expand2(f: fn(::TokenStream, ::TokenStream) -> ::TokenStream) -> Self {
+impl Client<fn(crate::TokenStream, crate::TokenStream) -> crate::TokenStream> {
+    pub const fn expand2(
+        f: fn(crate::TokenStream, crate::TokenStream) -> crate::TokenStream
+    ) -> Self {
         Client {
             get_handle_counters: HandleCounters::get,
             run: __run_expand2,
@@ -448,17 +453,17 @@ pub enum ProcMacro {
     CustomDerive {
         trait_name: &'static str,
         attributes: &'static [&'static str],
-        client: Client<fn(::TokenStream) -> ::TokenStream>,
+        client: Client<fn(crate::TokenStream) -> crate::TokenStream>,
     },
 
     Attr {
         name: &'static str,
-        client: Client<fn(::TokenStream, ::TokenStream) -> ::TokenStream>,
+        client: Client<fn(crate::TokenStream, crate::TokenStream) -> crate::TokenStream>,
     },
 
     Bang {
         name: &'static str,
-        client: Client<fn(::TokenStream) -> ::TokenStream>,
+        client: Client<fn(crate::TokenStream) -> crate::TokenStream>,
     },
 }
 
@@ -466,7 +471,7 @@ impl ProcMacro {
     pub const fn custom_derive(
         trait_name: &'static str,
         attributes: &'static [&'static str],
-        expand: fn(::TokenStream) -> ::TokenStream,
+        expand: fn(crate::TokenStream) -> crate::TokenStream,
     ) -> Self {
         ProcMacro::CustomDerive {
             trait_name,
@@ -477,7 +482,7 @@ impl ProcMacro {
 
     pub const fn attr(
         name: &'static str,
-        expand: fn(::TokenStream, ::TokenStream) -> ::TokenStream,
+        expand: fn(crate::TokenStream, crate::TokenStream) -> crate::TokenStream,
     ) -> Self {
         ProcMacro::Attr {
             name,
@@ -485,7 +490,10 @@ impl ProcMacro {
         }
     }
 
-    pub const fn bang(name: &'static str, expand: fn(::TokenStream) -> ::TokenStream) -> Self {
+    pub const fn bang(
+        name: &'static str,
+        expand: fn(crate::TokenStream) -> crate::TokenStream
+    ) -> Self {
         ProcMacro::Bang {
             name,
             client: Client::expand1(expand),
diff --git a/src/libproc_macro/bridge/mod.rs b/src/libproc_macro/bridge/mod.rs
index 6c3e534bf9197..3173651b03951 100644
--- a/src/libproc_macro/bridge/mod.rs
+++ b/src/libproc_macro/bridge/mod.rs
@@ -17,7 +17,7 @@ use std::panic;
 use std::sync::atomic::AtomicUsize;
 use std::sync::Once;
 use std::thread;
-use {Delimiter, Level, LineColumn, Spacing};
+use crate::{Delimiter, Level, LineColumn, Spacing};
 
 /// Higher-order macro describing the server RPC API, allowing automatic
 /// generation of type-safe Rust APIs, both client-side and server-side.
@@ -196,9 +196,9 @@ mod scoped_cell;
 #[forbid(unsafe_code)]
 pub mod server;
 
-use self::buffer::Buffer;
-pub use self::rpc::PanicMessage;
-use self::rpc::{Decode, DecodeMut, Encode, Reader, Writer};
+use buffer::Buffer;
+pub use rpc::PanicMessage;
+use rpc::{Decode, DecodeMut, Encode, Reader, Writer};
 
 /// An active connection between a server and a client.
 /// The server creates the bridge (`Bridge::run_server` in `server.rs`),
diff --git a/src/libproc_macro/bridge/rpc.rs b/src/libproc_macro/bridge/rpc.rs
index 74ae711a47372..a3bc0d2290846 100644
--- a/src/libproc_macro/bridge/rpc.rs
+++ b/src/libproc_macro/bridge/rpc.rs
@@ -40,7 +40,7 @@ macro_rules! rpc_encode_decode {
         }
 
         impl<S> DecodeMut<'_, '_, S> for $ty {
-            fn decode(r: &mut Reader, s: &mut S) -> Self {
+            fn decode(r: &mut Reader<'_>, s: &mut S) -> Self {
                 let mut byte = 0x80;
                 let mut v = 0;
                 let mut shift = 0;
@@ -61,7 +61,7 @@ macro_rules! rpc_encode_decode {
         }
 
         impl<S> DecodeMut<'_, '_, S> for $name {
-            fn decode(r: &mut Reader, s: &mut S) -> Self {
+            fn decode(r: &mut Reader<'_>, s: &mut S) -> Self {
                 $name {
                     $($field: DecodeMut::decode(r, s)),*
                 }
@@ -119,7 +119,7 @@ impl<S> Encode<S> for () {
 }
 
 impl<S> DecodeMut<'_, '_, S> for () {
-    fn decode(_: &mut Reader, _: &mut S) -> Self {}
+    fn decode(_: &mut Reader<'_>, _: &mut S) -> Self {}
 }
 
 impl<S> Encode<S> for u8 {
@@ -129,7 +129,7 @@ impl<S> Encode<S> for u8 {
 }
 
 impl<S> DecodeMut<'_, '_, S> for u8 {
-    fn decode(r: &mut Reader, _: &mut S) -> Self {
+    fn decode(r: &mut Reader<'_>, _: &mut S) -> Self {
         let x = r[0];
         *r = &r[1..];
         x
@@ -146,7 +146,7 @@ impl<S> Encode<S> for bool {
 }
 
 impl<S> DecodeMut<'_, '_, S> for bool {
-    fn decode(r: &mut Reader, s: &mut S) -> Self {
+    fn decode(r: &mut Reader<'_>, s: &mut S) -> Self {
         match u8::decode(r, s) {
             0 => false,
             1 => true,
@@ -162,7 +162,7 @@ impl<S> Encode<S> for char {
 }
 
 impl<S> DecodeMut<'_, '_, S> for char {
-    fn decode(r: &mut Reader, s: &mut S) -> Self {
+    fn decode(r: &mut Reader<'_>, s: &mut S) -> Self {
         char::from_u32(u32::decode(r, s)).unwrap()
     }
 }
@@ -174,7 +174,7 @@ impl<S> Encode<S> for NonZeroU32 {
 }
 
 impl<S> DecodeMut<'_, '_, S> for NonZeroU32 {
-    fn decode(r: &mut Reader, s: &mut S) -> Self {
+    fn decode(r: &mut Reader<'_>, s: &mut S) -> Self {
         Self::new(u32::decode(r, s)).unwrap()
     }
 }
@@ -251,7 +251,7 @@ impl<S> Encode<S> for String {
 }
 
 impl<S> DecodeMut<'_, '_, S> for String {
-    fn decode(r: &mut Reader, s: &mut S) -> Self {
+    fn decode(r: &mut Reader<'_>, s: &mut S) -> Self {
         <&str>::decode(r, s).to_string()
     }
 }
@@ -306,7 +306,7 @@ impl<S> Encode<S> for PanicMessage {
 }
 
 impl<S> DecodeMut<'_, '_, S> for PanicMessage {
-    fn decode(r: &mut Reader, s: &mut S) -> Self {
+    fn decode(r: &mut Reader<'_>, s: &mut S) -> Self {
         match Option::<String>::decode(r, s) {
             Some(s) => PanicMessage::String(s),
             None => PanicMessage::Unknown,
diff --git a/src/libproc_macro/bridge/server.rs b/src/libproc_macro/bridge/server.rs
index 9a7cb1318dbe4..75806eb9d1760 100644
--- a/src/libproc_macro/bridge/server.rs
+++ b/src/libproc_macro/bridge/server.rs
@@ -131,7 +131,7 @@ pub trait ExecutionStrategy {
         &self,
         dispatcher: &mut impl DispatcherTrait,
         input: Buffer<u8>,
-        run_client: extern "C" fn(Bridge, D) -> Buffer<u8>,
+        run_client: extern "C" fn(Bridge<'_>, D) -> Buffer<u8>,
         client_data: D,
     ) -> Buffer<u8>;
 }
@@ -143,7 +143,7 @@ impl ExecutionStrategy for SameThread {
         &self,
         dispatcher: &mut impl DispatcherTrait,
         input: Buffer<u8>,
-        run_client: extern "C" fn(Bridge, D) -> Buffer<u8>,
+        run_client: extern "C" fn(Bridge<'_>, D) -> Buffer<u8>,
         client_data: D,
     ) -> Buffer<u8> {
         let mut dispatch = |b| dispatcher.dispatch(b);
@@ -168,7 +168,7 @@ impl ExecutionStrategy for CrossThread1 {
         &self,
         dispatcher: &mut impl DispatcherTrait,
         input: Buffer<u8>,
-        run_client: extern "C" fn(Bridge, D) -> Buffer<u8>,
+        run_client: extern "C" fn(Bridge<'_>, D) -> Buffer<u8>,
         client_data: D,
     ) -> Buffer<u8> {
         use std::sync::mpsc::channel;
@@ -206,7 +206,7 @@ impl ExecutionStrategy for CrossThread2 {
         &self,
         dispatcher: &mut impl DispatcherTrait,
         input: Buffer<u8>,
-        run_client: extern "C" fn(Bridge, D) -> Buffer<u8>,
+        run_client: extern "C" fn(Bridge<'_>, D) -> Buffer<u8>,
         client_data: D,
     ) -> Buffer<u8> {
         use std::sync::{Arc, Mutex};
@@ -273,7 +273,7 @@ fn run_server<
     handle_counters: &'static client::HandleCounters,
     server: S,
     input: I,
-    run_client: extern "C" fn(Bridge, D) -> Buffer<u8>,
+    run_client: extern "C" fn(Bridge<'_>, D) -> Buffer<u8>,
     client_data: D,
 ) -> Result<O, PanicMessage> {
     let mut dispatcher = Dispatcher {
@@ -289,7 +289,7 @@ fn run_server<
     Result::decode(&mut &b[..], &mut dispatcher.handle_store)
 }
 
-impl client::Client<fn(::TokenStream) -> ::TokenStream> {
+impl client::Client<fn(crate::TokenStream) -> crate::TokenStream> {
     pub fn run<S: Server>(
         &self,
         strategy: &impl ExecutionStrategy,
@@ -313,7 +313,7 @@ impl client::Client<fn(::TokenStream) -> ::TokenStream> {
     }
 }
 
-impl client::Client<fn(::TokenStream, ::TokenStream) -> ::TokenStream> {
+impl client::Client<fn(crate::TokenStream, crate::TokenStream) -> crate::TokenStream> {
     pub fn run<S: Server>(
         &self,
         strategy: &impl ExecutionStrategy,
diff --git a/src/libproc_macro/diagnostic.rs b/src/libproc_macro/diagnostic.rs
index 64d0c3893c730..7a0c9419f6234 100644
--- a/src/libproc_macro/diagnostic.rs
+++ b/src/libproc_macro/diagnostic.rs
@@ -1,4 +1,4 @@
-use Span;
+use crate::Span;
 
 /// An enum representing a diagnostic level.
 #[unstable(feature = "proc_macro_diagnostic", issue = "54140")]
@@ -80,7 +80,7 @@ macro_rules! diagnostic_child_methods {
 /// Iterator over the children diagnostics of a `Diagnostic`.
 #[derive(Debug, Clone)]
 #[unstable(feature = "proc_macro_diagnostic", issue = "54140")]
-pub struct Children<'a>(::std::slice::Iter<'a, Diagnostic>);
+pub struct Children<'a>(std::slice::Iter<'a, Diagnostic>);
 
 #[unstable(feature = "proc_macro_diagnostic", issue = "54140")]
 impl<'a> Iterator for Children<'a> {
@@ -161,22 +161,22 @@ impl Diagnostic {
 
     /// Returns an iterator over the children diagnostics of `self`.
     #[unstable(feature = "proc_macro_diagnostic", issue = "54140")]
-    pub fn children(&self) -> Children {
+    pub fn children(&self) -> Children<'_> {
         Children(self.children.iter())
     }
 
     /// Emit the diagnostic.
     #[unstable(feature = "proc_macro_diagnostic", issue = "54140")]
     pub fn emit(self) {
-        fn to_internal(spans: Vec<Span>) -> ::bridge::client::MultiSpan {
-            let mut multi_span = ::bridge::client::MultiSpan::new();
+        fn to_internal(spans: Vec<Span>) -> crate::bridge::client::MultiSpan {
+            let mut multi_span = crate::bridge::client::MultiSpan::new();
             for span in spans {
                 multi_span.push(span.0);
             }
             multi_span
         }
 
-        let mut diag = ::bridge::client::Diagnostic::new(
+        let mut diag = crate::bridge::client::Diagnostic::new(
             self.level,
             &self.message[..],
             to_internal(self.spans),
diff --git a/src/libproc_macro/lib.rs b/src/libproc_macro/lib.rs
index 868190d01057d..bb6f5e234f7c2 100644
--- a/src/libproc_macro/lib.rs
+++ b/src/libproc_macro/lib.rs
@@ -17,7 +17,8 @@
        test(no_crate_inject, attr(deny(warnings))),
        test(attr(allow(dead_code, deprecated, unused_variables, unused_mut))))]
 
-#![feature(nll)]
+#![deny(rust_2018_idioms)]
+
 #![feature(staged_api)]
 #![feature(const_fn)]
 #![feature(extern_types)]
@@ -114,7 +115,7 @@ impl ToString for TokenStream {
 /// with `Delimiter::None` delimiters and negative numeric literals.
 #[stable(feature = "proc_macro_lib", since = "1.15.0")]
 impl fmt::Display for TokenStream {
-    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         f.write_str(&self.to_string())
     }
 }
@@ -122,7 +123,7 @@ impl fmt::Display for TokenStream {
 /// Prints token in a form convenient for debugging.
 #[stable(feature = "proc_macro_lib", since = "1.15.0")]
 impl fmt::Debug for TokenStream {
-    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         f.write_str("TokenStream ")?;
         f.debug_list().entries(self.clone()).finish()
     }
@@ -183,7 +184,7 @@ impl Extend<TokenStream> for TokenStream {
 /// Public implementation details for the `TokenStream` type, such as iterators.
 #[stable(feature = "proc_macro_lib2", since = "1.29.0")]
 pub mod token_stream {
-    use {bridge, Group, Ident, Literal, Punct, TokenTree, TokenStream};
+    use crate::{bridge, Group, Ident, Literal, Punct, TokenTree, TokenStream};
 
     /// An iterator over `TokenStream`'s `TokenTree`s.
     /// The iteration is "shallow", e.g., the iterator doesn't recurse into delimited groups,
@@ -340,7 +341,7 @@ impl Span {
 /// Prints a span in a form convenient for debugging.
 #[stable(feature = "proc_macro_lib2", since = "1.29.0")]
 impl fmt::Debug for Span {
-    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         self.0.fmt(f)
     }
 }
@@ -398,7 +399,7 @@ impl SourceFile {
 
 #[unstable(feature = "proc_macro_span", issue = "54725")]
 impl fmt::Debug for SourceFile {
-    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         f.debug_struct("SourceFile")
             .field("path", &self.path())
             .field("is_real", &self.is_real())
@@ -483,7 +484,7 @@ impl TokenTree {
 /// Prints token tree in a form convenient for debugging.
 #[stable(feature = "proc_macro_lib2", since = "1.29.0")]
 impl fmt::Debug for TokenTree {
-    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         // Each of these has the name in the struct type in the derived debug,
         // so don't bother with an extra layer of indirection
         match *self {
@@ -542,7 +543,7 @@ impl ToString for TokenTree {
 /// with `Delimiter::None` delimiters and negative numeric literals.
 #[stable(feature = "proc_macro_lib2", since = "1.29.0")]
 impl fmt::Display for TokenTree {
-    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         f.write_str(&self.to_string())
     }
 }
@@ -667,14 +668,14 @@ impl ToString for Group {
 /// with `Delimiter::None` delimiters.
 #[stable(feature = "proc_macro_lib2", since = "1.29.0")]
 impl fmt::Display for Group {
-    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         f.write_str(&self.to_string())
     }
 }
 
 #[stable(feature = "proc_macro_lib2", since = "1.29.0")]
 impl fmt::Debug for Group {
-    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         f.debug_struct("Group")
             .field("delimiter", &self.delimiter())
             .field("stream", &self.stream())
@@ -763,14 +764,14 @@ impl ToString for Punct {
 /// back into the same character.
 #[stable(feature = "proc_macro_lib2", since = "1.29.0")]
 impl fmt::Display for Punct {
-    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         f.write_str(&self.to_string())
     }
 }
 
 #[stable(feature = "proc_macro_lib2", since = "1.29.0")]
 impl fmt::Debug for Punct {
-    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         f.debug_struct("Punct")
             .field("ch", &self.as_char())
             .field("spacing", &self.spacing())
@@ -842,14 +843,14 @@ impl ToString for Ident {
 /// back into the same identifier.
 #[stable(feature = "proc_macro_lib2", since = "1.29.0")]
 impl fmt::Display for Ident {
-    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         f.write_str(&self.to_string())
     }
 }
 
 #[stable(feature = "proc_macro_lib2", since = "1.29.0")]
 impl fmt::Debug for Ident {
-    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         f.debug_struct("Ident")
             .field("ident", &self.to_string())
             .field("span", &self.span())
@@ -1092,14 +1093,14 @@ impl ToString for Literal {
 /// back into the same literal (except for possible rounding for floating point literals).
 #[stable(feature = "proc_macro_lib2", since = "1.29.0")]
 impl fmt::Display for Literal {
-    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         f.write_str(&self.to_string())
     }
 }
 
 #[stable(feature = "proc_macro_lib2", since = "1.29.0")]
 impl fmt::Debug for Literal {
-    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         // FIXME(eddyb) `Literal` should not expose internal `Debug` impls.
         self.0.fmt(f)
     }
diff --git a/src/libproc_macro/quote.rs b/src/libproc_macro/quote.rs
index bd7e96210a950..e3d31b78f4a09 100644
--- a/src/libproc_macro/quote.rs
+++ b/src/libproc_macro/quote.rs
@@ -4,7 +4,7 @@
 //! This quasiquoter uses macros 2.0 hygiene to reliably access
 //! items from `proc_macro`, to build a `proc_macro::TokenStream`.
 
-use {Delimiter, Group, Ident, Literal, Punct, Spacing, Span, TokenStream, TokenTree};
+use crate::{Delimiter, Group, Ident, Literal, Punct, Spacing, Span, TokenStream, TokenTree};
 
 macro_rules! quote_tt {
     (($($t:tt)*)) => { Group::new(Delimiter::Parenthesis, quote!($($t)*)) };
@@ -63,7 +63,7 @@ macro_rules! quote {
 #[unstable(feature = "proc_macro_quote", issue = "54722")]
 pub fn quote(stream: TokenStream) -> TokenStream {
     if stream.is_empty() {
-        return quote!(::TokenStream::new());
+        return quote!(crate::TokenStream::new());
     }
     let mut after_dollar = false;
     let tokens = stream
@@ -73,7 +73,7 @@ pub fn quote(stream: TokenStream) -> TokenStream {
                 after_dollar = false;
                 match tree {
                     TokenTree::Ident(_) => {
-                        return Some(quote!(Into::<::TokenStream>::into(
+                        return Some(quote!(Into::<crate::TokenStream>::into(
                         Clone::clone(&(@ tree))),));
                     }
                     TokenTree::Punct(ref tt) if tt.as_char() == '$' => {}
@@ -86,33 +86,33 @@ pub fn quote(stream: TokenStream) -> TokenStream {
                 }
             }
 
-            Some(quote!(::TokenStream::from((@ match tree {
-                TokenTree::Punct(tt) => quote!(::TokenTree::Punct(::Punct::new(
+            Some(quote!(crate::TokenStream::from((@ match tree {
+                TokenTree::Punct(tt) => quote!(crate::TokenTree::Punct(crate::Punct::new(
                     (@ TokenTree::from(Literal::character(tt.as_char()))),
                     (@ match tt.spacing() {
-                        Spacing::Alone => quote!(::Spacing::Alone),
-                        Spacing::Joint => quote!(::Spacing::Joint),
+                        Spacing::Alone => quote!(crate::Spacing::Alone),
+                        Spacing::Joint => quote!(crate::Spacing::Joint),
                     }),
                 ))),
-                TokenTree::Group(tt) => quote!(::TokenTree::Group(::Group::new(
+                TokenTree::Group(tt) => quote!(crate::TokenTree::Group(crate::Group::new(
                     (@ match tt.delimiter() {
-                        Delimiter::Parenthesis => quote!(::Delimiter::Parenthesis),
-                        Delimiter::Brace => quote!(::Delimiter::Brace),
-                        Delimiter::Bracket => quote!(::Delimiter::Bracket),
-                        Delimiter::None => quote!(::Delimiter::None),
+                        Delimiter::Parenthesis => quote!(crate::Delimiter::Parenthesis),
+                        Delimiter::Brace => quote!(crate::Delimiter::Brace),
+                        Delimiter::Bracket => quote!(crate::Delimiter::Bracket),
+                        Delimiter::None => quote!(crate::Delimiter::None),
                     }),
                     (@ quote(tt.stream())),
                 ))),
-                TokenTree::Ident(tt) => quote!(::TokenTree::Ident(::Ident::new(
+                TokenTree::Ident(tt) => quote!(crate::TokenTree::Ident(crate::Ident::new(
                     (@ TokenTree::from(Literal::string(&tt.to_string()))),
                     (@ quote_span(tt.span())),
                 ))),
-                TokenTree::Literal(tt) => quote!(::TokenTree::Literal({
+                TokenTree::Literal(tt) => quote!(crate::TokenTree::Literal({
                     let mut iter = (@ TokenTree::from(Literal::string(&tt.to_string())))
-                        .parse::<::TokenStream>()
+                        .parse::<crate::TokenStream>()
                         .unwrap()
                         .into_iter();
-                    if let (Some(::TokenTree::Literal(mut lit)), None) =
+                    if let (Some(crate::TokenTree::Literal(mut lit)), None) =
                         (iter.next(), iter.next())
                     {
                         lit.set_span((@ quote_span(tt.span())));
@@ -129,12 +129,12 @@ pub fn quote(stream: TokenStream) -> TokenStream {
         panic!("unexpected trailing `$` in `quote!`");
     }
 
-    quote!([(@ tokens)].iter().cloned().collect::<::TokenStream>())
+    quote!([(@ tokens)].iter().cloned().collect::<crate::TokenStream>())
 }
 
 /// Quote a `Span` into a `TokenStream`.
 /// This is needed to implement a custom quoter.
 #[unstable(feature = "proc_macro_quote", issue = "54722")]
 pub fn quote_span(_: Span) -> TokenStream {
-    quote!(::Span::def_site())
+    quote!(crate::Span::def_site())
 }

From 4ae8abab9369357a0e5cabd66673ad3d4af307b1 Mon Sep 17 00:00:00 2001
From: Hirokazu Hata <h.hata.ai.t@gmail.com>
Date: Mon, 4 Feb 2019 00:56:16 +0900
Subject: [PATCH 04/24] Transition libtest to 2018 edition

---
 src/libtest/Cargo.toml         |  1 +
 src/libtest/formatters/json.rs |  2 +-
 src/libtest/lib.rs             | 33 +++++++++++++++++----------------
 src/libtest/stats.rs           |  6 +++---
 4 files changed, 22 insertions(+), 20 deletions(-)

diff --git a/src/libtest/Cargo.toml b/src/libtest/Cargo.toml
index aade10ed6c324..10bdd6e877c4f 100644
--- a/src/libtest/Cargo.toml
+++ b/src/libtest/Cargo.toml
@@ -2,6 +2,7 @@
 authors = ["The Rust Project Developers"]
 name = "test"
 version = "0.0.0"
+edition = "2018"
 
 [lib]
 name = "test"
diff --git a/src/libtest/formatters/json.rs b/src/libtest/formatters/json.rs
index cc1568265c02e..a06497f98626a 100644
--- a/src/libtest/formatters/json.rs
+++ b/src/libtest/formatters/json.rs
@@ -145,7 +145,7 @@ impl<T: Write> OutputFormatter for JsonFormatter<T> {
 struct EscapedString<S: AsRef<str>>(S);
 
 impl<S: AsRef<str>> ::std::fmt::Display for EscapedString<S> {
-    fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
+    fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
         let mut start = 0;
 
         for (i, byte) in self.0.as_ref().bytes().enumerate() {
diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs
index c8eceeeaa5a81..b3d719d5c64db 100644
--- a/src/libtest/lib.rs
+++ b/src/libtest/lib.rs
@@ -17,6 +17,7 @@
 // this crate, which relies on this attribute (rather than the value of `--crate-name` passed by
 // cargo) to detect this crate.
 
+#![deny(rust_2018_idioms)]
 #![crate_name = "test"]
 #![unstable(feature = "test", issue = "27812")]
 #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
@@ -32,10 +33,10 @@
 #![feature(termination_trait_lib)]
 #![feature(test)]
 
-extern crate getopts;
+use getopts;
 #[cfg(any(unix, target_os = "cloudabi"))]
 extern crate libc;
-extern crate term;
+use term;
 
 // FIXME(#54291): rustc and/or LLVM don't yet support building with panic-unwind
 //                on aarch64-pc-windows-msvc, so we don't link libtest against
@@ -78,7 +79,7 @@ const QUIET_MODE_MAX_COLUMN: usize = 100; // insert a '\n' after 100 tests in qu
 
 // to be used by rustc to compile tests in libtest
 pub mod test {
-    pub use {assert_test_result, filter_tests, parse_opts, run_test, test_main, test_main_static,
+    pub use crate::{assert_test_result, filter_tests, parse_opts, run_test, test_main, test_main_static,
              Bencher, DynTestFn, DynTestName, Metric, MetricMap, Options, RunIgnored, ShouldPanic,
              StaticBenchFn, StaticTestFn, StaticTestName, TestDesc, TestDescAndFn, TestName,
              TestOpts, TestResult, TrFailed, TrFailedMsg, TrIgnored, TrOk};
@@ -87,7 +88,7 @@ pub mod test {
 pub mod stats;
 mod formatters;
 
-use formatters::{JsonFormatter, OutputFormatter, PrettyFormatter, TerseFormatter};
+use crate::formatters::{JsonFormatter, OutputFormatter, PrettyFormatter, TerseFormatter};
 
 /// Whether to execute tests concurrently or not
 #[derive(Copy, Clone, Debug, PartialEq, Eq)]
@@ -131,7 +132,7 @@ impl TestName {
     }
 }
 impl fmt::Display for TestName {
-    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         fmt::Display::fmt(self.as_slice(), f)
     }
 }
@@ -185,7 +186,7 @@ impl TestFn {
 }
 
 impl fmt::Debug for TestFn {
-    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         f.write_str(match *self {
             StaticTestFn(..) => "StaticTestFn(..)",
             StaticBenchFn(..) => "StaticBenchFn(..)",
@@ -823,7 +824,7 @@ pub fn list_tests_console(opts: &TestOpts, tests: Vec<TestDescAndFn>) -> io::Res
     let mut nbench = 0;
 
     for test in filter_tests(&opts, tests) {
-        use TestFn::*;
+        use crate::TestFn::*;
 
         let TestDescAndFn {
             desc: TestDesc { name, .. },
@@ -1454,12 +1455,12 @@ pub fn run_test(
 
     match testfn {
         DynBenchFn(bencher) => {
-            ::bench::benchmark(desc, monitor_ch, opts.nocapture, |harness| {
+            crate::bench::benchmark(desc, monitor_ch, opts.nocapture, |harness| {
                 bencher.run(harness)
             });
         }
         StaticBenchFn(benchfn) => {
-            ::bench::benchmark(desc, monitor_ch, opts.nocapture, |harness| {
+            crate::bench::benchmark(desc, monitor_ch, opts.nocapture, |harness| {
                 (benchfn.clone())(harness)
             });
         }
@@ -1673,7 +1674,7 @@ pub mod bench {
     use std::cmp;
     use std::io;
     use std::sync::{Arc, Mutex};
-    use stats;
+    use crate::stats;
     use super::{BenchMode, BenchSamples, Bencher, MonitorMsg, Sender, Sink, TestDesc, TestResult};
 
     pub fn benchmark<F>(desc: TestDesc, monitor_ch: Sender<MonitorMsg>, nocapture: bool, f: F)
@@ -1749,13 +1750,13 @@ pub mod bench {
 
 #[cfg(test)]
 mod tests {
-    use test::{filter_tests, parse_opts, run_test, DynTestFn, DynTestName, MetricMap, RunIgnored,
+    use crate::test::{filter_tests, parse_opts, run_test, DynTestFn, DynTestName, MetricMap, RunIgnored,
                ShouldPanic, StaticTestName, TestDesc, TestDescAndFn, TestOpts, TrFailed,
                TrFailedMsg, TrIgnored, TrOk};
     use std::sync::mpsc::channel;
-    use bench;
-    use Bencher;
-    use Concurrent;
+    use crate::bench;
+    use crate::Bencher;
+    use crate::Concurrent;
 
 
     fn one_ignored_one_unignored_test() -> Vec<TestDescAndFn> {
@@ -2156,7 +2157,7 @@ mod tests {
             allow_fail: false,
         };
 
-        ::bench::benchmark(desc, tx, true, f);
+        crate::bench::benchmark(desc, tx, true, f);
         rx.recv().unwrap();
     }
 
@@ -2175,7 +2176,7 @@ mod tests {
             allow_fail: false,
         };
 
-        ::bench::benchmark(desc, tx, true, f);
+        crate::bench::benchmark(desc, tx, true, f);
         rx.recv().unwrap();
     }
 }
diff --git a/src/libtest/stats.rs b/src/libtest/stats.rs
index 9fc5f09ba6c92..5c9421d5ea4b0 100644
--- a/src/libtest/stats.rs
+++ b/src/libtest/stats.rs
@@ -319,8 +319,8 @@ pub fn winsorize(samples: &mut [f64], pct: f64) {
 
 #[cfg(test)]
 mod tests {
-    use stats::Stats;
-    use stats::Summary;
+    use crate::stats::Stats;
+    use crate::stats::Summary;
     use std::f64;
     use std::io::prelude::*;
     use std::io;
@@ -899,7 +899,7 @@ mod tests {
 mod bench {
     extern crate test;
     use self::test::Bencher;
-    use stats::Stats;
+    use crate::stats::Stats;
 
     #[bench]
     pub fn sum_three_items(b: &mut Bencher) {

From 3c6787306d6b7a45e3b76f18ce543be700fb3c00 Mon Sep 17 00:00:00 2001
From: Hirokazu Hata <h.hata.ai.t@gmail.com>
Date: Mon, 4 Feb 2019 08:22:30 +0900
Subject: [PATCH 05/24] Excute rustfmt for fixing tidy check

---
 src/libtest/lib.rs | 141 +++++++++++++++++++++++++++------------------
 1 file changed, 86 insertions(+), 55 deletions(-)

diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs
index b3d719d5c64db..cced66f4a22bd 100644
--- a/src/libtest/lib.rs
+++ b/src/libtest/lib.rs
@@ -20,9 +20,12 @@
 #![deny(rust_2018_idioms)]
 #![crate_name = "test"]
 #![unstable(feature = "test", issue = "27812")]
-#![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
-       html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
-       html_root_url = "https://doc.rust-lang.org/nightly/", test(attr(deny(warnings))))]
+#![doc(
+    html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
+    html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
+    html_root_url = "https://doc.rust-lang.org/nightly/",
+    test(attr(deny(warnings)))
+)]
 #![feature(asm)]
 #![feature(fnbox)]
 #![cfg_attr(any(unix, target_os = "cloudabi"), feature(libc, rustc_private))]
@@ -47,52 +50,57 @@ use term;
 #[cfg(not(all(windows, target_arch = "aarch64")))]
 extern crate panic_unwind;
 
-pub use self::TestFn::*;
 pub use self::ColorConfig::*;
-pub use self::TestResult::*;
-pub use self::TestName::*;
-use self::TestEvent::*;
 use self::NamePadding::*;
 use self::OutputLocation::*;
+use self::TestEvent::*;
+pub use self::TestFn::*;
+pub use self::TestName::*;
+pub use self::TestResult::*;
 
-use std::panic::{catch_unwind, AssertUnwindSafe};
 use std::any::Any;
+use std::borrow::Cow;
 use std::boxed::FnBox;
 use std::cmp;
 use std::collections::BTreeMap;
 use std::env;
 use std::fmt;
 use std::fs::File;
-use std::io::prelude::*;
 use std::io;
+use std::io::prelude::*;
+use std::panic::{catch_unwind, AssertUnwindSafe};
 use std::path::PathBuf;
+use std::process;
 use std::process::Termination;
 use std::sync::mpsc::{channel, Sender};
 use std::sync::{Arc, Mutex};
 use std::thread;
 use std::time::{Duration, Instant};
-use std::borrow::Cow;
-use std::process;
 
 const TEST_WARN_TIMEOUT_S: u64 = 60;
 const QUIET_MODE_MAX_COLUMN: usize = 100; // insert a '\n' after 100 tests in quiet mode
 
 // to be used by rustc to compile tests in libtest
 pub mod test {
-    pub use crate::{assert_test_result, filter_tests, parse_opts, run_test, test_main, test_main_static,
-             Bencher, DynTestFn, DynTestName, Metric, MetricMap, Options, RunIgnored, ShouldPanic,
-             StaticBenchFn, StaticTestFn, StaticTestName, TestDesc, TestDescAndFn, TestName,
-             TestOpts, TestResult, TrFailed, TrFailedMsg, TrIgnored, TrOk};
+    pub use crate::{
+        assert_test_result, filter_tests, parse_opts, run_test, test_main, test_main_static,
+        Bencher, DynTestFn, DynTestName, Metric, MetricMap, Options, RunIgnored, ShouldPanic,
+        StaticBenchFn, StaticTestFn, StaticTestName, TestDesc, TestDescAndFn, TestName, TestOpts,
+        TestResult, TrFailed, TrFailedMsg, TrIgnored, TrOk,
+    };
 }
 
-pub mod stats;
 mod formatters;
+pub mod stats;
 
 use crate::formatters::{JsonFormatter, OutputFormatter, PrettyFormatter, TerseFormatter};
 
 /// Whether to execute tests concurrently or not
 #[derive(Copy, Clone, Debug, PartialEq, Eq)]
-pub enum Concurrent { Yes, No }
+pub enum Concurrent {
+    Yes,
+    No,
+}
 
 // The name of a test. By convention this follows the rules for rust
 // paths; i.e., it should be a series of identifiers separated by double
@@ -330,8 +338,7 @@ pub fn test_main_static(tests: &[&TestDescAndFn]) {
 pub fn assert_test_result<T: Termination>(result: T) {
     let code = result.report();
     assert_eq!(
-        code,
-        0,
+        code, 0,
         "the test returned a termination value with a non-zero status code ({}) \
          which indicates a failure",
         code
@@ -559,14 +566,16 @@ pub fn parse_opts(args: &[String]) -> Option<OptRes> {
     let include_ignored = matches.opt_present("include-ignored");
     if !allow_unstable && include_ignored {
         return Some(Err(
-            "The \"include-ignored\" flag is only accepted on the nightly compiler".into()
+            "The \"include-ignored\" flag is only accepted on the nightly compiler".into(),
         ));
     }
 
     let run_ignored = match (include_ignored, matches.opt_present("ignored")) {
-        (true, true) => return Some(Err(
-            "the options --include-ignored and --ignored are mutually exclusive".into()
-        )),
+        (true, true) => {
+            return Some(Err(
+                "the options --include-ignored and --ignored are mutually exclusive".into(),
+            ));
+        }
         (true, false) => RunIgnored::Yes,
         (false, true) => RunIgnored::Only,
         (false, false) => RunIgnored::No,
@@ -598,7 +607,7 @@ pub fn parse_opts(args: &[String]) -> Option<OptRes> {
                     "argument for --test-threads must be a number > 0 \
                      (error: {})",
                     e
-                )))
+                )));
             }
         },
         None => None,
@@ -614,7 +623,7 @@ pub fn parse_opts(args: &[String]) -> Option<OptRes> {
                 "argument for --color must be auto, always, or never (was \
                  {})",
                 v
-            )))
+            )));
         }
     };
 
@@ -636,7 +645,7 @@ pub fn parse_opts(args: &[String]) -> Option<OptRes> {
                 "argument for --format must be pretty, terse, or json (was \
                  {})",
                 v
-            )))
+            )));
         }
     };
 
@@ -1013,10 +1022,12 @@ fn use_color(opts: &TestOpts) -> bool {
     }
 }
 
-#[cfg(any(target_os = "cloudabi",
-          target_os = "redox",
-          all(target_arch = "wasm32", not(target_os = "emscripten")),
-          all(target_vendor = "fortanix", target_env = "sgx")))]
+#[cfg(any(
+    target_os = "cloudabi",
+    target_os = "redox",
+    all(target_arch = "wasm32", not(target_os = "emscripten")),
+    all(target_vendor = "fortanix", target_env = "sgx")
+))]
 fn stdout_isatty() -> bool {
     // FIXME: Implement isatty on Redox and SGX
     false
@@ -1247,21 +1258,34 @@ fn get_concurrency() -> usize {
         1
     }
 
-    #[cfg(any(all(target_arch = "wasm32", not(target_os = "emscripten")),
-              all(target_vendor = "fortanix", target_env = "sgx")))]
+    #[cfg(any(
+        all(target_arch = "wasm32", not(target_os = "emscripten")),
+        all(target_vendor = "fortanix", target_env = "sgx")
+    ))]
     fn num_cpus() -> usize {
         1
     }
 
-    #[cfg(any(target_os = "android", target_os = "cloudabi", target_os = "emscripten",
-              target_os = "fuchsia", target_os = "ios", target_os = "linux",
-              target_os = "macos", target_os = "solaris"))]
+    #[cfg(any(
+        target_os = "android",
+        target_os = "cloudabi",
+        target_os = "emscripten",
+        target_os = "fuchsia",
+        target_os = "ios",
+        target_os = "linux",
+        target_os = "macos",
+        target_os = "solaris"
+    ))]
     fn num_cpus() -> usize {
         unsafe { libc::sysconf(libc::_SC_NPROCESSORS_ONLN) as usize }
     }
 
-    #[cfg(any(target_os = "freebsd", target_os = "dragonfly", target_os = "bitrig",
-              target_os = "netbsd"))]
+    #[cfg(any(
+        target_os = "freebsd",
+        target_os = "dragonfly",
+        target_os = "bitrig",
+        target_os = "netbsd"
+    ))]
     fn num_cpus() -> usize {
         use std::ptr;
 
@@ -1344,18 +1368,20 @@ pub fn filter_tests(opts: &TestOpts, tests: Vec<TestDescAndFn>) -> Vec<TestDescA
     }
 
     // Skip tests that match any of the skip filters
-    filtered.retain(|test| {
-        !opts.skip.iter().any(|sf| matches_filter(test, sf))
-    });
+    filtered.retain(|test| !opts.skip.iter().any(|sf| matches_filter(test, sf)));
 
     // maybe unignore tests
     match opts.run_ignored {
         RunIgnored::Yes => {
-            filtered.iter_mut().for_each(|test| test.desc.ignore = false);
-        },
+            filtered
+                .iter_mut()
+                .for_each(|test| test.desc.ignore = false);
+        }
         RunIgnored::Only => {
             filtered.retain(|test| test.desc.ignore);
-            filtered.iter_mut().for_each(|test| test.desc.ignore = false);
+            filtered
+                .iter_mut()
+                .for_each(|test| test.desc.ignore = false);
         }
         RunIgnored::No => {}
     }
@@ -1397,7 +1423,8 @@ pub fn run_test(
 ) {
     let TestDescAndFn { desc, testfn } = test;
 
-    let ignore_because_panic_abort = cfg!(target_arch = "wasm32") && !cfg!(target_os = "emscripten")
+    let ignore_because_panic_abort = cfg!(target_arch = "wasm32")
+        && !cfg!(target_os = "emscripten")
         && desc.should_panic != ShouldPanic::No;
 
     if force_ignore || desc.ignore || ignore_because_panic_abort {
@@ -1488,7 +1515,8 @@ fn calc_result(desc: &TestDesc, task_result: Result<(), Box<dyn Any + Send>>) ->
     match (&desc.should_panic, task_result) {
         (&ShouldPanic::No, Ok(())) | (&ShouldPanic::Yes, Err(_)) => TrOk,
         (&ShouldPanic::YesWithMessage(msg), Err(ref err)) => {
-            if err.downcast_ref::<String>()
+            if err
+                .downcast_ref::<String>()
                 .map(|e| &**e)
                 .or_else(|| err.downcast_ref::<&'static str>().map(|e| *e))
                 .map(|e| e.contains(msg))
@@ -1535,7 +1563,8 @@ impl MetricMap {
     }
 
     pub fn fmt_metrics(&self) -> String {
-        let v = self.0
+        let v = self
+            .0
             .iter()
             .map(|(k, v)| format!("{}: {} (+/- {})", *k, v.value, v.noise))
             .collect::<Vec<_>>();
@@ -1644,7 +1673,8 @@ where
 
         // If we've run for 100ms and seem to have converged to a
         // stable median.
-        if loop_run > Duration::from_millis(100) && summ.median_abs_dev_pct < 1.0
+        if loop_run > Duration::from_millis(100)
+            && summ.median_abs_dev_pct < 1.0
             && summ.median - summ5.median < summ5.median_abs_dev
         {
             return summ5;
@@ -1670,12 +1700,12 @@ where
 }
 
 pub mod bench {
-    use std::panic::{catch_unwind, AssertUnwindSafe};
+    use super::{BenchMode, BenchSamples, Bencher, MonitorMsg, Sender, Sink, TestDesc, TestResult};
+    use crate::stats;
     use std::cmp;
     use std::io;
+    use std::panic::{catch_unwind, AssertUnwindSafe};
     use std::sync::{Arc, Mutex};
-    use crate::stats;
-    use super::{BenchMode, BenchSamples, Bencher, MonitorMsg, Sender, Sink, TestDesc, TestResult};
 
     pub fn benchmark<F>(desc: TestDesc, monitor_ch: Sender<MonitorMsg>, nocapture: bool, f: F)
     where
@@ -1750,14 +1780,15 @@ pub mod bench {
 
 #[cfg(test)]
 mod tests {
-    use crate::test::{filter_tests, parse_opts, run_test, DynTestFn, DynTestName, MetricMap, RunIgnored,
-               ShouldPanic, StaticTestName, TestDesc, TestDescAndFn, TestOpts, TrFailed,
-               TrFailedMsg, TrIgnored, TrOk};
-    use std::sync::mpsc::channel;
     use crate::bench;
+    use crate::test::{
+        filter_tests, parse_opts, run_test, DynTestFn, DynTestName, MetricMap, RunIgnored,
+        ShouldPanic, StaticTestName, TestDesc, TestDescAndFn, TestOpts, TrFailed, TrFailedMsg,
+        TrIgnored, TrOk,
+    };
     use crate::Bencher;
     use crate::Concurrent;
-
+    use std::sync::mpsc::channel;
 
     fn one_ignored_one_unignored_test() -> Vec<TestDescAndFn> {
         vec![

From 27c8dfddac4c69a6fd399abe537e1007306c58cf Mon Sep 17 00:00:00 2001
From: Austin Bonander <austin.bonander@gmail.com>
Date: Sun, 3 Feb 2019 22:38:43 -0800
Subject: [PATCH 06/24] Improve error message and docs for non-UTF-8 bytes in
 stdio on Windows

cc #23344
---
 src/libstd/io/stdio.rs          | 45 +++++++++++++++++++++++++++++++++
 src/libstd/sys/windows/stdio.rs |  4 ++-
 2 files changed, 48 insertions(+), 1 deletion(-)

diff --git a/src/libstd/io/stdio.rs b/src/libstd/io/stdio.rs
index d249469323063..4068c0f9c7de5 100644
--- a/src/libstd/io/stdio.rs
+++ b/src/libstd/io/stdio.rs
@@ -131,6 +131,11 @@ fn handle_ebadf<T>(r: io::Result<T>, default: T) -> io::Result<T> {
 ///
 /// [`io::stdin`]: fn.stdin.html
 /// [`BufRead`]: trait.BufRead.html
+///
+/// ### Note: Windows Portability Consideration
+/// When operating in a console, the Windows implementation of this stream does not support
+/// non-UTF-8 byte sequences. Attempting to read bytes that are not valid UTF-8 will return
+/// an error.
 #[stable(feature = "rust1", since = "1.0.0")]
 pub struct Stdin {
     inner: Arc<Mutex<BufReader<Maybe<StdinRaw>>>>,
@@ -144,6 +149,11 @@ pub struct Stdin {
 /// [`Read`]: trait.Read.html
 /// [`BufRead`]: trait.BufRead.html
 /// [`Stdin::lock`]: struct.Stdin.html#method.lock
+///
+/// ### Note: Windows Portability Consideration
+/// When operating in a console, the Windows implementation of this stream does not support
+/// non-UTF-8 byte sequences. Attempting to read bytes that are not valid UTF-8 will return
+/// an error.
 #[stable(feature = "rust1", since = "1.0.0")]
 pub struct StdinLock<'a> {
     inner: MutexGuard<'a, BufReader<Maybe<StdinRaw>>>,
@@ -157,6 +167,11 @@ pub struct StdinLock<'a> {
 ///
 /// [lock]: struct.Stdin.html#method.lock
 ///
+/// ### Note: Windows Portability Consideration
+/// When operating in a console, the Windows implementation of this stream does not support
+/// non-UTF-8 byte sequences. Attempting to read bytes that are not valid UTF-8 will return
+/// an error.
+///
 /// # Examples
 ///
 /// Using implicit synchronization:
@@ -328,6 +343,11 @@ impl<'a> fmt::Debug for StdinLock<'a> {
 ///
 /// Created by the [`io::stdout`] method.
 ///
+/// ### Note: Windows Portability Consideration
+/// When operating in a console, the Windows implementation of this stream does not support
+/// non-UTF-8 byte sequences. Attempting to write bytes that are not valid UTF-8 will return
+/// an error.
+///
 /// [`lock`]: #method.lock
 /// [`io::stdout`]: fn.stdout.html
 #[stable(feature = "rust1", since = "1.0.0")]
@@ -343,6 +363,11 @@ pub struct Stdout {
 /// This handle implements the [`Write`] trait, and is constructed via
 /// the [`Stdout::lock`] method.
 ///
+/// ### Note: Windows Portability Consideration
+/// When operating in a console, the Windows implementation of this stream does not support
+/// non-UTF-8 byte sequences. Attempting to write bytes that are not valid UTF-8 will return
+/// an error.
+///
 /// [`Write`]: trait.Write.html
 /// [`Stdout::lock`]: struct.Stdout.html#method.lock
 #[stable(feature = "rust1", since = "1.0.0")]
@@ -358,6 +383,11 @@ pub struct StdoutLock<'a> {
 ///
 /// [Stdout::lock]: struct.Stdout.html#method.lock
 ///
+/// ### Note: Windows Portability Consideration
+/// When operating in a console, the Windows implementation of this stream does not support
+/// non-UTF-8 byte sequences. Attempting to write bytes that are not valid UTF-8 will return
+/// an error.
+///
 /// # Examples
 ///
 /// Using implicit synchronization:
@@ -476,6 +506,11 @@ impl<'a> fmt::Debug for StdoutLock<'a> {
 /// For more information, see the [`io::stderr`] method.
 ///
 /// [`io::stderr`]: fn.stderr.html
+///
+/// ### Note: Windows Portability Consideration
+/// When operating in a console, the Windows implementation of this stream does not support
+/// non-UTF-8 byte sequences. Attempting to write bytes that are not valid UTF-8 will return
+/// an error.
 #[stable(feature = "rust1", since = "1.0.0")]
 pub struct Stderr {
     inner: Arc<ReentrantMutex<RefCell<Maybe<StderrRaw>>>>,
@@ -487,6 +522,11 @@ pub struct Stderr {
 /// the [`Stderr::lock`] method.
 ///
 /// [`Stderr::lock`]: struct.Stderr.html#method.lock
+///
+/// ### Note: Windows Portability Consideration
+/// When operating in a console, the Windows implementation of this stream does not support
+/// non-UTF-8 byte sequences. Attempting to write bytes that are not valid UTF-8 will return
+/// an error.
 #[stable(feature = "rust1", since = "1.0.0")]
 pub struct StderrLock<'a> {
     inner: ReentrantMutexGuard<'a, RefCell<Maybe<StderrRaw>>>,
@@ -496,6 +536,11 @@ pub struct StderrLock<'a> {
 ///
 /// This handle is not buffered.
 ///
+/// ### Note: Windows Portability Consideration
+/// When operating in a console, the Windows implementation of this stream does not support
+/// non-UTF-8 byte sequences. Attempting to write bytes that are not valid UTF-8 will return
+/// an error.
+///
 /// # Examples
 ///
 /// Using implicit synchronization:
diff --git a/src/libstd/sys/windows/stdio.rs b/src/libstd/sys/windows/stdio.rs
index a4f4bd22cd921..0ea19a855257b 100644
--- a/src/libstd/sys/windows/stdio.rs
+++ b/src/libstd/sys/windows/stdio.rs
@@ -188,7 +188,9 @@ impl Output {
 }
 
 fn invalid_encoding() -> io::Error {
-    io::Error::new(io::ErrorKind::InvalidData, "text was not valid unicode")
+    io::Error::new(io::ErrorKind::InvalidData,
+                   "Windows stdio in console mode does not support non-UTF-8 byte sequences; \
+                    see https://github.com/rust-lang/rust/issues/23344")
 }
 
 fn readconsole_input_control(wakeup_mask: c::ULONG) -> c::CONSOLE_READCONSOLE_CONTROL {

From 94f121ff3f47fecdcf458b691f1bf87f8b1f1f1d Mon Sep 17 00:00:00 2001
From: Taiki Endo <te316e89@gmail.com>
Date: Mon, 4 Feb 2019 21:49:54 +0900
Subject: [PATCH 07/24] libsyntax_ext => 2018

---
 src/libsyntax_ext/Cargo.toml                  |   1 +
 src/libsyntax_ext/asm.rs                      |  11 +-
 src/libsyntax_ext/assert.rs                   |   5 +-
 src/libsyntax_ext/cfg.rs                      |   8 +-
 src/libsyntax_ext/compile_error.rs            |   5 +-
 src/libsyntax_ext/concat.rs                   |   3 +-
 src/libsyntax_ext/concat_idents.rs            |   5 +-
 src/libsyntax_ext/deriving/bounds.rs          |  11 +-
 src/libsyntax_ext/deriving/clone.rs           |  25 ++--
 src/libsyntax_ext/deriving/cmp/eq.rs          |  19 +--
 src/libsyntax_ext/deriving/cmp/ord.rs         |  12 +-
 src/libsyntax_ext/deriving/cmp/partial_eq.rs  |  18 +--
 src/libsyntax_ext/deriving/cmp/partial_ord.rs |  22 ++--
 src/libsyntax_ext/deriving/custom.rs          |  15 +--
 src/libsyntax_ext/deriving/debug.rs           |  12 +-
 src/libsyntax_ext/deriving/decodable.rs       |  22 ++--
 src/libsyntax_ext/deriving/default.rs         |  14 ++-
 src/libsyntax_ext/deriving/encodable.rs       |  18 +--
 src/libsyntax_ext/deriving/generic/mod.rs     | 108 +++++++++---------
 src/libsyntax_ext/deriving/generic/ty.rs      |  29 +++--
 src/libsyntax_ext/deriving/hash.rs            |  10 +-
 src/libsyntax_ext/deriving/mod.rs             |   4 +-
 src/libsyntax_ext/diagnostics.rs              |   2 +
 src/libsyntax_ext/env.rs                      |   7 +-
 src/libsyntax_ext/format.rs                   |  33 +++---
 src/libsyntax_ext/format_foreign.rs           |  30 +++--
 src/libsyntax_ext/global_asm.rs               |   9 +-
 src/libsyntax_ext/lib.rs                      |  16 +--
 src/libsyntax_ext/log_syntax.rs               |   2 +-
 src/libsyntax_ext/proc_macro_decls.rs         |   7 +-
 src/libsyntax_ext/proc_macro_impl.rs          |  26 ++---
 src/libsyntax_ext/proc_macro_server.rs        |   7 +-
 src/libsyntax_ext/test.rs                     |  14 +--
 src/libsyntax_ext/test_case.rs                |   2 +-
 src/libsyntax_ext/trace_macros.rs             |   5 +-
 35 files changed, 269 insertions(+), 268 deletions(-)

diff --git a/src/libsyntax_ext/Cargo.toml b/src/libsyntax_ext/Cargo.toml
index 7ad08f75e8bdd..c22b55b8c13a0 100644
--- a/src/libsyntax_ext/Cargo.toml
+++ b/src/libsyntax_ext/Cargo.toml
@@ -2,6 +2,7 @@
 authors = ["The Rust Project Developers"]
 name = "syntax_ext"
 version = "0.0.0"
+edition = "2018"
 
 [lib]
 name = "syntax_ext"
diff --git a/src/libsyntax_ext/asm.rs b/src/libsyntax_ext/asm.rs
index 41ee6e91b3dc9..ebcdceea7c5a9 100644
--- a/src/libsyntax_ext/asm.rs
+++ b/src/libsyntax_ext/asm.rs
@@ -1,13 +1,13 @@
 // Inline assembly support.
 //
-use self::State::*;
+use State::*;
 
 use rustc_data_structures::thin_vec::ThinVec;
 
-use errors::DiagnosticBuilder;
+use crate::errors::DiagnosticBuilder;
+
 use syntax::ast;
-use syntax::ext::base;
-use syntax::ext::base::*;
+use syntax::ext::base::{self, *};
 use syntax::feature_gate;
 use syntax::parse::{self, token};
 use syntax::ptr::P;
@@ -15,6 +15,7 @@ use syntax::symbol::Symbol;
 use syntax::ast::AsmDialect;
 use syntax_pos::Span;
 use syntax::tokenstream;
+use syntax::{span_err, struct_span_err};
 
 enum State {
     Asm,
@@ -40,7 +41,7 @@ impl State {
 
 const OPTIONS: &[&str] = &["volatile", "alignstack", "intel"];
 
-pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt,
+pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt<'_>,
                        sp: Span,
                        tts: &[tokenstream::TokenTree])
                        -> Box<dyn base::MacResult + 'cx> {
diff --git a/src/libsyntax_ext/assert.rs b/src/libsyntax_ext/assert.rs
index b27f495322a42..984ef26f5ab8b 100644
--- a/src/libsyntax_ext/assert.rs
+++ b/src/libsyntax_ext/assert.rs
@@ -1,4 +1,5 @@
-use errors::DiagnosticBuilder;
+use crate::errors::DiagnosticBuilder;
+
 use syntax::ast::{self, *};
 use syntax::source_map::Spanned;
 use syntax::ext::base::*;
@@ -11,7 +12,7 @@ use syntax::tokenstream::{TokenStream, TokenTree};
 use syntax_pos::{Span, DUMMY_SP};
 
 pub fn expand_assert<'cx>(
-    cx: &'cx mut ExtCtxt,
+    cx: &'cx mut ExtCtxt<'_>,
     sp: Span,
     tts: &[TokenTree],
 ) -> Box<dyn MacResult + 'cx> {
diff --git a/src/libsyntax_ext/cfg.rs b/src/libsyntax_ext/cfg.rs
index 3b47b03cbe8dc..e2104550878ec 100644
--- a/src/libsyntax_ext/cfg.rs
+++ b/src/libsyntax_ext/cfg.rs
@@ -2,17 +2,17 @@
 /// a literal `true` or `false` based on whether the given cfg matches the
 /// current compilation environment.
 
-use errors::DiagnosticBuilder;
+use crate::errors::DiagnosticBuilder;
+
 use syntax::ast;
-use syntax::ext::base::*;
-use syntax::ext::base;
+use syntax::ext::base::{self, *};
 use syntax::ext::build::AstBuilder;
 use syntax::attr;
 use syntax::tokenstream;
 use syntax::parse::token;
 use syntax_pos::Span;
 
-pub fn expand_cfg<'cx>(cx: &mut ExtCtxt,
+pub fn expand_cfg<'cx>(cx: &mut ExtCtxt<'_>,
                        sp: Span,
                        tts: &[tokenstream::TokenTree])
                        -> Box<dyn base::MacResult + 'static> {
diff --git a/src/libsyntax_ext/compile_error.rs b/src/libsyntax_ext/compile_error.rs
index 8f7f5deb091ac..59d3f2c9c7813 100644
--- a/src/libsyntax_ext/compile_error.rs
+++ b/src/libsyntax_ext/compile_error.rs
@@ -1,11 +1,10 @@
 // The compiler code necessary to support the compile_error! extension.
 
-use syntax::ext::base::*;
-use syntax::ext::base;
+use syntax::ext::base::{self, *};
 use syntax_pos::Span;
 use syntax::tokenstream;
 
-pub fn expand_compile_error<'cx>(cx: &'cx mut ExtCtxt,
+pub fn expand_compile_error<'cx>(cx: &'cx mut ExtCtxt<'_>,
                               sp: Span,
                               tts: &[tokenstream::TokenTree])
                               -> Box<dyn base::MacResult + 'cx> {
diff --git a/src/libsyntax_ext/concat.rs b/src/libsyntax_ext/concat.rs
index f148f8e003df3..230b00c0f8f55 100644
--- a/src/libsyntax_ext/concat.rs
+++ b/src/libsyntax_ext/concat.rs
@@ -3,12 +3,11 @@ use syntax::ext::base;
 use syntax::ext::build::AstBuilder;
 use syntax::symbol::Symbol;
 use syntax::tokenstream;
-use syntax_pos;
 
 use std::string::String;
 
 pub fn expand_syntax_ext(
-    cx: &mut base::ExtCtxt,
+    cx: &mut base::ExtCtxt<'_>,
     sp: syntax_pos::Span,
     tts: &[tokenstream::TokenTree],
 ) -> Box<dyn base::MacResult + 'static> {
diff --git a/src/libsyntax_ext/concat_idents.rs b/src/libsyntax_ext/concat_idents.rs
index de96de4bdc2bc..8c9eb4bf2d8ff 100644
--- a/src/libsyntax_ext/concat_idents.rs
+++ b/src/libsyntax_ext/concat_idents.rs
@@ -1,8 +1,7 @@
 use rustc_data_structures::thin_vec::ThinVec;
 
 use syntax::ast;
-use syntax::ext::base::*;
-use syntax::ext::base;
+use syntax::ext::base::{self, *};
 use syntax::feature_gate;
 use syntax::parse::token;
 use syntax::ptr::P;
@@ -10,7 +9,7 @@ use syntax_pos::Span;
 use syntax_pos::symbol::Symbol;
 use syntax::tokenstream::TokenTree;
 
-pub fn expand_syntax_ext<'cx>(cx: &'cx mut ExtCtxt,
+pub fn expand_syntax_ext<'cx>(cx: &'cx mut ExtCtxt<'_>,
                               sp: Span,
                               tts: &[TokenTree])
                               -> Box<dyn base::MacResult + 'cx> {
diff --git a/src/libsyntax_ext/deriving/bounds.rs b/src/libsyntax_ext/deriving/bounds.rs
index dcfc6ab0391b8..c7b805e0bdca6 100644
--- a/src/libsyntax_ext/deriving/bounds.rs
+++ b/src/libsyntax_ext/deriving/bounds.rs
@@ -1,11 +1,12 @@
-use deriving::path_std;
-use deriving::generic::*;
-use deriving::generic::ty::*;
+use crate::deriving::path_std;
+use crate::deriving::generic::*;
+use crate::deriving::generic::ty::*;
+
 use syntax::ast::MetaItem;
 use syntax::ext::base::{Annotatable, ExtCtxt};
 use syntax_pos::Span;
 
-pub fn expand_deriving_unsafe_bound(cx: &mut ExtCtxt,
+pub fn expand_deriving_unsafe_bound(cx: &mut ExtCtxt<'_>,
                                     span: Span,
                                     _: &MetaItem,
                                     _: &Annotatable,
@@ -13,7 +14,7 @@ pub fn expand_deriving_unsafe_bound(cx: &mut ExtCtxt,
     cx.span_err(span, "this unsafe trait should be implemented explicitly");
 }
 
-pub fn expand_deriving_copy(cx: &mut ExtCtxt,
+pub fn expand_deriving_copy(cx: &mut ExtCtxt<'_>,
                             span: Span,
                             mitem: &MetaItem,
                             item: &Annotatable,
diff --git a/src/libsyntax_ext/deriving/clone.rs b/src/libsyntax_ext/deriving/clone.rs
index 38d433e842cd7..b347092e1bc4c 100644
--- a/src/libsyntax_ext/deriving/clone.rs
+++ b/src/libsyntax_ext/deriving/clone.rs
@@ -1,9 +1,8 @@
-use deriving::path_std;
-use deriving::generic::*;
-use deriving::generic::ty::*;
+use crate::deriving::path_std;
+use crate::deriving::generic::*;
+use crate::deriving::generic::ty::*;
 
-use syntax::ast::{self, Expr, Generics, ItemKind, MetaItem, VariantData};
-use syntax::ast::GenericArg;
+use syntax::ast::{self, Expr, GenericArg, Generics, ItemKind, MetaItem, VariantData};
 use syntax::attr;
 use syntax::ext::base::{Annotatable, ExtCtxt};
 use syntax::ext::build::AstBuilder;
@@ -11,7 +10,7 @@ use syntax::ptr::P;
 use syntax::symbol::{Symbol, keywords};
 use syntax_pos::Span;
 
-pub fn expand_deriving_clone(cx: &mut ExtCtxt,
+pub fn expand_deriving_clone(cx: &mut ExtCtxt<'_>,
                              span: Span,
                              mitem: &MetaItem,
                              item: &Annotatable,
@@ -105,12 +104,12 @@ pub fn expand_deriving_clone(cx: &mut ExtCtxt,
 }
 
 fn cs_clone_shallow(name: &str,
-                    cx: &mut ExtCtxt,
+                    cx: &mut ExtCtxt<'_>,
                     trait_span: Span,
-                    substr: &Substructure,
+                    substr: &Substructure<'_>,
                     is_union: bool)
                     -> P<Expr> {
-    fn assert_ty_bounds(cx: &mut ExtCtxt, stmts: &mut Vec<ast::Stmt>,
+    fn assert_ty_bounds(cx: &mut ExtCtxt<'_>, stmts: &mut Vec<ast::Stmt>,
                         ty: P<ast::Ty>, span: Span, helper_name: &str) {
         // Generate statement `let _: helper_name<ty>;`,
         // set the expn ID so we can use the unstable struct.
@@ -120,7 +119,7 @@ fn cs_clone_shallow(name: &str,
                                         vec![GenericArg::Type(ty)], vec![]);
         stmts.push(cx.stmt_let_type_only(span, cx.ty_path(assert_path)));
     }
-    fn process_variant(cx: &mut ExtCtxt, stmts: &mut Vec<ast::Stmt>, variant: &VariantData) {
+    fn process_variant(cx: &mut ExtCtxt<'_>, stmts: &mut Vec<ast::Stmt>, variant: &VariantData) {
         for field in variant.fields() {
             // let _: AssertParamIsClone<FieldTy>;
             assert_ty_bounds(cx, stmts, field.ty.clone(), field.span, "AssertParamIsClone");
@@ -151,14 +150,14 @@ fn cs_clone_shallow(name: &str,
 }
 
 fn cs_clone(name: &str,
-            cx: &mut ExtCtxt,
+            cx: &mut ExtCtxt<'_>,
             trait_span: Span,
-            substr: &Substructure)
+            substr: &Substructure<'_>)
             -> P<Expr> {
     let ctor_path;
     let all_fields;
     let fn_path = cx.std_path(&["clone", "Clone", "clone"]);
-    let subcall = |cx: &mut ExtCtxt, field: &FieldInfo| {
+    let subcall = |cx: &mut ExtCtxt<'_>, field: &FieldInfo<'_>| {
         let args = vec![cx.expr_addr_of(field.span, field.self_.clone())];
         cx.expr_call_global(field.span, fn_path.clone(), args)
     };
diff --git a/src/libsyntax_ext/deriving/cmp/eq.rs b/src/libsyntax_ext/deriving/cmp/eq.rs
index dbba8c3b7a006..a1035ff641fa1 100644
--- a/src/libsyntax_ext/deriving/cmp/eq.rs
+++ b/src/libsyntax_ext/deriving/cmp/eq.rs
@@ -1,6 +1,6 @@
-use deriving::path_std;
-use deriving::generic::*;
-use deriving::generic::ty::*;
+use crate::deriving::path_std;
+use crate::deriving::generic::*;
+use crate::deriving::generic::ty::*;
 
 use syntax::ast::{self, Expr, MetaItem, GenericArg};
 use syntax::ext::base::{Annotatable, ExtCtxt};
@@ -9,7 +9,7 @@ use syntax::ptr::P;
 use syntax::symbol::Symbol;
 use syntax_pos::Span;
 
-pub fn expand_deriving_eq(cx: &mut ExtCtxt,
+pub fn expand_deriving_eq(cx: &mut ExtCtxt<'_>,
                           span: Span,
                           mitem: &MetaItem,
                           item: &Annotatable,
@@ -44,8 +44,11 @@ pub fn expand_deriving_eq(cx: &mut ExtCtxt,
     trait_def.expand_ext(cx, mitem, item, push, true)
 }
 
-fn cs_total_eq_assert(cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure) -> P<Expr> {
-    fn assert_ty_bounds(cx: &mut ExtCtxt, stmts: &mut Vec<ast::Stmt>,
+fn cs_total_eq_assert(cx: &mut ExtCtxt<'_>,
+                      trait_span: Span,
+                      substr: &Substructure<'_>)
+                      -> P<Expr> {
+    fn assert_ty_bounds(cx: &mut ExtCtxt<'_>, stmts: &mut Vec<ast::Stmt>,
                         ty: P<ast::Ty>, span: Span, helper_name: &str) {
         // Generate statement `let _: helper_name<ty>;`,
         // set the expn ID so we can use the unstable struct.
@@ -55,7 +58,9 @@ fn cs_total_eq_assert(cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure)
                                         vec![GenericArg::Type(ty)], vec![]);
         stmts.push(cx.stmt_let_type_only(span, cx.ty_path(assert_path)));
     }
-    fn process_variant(cx: &mut ExtCtxt, stmts: &mut Vec<ast::Stmt>, variant: &ast::VariantData) {
+    fn process_variant(cx: &mut ExtCtxt<'_>,
+                       stmts: &mut Vec<ast::Stmt>,
+                       variant: &ast::VariantData) {
         for field in variant.fields() {
             // let _: AssertParamIsEq<FieldTy>;
             assert_ty_bounds(cx, stmts, field.ty.clone(), field.span, "AssertParamIsEq");
diff --git a/src/libsyntax_ext/deriving/cmp/ord.rs b/src/libsyntax_ext/deriving/cmp/ord.rs
index 21bd56710ac9b..e4f939c151f3e 100644
--- a/src/libsyntax_ext/deriving/cmp/ord.rs
+++ b/src/libsyntax_ext/deriving/cmp/ord.rs
@@ -1,6 +1,6 @@
-use deriving::path_std;
-use deriving::generic::*;
-use deriving::generic::ty::*;
+use crate::deriving::path_std;
+use crate::deriving::generic::*;
+use crate::deriving::generic::ty::*;
 
 use syntax::ast::{self, Expr, MetaItem};
 use syntax::ext::base::{Annotatable, ExtCtxt};
@@ -9,7 +9,7 @@ use syntax::ptr::P;
 use syntax::symbol::Symbol;
 use syntax_pos::Span;
 
-pub fn expand_deriving_ord(cx: &mut ExtCtxt,
+pub fn expand_deriving_ord(cx: &mut ExtCtxt<'_>,
                            span: Span,
                            mitem: &MetaItem,
                            item: &Annotatable,
@@ -44,7 +44,7 @@ pub fn expand_deriving_ord(cx: &mut ExtCtxt,
 }
 
 
-pub fn ordering_collapsed(cx: &mut ExtCtxt,
+pub fn ordering_collapsed(cx: &mut ExtCtxt<'_>,
                           span: Span,
                           self_arg_tags: &[ast::Ident])
                           -> P<ast::Expr> {
@@ -53,7 +53,7 @@ pub fn ordering_collapsed(cx: &mut ExtCtxt,
     cx.expr_method_call(span, lft, cx.ident_of("cmp"), vec![rgt])
 }
 
-pub fn cs_cmp(cx: &mut ExtCtxt, span: Span, substr: &Substructure) -> P<Expr> {
+pub fn cs_cmp(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_>) -> P<Expr> {
     let test_id = cx.ident_of("cmp").gensym();
     let equals_path = cx.path_global(span, cx.std_path(&["cmp", "Ordering", "Equal"]));
 
diff --git a/src/libsyntax_ext/deriving/cmp/partial_eq.rs b/src/libsyntax_ext/deriving/cmp/partial_eq.rs
index 4ec24bce4cd48..07026ae373919 100644
--- a/src/libsyntax_ext/deriving/cmp/partial_eq.rs
+++ b/src/libsyntax_ext/deriving/cmp/partial_eq.rs
@@ -1,6 +1,6 @@
-use deriving::{path_local, path_std};
-use deriving::generic::*;
-use deriving::generic::ty::*;
+use crate::deriving::{path_local, path_std};
+use crate::deriving::generic::*;
+use crate::deriving::generic::ty::*;
 
 use syntax::ast::{BinOpKind, Expr, MetaItem};
 use syntax::ext::base::{Annotatable, ExtCtxt};
@@ -9,22 +9,22 @@ use syntax::ptr::P;
 use syntax::symbol::Symbol;
 use syntax_pos::Span;
 
-pub fn expand_deriving_partial_eq(cx: &mut ExtCtxt,
+pub fn expand_deriving_partial_eq(cx: &mut ExtCtxt<'_>,
                                   span: Span,
                                   mitem: &MetaItem,
                                   item: &Annotatable,
                                   push: &mut dyn FnMut(Annotatable)) {
     // structures are equal if all fields are equal, and non equal, if
     // any fields are not equal or if the enum variants are different
-    fn cs_op(cx: &mut ExtCtxt,
+    fn cs_op(cx: &mut ExtCtxt<'_>,
              span: Span,
-             substr: &Substructure,
+             substr: &Substructure<'_>,
              op: BinOpKind,
              combiner: BinOpKind,
              base: bool)
              -> P<Expr>
     {
-        let op = |cx: &mut ExtCtxt, span: Span, self_f: P<Expr>, other_fs: &[P<Expr>]| {
+        let op = |cx: &mut ExtCtxt<'_>, span: Span, self_f: P<Expr>, other_fs: &[P<Expr>]| {
             let other_f = match (other_fs.len(), other_fs.get(0)) {
                 (1, Some(o_f)) => o_f,
                 _ => cx.span_bug(span, "not exactly 2 arguments in `derive(PartialEq)`"),
@@ -53,10 +53,10 @@ pub fn expand_deriving_partial_eq(cx: &mut ExtCtxt,
             substr)
     }
 
-    fn cs_eq(cx: &mut ExtCtxt, span: Span, substr: &Substructure) -> P<Expr> {
+    fn cs_eq(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_>) -> P<Expr> {
         cs_op(cx, span, substr, BinOpKind::Eq, BinOpKind::And, true)
     }
-    fn cs_ne(cx: &mut ExtCtxt, span: Span, substr: &Substructure) -> P<Expr> {
+    fn cs_ne(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_>) -> P<Expr> {
         cs_op(cx, span, substr, BinOpKind::Ne, BinOpKind::Or, false)
     }
 
diff --git a/src/libsyntax_ext/deriving/cmp/partial_ord.rs b/src/libsyntax_ext/deriving/cmp/partial_ord.rs
index 9ef481edf51ca..e99abeb118ea2 100644
--- a/src/libsyntax_ext/deriving/cmp/partial_ord.rs
+++ b/src/libsyntax_ext/deriving/cmp/partial_ord.rs
@@ -1,8 +1,8 @@
-pub use self::OrderingOp::*;
+pub use OrderingOp::*;
 
-use deriving::{path_local, pathvec_std, path_std};
-use deriving::generic::*;
-use deriving::generic::ty::*;
+use crate::deriving::{path_local, pathvec_std, path_std};
+use crate::deriving::generic::*;
+use crate::deriving::generic::ty::*;
 
 use syntax::ast::{self, BinOpKind, Expr, MetaItem};
 use syntax::ext::base::{Annotatable, ExtCtxt};
@@ -11,7 +11,7 @@ use syntax::ptr::P;
 use syntax::symbol::Symbol;
 use syntax_pos::Span;
 
-pub fn expand_deriving_partial_ord(cx: &mut ExtCtxt,
+pub fn expand_deriving_partial_ord(cx: &mut ExtCtxt<'_>,
                                    span: Span,
                                    mitem: &MetaItem,
                                    item: &Annotatable,
@@ -95,7 +95,7 @@ pub enum OrderingOp {
     GeOp,
 }
 
-pub fn some_ordering_collapsed(cx: &mut ExtCtxt,
+pub fn some_ordering_collapsed(cx: &mut ExtCtxt<'_>,
                                span: Span,
                                op: OrderingOp,
                                self_arg_tags: &[ast::Ident])
@@ -112,7 +112,7 @@ pub fn some_ordering_collapsed(cx: &mut ExtCtxt,
     cx.expr_method_call(span, lft, cx.ident_of(op_str), vec![rgt])
 }
 
-pub fn cs_partial_cmp(cx: &mut ExtCtxt, span: Span, substr: &Substructure) -> P<Expr> {
+pub fn cs_partial_cmp(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_>) -> P<Expr> {
     let test_id = cx.ident_of("cmp").gensym();
     let ordering = cx.path_global(span, cx.std_path(&["cmp", "Ordering", "Equal"]));
     let ordering_expr = cx.expr_path(ordering.clone());
@@ -184,14 +184,14 @@ pub fn cs_partial_cmp(cx: &mut ExtCtxt, span: Span, substr: &Substructure) -> P<
 /// Strict inequality.
 fn cs_op(less: bool,
          inclusive: bool,
-         cx: &mut ExtCtxt,
+         cx: &mut ExtCtxt<'_>,
          span: Span,
-         substr: &Substructure) -> P<Expr> {
-    let ordering_path = |cx: &mut ExtCtxt, name: &str| {
+         substr: &Substructure<'_>) -> P<Expr> {
+    let ordering_path = |cx: &mut ExtCtxt<'_>, name: &str| {
         cx.expr_path(cx.path_global(span, cx.std_path(&["cmp", "Ordering", name])))
     };
 
-    let par_cmp = |cx: &mut ExtCtxt, span, self_f: P<Expr>, other_fs: &[P<Expr>], default| {
+    let par_cmp = |cx: &mut ExtCtxt<'_>, span, self_f: P<Expr>, other_fs: &[P<Expr>], default| {
         let other_f = match (other_fs.len(), other_fs.get(0)) {
             (1, Some(o_f)) => o_f,
             _ => cx.span_bug(span, "not exactly 2 arguments in `derive(PartialOrd)`"),
diff --git a/src/libsyntax_ext/deriving/custom.rs b/src/libsyntax_ext/deriving/custom.rs
index 2f20814ef3efd..7d9b8402cac3f 100644
--- a/src/libsyntax_ext/deriving/custom.rs
+++ b/src/libsyntax_ext/deriving/custom.rs
@@ -1,4 +1,7 @@
-use errors::FatalError;
+use crate::errors::FatalError;
+use crate::proc_macro_impl::EXEC_STRATEGY;
+use crate::proc_macro_server;
+
 use syntax::ast::{self, ItemKind, Attribute, Mac};
 use syntax::attr::{mark_used, mark_known};
 use syntax::source_map::Span;
@@ -9,8 +12,6 @@ use syntax::tokenstream;
 use syntax::visit::Visitor;
 use syntax_pos::DUMMY_SP;
 
-use proc_macro_impl::EXEC_STRATEGY;
-
 struct MarkAttrs<'a>(&'a [ast::Name]);
 
 impl<'a> Visitor<'a> for MarkAttrs<'a> {
@@ -25,15 +26,15 @@ impl<'a> Visitor<'a> for MarkAttrs<'a> {
 }
 
 pub struct ProcMacroDerive {
-    pub client: ::proc_macro::bridge::client::Client<
-        fn(::proc_macro::TokenStream) -> ::proc_macro::TokenStream,
+    pub client: proc_macro::bridge::client::Client<
+        fn(proc_macro::TokenStream) -> proc_macro::TokenStream,
     >,
     pub attrs: Vec<ast::Name>,
 }
 
 impl MultiItemModifier for ProcMacroDerive {
     fn expand(&self,
-              ecx: &mut ExtCtxt,
+              ecx: &mut ExtCtxt<'_>,
               span: Span,
               _meta_item: &ast::MetaItem,
               item: Annotatable)
@@ -67,7 +68,7 @@ impl MultiItemModifier for ProcMacroDerive {
         let token = Token::interpolated(token::NtItem(item));
         let input = tokenstream::TokenTree::Token(DUMMY_SP, token).into();
 
-        let server = ::proc_macro_server::Rustc::new(ecx);
+        let server = proc_macro_server::Rustc::new(ecx);
         let stream = match self.client.run(&EXEC_STRATEGY, server, input) {
             Ok(stream) => stream,
             Err(e) => {
diff --git a/src/libsyntax_ext/deriving/debug.rs b/src/libsyntax_ext/deriving/debug.rs
index b3e5bd9283ef6..7dc2d007d73d6 100644
--- a/src/libsyntax_ext/deriving/debug.rs
+++ b/src/libsyntax_ext/deriving/debug.rs
@@ -1,6 +1,6 @@
-use deriving::path_std;
-use deriving::generic::*;
-use deriving::generic::ty::*;
+use crate::deriving::path_std;
+use crate::deriving::generic::*;
+use crate::deriving::generic::ty::*;
 
 use rustc_data_structures::thin_vec::ThinVec;
 
@@ -11,7 +11,7 @@ use syntax::ext::build::AstBuilder;
 use syntax::ptr::P;
 use syntax_pos::{DUMMY_SP, Span};
 
-pub fn expand_deriving_debug(cx: &mut ExtCtxt,
+pub fn expand_deriving_debug(cx: &mut ExtCtxt<'_>,
                              span: Span,
                              mitem: &MetaItem,
                              item: &Annotatable,
@@ -47,7 +47,7 @@ pub fn expand_deriving_debug(cx: &mut ExtCtxt,
 }
 
 /// We use the debug builders to do the heavy lifting here
-fn show_substructure(cx: &mut ExtCtxt, span: Span, substr: &Substructure) -> P<Expr> {
+fn show_substructure(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_>) -> P<Expr> {
     // build fmt.debug_struct(<name>).field(<fieldname>, &<fieldval>)....build()
     // or fmt.debug_tuple(<name>).field(&<fieldval>)....build()
     // based on the "shape".
@@ -124,7 +124,7 @@ fn show_substructure(cx: &mut ExtCtxt, span: Span, substr: &Substructure) -> P<E
     cx.expr_block(block)
 }
 
-fn stmt_let_undescore(cx: &mut ExtCtxt, sp: Span, expr: P<ast::Expr>) -> ast::Stmt {
+fn stmt_let_undescore(cx: &mut ExtCtxt<'_>, sp: Span, expr: P<ast::Expr>) -> ast::Stmt {
     let local = P(ast::Local {
         pat: cx.pat_wild(sp),
         ty: None,
diff --git a/src/libsyntax_ext/deriving/decodable.rs b/src/libsyntax_ext/deriving/decodable.rs
index 89c630e991530..b082351d5f684 100644
--- a/src/libsyntax_ext/deriving/decodable.rs
+++ b/src/libsyntax_ext/deriving/decodable.rs
@@ -1,9 +1,9 @@
 //! The compiler code necessary for `#[derive(Decodable)]`. See encodable.rs for more.
 
-use deriving::{self, pathvec_std};
-use deriving::generic::*;
-use deriving::generic::ty::*;
-use deriving::warn_if_deprecated;
+use crate::deriving::{self, pathvec_std};
+use crate::deriving::generic::*;
+use crate::deriving::generic::ty::*;
+use crate::deriving::warn_if_deprecated;
 
 use syntax::ast;
 use syntax::ast::{Expr, MetaItem, Mutability};
@@ -13,7 +13,7 @@ use syntax::ptr::P;
 use syntax::symbol::Symbol;
 use syntax_pos::Span;
 
-pub fn expand_deriving_rustc_decodable(cx: &mut ExtCtxt,
+pub fn expand_deriving_rustc_decodable(cx: &mut ExtCtxt<'_>,
                                        span: Span,
                                        mitem: &MetaItem,
                                        item: &Annotatable,
@@ -21,7 +21,7 @@ pub fn expand_deriving_rustc_decodable(cx: &mut ExtCtxt,
     expand_deriving_decodable_imp(cx, span, mitem, item, push, "rustc_serialize")
 }
 
-pub fn expand_deriving_decodable(cx: &mut ExtCtxt,
+pub fn expand_deriving_decodable(cx: &mut ExtCtxt<'_>,
                                  span: Span,
                                  mitem: &MetaItem,
                                  item: &Annotatable,
@@ -30,7 +30,7 @@ pub fn expand_deriving_decodable(cx: &mut ExtCtxt,
     expand_deriving_decodable_imp(cx, span, mitem, item, push, "serialize")
 }
 
-fn expand_deriving_decodable_imp(cx: &mut ExtCtxt,
+fn expand_deriving_decodable_imp(cx: &mut ExtCtxt<'_>,
                                  span: Span,
                                  mitem: &MetaItem,
                                  item: &Annotatable,
@@ -79,9 +79,9 @@ fn expand_deriving_decodable_imp(cx: &mut ExtCtxt,
     trait_def.expand(cx, mitem, item, push)
 }
 
-fn decodable_substructure(cx: &mut ExtCtxt,
+fn decodable_substructure(cx: &mut ExtCtxt<'_>,
                           trait_span: Span,
-                          substr: &Substructure,
+                          substr: &Substructure<'_>,
                           krate: &str)
                           -> P<Expr> {
     let decoder = substr.nonself_args[0].clone();
@@ -168,13 +168,13 @@ fn decodable_substructure(cx: &mut ExtCtxt,
 /// Create a decoder for a single enum variant/struct:
 /// - `outer_pat_path` is the path to this enum variant/struct
 /// - `getarg` should retrieve the `usize`-th field with name `@str`.
-fn decode_static_fields<F>(cx: &mut ExtCtxt,
+fn decode_static_fields<F>(cx: &mut ExtCtxt<'_>,
                            trait_span: Span,
                            outer_pat_path: ast::Path,
                            fields: &StaticFields,
                            mut getarg: F)
                            -> P<Expr>
-    where F: FnMut(&mut ExtCtxt, Span, Symbol, usize) -> P<Expr>
+    where F: FnMut(&mut ExtCtxt<'_>, Span, Symbol, usize) -> P<Expr>
 {
     match *fields {
         Unnamed(ref fields, is_tuple) => {
diff --git a/src/libsyntax_ext/deriving/default.rs b/src/libsyntax_ext/deriving/default.rs
index 32d02bec7989b..6db0a29165a4a 100644
--- a/src/libsyntax_ext/deriving/default.rs
+++ b/src/libsyntax_ext/deriving/default.rs
@@ -1,15 +1,16 @@
-use deriving::path_std;
-use deriving::generic::*;
-use deriving::generic::ty::*;
+use crate::deriving::path_std;
+use crate::deriving::generic::*;
+use crate::deriving::generic::ty::*;
 
 use syntax::ast::{Expr, MetaItem};
 use syntax::ext::base::{Annotatable, DummyResult, ExtCtxt};
 use syntax::ext::build::AstBuilder;
 use syntax::ptr::P;
 use syntax::symbol::Symbol;
+use syntax::span_err;
 use syntax_pos::Span;
 
-pub fn expand_deriving_default(cx: &mut ExtCtxt,
+pub fn expand_deriving_default(cx: &mut ExtCtxt<'_>,
                                span: Span,
                                mitem: &MetaItem,
                                item: &Annotatable,
@@ -42,7 +43,10 @@ pub fn expand_deriving_default(cx: &mut ExtCtxt,
     trait_def.expand(cx, mitem, item, push)
 }
 
-fn default_substructure(cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure) -> P<Expr> {
+fn default_substructure(cx: &mut ExtCtxt<'_>,
+                        trait_span: Span,
+                        substr: &Substructure<'_>)
+                        -> P<Expr> {
     let default_ident = cx.std_path(&["default", "Default", "default"]);
     let default_call = |span| cx.expr_call_global(span, default_ident.clone(), Vec::new());
 
diff --git a/src/libsyntax_ext/deriving/encodable.rs b/src/libsyntax_ext/deriving/encodable.rs
index c8935874158a2..dd5646342b362 100644
--- a/src/libsyntax_ext/deriving/encodable.rs
+++ b/src/libsyntax_ext/deriving/encodable.rs
@@ -82,10 +82,10 @@
 //! }
 //! ```
 
-use deriving::{self, pathvec_std};
-use deriving::generic::*;
-use deriving::generic::ty::*;
-use deriving::warn_if_deprecated;
+use crate::deriving::{self, pathvec_std};
+use crate::deriving::generic::*;
+use crate::deriving::generic::ty::*;
+use crate::deriving::warn_if_deprecated;
 
 use syntax::ast::{Expr, ExprKind, MetaItem, Mutability};
 use syntax::ext::base::{Annotatable, ExtCtxt};
@@ -94,7 +94,7 @@ use syntax::ptr::P;
 use syntax::symbol::Symbol;
 use syntax_pos::Span;
 
-pub fn expand_deriving_rustc_encodable(cx: &mut ExtCtxt,
+pub fn expand_deriving_rustc_encodable(cx: &mut ExtCtxt<'_>,
                                        span: Span,
                                        mitem: &MetaItem,
                                        item: &Annotatable,
@@ -102,7 +102,7 @@ pub fn expand_deriving_rustc_encodable(cx: &mut ExtCtxt,
     expand_deriving_encodable_imp(cx, span, mitem, item, push, "rustc_serialize")
 }
 
-pub fn expand_deriving_encodable(cx: &mut ExtCtxt,
+pub fn expand_deriving_encodable(cx: &mut ExtCtxt<'_>,
                                  span: Span,
                                  mitem: &MetaItem,
                                  item: &Annotatable,
@@ -111,7 +111,7 @@ pub fn expand_deriving_encodable(cx: &mut ExtCtxt,
     expand_deriving_encodable_imp(cx, span, mitem, item, push, "serialize")
 }
 
-fn expand_deriving_encodable_imp(cx: &mut ExtCtxt,
+fn expand_deriving_encodable_imp(cx: &mut ExtCtxt<'_>,
                                  span: Span,
                                  mitem: &MetaItem,
                                  item: &Annotatable,
@@ -162,9 +162,9 @@ fn expand_deriving_encodable_imp(cx: &mut ExtCtxt,
     trait_def.expand(cx, mitem, item, push)
 }
 
-fn encodable_substructure(cx: &mut ExtCtxt,
+fn encodable_substructure(cx: &mut ExtCtxt<'_>,
                           trait_span: Span,
-                          substr: &Substructure,
+                          substr: &Substructure<'_>,
                           krate: &'static str)
                           -> P<Expr> {
     let encoder = substr.nonself_args[0].clone();
diff --git a/src/libsyntax_ext/deriving/generic/mod.rs b/src/libsyntax_ext/deriving/generic/mod.rs
index 22643db501693..0c88ae0311d52 100644
--- a/src/libsyntax_ext/deriving/generic/mod.rs
+++ b/src/libsyntax_ext/deriving/generic/mod.rs
@@ -174,8 +174,8 @@
 //!                 (<ident of C1>, <span of C1>, Named(vec![(<ident of x>, <span of x>)]))])
 //! ```
 
-pub use self::StaticFields::*;
-pub use self::SubstructureFields::*;
+pub use StaticFields::*;
+pub use SubstructureFields::*;
 
 use std::cell::RefCell;
 use std::iter;
@@ -195,9 +195,9 @@ use syntax::symbol::{Symbol, keywords};
 use syntax::parse::ParseSess;
 use syntax_pos::{DUMMY_SP, Span};
 
-use self::ty::{LifetimeBounds, Path, Ptr, PtrTy, Self_, Ty};
+use ty::{LifetimeBounds, Path, Ptr, PtrTy, Self_, Ty};
 
-use deriving;
+use crate::deriving;
 
 pub mod ty;
 
@@ -321,7 +321,7 @@ pub enum SubstructureFields<'a> {
 /// Combine the values of all the fields together. The last argument is
 /// all the fields of all the structures.
 pub type CombineSubstructureFunc<'a> =
-    Box<dyn FnMut(&mut ExtCtxt, Span, &Substructure) -> P<Expr> + 'a>;
+    Box<dyn FnMut(&mut ExtCtxt<'_>, Span, &Substructure<'_>) -> P<Expr> + 'a>;
 
 /// Deal with non-matching enum variants.  The tuple is a list of
 /// identifiers (one for each `Self` argument, which could be any of the
@@ -329,7 +329,7 @@ pub type CombineSubstructureFunc<'a> =
 /// holding the variant index value for each of the `Self` arguments.  The
 /// last argument is all the non-`Self` args of the method being derived.
 pub type EnumNonMatchCollapsedFunc<'a> =
-    Box<dyn FnMut(&mut ExtCtxt, Span, (&[Ident], &[Ident]), &[P<Expr>]) -> P<Expr> + 'a>;
+    Box<dyn FnMut(&mut ExtCtxt<'_>, Span, (&[Ident], &[Ident]), &[P<Expr>]) -> P<Expr> + 'a>;
 
 pub fn combine_substructure<'a>(f: CombineSubstructureFunc<'a>)
                                 -> RefCell<CombineSubstructureFunc<'a>> {
@@ -342,7 +342,7 @@ pub fn combine_substructure<'a>(f: CombineSubstructureFunc<'a>)
 fn find_type_parameters(ty: &ast::Ty,
                         ty_param_names: &[ast::Name],
                         span: Span,
-                        cx: &ExtCtxt)
+                        cx: &ExtCtxt<'_>)
                         -> Vec<P<ast::Ty>> {
     use syntax::visit;
 
@@ -386,7 +386,7 @@ fn find_type_parameters(ty: &ast::Ty,
 
 impl<'a> TraitDef<'a> {
     pub fn expand(self,
-                  cx: &mut ExtCtxt,
+                  cx: &mut ExtCtxt<'_>,
                   mitem: &ast::MetaItem,
                   item: &'a Annotatable,
                   push: &mut dyn FnMut(Annotatable)) {
@@ -394,7 +394,7 @@ impl<'a> TraitDef<'a> {
     }
 
     pub fn expand_ext(self,
-                      cx: &mut ExtCtxt,
+                      cx: &mut ExtCtxt<'_>,
                       mitem: &ast::MetaItem,
                       item: &'a Annotatable,
                       push: &mut dyn FnMut(Annotatable),
@@ -513,7 +513,7 @@ impl<'a> TraitDef<'a> {
     /// where B1, ..., BN are the bounds given by `bounds_paths`.'. Z is a phantom type, and
     /// therefore does not get bound by the derived trait.
     fn create_derived_impl(&self,
-                           cx: &mut ExtCtxt,
+                           cx: &mut ExtCtxt<'_>,
                            type_ident: Ident,
                            generics: &Generics,
                            field_tys: Vec<P<ast::Ty>>,
@@ -696,7 +696,7 @@ impl<'a> TraitDef<'a> {
     }
 
     fn expand_struct_def(&self,
-                         cx: &mut ExtCtxt,
+                         cx: &mut ExtCtxt<'_>,
                          struct_def: &'a VariantData,
                          type_ident: Ident,
                          generics: &Generics,
@@ -746,7 +746,7 @@ impl<'a> TraitDef<'a> {
     }
 
     fn expand_enum_def(&self,
-                       cx: &mut ExtCtxt,
+                       cx: &mut ExtCtxt<'_>,
                        enum_def: &'a EnumDef,
                        type_attrs: &[ast::Attribute],
                        type_ident: Ident,
@@ -832,12 +832,12 @@ fn find_repr_type_name(sess: &ParseSess, type_attrs: &[ast::Attribute]) -> &'sta
 
 impl<'a> MethodDef<'a> {
     fn call_substructure_method(&self,
-                                cx: &mut ExtCtxt,
-                                trait_: &TraitDef,
+                                cx: &mut ExtCtxt<'_>,
+                                trait_: &TraitDef<'_>,
                                 type_ident: Ident,
                                 self_args: &[P<Expr>],
                                 nonself_args: &[P<Expr>],
-                                fields: &SubstructureFields)
+                                fields: &SubstructureFields<'_>)
                                 -> P<Expr> {
         let substructure = Substructure {
             type_ident,
@@ -847,13 +847,13 @@ impl<'a> MethodDef<'a> {
             fields,
         };
         let mut f = self.combine_substructure.borrow_mut();
-        let f: &mut CombineSubstructureFunc = &mut *f;
+        let f: &mut CombineSubstructureFunc<'_> = &mut *f;
         f(cx, trait_.span, &substructure)
     }
 
     fn get_ret_ty(&self,
-                  cx: &mut ExtCtxt,
-                  trait_: &TraitDef,
+                  cx: &mut ExtCtxt<'_>,
+                  trait_: &TraitDef<'_>,
                   generics: &Generics,
                   type_ident: Ident)
                   -> P<ast::Ty> {
@@ -866,8 +866,8 @@ impl<'a> MethodDef<'a> {
 
     fn split_self_nonself_args
         (&self,
-         cx: &mut ExtCtxt,
-         trait_: &TraitDef,
+         cx: &mut ExtCtxt<'_>,
+         trait_: &TraitDef<'_>,
          type_ident: Ident,
          generics: &Generics)
          -> (Option<ast::ExplicitSelf>, Vec<P<Expr>>, Vec<P<Expr>>, Vec<(Ident, P<ast::Ty>)>) {
@@ -912,8 +912,8 @@ impl<'a> MethodDef<'a> {
     }
 
     fn create_method(&self,
-                     cx: &mut ExtCtxt,
-                     trait_: &TraitDef,
+                     cx: &mut ExtCtxt<'_>,
+                     trait_: &TraitDef<'_>,
                      type_ident: Ident,
                      generics: &Generics,
                      abi: Abi,
@@ -1005,7 +1005,7 @@ impl<'a> MethodDef<'a> {
     /// }
     /// ```
     fn expand_struct_method_body<'b>(&self,
-                                     cx: &mut ExtCtxt,
+                                     cx: &mut ExtCtxt<'_>,
                                      trait_: &TraitDef<'b>,
                                      struct_def: &'b VariantData,
                                      type_ident: Ident,
@@ -1077,8 +1077,8 @@ impl<'a> MethodDef<'a> {
     }
 
     fn expand_static_struct_method_body(&self,
-                                        cx: &mut ExtCtxt,
-                                        trait_: &TraitDef,
+                                        cx: &mut ExtCtxt<'_>,
+                                        trait_: &TraitDef<'_>,
                                         struct_def: &VariantData,
                                         type_ident: Ident,
                                         self_args: &[P<Expr>],
@@ -1125,7 +1125,7 @@ impl<'a> MethodDef<'a> {
     /// as their results are unused.  The point of `__self_vi` and
     /// `__arg_1_vi` is for `PartialOrd`; see #15503.)
     fn expand_enum_method_body<'b>(&self,
-                                   cx: &mut ExtCtxt,
+                                   cx: &mut ExtCtxt<'_>,
                                    trait_: &TraitDef<'b>,
                                    enum_def: &'b EnumDef,
                                    type_attrs: &[ast::Attribute],
@@ -1179,7 +1179,7 @@ impl<'a> MethodDef<'a> {
     /// }
     /// ```
     fn build_enum_match_tuple<'b>(&self,
-                                  cx: &mut ExtCtxt,
+                                  cx: &mut ExtCtxt<'_>,
                                   trait_: &TraitDef<'b>,
                                   enum_def: &'b EnumDef,
                                   type_attrs: &[ast::Attribute],
@@ -1230,7 +1230,7 @@ impl<'a> MethodDef<'a> {
             .enumerate()
             .filter(|&(_, v)| !(self.unify_fieldless_variants && v.node.data.fields().is_empty()))
             .map(|(index, variant)| {
-                let mk_self_pat = |cx: &mut ExtCtxt, self_arg_name: &str| {
+                let mk_self_pat = |cx: &mut ExtCtxt<'_>, self_arg_name: &str| {
                     let (p, idents) = trait_.create_enum_variant_pattern(cx,
                                                      type_ident,
                                                      variant,
@@ -1296,7 +1296,7 @@ impl<'a> MethodDef<'a> {
                                     other: others,
                                     attrs,
                         }
-                    }).collect::<Vec<FieldInfo>>();
+                    }).collect::<Vec<FieldInfo<'_>>>();
 
                 // Now, for some given VariantK, we have built up
                 // expressions for referencing every field of every
@@ -1501,8 +1501,8 @@ impl<'a> MethodDef<'a> {
     }
 
     fn expand_static_enum_method_body(&self,
-                                      cx: &mut ExtCtxt,
-                                      trait_: &TraitDef,
+                                      cx: &mut ExtCtxt<'_>,
+                                      trait_: &TraitDef<'_>,
                                       enum_def: &EnumDef,
                                       type_ident: Ident,
                                       self_args: &[P<Expr>],
@@ -1527,7 +1527,7 @@ impl<'a> MethodDef<'a> {
 
 // general helper methods.
 impl<'a> TraitDef<'a> {
-    fn summarise_struct(&self, cx: &mut ExtCtxt, struct_def: &VariantData) -> StaticFields {
+    fn summarise_struct(&self, cx: &mut ExtCtxt<'_>, struct_def: &VariantData) -> StaticFields {
         let mut named_idents = Vec::new();
         let mut just_spans = Vec::new();
         for field in struct_def.fields() {
@@ -1553,7 +1553,7 @@ impl<'a> TraitDef<'a> {
     }
 
     fn create_subpatterns(&self,
-                          cx: &mut ExtCtxt,
+                          cx: &mut ExtCtxt<'_>,
                           field_paths: Vec<ast::Ident>,
                           mutbl: ast::Mutability,
                           use_temporaries: bool)
@@ -1573,7 +1573,7 @@ impl<'a> TraitDef<'a> {
 
     fn create_struct_pattern
         (&self,
-         cx: &mut ExtCtxt,
+         cx: &mut ExtCtxt<'_>,
          struct_path: ast::Path,
          struct_def: &'a VariantData,
          prefix: &str,
@@ -1633,7 +1633,7 @@ impl<'a> TraitDef<'a> {
 
     fn create_enum_variant_pattern
         (&self,
-         cx: &mut ExtCtxt,
+         cx: &mut ExtCtxt<'_>,
          enum_ident: ast::Ident,
          variant: &'a ast::Variant,
          prefix: &str,
@@ -1652,10 +1652,10 @@ impl<'a> TraitDef<'a> {
 pub fn cs_fold_fields<'a, F>(use_foldl: bool,
                              mut f: F,
                              base: P<Expr>,
-                             cx: &mut ExtCtxt,
+                             cx: &mut ExtCtxt<'_>,
                              all_fields: &[FieldInfo<'a>])
                              -> P<Expr>
-    where F: FnMut(&mut ExtCtxt, Span, P<Expr>, P<Expr>, &[P<Expr>]) -> P<Expr>
+    where F: FnMut(&mut ExtCtxt<'_>, Span, P<Expr>, P<Expr>, &[P<Expr>]) -> P<Expr>
 {
     if use_foldl {
         all_fields.iter().fold(base, |old, field| {
@@ -1668,10 +1668,10 @@ pub fn cs_fold_fields<'a, F>(use_foldl: bool,
     }
 }
 
-pub fn cs_fold_enumnonmatch(mut enum_nonmatch_f: EnumNonMatchCollapsedFunc,
-                            cx: &mut ExtCtxt,
+pub fn cs_fold_enumnonmatch(mut enum_nonmatch_f: EnumNonMatchCollapsedFunc<'_>,
+                            cx: &mut ExtCtxt<'_>,
                             trait_span: Span,
-                            substructure: &Substructure)
+                            substructure: &Substructure<'_>)
                             -> P<Expr>
 {
     match *substructure.fields {
@@ -1685,7 +1685,7 @@ pub fn cs_fold_enumnonmatch(mut enum_nonmatch_f: EnumNonMatchCollapsedFunc,
     }
 }
 
-pub fn cs_fold_static(cx: &mut ExtCtxt,
+pub fn cs_fold_static(cx: &mut ExtCtxt<'_>,
                       trait_span: Span)
                       -> P<Expr>
 {
@@ -1697,12 +1697,12 @@ pub fn cs_fold_static(cx: &mut ExtCtxt,
 pub fn cs_fold<F>(use_foldl: bool,
                   f: F,
                   base: P<Expr>,
-                  enum_nonmatch_f: EnumNonMatchCollapsedFunc,
-                  cx: &mut ExtCtxt,
+                  enum_nonmatch_f: EnumNonMatchCollapsedFunc<'_>,
+                  cx: &mut ExtCtxt<'_>,
                   trait_span: Span,
-                  substructure: &Substructure)
+                  substructure: &Substructure<'_>)
                   -> P<Expr>
-    where F: FnMut(&mut ExtCtxt, Span, P<Expr>, P<Expr>, &[P<Expr>]) -> P<Expr>
+    where F: FnMut(&mut ExtCtxt<'_>, Span, P<Expr>, P<Expr>, &[P<Expr>]) -> P<Expr>
 {
     match *substructure.fields {
         EnumMatching(.., ref all_fields) |
@@ -1730,13 +1730,13 @@ pub fn cs_fold<F>(use_foldl: bool,
 pub fn cs_fold1<F, B>(use_foldl: bool,
                       f: F,
                       mut b: B,
-                      enum_nonmatch_f: EnumNonMatchCollapsedFunc,
-                      cx: &mut ExtCtxt,
+                      enum_nonmatch_f: EnumNonMatchCollapsedFunc<'_>,
+                      cx: &mut ExtCtxt<'_>,
                       trait_span: Span,
-                      substructure: &Substructure)
+                      substructure: &Substructure<'_>)
                       -> P<Expr>
-    where F: FnMut(&mut ExtCtxt, Span, P<Expr>, P<Expr>, &[P<Expr>]) -> P<Expr>,
-          B: FnMut(&mut ExtCtxt, Option<(Span, P<Expr>, &[P<Expr>])>) -> P<Expr>
+    where F: FnMut(&mut ExtCtxt<'_>, Span, P<Expr>, P<Expr>, &[P<Expr>]) -> P<Expr>,
+          B: FnMut(&mut ExtCtxt<'_>, Option<(Span, P<Expr>, &[P<Expr>])>) -> P<Expr>
 {
     match *substructure.fields {
         EnumMatching(.., ref all_fields) |
@@ -1776,12 +1776,12 @@ pub fn cs_fold1<F, B>(use_foldl: bool,
 /// ```
 #[inline]
 pub fn cs_same_method<F>(f: F,
-                         mut enum_nonmatch_f: EnumNonMatchCollapsedFunc,
-                         cx: &mut ExtCtxt,
+                         mut enum_nonmatch_f: EnumNonMatchCollapsedFunc<'_>,
+                         cx: &mut ExtCtxt<'_>,
                          trait_span: Span,
-                         substructure: &Substructure)
+                         substructure: &Substructure<'_>)
                          -> P<Expr>
-    where F: FnOnce(&mut ExtCtxt, Span, Vec<P<Expr>>) -> P<Expr>
+    where F: FnOnce(&mut ExtCtxt<'_>, Span, Vec<P<Expr>>) -> P<Expr>
 {
     match *substructure.fields {
         EnumMatching(.., ref all_fields) |
diff --git a/src/libsyntax_ext/deriving/generic/ty.rs b/src/libsyntax_ext/deriving/generic/ty.rs
index 83ec99b3573b4..ea6e07922b2b3 100644
--- a/src/libsyntax_ext/deriving/generic/ty.rs
+++ b/src/libsyntax_ext/deriving/generic/ty.rs
@@ -1,11 +1,10 @@
 //! A mini version of ast::Ty, which is easier to use, and features an explicit `Self` type to use
 //! when specifying impls to be derived.
 
-pub use self::PtrTy::*;
-pub use self::Ty::*;
+pub use PtrTy::*;
+pub use Ty::*;
 
-use syntax::ast;
-use syntax::ast::{Expr, GenericParamKind, Generics, Ident, SelfKind, GenericArg};
+use syntax::ast::{self, Expr, GenericParamKind, Generics, Ident, SelfKind, GenericArg};
 use syntax::ext::base::ExtCtxt;
 use syntax::ext::build::AstBuilder;
 use syntax::source_map::{respan, DUMMY_SP};
@@ -60,7 +59,7 @@ impl<'a> Path<'a> {
     }
 
     pub fn to_ty(&self,
-                 cx: &ExtCtxt,
+                 cx: &ExtCtxt<'_>,
                  span: Span,
                  self_ty: Ident,
                  self_generics: &Generics)
@@ -68,7 +67,7 @@ impl<'a> Path<'a> {
         cx.ty_path(self.to_path(cx, span, self_ty, self_generics))
     }
     pub fn to_path(&self,
-                   cx: &ExtCtxt,
+                   cx: &ExtCtxt<'_>,
                    span: Span,
                    self_ty: Ident,
                    self_generics: &Generics)
@@ -127,19 +126,19 @@ pub fn nil_ty<'r>() -> Ty<'r> {
     Tuple(Vec::new())
 }
 
-fn mk_lifetime(cx: &ExtCtxt, span: Span, lt: &Option<&str>) -> Option<ast::Lifetime> {
+fn mk_lifetime(cx: &ExtCtxt<'_>, span: Span, lt: &Option<&str>) -> Option<ast::Lifetime> {
     lt.map(|s|
         cx.lifetime(span, Ident::from_str(s))
     )
 }
 
-fn mk_lifetimes(cx: &ExtCtxt, span: Span, lt: &Option<&str>) -> Vec<ast::Lifetime> {
+fn mk_lifetimes(cx: &ExtCtxt<'_>, span: Span, lt: &Option<&str>) -> Vec<ast::Lifetime> {
     mk_lifetime(cx, span, lt).into_iter().collect()
 }
 
 impl<'a> Ty<'a> {
     pub fn to_ty(&self,
-                 cx: &ExtCtxt,
+                 cx: &ExtCtxt<'_>,
                  span: Span,
                  self_ty: Ident,
                  self_generics: &Generics)
@@ -167,7 +166,7 @@ impl<'a> Ty<'a> {
     }
 
     pub fn to_path(&self,
-                   cx: &ExtCtxt,
+                   cx: &ExtCtxt<'_>,
                    span: Span,
                    self_ty: Ident,
                    generics: &Generics)
@@ -193,11 +192,11 @@ impl<'a> Ty<'a> {
 }
 
 
-fn mk_ty_param(cx: &ExtCtxt,
+fn mk_ty_param(cx: &ExtCtxt<'_>,
                span: Span,
                name: &str,
                attrs: &[ast::Attribute],
-               bounds: &[Path],
+               bounds: &[Path<'_>],
                self_ident: Ident,
                self_generics: &Generics)
                -> ast::GenericParam {
@@ -237,7 +236,7 @@ impl<'a> LifetimeBounds<'a> {
         }
     }
     pub fn to_generics(&self,
-                       cx: &ExtCtxt,
+                       cx: &ExtCtxt<'_>,
                        span: Span,
                        self_ty: Ident,
                        self_generics: &Generics)
@@ -262,9 +261,9 @@ impl<'a> LifetimeBounds<'a> {
     }
 }
 
-pub fn get_explicit_self(cx: &ExtCtxt,
+pub fn get_explicit_self(cx: &ExtCtxt<'_>,
                          span: Span,
-                         self_ptr: &Option<PtrTy>)
+                         self_ptr: &Option<PtrTy<'_>>)
                          -> (P<Expr>, ast::ExplicitSelf) {
     // this constructs a fresh `self` path
     let self_path = cx.expr_self(span);
diff --git a/src/libsyntax_ext/deriving/hash.rs b/src/libsyntax_ext/deriving/hash.rs
index 4af2bd57b00e2..0d4f2ddc3be7b 100644
--- a/src/libsyntax_ext/deriving/hash.rs
+++ b/src/libsyntax_ext/deriving/hash.rs
@@ -1,6 +1,6 @@
-use deriving::{self, pathvec_std, path_std};
-use deriving::generic::*;
-use deriving::generic::ty::*;
+use crate::deriving::{self, pathvec_std, path_std};
+use crate::deriving::generic::*;
+use crate::deriving::generic::ty::*;
 
 use syntax::ast::{Expr, MetaItem, Mutability};
 use syntax::ext::base::{Annotatable, ExtCtxt};
@@ -8,7 +8,7 @@ use syntax::ext::build::AstBuilder;
 use syntax::ptr::P;
 use syntax_pos::Span;
 
-pub fn expand_deriving_hash(cx: &mut ExtCtxt,
+pub fn expand_deriving_hash(cx: &mut ExtCtxt<'_>,
                             span: Span,
                             mitem: &MetaItem,
                             item: &Annotatable,
@@ -50,7 +50,7 @@ pub fn expand_deriving_hash(cx: &mut ExtCtxt,
     hash_trait_def.expand(cx, mitem, item, push);
 }
 
-fn hash_substructure(cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure) -> P<Expr> {
+fn hash_substructure(cx: &mut ExtCtxt<'_>, trait_span: Span, substr: &Substructure<'_>) -> P<Expr> {
     let state_expr = match (substr.nonself_args.len(), substr.nonself_args.get(0)) {
         (1, Some(o_f)) => o_f,
         _ => {
diff --git a/src/libsyntax_ext/deriving/mod.rs b/src/libsyntax_ext/deriving/mod.rs
index 7548d43f18444..2c8a996cdb0cb 100644
--- a/src/libsyntax_ext/deriving/mod.rs
+++ b/src/libsyntax_ext/deriving/mod.rs
@@ -90,7 +90,7 @@ derive_traits! {
 }
 
 #[inline] // because `name` is a compile-time constant
-fn warn_if_deprecated(ecx: &mut ExtCtxt, sp: Span, name: &str) {
+fn warn_if_deprecated(ecx: &mut ExtCtxt<'_>, sp: Span, name: &str) {
     if let Some(replacement) = match name {
         "Encodable" => Some("RustcEncodable"),
         "Decodable" => Some("RustcDecodable"),
@@ -131,7 +131,7 @@ fn hygienic_type_parameter(item: &Annotatable, base: &str) -> String {
 }
 
 /// Constructs an expression that calls an intrinsic
-fn call_intrinsic(cx: &ExtCtxt,
+fn call_intrinsic(cx: &ExtCtxt<'_>,
                   mut span: Span,
                   intrinsic: &str,
                   args: Vec<P<ast::Expr>>)
diff --git a/src/libsyntax_ext/diagnostics.rs b/src/libsyntax_ext/diagnostics.rs
index e8ad4af68508e..9bbd9fdec17d6 100644
--- a/src/libsyntax_ext/diagnostics.rs
+++ b/src/libsyntax_ext/diagnostics.rs
@@ -1,5 +1,7 @@
 #![allow(non_snake_case)]
 
+use syntax::{register_diagnostic, register_long_diagnostics};
+
 // Error messages for EXXXX errors.
 // Each message should start and end with a new line, and be wrapped to 80 characters.
 // In vim you can `:set tw=80` and use `gq` to wrap paragraphs. Use `:set tw=0` to disable.
diff --git a/src/libsyntax_ext/env.rs b/src/libsyntax_ext/env.rs
index 16fb64a5f3912..ccff4aec2c8c7 100644
--- a/src/libsyntax_ext/env.rs
+++ b/src/libsyntax_ext/env.rs
@@ -4,8 +4,7 @@
 //
 
 use syntax::ast::{self, Ident, GenericArg};
-use syntax::ext::base::*;
-use syntax::ext::base;
+use syntax::ext::base::{self, *};
 use syntax::ext::build::AstBuilder;
 use syntax::symbol::{keywords, Symbol};
 use syntax_pos::Span;
@@ -13,7 +12,7 @@ use syntax::tokenstream;
 
 use std::env;
 
-pub fn expand_option_env<'cx>(cx: &'cx mut ExtCtxt,
+pub fn expand_option_env<'cx>(cx: &'cx mut ExtCtxt<'_>,
                               sp: Span,
                               tts: &[tokenstream::TokenTree])
                               -> Box<dyn base::MacResult + 'cx> {
@@ -44,7 +43,7 @@ pub fn expand_option_env<'cx>(cx: &'cx mut ExtCtxt,
     MacEager::expr(e)
 }
 
-pub fn expand_env<'cx>(cx: &'cx mut ExtCtxt,
+pub fn expand_env<'cx>(cx: &'cx mut ExtCtxt<'_>,
                        sp: Span,
                        tts: &[tokenstream::TokenTree])
                        -> Box<dyn base::MacResult + 'cx> {
diff --git a/src/libsyntax_ext/format.rs b/src/libsyntax_ext/format.rs
index 4c473fe7612af..6bb7ee1d5ddfd 100644
--- a/src/libsyntax_ext/format.rs
+++ b/src/libsyntax_ext/format.rs
@@ -1,9 +1,11 @@
-use self::ArgumentType::*;
-use self::Position::*;
+use ArgumentType::*;
+use Position::*;
 
 use fmt_macros as parse;
 
-use errors::DiagnosticBuilder;
+use crate::errors::DiagnosticBuilder;
+use crate::errors::Applicability;
+
 use syntax::ast;
 use syntax::ext::base::{self, *};
 use syntax::ext::build::AstBuilder;
@@ -13,7 +15,6 @@ use syntax::ptr::P;
 use syntax::symbol::Symbol;
 use syntax::tokenstream;
 use syntax_pos::{MultiSpan, Span, DUMMY_SP};
-use errors::Applicability;
 
 use rustc_data_structures::fx::{FxHashMap, FxHashSet};
 use std::borrow::Cow;
@@ -184,7 +185,7 @@ fn parse_args<'a>(
 }
 
 impl<'a, 'b> Context<'a, 'b> {
-    fn resolve_name_inplace(&self, p: &mut parse::Piece) {
+    fn resolve_name_inplace(&self, p: &mut parse::Piece<'_>) {
         // NOTE: the `unwrap_or` branch is needed in case of invalid format
         // arguments, e.g., `format_args!("{foo}")`.
         let lookup = |s| *self.names.get(s).unwrap_or(&0);
@@ -208,7 +209,7 @@ impl<'a, 'b> Context<'a, 'b> {
     /// Verifies one piece of a parse string, and remembers it if valid.
     /// All errors are not emitted as fatal so we can continue giving errors
     /// about this and possibly other format strings.
-    fn verify_piece(&mut self, p: &parse::Piece) {
+    fn verify_piece(&mut self, p: &parse::Piece<'_>) {
         match *p {
             parse::String(..) => {}
             parse::NextArgument(ref arg) => {
@@ -231,7 +232,7 @@ impl<'a, 'b> Context<'a, 'b> {
         }
     }
 
-    fn verify_count(&mut self, c: parse::Count) {
+    fn verify_count(&mut self, c: parse::Count<'_>) {
         match c {
             parse::CountImplied |
             parse::CountIs(..) => {}
@@ -244,7 +245,7 @@ impl<'a, 'b> Context<'a, 'b> {
         }
     }
 
-    fn describe_num_args(&self) -> Cow<str> {
+    fn describe_num_args(&self) -> Cow<'_, str> {
         match self.args.len() {
             0 => "no arguments were given".into(),
             1 => "there is 1 argument".into(),
@@ -385,11 +386,11 @@ impl<'a, 'b> Context<'a, 'b> {
         self.count_args_index_offset = sofar;
     }
 
-    fn rtpath(ecx: &ExtCtxt, s: &str) -> Vec<ast::Ident> {
+    fn rtpath(ecx: &ExtCtxt<'_>, s: &str) -> Vec<ast::Ident> {
         ecx.std_path(&["fmt", "rt", "v1", s])
     }
 
-    fn build_count(&self, c: parse::Count) -> P<ast::Expr> {
+    fn build_count(&self, c: parse::Count<'_>) -> P<ast::Expr> {
         let sp = self.macsp;
         let count = |c, arg| {
             let mut path = Context::rtpath(self.ecx, "Count");
@@ -426,7 +427,7 @@ impl<'a, 'b> Context<'a, 'b> {
     /// Build a static `rt::Argument` from a `parse::Piece` or append
     /// to the `literal` string.
     fn build_piece(&mut self,
-                   piece: &parse::Piece,
+                   piece: &parse::Piece<'_>,
                    arg_index_consumed: &mut Vec<usize>)
                    -> Option<P<ast::Expr>> {
         let sp = self.macsp;
@@ -647,7 +648,7 @@ impl<'a, 'b> Context<'a, 'b> {
         self.ecx.expr_call_global(self.macsp, path, fn_args)
     }
 
-    fn format_arg(ecx: &ExtCtxt,
+    fn format_arg(ecx: &ExtCtxt<'_>,
                   macsp: Span,
                   mut sp: Span,
                   ty: &ArgumentType,
@@ -686,7 +687,7 @@ impl<'a, 'b> Context<'a, 'b> {
     }
 }
 
-pub fn expand_format_args<'cx>(ecx: &'cx mut ExtCtxt,
+pub fn expand_format_args<'cx>(ecx: &'cx mut ExtCtxt<'_>,
                                mut sp: Span,
                                tts: &[tokenstream::TokenTree])
                                -> Box<dyn base::MacResult + 'cx> {
@@ -703,7 +704,7 @@ pub fn expand_format_args<'cx>(ecx: &'cx mut ExtCtxt,
 }
 
 pub fn expand_format_args_nl<'cx>(
-    ecx: &'cx mut ExtCtxt,
+    ecx: &'cx mut ExtCtxt<'_>,
     mut sp: Span,
     tts: &[tokenstream::TokenTree],
 ) -> Box<dyn base::MacResult + 'cx> {
@@ -734,7 +735,7 @@ pub fn expand_format_args_nl<'cx>(
 
 /// Take the various parts of `format_args!(efmt, args..., name=names...)`
 /// and construct the appropriate formatting expression.
-pub fn expand_preparsed_format_args(ecx: &mut ExtCtxt,
+pub fn expand_preparsed_format_args(ecx: &mut ExtCtxt<'_>,
                                     sp: Span,
                                     efmt: P<ast::Expr>,
                                     args: Vec<P<ast::Expr>>,
@@ -952,7 +953,7 @@ pub fn expand_preparsed_format_args(ecx: &mut ExtCtxt,
         piece
     }).collect::<Vec<_>>();
 
-    let numbered_position_args = pieces.iter().any(|arg: &parse::Piece| {
+    let numbered_position_args = pieces.iter().any(|arg: &parse::Piece<'_>| {
         match *arg {
             parse::String(_) => false,
             parse::NextArgument(arg) => {
diff --git a/src/libsyntax_ext/format_foreign.rs b/src/libsyntax_ext/format_foreign.rs
index 8ac6d460ec3d9..381325b2963ef 100644
--- a/src/libsyntax_ext/format_foreign.rs
+++ b/src/libsyntax_ext/format_foreign.rs
@@ -68,7 +68,7 @@ pub mod printf {
         pub position: (usize, usize),
     }
 
-    impl<'a> Format<'a> {
+    impl Format<'_> {
         /// Translate this directive into an equivalent Rust formatting directive.
         ///
         /// Returns `None` in cases where the `printf` directive does not have an exact Rust
@@ -249,12 +249,12 @@ pub mod printf {
             }
         }
 
-        fn translate(&self, s: &mut String) -> ::std::fmt::Result {
+        fn translate(&self, s: &mut String) -> std::fmt::Result {
             use std::fmt::Write;
             match *self {
                 Num::Num(n) => write!(s, "{}", n),
                 Num::Arg(n) => {
-                    let n = n.checked_sub(1).ok_or(::std::fmt::Error)?;
+                    let n = n.checked_sub(1).ok_or(std::fmt::Error)?;
                     write!(s, "{}$", n)
                 },
                 Num::Next => write!(s, "*"),
@@ -263,7 +263,7 @@ pub mod printf {
     }
 
     /// Returns an iterator over all substitutions in a given string.
-    pub fn iter_subs(s: &str) -> Substitutions {
+    pub fn iter_subs(s: &str) -> Substitutions<'_> {
         Substitutions {
             s,
             pos: 0,
@@ -309,7 +309,7 @@ pub mod printf {
     }
 
     /// Parse the next substitution from the input string.
-    pub fn parse_next_substitution(s: &str) -> Option<(Substitution, &str)> {
+    pub fn parse_next_substitution(s: &str) -> Option<(Substitution<'_>, &str)> {
         use self::State::*;
 
         let at = {
@@ -389,7 +389,7 @@ pub mod printf {
         let mut precision: Option<Num> = None;
         let mut length: Option<&str> = None;
         let mut type_: &str = "";
-        let end: Cur;
+        let end: Cur<'_>;
 
         if let Start = state {
             match c {
@@ -575,7 +575,7 @@ pub mod printf {
         Some((Substitution::Format(f), end.slice_after()))
     }
 
-    fn at_next_cp_while<F>(mut cur: Cur, mut pred: F) -> Cur
+    fn at_next_cp_while<F>(mut cur: Cur<'_>, mut pred: F) -> Cur<'_>
     where F: FnMut(char) -> bool {
         loop {
             match cur.next_cp() {
@@ -769,7 +769,7 @@ pub mod shell {
         Escape((usize, usize)),
     }
 
-    impl<'a> Substitution<'a> {
+    impl Substitution<'_> {
         pub fn as_str(&self) -> String {
             match self {
                 Substitution::Ordinal(n, _) => format!("${}", n),
@@ -804,7 +804,7 @@ pub mod shell {
     }
 
     /// Returns an iterator over all substitutions in a given string.
-    pub fn iter_subs(s: &str) -> Substitutions {
+    pub fn iter_subs(s: &str) -> Substitutions<'_> {
         Substitutions {
             s,
             pos: 0,
@@ -839,7 +839,7 @@ pub mod shell {
     }
 
     /// Parse the next substitution from the input string.
-    pub fn parse_next_substitution(s: &str) -> Option<(Substitution, &str)> {
+    pub fn parse_next_substitution(s: &str) -> Option<(Substitution<'_>, &str)> {
         let at = {
             let start = s.find('$')?;
             match s[start+1..].chars().next()? {
@@ -868,7 +868,7 @@ pub mod shell {
         }
     }
 
-    fn at_next_cp_while<F>(mut cur: Cur, mut pred: F) -> Cur
+    fn at_next_cp_while<F>(mut cur: Cur<'_>, mut pred: F) -> Cur<'_>
     where F: FnMut(char) -> bool {
         loop {
             match cur.next_cp() {
@@ -962,8 +962,6 @@ pub mod shell {
 }
 
 mod strcursor {
-    use std;
-
     pub struct StrCursor<'a> {
         s: &'a str,
         pub at: usize,
@@ -1028,7 +1026,7 @@ mod strcursor {
         }
     }
 
-    impl<'a> Copy for StrCursor<'a> {}
+    impl Copy for StrCursor<'_> {}
 
     impl<'a> Clone for StrCursor<'a> {
         fn clone(&self) -> StrCursor<'a> {
@@ -1036,8 +1034,8 @@ mod strcursor {
         }
     }
 
-    impl<'a> std::fmt::Debug for StrCursor<'a> {
-        fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::fmt::Result {
+    impl std::fmt::Debug for StrCursor<'_> {
+        fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
             write!(fmt, "StrCursor({:?} | {:?})", self.slice_before(), self.slice_after())
         }
     }
diff --git a/src/libsyntax_ext/global_asm.rs b/src/libsyntax_ext/global_asm.rs
index 0a12e27c4fc21..14dbd9300232b 100644
--- a/src/libsyntax_ext/global_asm.rs
+++ b/src/libsyntax_ext/global_asm.rs
@@ -8,21 +8,22 @@
 /// LLVM's `module asm "some assembly here"`. All of LLVM's caveats
 /// therefore apply.
 
-use errors::DiagnosticBuilder;
+use crate::errors::DiagnosticBuilder;
+
 use syntax::ast;
 use syntax::source_map::respan;
-use syntax::ext::base;
-use syntax::ext::base::*;
+use syntax::ext::base::{self, *};
 use syntax::feature_gate;
 use syntax::parse::token;
 use syntax::ptr::P;
 use syntax::symbol::Symbol;
 use syntax_pos::Span;
 use syntax::tokenstream;
+use smallvec::smallvec;
 
 pub const MACRO: &str = "global_asm";
 
-pub fn expand_global_asm<'cx>(cx: &'cx mut ExtCtxt,
+pub fn expand_global_asm<'cx>(cx: &'cx mut ExtCtxt<'_>,
                               sp: Span,
                               tts: &[tokenstream::TokenTree]) -> Box<dyn base::MacResult + 'cx> {
     if !cx.ecfg.enable_global_asm() {
diff --git a/src/libsyntax_ext/lib.rs b/src/libsyntax_ext/lib.rs
index 5e767d237cc0e..9308cfb3a4f2e 100644
--- a/src/libsyntax_ext/lib.rs
+++ b/src/libsyntax_ext/lib.rs
@@ -4,29 +4,21 @@
        html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
        html_root_url = "https://doc.rust-lang.org/nightly/")]
 
+#![deny(rust_2018_idioms)]
+
 #![feature(in_band_lifetimes)]
 #![feature(proc_macro_diagnostic)]
 #![feature(proc_macro_internals)]
 #![feature(proc_macro_span)]
 #![feature(decl_macro)]
-#![feature(nll)]
 #![feature(str_escape)]
 #![feature(rustc_diagnostic_macros)]
 
 #![recursion_limit="256"]
 
-extern crate fmt_macros;
-#[macro_use]
-extern crate syntax;
-extern crate syntax_pos;
 extern crate proc_macro;
-extern crate rustc_data_structures;
-extern crate rustc_errors as errors;
-extern crate rustc_target;
-#[macro_use]
-extern crate smallvec;
-#[macro_use]
-extern crate log;
+
+use rustc_errors as errors;
 
 mod diagnostics;
 
diff --git a/src/libsyntax_ext/log_syntax.rs b/src/libsyntax_ext/log_syntax.rs
index a143186b9451f..658ce98d26884 100644
--- a/src/libsyntax_ext/log_syntax.rs
+++ b/src/libsyntax_ext/log_syntax.rs
@@ -4,7 +4,7 @@ use syntax::print;
 use syntax::tokenstream;
 use syntax_pos;
 
-pub fn expand_syntax_ext<'cx>(cx: &'cx mut base::ExtCtxt,
+pub fn expand_syntax_ext<'cx>(cx: &'cx mut base::ExtCtxt<'_>,
                               sp: syntax_pos::Span,
                               tts: &[tokenstream::TokenTree])
                               -> Box<dyn base::MacResult + 'cx> {
diff --git a/src/libsyntax_ext/proc_macro_decls.rs b/src/libsyntax_ext/proc_macro_decls.rs
index 46c502965eea8..fbc4d8990742c 100644
--- a/src/libsyntax_ext/proc_macro_decls.rs
+++ b/src/libsyntax_ext/proc_macro_decls.rs
@@ -1,6 +1,7 @@
 use std::mem;
 
-use errors;
+use crate::deriving;
+use crate::errors;
 
 use syntax::ast::{self, Ident};
 use syntax::attr;
@@ -18,8 +19,6 @@ use syntax::visit::{self, Visitor};
 
 use syntax_pos::{Span, DUMMY_SP};
 
-use deriving;
-
 const PROC_MACRO_KINDS: [&str; 3] = ["proc_macro_derive", "proc_macro_attribute", "proc_macro"];
 
 struct ProcMacroDerive {
@@ -324,7 +323,7 @@ impl<'a> Visitor<'a> for CollectProcMacros<'a> {
 //          ];
 //      }
 fn mk_decls(
-    cx: &mut ExtCtxt,
+    cx: &mut ExtCtxt<'_>,
     custom_derives: &[ProcMacroDerive],
     custom_attrs: &[ProcMacroDef],
     custom_macros: &[ProcMacroDef],
diff --git a/src/libsyntax_ext/proc_macro_impl.rs b/src/libsyntax_ext/proc_macro_impl.rs
index 60d167d01eebe..88e20e3dc7c9e 100644
--- a/src/libsyntax_ext/proc_macro_impl.rs
+++ b/src/libsyntax_ext/proc_macro_impl.rs
@@ -1,27 +1,27 @@
-use errors::FatalError;
+use crate::errors::FatalError;
+use crate::proc_macro_server;
 
 use syntax::source_map::Span;
-use syntax::ext::base::*;
+use syntax::ext::base::{self, *};
 use syntax::tokenstream::TokenStream;
-use syntax::ext::base;
 
-pub const EXEC_STRATEGY: ::proc_macro::bridge::server::SameThread =
-    ::proc_macro::bridge::server::SameThread;
+pub const EXEC_STRATEGY: proc_macro::bridge::server::SameThread =
+    proc_macro::bridge::server::SameThread;
 
 pub struct AttrProcMacro {
-    pub client: ::proc_macro::bridge::client::Client<
-        fn(::proc_macro::TokenStream, ::proc_macro::TokenStream) -> ::proc_macro::TokenStream,
+    pub client: proc_macro::bridge::client::Client<
+        fn(proc_macro::TokenStream, proc_macro::TokenStream) -> proc_macro::TokenStream,
     >,
 }
 
 impl base::AttrProcMacro for AttrProcMacro {
     fn expand<'cx>(&self,
-                   ecx: &'cx mut ExtCtxt,
+                   ecx: &'cx mut ExtCtxt<'_>,
                    span: Span,
                    annotation: TokenStream,
                    annotated: TokenStream)
                    -> TokenStream {
-        let server = ::proc_macro_server::Rustc::new(ecx);
+        let server = proc_macro_server::Rustc::new(ecx);
         match self.client.run(&EXEC_STRATEGY, server, annotation, annotated) {
             Ok(stream) => stream,
             Err(e) => {
@@ -39,18 +39,18 @@ impl base::AttrProcMacro for AttrProcMacro {
 }
 
 pub struct BangProcMacro {
-    pub client: ::proc_macro::bridge::client::Client<
-        fn(::proc_macro::TokenStream) -> ::proc_macro::TokenStream,
+    pub client: proc_macro::bridge::client::Client<
+        fn(proc_macro::TokenStream) -> proc_macro::TokenStream,
     >,
 }
 
 impl base::ProcMacro for BangProcMacro {
     fn expand<'cx>(&self,
-                   ecx: &'cx mut ExtCtxt,
+                   ecx: &'cx mut ExtCtxt<'_>,
                    span: Span,
                    input: TokenStream)
                    -> TokenStream {
-        let server = ::proc_macro_server::Rustc::new(ecx);
+        let server = proc_macro_server::Rustc::new(ecx);
         match self.client.run(&EXEC_STRATEGY, server, input) {
             Ok(stream) => stream,
             Err(e) => {
diff --git a/src/libsyntax_ext/proc_macro_server.rs b/src/libsyntax_ext/proc_macro_server.rs
index 7de9b9343a8fa..730262683c0b7 100644
--- a/src/libsyntax_ext/proc_macro_server.rs
+++ b/src/libsyntax_ext/proc_macro_server.rs
@@ -1,4 +1,5 @@
-use errors::{self, Diagnostic, DiagnosticBuilder};
+use crate::errors::{self, Diagnostic, DiagnosticBuilder};
+
 use std::panic;
 
 use proc_macro::bridge::{server, TokenTree};
@@ -369,7 +370,7 @@ pub(crate) struct Rustc<'a> {
 }
 
 impl<'a> Rustc<'a> {
-    pub fn new(cx: &'a ExtCtxt) -> Self {
+    pub fn new(cx: &'a ExtCtxt<'_>) -> Self {
         // No way to determine def location for a proc macro right now, so use call location.
         let location = cx.current_expansion.mark.expn_info().unwrap().call_site;
         let to_span = |transparency| {
@@ -650,7 +651,7 @@ impl server::Literal for Rustc<'_> {
     }
 }
 
-impl<'a> server::SourceFile for Rustc<'a> {
+impl server::SourceFile for Rustc<'_> {
     fn eq(&mut self, file1: &Self::SourceFile, file2: &Self::SourceFile) -> bool {
         Lrc::ptr_eq(file1, file2)
     }
diff --git a/src/libsyntax_ext/test.rs b/src/libsyntax_ext/test.rs
index 11c734b299c1e..832bebb6113e9 100644
--- a/src/libsyntax_ext/test.rs
+++ b/src/libsyntax_ext/test.rs
@@ -13,7 +13,7 @@ use syntax::source_map::{ExpnInfo, MacroAttribute};
 use std::iter;
 
 pub fn expand_test(
-    cx: &mut ExtCtxt,
+    cx: &mut ExtCtxt<'_>,
     attr_sp: Span,
     _meta_item: &ast::MetaItem,
     item: Annotatable,
@@ -22,7 +22,7 @@ pub fn expand_test(
 }
 
 pub fn expand_bench(
-    cx: &mut ExtCtxt,
+    cx: &mut ExtCtxt<'_>,
     attr_sp: Span,
     _meta_item: &ast::MetaItem,
     item: Annotatable,
@@ -31,7 +31,7 @@ pub fn expand_bench(
 }
 
 pub fn expand_test_or_bench(
-    cx: &mut ExtCtxt,
+    cx: &mut ExtCtxt<'_>,
     attr_sp: Span,
     item: Annotatable,
     is_bench: bool
@@ -180,7 +180,7 @@ pub fn expand_test_or_bench(
         ast::ItemKind::ExternCrate(Some(Symbol::intern("test")))
     );
 
-    debug!("Synthetic test item:\n{}\n", pprust::item_to_string(&test_const));
+    log::debug!("Synthetic test item:\n{}\n", pprust::item_to_string(&test_const));
 
     vec![
         // Access to libtest under a gensymed name
@@ -210,7 +210,7 @@ fn should_fail(i: &ast::Item) -> bool {
     attr::contains_name(&i.attrs, "allow_fail")
 }
 
-fn should_panic(cx: &ExtCtxt, i: &ast::Item) -> ShouldPanic {
+fn should_panic(cx: &ExtCtxt<'_>, i: &ast::Item) -> ShouldPanic {
     match attr::find_by_name(&i.attrs, "should_panic") {
         Some(attr) => {
             let ref sd = cx.parse_sess.span_diagnostic;
@@ -243,7 +243,7 @@ fn should_panic(cx: &ExtCtxt, i: &ast::Item) -> ShouldPanic {
     }
 }
 
-fn has_test_signature(cx: &ExtCtxt, i: &ast::Item) -> bool {
+fn has_test_signature(cx: &ExtCtxt<'_>, i: &ast::Item) -> bool {
     let has_should_panic_attr = attr::contains_name(&i.attrs, "should_panic");
     let ref sd = cx.parse_sess.span_diagnostic;
     if let ast::ItemKind::Fn(ref decl, ref header, ref generics, _) = i.node {
@@ -296,7 +296,7 @@ fn has_test_signature(cx: &ExtCtxt, i: &ast::Item) -> bool {
     }
 }
 
-fn has_bench_signature(cx: &ExtCtxt, i: &ast::Item) -> bool {
+fn has_bench_signature(cx: &ExtCtxt<'_>, i: &ast::Item) -> bool {
     let has_sig = if let ast::ItemKind::Fn(ref decl, _, _, _) = i.node {
         // N.B., inadequate check, but we're running
         // well before resolve, can't get too deep.
diff --git a/src/libsyntax_ext/test_case.rs b/src/libsyntax_ext/test_case.rs
index 04e33671872f5..63417b702d569 100644
--- a/src/libsyntax_ext/test_case.rs
+++ b/src/libsyntax_ext/test_case.rs
@@ -20,7 +20,7 @@ use syntax::source_map::{ExpnInfo, MacroAttribute};
 use syntax::feature_gate;
 
 pub fn expand(
-    ecx: &mut ExtCtxt,
+    ecx: &mut ExtCtxt<'_>,
     attr_sp: Span,
     _meta_item: &ast::MetaItem,
     anno_item: Annotatable
diff --git a/src/libsyntax_ext/trace_macros.rs b/src/libsyntax_ext/trace_macros.rs
index 638d7b5568bfb..4d35daf3de998 100644
--- a/src/libsyntax_ext/trace_macros.rs
+++ b/src/libsyntax_ext/trace_macros.rs
@@ -1,11 +1,10 @@
-use syntax::ext::base::ExtCtxt;
-use syntax::ext::base;
+use syntax::ext::base::{self, ExtCtxt};
 use syntax::feature_gate;
 use syntax::symbol::keywords;
 use syntax_pos::Span;
 use syntax::tokenstream::TokenTree;
 
-pub fn expand_trace_macros(cx: &mut ExtCtxt,
+pub fn expand_trace_macros(cx: &mut ExtCtxt<'_>,
                            sp: Span,
                            tt: &[TokenTree])
                            -> Box<dyn base::MacResult + 'static> {

From 4ca3c7b156f0ecb18c15e91800b6933a5c0f47b4 Mon Sep 17 00:00:00 2001
From: Hirokazu Hata <h.hata.ai.t@gmail.com>
Date: Tue, 5 Feb 2019 01:21:07 +0900
Subject: [PATCH 08/24] update rust-installer from 27dec6c to ccdc47b

---
 src/tools/rust-installer | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/tools/rust-installer b/src/tools/rust-installer
index 27dec6cae3a81..ccdc47b657a76 160000
--- a/src/tools/rust-installer
+++ b/src/tools/rust-installer
@@ -1 +1 @@
-Subproject commit 27dec6cae3a8132d8a073aad6775425c85095c99
+Subproject commit ccdc47b657a7600cbd0c2858eb52a8d712cfce18

From e957ed9d10ec589bdd523b88b4b44c41b1ecf763 Mon Sep 17 00:00:00 2001
From: Mark Mansi <markm@cs.wisc.edu>
Date: Tue, 5 Feb 2019 11:20:45 -0600
Subject: [PATCH 09/24] move librustc to 2018

---
 src/librustc/Cargo.toml                       |   1 +
 src/librustc/cfg/construct.rs                 |  10 +-
 src/librustc/cfg/graphviz.rs                  |   6 +-
 src/librustc/cfg/mod.rs                       |   6 +-
 src/librustc/dep_graph/cgu_reuse_tracker.rs   |   2 +-
 src/librustc/dep_graph/dep_node.rs            |  22 ++--
 src/librustc/dep_graph/dep_tracking_map.rs    |   2 +-
 src/librustc/dep_graph/graph.rs               |  10 +-
 src/librustc/dep_graph/prev.rs                |   2 +-
 src/librustc/dep_graph/safe.rs                |   6 +-
 src/librustc/dep_graph/serialized.rs          |   4 +-
 src/librustc/hir/check_attr.rs                |  10 +-
 src/librustc/hir/def.rs                       |   8 +-
 src/librustc/hir/def_id.rs                    |   6 +-
 src/librustc/hir/intravisit.rs                |   6 +-
 src/librustc/hir/lowering.rs                  |  28 ++---
 src/librustc/hir/map/blocks.rs                |   8 +-
 src/librustc/hir/map/collector.rs             |  20 ++--
 src/librustc/hir/map/def_collector.rs         |   8 +-
 src/librustc/hir/map/definitions.rs           |  10 +-
 src/librustc/hir/map/hir_id_validator.rs      |   6 +-
 src/librustc/hir/map/mod.rs                   |  24 ++---
 src/librustc/hir/mod.rs                       |  14 +--
 src/librustc/hir/pat_util.rs                  |   6 +-
 src/librustc/hir/print.rs                     |   8 +-
 src/librustc/ich/hcx.rs                       |  18 ++--
 src/librustc/ich/impls_cstore.rs              |  18 ++--
 src/librustc/ich/impls_hir.rs                 |  16 +--
 src/librustc/ich/impls_mir.rs                 |   4 +-
 src/librustc/ich/impls_misc.rs                |   2 +-
 src/librustc/ich/impls_syntax.rs              |   4 +-
 src/librustc/ich/impls_ty.rs                  |  54 +++++-----
 src/librustc/infer/at.rs                      |   2 +-
 src/librustc/infer/canonical/canonicalizer.rs |  10 +-
 src/librustc/infer/canonical/mod.rs           |  18 ++--
 .../infer/canonical/query_response.rs         |  24 ++---
 src/librustc/infer/canonical/substitute.rs    |   8 +-
 src/librustc/infer/combine.rs                 |  14 +--
 src/librustc/infer/equate.rs                  |  10 +-
 src/librustc/infer/error_reporting/mod.rs     |  22 ++--
 .../infer/error_reporting/need_type_info.rs   |  12 +--
 .../nice_region_error/different_lifetimes.rs  |   6 +-
 .../nice_region_error/find_anon_type.rs       |  12 +--
 .../error_reporting/nice_region_error/mod.rs  |  10 +-
 .../nice_region_error/named_anon_conflict.rs  |   8 +-
 .../nice_region_error/outlives_closure.rs     |  14 +--
 .../nice_region_error/placeholder_error.rs    |  24 ++---
 .../nice_region_error/static_impl_trait.rs    |  10 +-
 .../error_reporting/nice_region_error/util.rs |   8 +-
 src/librustc/infer/error_reporting/note.rs    |  10 +-
 src/librustc/infer/freshen.rs                 |   6 +-
 src/librustc/infer/fudge.rs                   |   6 +-
 src/librustc/infer/glb.rs                     |   6 +-
 src/librustc/infer/higher_ranked/mod.rs       |   4 +-
 src/librustc/infer/lattice.rs                 |   8 +-
 .../infer/lexical_region_resolve/graphviz.rs  |  14 +--
 .../infer/lexical_region_resolve/mod.rs       |  26 ++---
 src/librustc/infer/lub.rs                     |   6 +-
 src/librustc/infer/mod.rs                     |  36 +++----
 src/librustc/infer/opaque_types/mod.rs        |  22 ++--
 src/librustc/infer/outlives/env.rs            |   8 +-
 .../infer/outlives/free_region_map.rs         |   2 +-
 src/librustc/infer/outlives/obligations.rs    |  12 +--
 src/librustc/infer/outlives/verify.rs         |  14 +--
 src/librustc/infer/region_constraints/mod.rs  |   8 +-
 src/librustc/infer/resolve.rs                 |   4 +-
 src/librustc/infer/sub.rs                     |  10 +-
 src/librustc/infer/type_variable.rs           |   2 +-
 src/librustc/infer/unify_key.rs               |   2 +-
 src/librustc/lib.rs                           |  38 +++----
 src/librustc/lint/builtin.rs                  |   6 +-
 src/librustc/lint/context.rs                  |  30 +++---
 src/librustc/lint/levels.rs                   |  16 +--
 src/librustc/lint/mod.rs                      |  24 ++---
 src/librustc/middle/borrowck.rs               |   6 +-
 src/librustc/middle/cstore.rs                 |  12 +--
 src/librustc/middle/dead.rs                   |  24 ++---
 src/librustc/middle/dependency_format.rs      |  12 +--
 src/librustc/middle/entry.rs                  |  16 +--
 src/librustc/middle/exported_symbols.rs       |   8 +-
 src/librustc/middle/expr_use_visitor.rs       |  18 ++--
 src/librustc/middle/free_region.rs            |   8 +-
 src/librustc/middle/intrinsicck.rs            |  14 +--
 src/librustc/middle/lang_items.rs             |  14 +--
 src/librustc/middle/lib_features.rs           |   6 +-
 src/librustc/middle/liveness.rs               |  24 ++---
 src/librustc/middle/mem_categorization.rs     |  28 ++---
 src/librustc/middle/privacy.rs                |   2 +-
 src/librustc/middle/reachable.rs              |  28 ++---
 src/librustc/middle/recursion_limit.rs        |   2 +-
 src/librustc/middle/region.rs                 |  24 ++---
 src/librustc/middle/resolve_lifetime.rs       |  26 ++---
 src/librustc/middle/stability.rs              |  20 ++--
 src/librustc/middle/weak_lang_items.rs        |  14 +--
 src/librustc/mir/cache.rs                     |   6 +-
 src/librustc/mir/interpret/allocation.rs      |   4 +-
 src/librustc/mir/interpret/error.rs           |  16 +--
 src/librustc/mir/interpret/mod.rs             |  16 +--
 src/librustc/mir/interpret/pointer.rs         |   4 +-
 src/librustc/mir/interpret/value.rs           |   2 +-
 src/librustc/mir/mod.rs                       |  42 ++++----
 src/librustc/mir/mono.rs                      |   8 +-
 src/librustc/mir/tcx.rs                       |  12 +--
 src/librustc/mir/visit.rs                     |  10 +-
 src/librustc/session/config.rs                |  30 +++---
 src/librustc/session/filesearch.rs            |   2 +-
 src/librustc/session/mod.rs                   |  28 ++---
 src/librustc/session/search_paths.rs          |   4 +-
 src/librustc/traits/auto_trait.rs             |   8 +-
 src/librustc/traits/chalk_fulfill.rs          |  10 +-
 src/librustc/traits/codegen/mod.rs            |  12 +--
 src/librustc/traits/coherence.rs              |  20 ++--
 src/librustc/traits/engine.rs                 |   8 +-
 src/librustc/traits/error_reporting.rs        |  30 +++---
 src/librustc/traits/fulfill.rs                |   8 +-
 src/librustc/traits/mod.rs                    |  22 ++--
 src/librustc/traits/object_safety.rs          |  12 +--
 src/librustc/traits/on_unimplemented.rs       |   8 +-
 src/librustc/traits/project.rs                |  16 +--
 src/librustc/traits/query/dropck_outlives.rs  |  10 +-
 .../traits/query/evaluate_obligation.rs       |   6 +-
 src/librustc/traits/query/method_autoderef.rs |   4 +-
 src/librustc/traits/query/mod.rs              |   6 +-
 src/librustc/traits/query/normalize.rs        |  18 ++--
 .../traits/query/normalize_erasing_regions.rs |   4 +-
 src/librustc/traits/query/outlives_bounds.rs  |  12 +--
 .../traits/query/type_op/ascribe_user_type.rs |  10 +-
 src/librustc/traits/query/type_op/custom.rs   |  10 +-
 src/librustc/traits/query/type_op/eq.rs       |   6 +-
 .../query/type_op/implied_outlives_bounds.rs  |   8 +-
 src/librustc/traits/query/type_op/mod.rs      |  12 +--
 .../traits/query/type_op/normalize.rs         |   8 +-
 src/librustc/traits/query/type_op/outlives.rs |  10 +-
 .../traits/query/type_op/prove_predicate.rs   |   6 +-
 src/librustc/traits/query/type_op/subtype.rs  |   6 +-
 src/librustc/traits/select.rs                 |  26 ++---
 src/librustc/traits/specialize/mod.rs         |  14 +--
 .../traits/specialize/specialization_graph.rs |  16 +--
 src/librustc/traits/structural_impls.rs       |  22 ++--
 src/librustc/traits/util.rs                   |  14 +--
 src/librustc/ty/_match.rs                     |   6 +-
 src/librustc/ty/adjustment.rs                 |   8 +-
 src/librustc/ty/binding.rs                    |   6 +-
 src/librustc/ty/cast.rs                       |   2 +-
 src/librustc/ty/codec.rs                      |  14 +--
 src/librustc/ty/constness.rs                  |  10 +-
 src/librustc/ty/context.rs                    | 100 +++++++++---------
 src/librustc/ty/erase_regions.rs              |   4 +-
 src/librustc/ty/error.rs                      |   8 +-
 src/librustc/ty/fast_reject.rs                |   6 +-
 src/librustc/ty/flags.rs                      |   4 +-
 src/librustc/ty/fold.rs                       |   6 +-
 .../ty/inhabitedness/def_id_forest.rs         |   4 +-
 src/librustc/ty/inhabitedness/mod.rs          |  10 +-
 src/librustc/ty/instance.rs                   |  12 +--
 src/librustc/ty/item_path.rs                  |  10 +-
 src/librustc/ty/layout.rs                     |  22 ++--
 src/librustc/ty/mod.rs                        |  50 ++++-----
 src/librustc/ty/outlives.rs                   |   2 +-
 src/librustc/ty/query/config.rs               |  28 ++---
 src/librustc/ty/query/job.rs                  |  24 +++--
 src/librustc/ty/query/keys.rs                 |  14 +--
 src/librustc/ty/query/mod.rs                  |  78 +++++++-------
 src/librustc/ty/query/on_disk_cache.rs        |  36 +++----
 src/librustc/ty/query/plumbing.rs             |  48 ++++-----
 src/librustc/ty/query/values.rs               |   2 +-
 src/librustc/ty/relate.rs                     |  30 +++---
 src/librustc/ty/structural_impls.rs           |  54 +++++-----
 src/librustc/ty/sty.rs                        |  22 ++--
 src/librustc/ty/subst.rs                      |   8 +-
 src/librustc/ty/trait_def.rs                  |  16 +--
 src/librustc/ty/util.rs                       |  26 ++---
 src/librustc/ty/walk.rs                       |   2 +-
 src/librustc/ty/wf.rs                         |  12 +--
 src/librustc/util/bug.rs                      |   2 +-
 src/librustc/util/common.rs                   |   6 +-
 src/librustc/util/nodemap.rs                  |   4 +-
 src/librustc/util/ppaux.rs                    |  26 ++---
 src/librustc/util/profiling.rs                |   2 +-
 179 files changed, 1234 insertions(+), 1243 deletions(-)

diff --git a/src/librustc/Cargo.toml b/src/librustc/Cargo.toml
index a5521effc7d8d..c9a04f4c6834d 100644
--- a/src/librustc/Cargo.toml
+++ b/src/librustc/Cargo.toml
@@ -2,6 +2,7 @@
 authors = ["The Rust Project Developers"]
 name = "rustc"
 version = "0.0.0"
+edition = "2018"
 
 [lib]
 name = "rustc"
diff --git a/src/librustc/cfg/construct.rs b/src/librustc/cfg/construct.rs
index 669c2998d1cb2..f7ffbe8c65833 100644
--- a/src/librustc/cfg/construct.rs
+++ b/src/librustc/cfg/construct.rs
@@ -1,11 +1,11 @@
-use cfg::*;
-use middle::region;
+use crate::cfg::*;
+use crate::middle::region;
 use rustc_data_structures::graph::implementation as graph;
 use syntax::ptr::P;
-use ty::{self, TyCtxt};
+use crate::ty::{self, TyCtxt};
 
-use hir::{self, PatKind};
-use hir::def_id::DefId;
+use crate::hir::{self, PatKind};
+use crate::hir::def_id::DefId;
 
 struct CFGBuilder<'a, 'tcx: 'a> {
     tcx: TyCtxt<'a, 'tcx, 'tcx>,
diff --git a/src/librustc/cfg/graphviz.rs b/src/librustc/cfg/graphviz.rs
index 6dec421760899..969c38bd66329 100644
--- a/src/librustc/cfg/graphviz.rs
+++ b/src/librustc/cfg/graphviz.rs
@@ -4,9 +4,9 @@
 // For clarity, rename the graphviz crate locally to dot.
 use graphviz as dot;
 
-use cfg;
-use hir;
-use ty::TyCtxt;
+use crate::cfg;
+use crate::hir;
+use crate::ty::TyCtxt;
 
 pub type Node<'a> = (cfg::CFGIndex, &'a cfg::CFGNode);
 pub type Edge<'a> = &'a cfg::CFGEdge;
diff --git a/src/librustc/cfg/mod.rs b/src/librustc/cfg/mod.rs
index e58557839f9b9..345dff88b5f0b 100644
--- a/src/librustc/cfg/mod.rs
+++ b/src/librustc/cfg/mod.rs
@@ -2,9 +2,9 @@
 //! Uses `Graph` as the underlying representation.
 
 use rustc_data_structures::graph::implementation as graph;
-use ty::TyCtxt;
-use hir;
-use hir::def_id::DefId;
+use crate::ty::TyCtxt;
+use crate::hir;
+use crate::hir::def_id::DefId;
 
 mod construct;
 pub mod graphviz;
diff --git a/src/librustc/dep_graph/cgu_reuse_tracker.rs b/src/librustc/dep_graph/cgu_reuse_tracker.rs
index e8d1b71048705..13f6f95332973 100644
--- a/src/librustc/dep_graph/cgu_reuse_tracker.rs
+++ b/src/librustc/dep_graph/cgu_reuse_tracker.rs
@@ -2,7 +2,7 @@
 //! compilation. This is used for incremental compilation tests and debug
 //! output.
 
-use session::Session;
+use crate::session::Session;
 use rustc_data_structures::fx::FxHashMap;
 use std::sync::{Arc, Mutex};
 use syntax_pos::Span;
diff --git a/src/librustc/dep_graph/dep_node.rs b/src/librustc/dep_graph/dep_node.rs
index cda469657ed87..58087b76266b5 100644
--- a/src/librustc/dep_graph/dep_node.rs
+++ b/src/librustc/dep_graph/dep_node.rs
@@ -49,25 +49,25 @@
 //! user of the `DepNode` API of having to know how to compute the expected
 //! fingerprint for a given set of node parameters.
 
-use mir::interpret::GlobalId;
-use hir::def_id::{CrateNum, DefId, DefIndex, CRATE_DEF_INDEX};
-use hir::map::DefPathHash;
-use hir::HirId;
+use crate::mir::interpret::GlobalId;
+use crate::hir::def_id::{CrateNum, DefId, DefIndex, CRATE_DEF_INDEX};
+use crate::hir::map::DefPathHash;
+use crate::hir::HirId;
 
-use ich::{Fingerprint, StableHashingContext};
+use crate::ich::{Fingerprint, StableHashingContext};
 use rustc_data_structures::stable_hasher::{StableHasher, HashStable};
 use std::fmt;
 use std::hash::Hash;
 use syntax_pos::symbol::InternedString;
-use traits;
-use traits::query::{
+use crate::traits;
+use crate::traits::query::{
     CanonicalProjectionGoal, CanonicalTyGoal, CanonicalTypeOpAscribeUserTypeGoal,
     CanonicalTypeOpEqGoal, CanonicalTypeOpSubtypeGoal, CanonicalPredicateGoal,
     CanonicalTypeOpProvePredicateGoal, CanonicalTypeOpNormalizeGoal,
 };
-use ty::{TyCtxt, FnSig, Instance, InstanceDef,
+use crate::ty::{TyCtxt, FnSig, Instance, InstanceDef,
          ParamEnv, ParamEnvAnd, Predicate, PolyFnSig, PolyTraitRef, Ty};
-use ty::subst::Substs;
+use crate::ty::subst::Substs;
 
 // erase!() just makes tokens go away. It's used to specify which macro argument
 // is repeated (i.e., which sub-expression of the macro we are in) but don't need
@@ -389,7 +389,7 @@ impl fmt::Debug for DepNode {
 
         write!(f, "(")?;
 
-        ::ty::tls::with_opt(|opt_tcx| {
+        crate::ty::tls::with_opt(|opt_tcx| {
             if let Some(tcx) = opt_tcx {
                 if let Some(def_id) = self.extract_def_id(tcx) {
                     write!(f, "{}", tcx.def_path_debug_str(def_id))?;
@@ -825,6 +825,6 @@ impl WorkProductId {
     }
 }
 
-impl_stable_hash_for!(struct ::dep_graph::WorkProductId {
+impl_stable_hash_for!(struct crate::dep_graph::WorkProductId {
     hash
 });
diff --git a/src/librustc/dep_graph/dep_tracking_map.rs b/src/librustc/dep_graph/dep_tracking_map.rs
index 331a9c6109c4c..a296a3379c2ac 100644
--- a/src/librustc/dep_graph/dep_tracking_map.rs
+++ b/src/librustc/dep_graph/dep_tracking_map.rs
@@ -2,7 +2,7 @@ use rustc_data_structures::fx::FxHashMap;
 use std::cell::RefCell;
 use std::hash::Hash;
 use std::marker::PhantomData;
-use util::common::MemoizationMap;
+use crate::util::common::MemoizationMap;
 
 use super::{DepKind, DepNodeIndex, DepGraph};
 
diff --git a/src/librustc/dep_graph/graph.rs b/src/librustc/dep_graph/graph.rs
index c9353a451e2cd..663c408ac22fd 100644
--- a/src/librustc/dep_graph/graph.rs
+++ b/src/librustc/dep_graph/graph.rs
@@ -1,4 +1,4 @@
-use errors::{Diagnostic, DiagnosticBuilder};
+use crate::errors::{Diagnostic, DiagnosticBuilder};
 use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
 use rustc_data_structures::fx::{FxHashMap, FxHashSet};
 use rustc_data_structures::indexed_vec::{Idx, IndexVec};
@@ -7,11 +7,11 @@ use rustc_data_structures::sync::{Lrc, Lock, AtomicU32, Ordering};
 use std::env;
 use std::hash::Hash;
 use std::collections::hash_map::Entry;
-use ty::{self, TyCtxt};
-use util::common::{ProfileQueriesMsg, profq_msg};
+use crate::ty::{self, TyCtxt};
+use crate::util::common::{ProfileQueriesMsg, profq_msg};
 use parking_lot::{Mutex, Condvar};
 
-use ich::{StableHashingContext, StableHashingContextProvider, Fingerprint};
+use crate::ich::{StableHashingContext, StableHashingContextProvider, Fingerprint};
 
 use super::debug::EdgeFilter;
 use super::dep_node::{DepNode, DepKind, WorkProductId};
@@ -669,7 +669,7 @@ impl DepGraph {
                     // We failed to mark it green, so we try to force the query.
                     debug!("try_mark_previous_green({:?}) --- trying to force \
                             dependency {:?}", dep_node, dep_dep_node);
-                    if ::ty::query::force_from_dep_node(tcx, dep_dep_node) {
+                    if crate::ty::query::force_from_dep_node(tcx, dep_dep_node) {
                         let dep_dep_node_color = data.colors.get(dep_dep_node_index);
 
                         match dep_dep_node_color {
diff --git a/src/librustc/dep_graph/prev.rs b/src/librustc/dep_graph/prev.rs
index ea5350ac97fee..d971690bbe317 100644
--- a/src/librustc/dep_graph/prev.rs
+++ b/src/librustc/dep_graph/prev.rs
@@ -1,4 +1,4 @@
-use ich::Fingerprint;
+use crate::ich::Fingerprint;
 use rustc_data_structures::fx::FxHashMap;
 use super::dep_node::DepNode;
 use super::serialized::{SerializedDepGraph, SerializedDepNodeIndex};
diff --git a/src/librustc/dep_graph/safe.rs b/src/librustc/dep_graph/safe.rs
index f1e8224a70d14..fc767defe9c71 100644
--- a/src/librustc/dep_graph/safe.rs
+++ b/src/librustc/dep_graph/safe.rs
@@ -1,9 +1,9 @@
 //! The `DepGraphSafe` trait
 
-use hir::BodyId;
-use hir::def_id::DefId;
+use crate::hir::BodyId;
+use crate::hir::def_id::DefId;
 use syntax::ast::NodeId;
-use ty::TyCtxt;
+use crate::ty::TyCtxt;
 
 /// The `DepGraphSafe` trait is used to specify what kinds of values
 /// are safe to "leak" into a task. The idea is that this should be
diff --git a/src/librustc/dep_graph/serialized.rs b/src/librustc/dep_graph/serialized.rs
index 3c04f01a5e1eb..b64f71ed908d8 100644
--- a/src/librustc/dep_graph/serialized.rs
+++ b/src/librustc/dep_graph/serialized.rs
@@ -1,7 +1,7 @@
 //! The data that we will serialize and deserialize.
 
-use dep_graph::DepNode;
-use ich::Fingerprint;
+use crate::dep_graph::DepNode;
+use crate::ich::Fingerprint;
 use rustc_data_structures::indexed_vec::{IndexVec, Idx};
 
 newtype_index! {
diff --git a/src/librustc/hir/check_attr.rs b/src/librustc/hir/check_attr.rs
index 4ce41fec18240..75710210d7722 100644
--- a/src/librustc/hir/check_attr.rs
+++ b/src/librustc/hir/check_attr.rs
@@ -5,12 +5,12 @@
 //! item.
 
 
-use ty::TyCtxt;
-use ty::query::Providers;
+use crate::ty::TyCtxt;
+use crate::ty::query::Providers;
 
-use hir;
-use hir::def_id::DefId;
-use hir::intravisit::{self, Visitor, NestedVisitorMap};
+use crate::hir;
+use crate::hir::def_id::DefId;
+use crate::hir::intravisit::{self, Visitor, NestedVisitorMap};
 use std::fmt::{self, Display};
 use syntax_pos::Span;
 
diff --git a/src/librustc/hir/def.rs b/src/librustc/hir/def.rs
index f8f27992b3ea8..6566c6041b6e5 100644
--- a/src/librustc/hir/def.rs
+++ b/src/librustc/hir/def.rs
@@ -1,10 +1,10 @@
-use hir::def_id::DefId;
-use util::nodemap::{NodeMap, DefIdMap};
+use crate::hir::def_id::DefId;
+use crate::util::nodemap::{NodeMap, DefIdMap};
 use syntax::ast;
 use syntax::ext::base::MacroKind;
 use syntax_pos::Span;
-use hir;
-use ty;
+use crate::hir;
+use crate::ty;
 
 use self::Namespace::*;
 
diff --git a/src/librustc/hir/def_id.rs b/src/librustc/hir/def_id.rs
index 9181076740ba0..e06f09e21cbf3 100644
--- a/src/librustc/hir/def_id.rs
+++ b/src/librustc/hir/def_id.rs
@@ -1,6 +1,6 @@
-use ty;
-use ty::TyCtxt;
-use hir::map::definitions::FIRST_FREE_HIGH_DEF_INDEX;
+use crate::ty;
+use crate::ty::TyCtxt;
+use crate::hir::map::definitions::FIRST_FREE_HIGH_DEF_INDEX;
 use rustc_data_structures::indexed_vec::Idx;
 use serialize;
 use std::fmt;
diff --git a/src/librustc/hir/intravisit.rs b/src/librustc/hir/intravisit.rs
index 5f85e33fb87ee..86c3fb9e4fcd7 100644
--- a/src/librustc/hir/intravisit.rs
+++ b/src/librustc/hir/intravisit.rs
@@ -33,9 +33,9 @@
 
 use syntax::ast::{NodeId, CRATE_NODE_ID, Ident, Name, Attribute};
 use syntax_pos::Span;
-use hir::*;
-use hir::def::Def;
-use hir::map::Map;
+use crate::hir::*;
+use crate::hir::def::Def;
+use crate::hir::map::Map;
 use super::itemlikevisit::DeepVisitor;
 
 #[derive(Copy, Clone)]
diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs
index e3c913313adee..d0fd5bd6844b0 100644
--- a/src/librustc/hir/lowering.rs
+++ b/src/librustc/hir/lowering.rs
@@ -30,24 +30,24 @@
 //! get confused if the spans from leaf AST nodes occur in multiple places
 //! in the HIR, especially for multiple identifiers.
 
-use dep_graph::DepGraph;
-use errors::Applicability;
-use hir::{self, ParamName};
-use hir::HirVec;
-use hir::map::{DefKey, DefPathData, Definitions};
-use hir::def_id::{DefId, DefIndex, DefIndexAddressSpace, CRATE_DEF_INDEX};
-use hir::def::{Def, PathResolution, PerNS};
-use hir::GenericArg;
-use lint::builtin::{self, PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES,
+use crate::dep_graph::DepGraph;
+use crate::errors::Applicability;
+use crate::hir::{self, ParamName};
+use crate::hir::HirVec;
+use crate::hir::map::{DefKey, DefPathData, Definitions};
+use crate::hir::def_id::{DefId, DefIndex, DefIndexAddressSpace, CRATE_DEF_INDEX};
+use crate::hir::def::{Def, PathResolution, PerNS};
+use crate::hir::GenericArg;
+use crate::lint::builtin::{self, PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES,
                     ELIDED_LIFETIMES_IN_PATHS};
-use middle::cstore::CrateStore;
+use crate::middle::cstore::CrateStore;
 use rustc_data_structures::fx::FxHashSet;
 use rustc_data_structures::indexed_vec::IndexVec;
 use rustc_data_structures::thin_vec::ThinVec;
-use session::Session;
-use session::config::nightly_options;
-use util::common::FN_OUTPUT_NAME;
-use util::nodemap::{DefIdMap, NodeMap};
+use crate::session::Session;
+use crate::session::config::nightly_options;
+use crate::util::common::FN_OUTPUT_NAME;
+use crate::util::nodemap::{DefIdMap, NodeMap};
 
 use std::collections::{BTreeSet, BTreeMap};
 use std::fmt::Debug;
diff --git a/src/librustc/hir/map/blocks.rs b/src/librustc/hir/map/blocks.rs
index f61b8551927bb..d5fb578d8d492 100644
--- a/src/librustc/hir/map/blocks.rs
+++ b/src/librustc/hir/map/blocks.rs
@@ -11,10 +11,10 @@
 //! nested within a uniquely determined `FnLike`), and users can ask
 //! for the `Code` associated with a particular NodeId.
 
-use hir as ast;
-use hir::map;
-use hir::{Expr, FnDecl, Node};
-use hir::intravisit::FnKind;
+use crate::hir as ast;
+use crate::hir::map;
+use crate::hir::{Expr, FnDecl, Node};
+use crate::hir::intravisit::FnKind;
 use syntax::ast::{Attribute, Ident, NodeId};
 use syntax_pos::Span;
 
diff --git a/src/librustc/hir/map/collector.rs b/src/librustc/hir/map/collector.rs
index 9c4fa9e127287..f84bb77e29b27 100644
--- a/src/librustc/hir/map/collector.rs
+++ b/src/librustc/hir/map/collector.rs
@@ -1,19 +1,19 @@
 use super::*;
-use dep_graph::{DepGraph, DepKind, DepNodeIndex};
-use hir;
-use hir::def_id::{LOCAL_CRATE, CrateNum};
-use hir::intravisit::{Visitor, NestedVisitorMap};
+use crate::dep_graph::{DepGraph, DepKind, DepNodeIndex};
+use crate::hir;
+use crate::hir::def_id::{LOCAL_CRATE, CrateNum};
+use crate::hir::intravisit::{Visitor, NestedVisitorMap};
 use rustc_data_structures::svh::Svh;
-use ich::Fingerprint;
-use middle::cstore::CrateStore;
-use session::CrateDisambiguator;
-use session::Session;
+use crate::ich::Fingerprint;
+use crate::middle::cstore::CrateStore;
+use crate::session::CrateDisambiguator;
+use crate::session::Session;
 use std::iter::repeat;
 use syntax::ast::{NodeId, CRATE_NODE_ID};
 use syntax::source_map::SourceMap;
 use syntax_pos::Span;
 
-use ich::StableHashingContext;
+use crate::ich::StableHashingContext;
 use rustc_data_structures::stable_hasher::{HashStable, StableHasher, StableHasherResult};
 
 /// A Visitor that walks over the HIR and collects Nodes into a HIR map
@@ -253,7 +253,7 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
                     None => format!("{:?}", node)
                 };
 
-                let forgot_str = if hir_id == ::hir::DUMMY_HIR_ID {
+                let forgot_str = if hir_id == crate::hir::DUMMY_HIR_ID {
                     format!("\nMaybe you forgot to lower the node id {:?}?", id)
                 } else {
                     String::new()
diff --git a/src/librustc/hir/map/def_collector.rs b/src/librustc/hir/map/def_collector.rs
index c9b4b2bb99717..710170674f761 100644
--- a/src/librustc/hir/map/def_collector.rs
+++ b/src/librustc/hir/map/def_collector.rs
@@ -1,6 +1,6 @@
-use hir::map::definitions::*;
-use hir::def_id::{CRATE_DEF_INDEX, DefIndex, DefIndexAddressSpace};
-use session::CrateDisambiguator;
+use crate::hir::map::definitions::*;
+use crate::hir::def_id::{CRATE_DEF_INDEX, DefIndex, DefIndexAddressSpace};
+use crate::session::CrateDisambiguator;
 
 use syntax::ast::*;
 use syntax::ext::hygiene::Mark;
@@ -10,7 +10,7 @@ use syntax::symbol::Symbol;
 use syntax::parse::token::{self, Token};
 use syntax_pos::Span;
 
-use hir::map::{ITEM_LIKE_SPACE, REGULAR_SPACE};
+use crate::hir::map::{ITEM_LIKE_SPACE, REGULAR_SPACE};
 
 /// Creates def ids for nodes in the AST.
 pub struct DefCollector<'a> {
diff --git a/src/librustc/hir/map/definitions.rs b/src/librustc/hir/map/definitions.rs
index 4c622adefbdb1..a8193e1d34837 100644
--- a/src/librustc/hir/map/definitions.rs
+++ b/src/librustc/hir/map/definitions.rs
@@ -4,15 +4,15 @@
 //! There are also some rather random cases (like const initializer
 //! expressions) that are mostly just leftovers.
 
-use hir;
-use hir::def_id::{CrateNum, DefId, DefIndex, LOCAL_CRATE, DefIndexAddressSpace,
+use crate::hir;
+use crate::hir::def_id::{CrateNum, DefId, DefIndex, LOCAL_CRATE, DefIndexAddressSpace,
                   CRATE_DEF_INDEX};
-use ich::Fingerprint;
+use crate::ich::Fingerprint;
 use rustc_data_structures::fx::FxHashMap;
 use rustc_data_structures::indexed_vec::{IndexVec};
 use rustc_data_structures::stable_hasher::StableHasher;
 use serialize::{Encodable, Decodable, Encoder, Decoder};
-use session::CrateDisambiguator;
+use crate::session::CrateDisambiguator;
 use std::borrow::Borrow;
 use std::fmt::Write;
 use std::hash::Hash;
@@ -20,7 +20,7 @@ use syntax::ast;
 use syntax::ext::hygiene::Mark;
 use syntax::symbol::{Symbol, InternedString};
 use syntax_pos::{Span, DUMMY_SP};
-use util::nodemap::NodeMap;
+use crate::util::nodemap::NodeMap;
 
 /// The DefPathTable maps DefIndexes to DefKeys and vice versa.
 /// Internally the DefPathTable holds a tree of DefKeys, where each DefKey
diff --git a/src/librustc/hir/map/hir_id_validator.rs b/src/librustc/hir/map/hir_id_validator.rs
index 91c8c29144406..2c3ff4c9b5c05 100644
--- a/src/librustc/hir/map/hir_id_validator.rs
+++ b/src/librustc/hir/map/hir_id_validator.rs
@@ -1,7 +1,7 @@
-use hir::def_id::{DefId, DefIndex, CRATE_DEF_INDEX};
-use hir::{self, intravisit, HirId, ItemLocalId};
+use crate::hir::def_id::{DefId, DefIndex, CRATE_DEF_INDEX};
+use crate::hir::{self, intravisit, HirId, ItemLocalId};
 use syntax::ast::NodeId;
-use hir::itemlikevisit::ItemLikeVisitor;
+use crate::hir::itemlikevisit::ItemLikeVisitor;
 use rustc_data_structures::fx::FxHashMap;
 use rustc_data_structures::sync::{Lock, ParallelIterator, par_iter};
 
diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs
index 977ab05b20932..6db1ec3e99b53 100644
--- a/src/librustc/hir/map/mod.rs
+++ b/src/librustc/hir/map/mod.rs
@@ -3,11 +3,11 @@ pub use self::def_collector::{DefCollector, MacroInvocationData};
 pub use self::definitions::{Definitions, DefKey, DefPath, DefPathData,
                             DisambiguatedDefPathData, DefPathHash};
 
-use dep_graph::{DepGraph, DepNode, DepKind, DepNodeIndex};
+use crate::dep_graph::{DepGraph, DepNode, DepKind, DepNodeIndex};
 
-use hir::def_id::{CRATE_DEF_INDEX, DefId, LocalDefId, DefIndexAddressSpace};
+use crate::hir::def_id::{CRATE_DEF_INDEX, DefId, LocalDefId, DefIndexAddressSpace};
 
-use middle::cstore::CrateStoreDyn;
+use crate::middle::cstore::CrateStoreDyn;
 
 use rustc_target::spec::abi::Abi;
 use rustc_data_structures::svh::Svh;
@@ -17,15 +17,15 @@ use syntax::source_map::Spanned;
 use syntax::ext::base::MacroKind;
 use syntax_pos::{Span, DUMMY_SP};
 
-use hir::*;
-use hir::itemlikevisit::ItemLikeVisitor;
-use hir::print::Nested;
-use util::nodemap::FxHashMap;
-use util::common::time;
+use crate::hir::*;
+use crate::hir::itemlikevisit::ItemLikeVisitor;
+use crate::hir::print::Nested;
+use crate::util::nodemap::FxHashMap;
+use crate::util::common::time;
 
 use std::io;
 use std::result::Result::Err;
-use ty::TyCtxt;
+use crate::ty::TyCtxt;
 
 pub mod blocks;
 mod collector;
@@ -1152,13 +1152,13 @@ impl Named for StructField { fn name(&self) -> Name { self.ident.name } }
 impl Named for TraitItem { fn name(&self) -> Name { self.ident.name } }
 impl Named for ImplItem { fn name(&self) -> Name { self.ident.name } }
 
-pub fn map_crate<'hir>(sess: &::session::Session,
+pub fn map_crate<'hir>(sess: &crate::session::Session,
                        cstore: &CrateStoreDyn,
                        forest: &'hir Forest,
                        definitions: &'hir Definitions)
                        -> Map<'hir> {
     let ((map, crate_hash), hir_to_node_id) = join(|| {
-        let hcx = ::ich::StableHashingContext::new(sess, &forest.krate, definitions, cstore);
+        let hcx = crate::ich::StableHashingContext::new(sess, &forest.krate, definitions, cstore);
 
         let mut collector = NodeCollector::root(sess,
                                                 &forest.krate,
@@ -1269,7 +1269,7 @@ fn node_id_to_string(map: &Map<'_>, id: NodeId, include_id: bool) -> String {
     let path_str = || {
         // This functionality is used for debugging, try to use TyCtxt to get
         // the user-friendly path, otherwise fall back to stringifying DefPath.
-        ::ty::tls::with_opt(|tcx| {
+        crate::ty::tls::with_opt(|tcx| {
             if let Some(tcx) = tcx {
                 tcx.node_path_str(id)
             } else if let Some(path) = map.def_path_from_id(id) {
diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs
index 924b044da5fc3..f8fb2b88e2750 100644
--- a/src/librustc/hir/mod.rs
+++ b/src/librustc/hir/mod.rs
@@ -10,11 +10,11 @@ pub use self::PrimTy::*;
 pub use self::UnOp::*;
 pub use self::UnsafeSource::*;
 
-use errors::FatalError;
-use hir::def::Def;
-use hir::def_id::{DefId, DefIndex, LocalDefId, CRATE_DEF_INDEX};
-use util::nodemap::{NodeMap, FxHashSet};
-use mir::mono::Linkage;
+use crate::errors::FatalError;
+use crate::hir::def::Def;
+use crate::hir::def_id::{DefId, DefIndex, LocalDefId, CRATE_DEF_INDEX};
+use crate::util::nodemap::{NodeMap, FxHashSet};
+use crate::mir::mono::Linkage;
 
 use syntax_pos::{Span, DUMMY_SP, symbol::InternedString};
 use syntax::source_map::Spanned;
@@ -27,8 +27,8 @@ use syntax::ptr::P;
 use syntax::symbol::{Symbol, keywords};
 use syntax::tokenstream::TokenStream;
 use syntax::util::parser::ExprPrecedence;
-use ty::AdtKind;
-use ty::query::Providers;
+use crate::ty::AdtKind;
+use crate::ty::query::Providers;
 
 use rustc_data_structures::sync::{ParallelIterator, par_iter, Send, Sync, scope};
 use rustc_data_structures::thin_vec::ThinVec;
diff --git a/src/librustc/hir/pat_util.rs b/src/librustc/hir/pat_util.rs
index e2a03c638764d..c92cbc9b96c93 100644
--- a/src/librustc/hir/pat_util.rs
+++ b/src/librustc/hir/pat_util.rs
@@ -1,6 +1,6 @@
-use hir::def::Def;
-use hir::def_id::DefId;
-use hir::{self, HirId, PatKind};
+use crate::hir::def::Def;
+use crate::hir::def_id::DefId;
+use crate::hir::{self, HirId, PatKind};
 use syntax::ast;
 use syntax_pos::Span;
 
diff --git a/src/librustc/hir/print.rs b/src/librustc/hir/print.rs
index 89b5b7a190df6..9b6fcf259be14 100644
--- a/src/librustc/hir/print.rs
+++ b/src/librustc/hir/print.rs
@@ -11,9 +11,9 @@ use syntax::symbol::keywords;
 use syntax::util::parser::{self, AssocOp, Fixity};
 use syntax_pos::{self, BytePos, FileName};
 
-use hir;
-use hir::{PatKind, GenericBound, TraitBoundModifier, RangeEnd};
-use hir::{GenericParam, GenericParamKind, GenericArg};
+use crate::hir;
+use crate::hir::{PatKind, GenericBound, TraitBoundModifier, RangeEnd};
+use crate::hir::{GenericParam, GenericParamKind, GenericArg};
 
 use std::borrow::Cow;
 use std::cell::Cell;
@@ -2401,7 +2401,7 @@ fn stmt_ends_with_semi(stmt: &hir::StmtKind) -> bool {
 }
 
 fn bin_op_to_assoc_op(op: hir::BinOpKind) -> AssocOp {
-    use hir::BinOpKind::*;
+    use crate::hir::BinOpKind::*;
     match op {
         Add => AssocOp::Add,
         Sub => AssocOp::Subtract,
diff --git a/src/librustc/ich/hcx.rs b/src/librustc/ich/hcx.rs
index d5c9d9ff16dcb..e60fdd62debd1 100644
--- a/src/librustc/ich/hcx.rs
+++ b/src/librustc/ich/hcx.rs
@@ -1,11 +1,11 @@
-use hir;
-use hir::def_id::{DefId, DefIndex};
-use hir::map::DefPathHash;
-use hir::map::definitions::Definitions;
-use ich::{self, CachingSourceMapView, Fingerprint};
-use middle::cstore::CrateStore;
-use ty::{TyCtxt, fast_reject};
-use session::Session;
+use crate::hir;
+use crate::hir::def_id::{DefId, DefIndex};
+use crate::hir::map::DefPathHash;
+use crate::hir::map::definitions::Definitions;
+use crate::ich::{self, CachingSourceMapView, Fingerprint};
+use crate::middle::cstore::CrateStore;
+use crate::ty::{TyCtxt, fast_reject};
+use crate::session::Session;
 
 use std::cmp::Ord;
 use std::hash as std_hash;
@@ -218,7 +218,7 @@ impl<'a> StableHashingContextProvider<'a> for StableHashingContext<'a> {
     }
 }
 
-impl<'a> ::dep_graph::DepGraphSafe for StableHashingContext<'a> {
+impl<'a> crate::dep_graph::DepGraphSafe for StableHashingContext<'a> {
 }
 
 
diff --git a/src/librustc/ich/impls_cstore.rs b/src/librustc/ich/impls_cstore.rs
index fdea62a1dd8f6..17ed1a79d45e0 100644
--- a/src/librustc/ich/impls_cstore.rs
+++ b/src/librustc/ich/impls_cstore.rs
@@ -1,23 +1,21 @@
 //! This module contains `HashStable` implementations for various data types
 //! from rustc::middle::cstore in no particular order.
 
-use middle;
-
-impl_stable_hash_for!(enum middle::cstore::DepKind {
+impl_stable_hash_for!(enum crate::middle::cstore::DepKind {
     UnexportedMacrosOnly,
     MacrosOnly,
     Implicit,
     Explicit
 });
 
-impl_stable_hash_for!(enum middle::cstore::NativeLibraryKind {
+impl_stable_hash_for!(enum crate::middle::cstore::NativeLibraryKind {
     NativeStatic,
     NativeStaticNobundle,
     NativeFramework,
     NativeUnknown
 });
 
-impl_stable_hash_for!(struct middle::cstore::NativeLibrary {
+impl_stable_hash_for!(struct crate::middle::cstore::NativeLibrary {
     kind,
     name,
     cfg,
@@ -25,30 +23,30 @@ impl_stable_hash_for!(struct middle::cstore::NativeLibrary {
     wasm_import_module
 });
 
-impl_stable_hash_for!(struct middle::cstore::ForeignModule {
+impl_stable_hash_for!(struct crate::middle::cstore::ForeignModule {
     foreign_items,
     def_id
 });
 
-impl_stable_hash_for!(enum middle::cstore::LinkagePreference {
+impl_stable_hash_for!(enum crate::middle::cstore::LinkagePreference {
     RequireDynamic,
     RequireStatic
 });
 
-impl_stable_hash_for!(struct middle::cstore::ExternCrate {
+impl_stable_hash_for!(struct crate::middle::cstore::ExternCrate {
     src,
     span,
     path_len,
     direct
 });
 
-impl_stable_hash_for!(enum middle::cstore::ExternCrateSource {
+impl_stable_hash_for!(enum crate::middle::cstore::ExternCrateSource {
     Extern(def_id),
     Use,
     Path,
 });
 
-impl_stable_hash_for!(struct middle::cstore::CrateSource {
+impl_stable_hash_for!(struct crate::middle::cstore::CrateSource {
     dylib,
     rlib,
     rmeta
diff --git a/src/librustc/ich/impls_hir.rs b/src/librustc/ich/impls_hir.rs
index 1061ea752af11..2b359428b1fa1 100644
--- a/src/librustc/ich/impls_hir.rs
+++ b/src/librustc/ich/impls_hir.rs
@@ -1,10 +1,10 @@
 //! This module contains `HashStable` implementations for various HIR data
 //! types in no particular order.
 
-use hir;
-use hir::map::DefPathHash;
-use hir::def_id::{DefId, LocalDefId, CrateNum, CRATE_DEF_INDEX};
-use ich::{StableHashingContext, NodeIdHashingMode, Fingerprint};
+use crate::hir;
+use crate::hir::map::DefPathHash;
+use crate::hir::def_id::{DefId, LocalDefId, CrateNum, CRATE_DEF_INDEX};
+use crate::ich::{StableHashingContext, NodeIdHashingMode, Fingerprint};
 use rustc_data_structures::stable_hasher::{HashStable, ToStableHashKey,
                                            StableHasher, StableHasherResult};
 use std::mem;
@@ -619,7 +619,7 @@ impl<'a> HashStable<StableHashingContext<'a>> for hir::MatchSource {
     fn hash_stable<W: StableHasherResult>(&self,
                                           hcx: &mut StableHashingContext<'a>,
                                           hasher: &mut StableHasher<W>) {
-        use hir::MatchSource;
+        use crate::hir::MatchSource;
 
         mem::discriminant(self).hash_stable(hcx, hasher);
         match *self {
@@ -1116,12 +1116,12 @@ impl_stable_hash_for!(struct hir::def::Export {
     span
 });
 
-impl_stable_hash_for!(struct ::middle::lib_features::LibFeatures {
+impl_stable_hash_for!(struct crate::middle::lib_features::LibFeatures {
     stable,
     unstable
 });
 
-impl<'a> HashStable<StableHashingContext<'a>> for ::middle::lang_items::LangItem {
+impl<'a> HashStable<StableHashingContext<'a>> for crate::middle::lang_items::LangItem {
     fn hash_stable<W: StableHasherResult>(&self,
                                           _: &mut StableHashingContext<'a>,
                                           hasher: &mut StableHasher<W>) {
@@ -1129,7 +1129,7 @@ impl<'a> HashStable<StableHashingContext<'a>> for ::middle::lang_items::LangItem
     }
 }
 
-impl_stable_hash_for!(struct ::middle::lang_items::LanguageItems {
+impl_stable_hash_for!(struct crate::middle::lang_items::LanguageItems {
     items,
     missing
 });
diff --git a/src/librustc/ich/impls_mir.rs b/src/librustc/ich/impls_mir.rs
index 002ac7cc7a9bb..51fc78ffc8669 100644
--- a/src/librustc/ich/impls_mir.rs
+++ b/src/librustc/ich/impls_mir.rs
@@ -1,8 +1,8 @@
 //! This module contains `HashStable` implementations for various MIR data
 //! types in no particular order.
 
-use ich::StableHashingContext;
-use mir;
+use crate::ich::StableHashingContext;
+use crate::mir;
 use rustc_data_structures::stable_hasher::{HashStable, StableHasher,
                                            StableHasherResult};
 use std::mem;
diff --git a/src/librustc/ich/impls_misc.rs b/src/librustc/ich/impls_misc.rs
index f79adc8109a7f..8a388fafce5e8 100644
--- a/src/librustc/ich/impls_misc.rs
+++ b/src/librustc/ich/impls_misc.rs
@@ -1,7 +1,7 @@
 //! This module contains `HashStable` implementations for various data types
 //! that don't fit into any of the other impls_xxx modules.
 
-impl_stable_hash_for!(enum ::session::search_paths::PathKind {
+impl_stable_hash_for!(enum crate::session::search_paths::PathKind {
     Native,
     Crate,
     Dependency,
diff --git a/src/librustc/ich/impls_syntax.rs b/src/librustc/ich/impls_syntax.rs
index e10359636f749..f34423ccca655 100644
--- a/src/librustc/ich/impls_syntax.rs
+++ b/src/librustc/ich/impls_syntax.rs
@@ -1,7 +1,7 @@
 //! This module contains `HashStable` implementations for various data types
 //! from libsyntax in no particular order.
 
-use ich::StableHashingContext;
+use crate::ich::StableHashingContext;
 
 use std::hash as std_hash;
 use std::mem;
@@ -13,7 +13,7 @@ use syntax::symbol::{InternedString, LocalInternedString};
 use syntax::tokenstream;
 use syntax_pos::SourceFile;
 
-use hir::def_id::{DefId, CrateNum, CRATE_DEF_INDEX};
+use crate::hir::def_id::{DefId, CrateNum, CRATE_DEF_INDEX};
 
 use smallvec::SmallVec;
 use rustc_data_structures::stable_hasher::{HashStable, ToStableHashKey,
diff --git a/src/librustc/ich/impls_ty.rs b/src/librustc/ich/impls_ty.rs
index bd2349161f74a..1e1dbd0b621ec 100644
--- a/src/librustc/ich/impls_ty.rs
+++ b/src/librustc/ich/impls_ty.rs
@@ -1,18 +1,18 @@
 //! This module contains `HashStable` implementations for various data types
 //! from rustc::ty in no particular order.
 
-use ich::{Fingerprint, StableHashingContext, NodeIdHashingMode};
+use crate::ich::{Fingerprint, StableHashingContext, NodeIdHashingMode};
 use rustc_data_structures::fx::FxHashMap;
 use rustc_data_structures::stable_hasher::{HashStable, ToStableHashKey,
                                            StableHasher, StableHasherResult};
 use std::cell::RefCell;
 use std::hash as std_hash;
 use std::mem;
-use middle::region;
-use infer;
-use traits;
-use ty;
-use mir;
+use crate::middle::region;
+use crate::infer;
+use crate::traits;
+use crate::ty;
+use crate::mir;
 
 impl<'a, 'gcx, T> HashStable<StableHashingContext<'a>>
 for &'gcx ty::List<T>
@@ -306,7 +306,7 @@ impl_stable_hash_for!(
         ByRef(id, alloc, offset),
     }
 );
-impl_stable_hash_for!(struct ::mir::interpret::RawConst<'tcx> {
+impl_stable_hash_for!(struct crate::mir::interpret::RawConst<'tcx> {
     alloc_id,
     ty,
 });
@@ -512,20 +512,22 @@ impl_stable_hash_for!(enum ty::GenericParamDefKind {
 });
 
 impl_stable_hash_for!(
-    impl<T> for enum ::middle::resolve_lifetime::Set1<T> [ ::middle::resolve_lifetime::Set1 ] {
+    impl<T> for enum crate::middle::resolve_lifetime::Set1<T>
+        [ crate::middle::resolve_lifetime::Set1 ]
+    {
         Empty,
         Many,
         One(value),
     }
 );
 
-impl_stable_hash_for!(enum ::middle::resolve_lifetime::LifetimeDefOrigin {
+impl_stable_hash_for!(enum crate::middle::resolve_lifetime::LifetimeDefOrigin {
     ExplicitOrElided,
     InBand,
     Error,
 });
 
-impl_stable_hash_for!(enum ::middle::resolve_lifetime::Region {
+impl_stable_hash_for!(enum crate::middle::resolve_lifetime::Region {
     Static,
     EarlyBound(index, decl, is_in_band),
     LateBound(db_index, decl, is_in_band),
@@ -547,9 +549,9 @@ impl_stable_hash_for!(enum ty::cast::CastKind {
     FnPtrAddrCast
 });
 
-impl_stable_hash_for!(struct ::middle::region::Scope { id, data });
+impl_stable_hash_for!(struct crate::middle::region::Scope { id, data });
 
-impl_stable_hash_for!(enum ::middle::region::ScopeData {
+impl_stable_hash_for!(enum crate::middle::region::ScopeData {
     Node,
     CallSite,
     Arguments,
@@ -588,7 +590,7 @@ for ty::TyKind<'gcx>
     fn hash_stable<W: StableHasherResult>(&self,
                                           hcx: &mut StableHashingContext<'a>,
                                           hasher: &mut StableHasher<W>) {
-        use ty::TyKind::*;
+        use crate::ty::TyKind::*;
 
         mem::discriminant(self).hash_stable(hcx, hasher);
         match *self {
@@ -882,7 +884,7 @@ impl_stable_hash_for!(enum traits::Reveal {
     All
 });
 
-impl_stable_hash_for!(enum ::middle::privacy::AccessLevel {
+impl_stable_hash_for!(enum crate::middle::privacy::AccessLevel {
     ReachableFromImplTrait,
     Reachable,
     Exported,
@@ -890,12 +892,12 @@ impl_stable_hash_for!(enum ::middle::privacy::AccessLevel {
 });
 
 impl<'a> HashStable<StableHashingContext<'a>>
-for ::middle::privacy::AccessLevels {
+for crate::middle::privacy::AccessLevels {
     fn hash_stable<W: StableHasherResult>(&self,
                                           hcx: &mut StableHashingContext<'a>,
                                           hasher: &mut StableHasher<W>) {
         hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
-            let ::middle::privacy::AccessLevels {
+            let crate::middle::privacy::AccessLevels {
                 ref map
             } = *self;
 
@@ -908,14 +910,14 @@ impl_stable_hash_for!(struct ty::CrateInherentImpls {
     inherent_impls
 });
 
-impl_stable_hash_for!(enum ::session::CompileIncomplete {
+impl_stable_hash_for!(enum crate::session::CompileIncomplete {
     Stopped,
     Errored(error_reported)
 });
 
-impl_stable_hash_for!(struct ::util::common::ErrorReported {});
+impl_stable_hash_for!(struct crate::util::common::ErrorReported {});
 
-impl_stable_hash_for!(tuple_struct ::middle::reachable::ReachableSet {
+impl_stable_hash_for!(tuple_struct crate::middle::reachable::ReachableSet {
     reachable_set
 });
 
@@ -924,7 +926,7 @@ for traits::Vtable<'gcx, N> where N: HashStable<StableHashingContext<'a>> {
     fn hash_stable<W: StableHasherResult>(&self,
                                           hcx: &mut StableHashingContext<'a>,
                                           hasher: &mut StableHasher<W>) {
-        use traits::Vtable::*;
+        use crate::traits::Vtable::*;
 
         mem::discriminant(self).hash_stable(hcx, hasher);
 
@@ -1105,7 +1107,7 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for traits::WhereClause<'tcx
     fn hash_stable<W: StableHasherResult>(&self,
                                           hcx: &mut StableHashingContext<'a>,
                                           hasher: &mut StableHasher<W>) {
-        use traits::WhereClause::*;
+        use crate::traits::WhereClause::*;
 
         mem::discriminant(self).hash_stable(hcx, hasher);
         match self {
@@ -1121,7 +1123,7 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for traits::WellFormed<'tcx>
     fn hash_stable<W: StableHasherResult>(&self,
                                           hcx: &mut StableHashingContext<'a>,
                                           hasher: &mut StableHasher<W>) {
-        use traits::WellFormed::*;
+        use crate::traits::WellFormed::*;
 
         mem::discriminant(self).hash_stable(hcx, hasher);
         match self {
@@ -1135,7 +1137,7 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for traits::FromEnv<'tcx> {
     fn hash_stable<W: StableHasherResult>(&self,
                                           hcx: &mut StableHashingContext<'a>,
                                           hasher: &mut StableHasher<W>) {
-        use traits::FromEnv::*;
+        use crate::traits::FromEnv::*;
 
         mem::discriminant(self).hash_stable(hcx, hasher);
         match self {
@@ -1149,7 +1151,7 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for traits::DomainGoal<'tcx>
     fn hash_stable<W: StableHasherResult>(&self,
                                           hcx: &mut StableHashingContext<'a>,
                                           hasher: &mut StableHasher<W>) {
-        use traits::DomainGoal::*;
+        use crate::traits::DomainGoal::*;
 
         mem::discriminant(self).hash_stable(hcx, hasher);
         match self {
@@ -1165,7 +1167,7 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for traits::Goal<'tcx> {
     fn hash_stable<W: StableHasherResult>(&self,
                                           hcx: &mut StableHashingContext<'a>,
                                           hasher: &mut StableHasher<W>) {
-        use traits::GoalKind::*;
+        use crate::traits::GoalKind::*;
 
         mem::discriminant(self).hash_stable(hcx, hasher);
         match self {
@@ -1208,7 +1210,7 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for traits::Clause<'tcx> {
     fn hash_stable<W: StableHasherResult>(&self,
                                           hcx: &mut StableHashingContext<'a>,
                                           hasher: &mut StableHasher<W>) {
-        use traits::Clause::*;
+        use crate::traits::Clause::*;
 
         mem::discriminant(self).hash_stable(hcx, hasher);
         match self {
diff --git a/src/librustc/infer/at.rs b/src/librustc/infer/at.rs
index 328d518ca66aa..7b2b1184a6336 100644
--- a/src/librustc/infer/at.rs
+++ b/src/librustc/infer/at.rs
@@ -27,7 +27,7 @@
 
 use super::*;
 
-use ty::relate::{Relate, TypeRelation};
+use crate::ty::relate::{Relate, TypeRelation};
 
 pub struct At<'a, 'gcx: 'tcx, 'tcx: 'a> {
     pub infcx: &'a InferCtxt<'a, 'gcx, 'tcx>,
diff --git a/src/librustc/infer/canonical/canonicalizer.rs b/src/librustc/infer/canonical/canonicalizer.rs
index 408cba42ae04b..4e1c797a2c72a 100644
--- a/src/librustc/infer/canonical/canonicalizer.rs
+++ b/src/librustc/infer/canonical/canonicalizer.rs
@@ -5,15 +5,15 @@
 //!
 //! [c]: https://rust-lang.github.io/rustc-guide/traits/canonicalization.html
 
-use infer::canonical::{
+use crate::infer::canonical::{
     Canonical, CanonicalTyVarKind, CanonicalVarInfo, CanonicalVarKind, Canonicalized,
     OriginalQueryValues,
 };
-use infer::InferCtxt;
+use crate::infer::InferCtxt;
 use std::sync::atomic::Ordering;
-use ty::fold::{TypeFoldable, TypeFolder};
-use ty::subst::Kind;
-use ty::{self, BoundVar, Lift, List, Ty, TyCtxt, TypeFlags};
+use crate::ty::fold::{TypeFoldable, TypeFolder};
+use crate::ty::subst::Kind;
+use crate::ty::{self, BoundVar, Lift, List, Ty, TyCtxt, TypeFlags};
 
 use rustc_data_structures::fx::FxHashMap;
 use rustc_data_structures::indexed_vec::Idx;
diff --git a/src/librustc/infer/canonical/mod.rs b/src/librustc/infer/canonical/mod.rs
index eaf72f5a68710..6f28c0b131f61 100644
--- a/src/librustc/infer/canonical/mod.rs
+++ b/src/librustc/infer/canonical/mod.rs
@@ -21,16 +21,16 @@
 //!
 //! [c]: https://rust-lang.github.io/rustc-guide/traits/canonicalization.html
 
-use infer::{InferCtxt, RegionVariableOrigin, TypeVariableOrigin};
+use crate::infer::{InferCtxt, RegionVariableOrigin, TypeVariableOrigin};
 use rustc_data_structures::indexed_vec::IndexVec;
 use rustc_data_structures::sync::Lrc;
 use serialize::UseSpecializedDecodable;
 use smallvec::SmallVec;
 use std::ops::Index;
 use syntax::source_map::Span;
-use ty::fold::TypeFoldable;
-use ty::subst::Kind;
-use ty::{self, BoundVar, Lift, List, Region, TyCtxt};
+use crate::ty::fold::TypeFoldable;
+use crate::ty::subst::Kind;
+use crate::ty::{self, BoundVar, Lift, List, Region, TyCtxt};
 
 mod canonicalizer;
 
@@ -393,14 +393,14 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
 }
 
 CloneTypeFoldableAndLiftImpls! {
-    ::infer::canonical::Certainty,
-    ::infer::canonical::CanonicalVarInfo,
-    ::infer::canonical::CanonicalVarKind,
+    crate::infer::canonical::Certainty,
+    crate::infer::canonical::CanonicalVarInfo,
+    crate::infer::canonical::CanonicalVarKind,
 }
 
 CloneTypeFoldableImpls! {
     for <'tcx> {
-        ::infer::canonical::CanonicalVarInfos<'tcx>,
+        crate::infer::canonical::CanonicalVarInfos<'tcx>,
     }
 }
 
@@ -431,7 +431,7 @@ impl<'tcx> CanonicalVarValues<'tcx> {
     /// we'll return a substitution `subst` with:
     /// `subst.var_values == [Type(^0), Lifetime(^1), Type(^2)]`.
     pub fn make_identity<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Self {
-        use ty::subst::UnpackedKind;
+        use crate::ty::subst::UnpackedKind;
 
         CanonicalVarValues {
             var_values: self.var_values.iter()
diff --git a/src/librustc/infer/canonical/query_response.rs b/src/librustc/infer/canonical/query_response.rs
index 7f113f07276d8..409afca43203d 100644
--- a/src/librustc/infer/canonical/query_response.rs
+++ b/src/librustc/infer/canonical/query_response.rs
@@ -7,26 +7,26 @@
 //!
 //! [c]: https://rust-lang.github.io/rustc-guide/traits/canonicalization.html
 
-use infer::canonical::substitute::substitute_value;
-use infer::canonical::{
+use crate::infer::canonical::substitute::substitute_value;
+use crate::infer::canonical::{
     Canonical, CanonicalVarValues, CanonicalizedQueryResponse, Certainty,
     OriginalQueryValues, QueryRegionConstraint, QueryResponse,
 };
-use infer::region_constraints::{Constraint, RegionConstraintData};
-use infer::InferCtxtBuilder;
-use infer::{InferCtxt, InferOk, InferResult};
+use crate::infer::region_constraints::{Constraint, RegionConstraintData};
+use crate::infer::InferCtxtBuilder;
+use crate::infer::{InferCtxt, InferOk, InferResult};
 use rustc_data_structures::indexed_vec::Idx;
 use rustc_data_structures::indexed_vec::IndexVec;
 use rustc_data_structures::sync::Lrc;
 use std::fmt::Debug;
 use syntax_pos::DUMMY_SP;
-use traits::query::{Fallible, NoSolution};
-use traits::TraitEngine;
-use traits::{Obligation, ObligationCause, PredicateObligation};
-use ty::fold::TypeFoldable;
-use ty::subst::{Kind, UnpackedKind};
-use ty::{self, BoundVar, Lift, Ty, TyCtxt};
-use util::captures::Captures;
+use crate::traits::query::{Fallible, NoSolution};
+use crate::traits::TraitEngine;
+use crate::traits::{Obligation, ObligationCause, PredicateObligation};
+use crate::ty::fold::TypeFoldable;
+use crate::ty::subst::{Kind, UnpackedKind};
+use crate::ty::{self, BoundVar, Lift, Ty, TyCtxt};
+use crate::util::captures::Captures;
 
 impl<'cx, 'gcx, 'tcx> InferCtxtBuilder<'cx, 'gcx, 'tcx> {
     /// The "main method" for a canonicalized trait query. Given the
diff --git a/src/librustc/infer/canonical/substitute.rs b/src/librustc/infer/canonical/substitute.rs
index d3ed00481dcee..5af4e8366818b 100644
--- a/src/librustc/infer/canonical/substitute.rs
+++ b/src/librustc/infer/canonical/substitute.rs
@@ -6,10 +6,10 @@
 //!
 //! [c]: https://rust-lang.github.io/rustc-guide/traits/canonicalization.html
 
-use infer::canonical::{Canonical, CanonicalVarValues};
-use ty::fold::TypeFoldable;
-use ty::subst::UnpackedKind;
-use ty::{self, TyCtxt};
+use crate::infer::canonical::{Canonical, CanonicalVarValues};
+use crate::ty::fold::TypeFoldable;
+use crate::ty::subst::UnpackedKind;
+use crate::ty::{self, TyCtxt};
 
 impl<'tcx, V> Canonical<'tcx, V> {
     /// Instantiate the wrapped value, replacing each canonical value
diff --git a/src/librustc/infer/combine.rs b/src/librustc/infer/combine.rs
index 40c11695d51e2..7e22521473491 100644
--- a/src/librustc/infer/combine.rs
+++ b/src/librustc/infer/combine.rs
@@ -29,13 +29,13 @@ use super::lub::Lub;
 use super::sub::Sub;
 use super::type_variable::TypeVariableValue;
 
-use hir::def_id::DefId;
-use ty::{IntType, UintType};
-use ty::{self, Ty, TyCtxt};
-use ty::error::TypeError;
-use ty::relate::{self, Relate, RelateResult, TypeRelation};
-use ty::subst::Substs;
-use traits::{Obligation, PredicateObligations};
+use crate::hir::def_id::DefId;
+use crate::ty::{IntType, UintType};
+use crate::ty::{self, Ty, TyCtxt};
+use crate::ty::error::TypeError;
+use crate::ty::relate::{self, Relate, RelateResult, TypeRelation};
+use crate::ty::subst::Substs;
+use crate::traits::{Obligation, PredicateObligations};
 
 use syntax::ast;
 use syntax_pos::Span;
diff --git a/src/librustc/infer/equate.rs b/src/librustc/infer/equate.rs
index 60a7eb0d54f8b..a4b62307a60b8 100644
--- a/src/librustc/infer/equate.rs
+++ b/src/librustc/infer/equate.rs
@@ -1,12 +1,12 @@
 use super::combine::{CombineFields, RelationDir};
 use super::{Subtype};
 
-use hir::def_id::DefId;
+use crate::hir::def_id::DefId;
 
-use ty::{self, Ty, TyCtxt};
-use ty::TyVar;
-use ty::subst::Substs;
-use ty::relate::{self, Relate, RelateResult, TypeRelation};
+use crate::ty::{self, Ty, TyCtxt};
+use crate::ty::TyVar;
+use crate::ty::subst::Substs;
+use crate::ty::relate::{self, Relate, RelateResult, TypeRelation};
 
 /// Ensures `a` is made equal to `b`. Returns `a` on success.
 pub struct Equate<'combine, 'infcx: 'combine, 'gcx: 'infcx+'tcx, 'tcx: 'infcx> {
diff --git a/src/librustc/infer/error_reporting/mod.rs b/src/librustc/infer/error_reporting/mod.rs
index 66e4cd49c807f..8510533391287 100644
--- a/src/librustc/infer/error_reporting/mod.rs
+++ b/src/librustc/infer/error_reporting/mod.rs
@@ -48,19 +48,19 @@
 use super::lexical_region_resolve::RegionResolutionError;
 use super::region_constraints::GenericKind;
 use super::{InferCtxt, RegionVariableOrigin, SubregionOrigin, TypeTrace, ValuePairs};
-use infer::{self, SuppressRegionErrors};
+use crate::infer::{self, SuppressRegionErrors};
 
-use errors::{Applicability, DiagnosticBuilder, DiagnosticStyledString};
-use hir;
-use hir::def_id::DefId;
-use hir::Node;
-use middle::region;
+use crate::errors::{Applicability, DiagnosticBuilder, DiagnosticStyledString};
+use crate::hir;
+use crate::hir::def_id::DefId;
+use crate::hir::Node;
+use crate::middle::region;
 use std::{cmp, fmt};
 use syntax::ast::DUMMY_NODE_ID;
 use syntax_pos::{Pos, Span};
-use traits::{ObligationCause, ObligationCauseCode};
-use ty::error::TypeError;
-use ty::{self, subst::Subst, Region, Ty, TyCtxt, TyKind, TypeFoldable};
+use crate::traits::{ObligationCause, ObligationCauseCode};
+use crate::ty::error::TypeError;
+use crate::ty::{self, subst::Subst, Region, Ty, TyCtxt, TyKind, TypeFoldable};
 
 mod note;
 
@@ -1479,7 +1479,7 @@ enum FailureCode {
 impl<'tcx> ObligationCause<'tcx> {
     fn as_failure_code(&self, terr: &TypeError<'tcx>) -> FailureCode {
         use self::FailureCode::*;
-        use traits::ObligationCauseCode::*;
+        use crate::traits::ObligationCauseCode::*;
         match self.code {
             CompareImplMethodObligation { .. } => Error0308("method not compatible with trait"),
             MatchExpressionArm { source, .. } => Error0308(match source {
@@ -1509,7 +1509,7 @@ impl<'tcx> ObligationCause<'tcx> {
     }
 
     fn as_requirement_str(&self) -> &'static str {
-        use traits::ObligationCauseCode::*;
+        use crate::traits::ObligationCauseCode::*;
         match self.code {
             CompareImplMethodObligation { .. } => "method type is compatible with trait",
             ExprAssignable => "expression is assignable",
diff --git a/src/librustc/infer/error_reporting/need_type_info.rs b/src/librustc/infer/error_reporting/need_type_info.rs
index 8ee367c87c3ea..fac498bd6dd78 100644
--- a/src/librustc/infer/error_reporting/need_type_info.rs
+++ b/src/librustc/infer/error_reporting/need_type_info.rs
@@ -1,11 +1,11 @@
-use hir::{self, Local, Pat, Body, HirId};
-use hir::intravisit::{self, Visitor, NestedVisitorMap};
-use infer::InferCtxt;
-use infer::type_variable::TypeVariableOrigin;
-use ty::{self, Ty, Infer, TyVar};
+use crate::hir::{self, Local, Pat, Body, HirId};
+use crate::hir::intravisit::{self, Visitor, NestedVisitorMap};
+use crate::infer::InferCtxt;
+use crate::infer::type_variable::TypeVariableOrigin;
+use crate::ty::{self, Ty, Infer, TyVar};
 use syntax::source_map::CompilerDesugaringKind;
 use syntax_pos::Span;
-use errors::DiagnosticBuilder;
+use crate::errors::DiagnosticBuilder;
 
 struct FindLocalByTypeVisitor<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> {
     infcx: &'a InferCtxt<'a, 'gcx, 'tcx>,
diff --git a/src/librustc/infer/error_reporting/nice_region_error/different_lifetimes.rs b/src/librustc/infer/error_reporting/nice_region_error/different_lifetimes.rs
index 8be49b2792441..0f4401517792c 100644
--- a/src/librustc/infer/error_reporting/nice_region_error/different_lifetimes.rs
+++ b/src/librustc/infer/error_reporting/nice_region_error/different_lifetimes.rs
@@ -1,9 +1,9 @@
 //! Error Reporting for Anonymous Region Lifetime Errors
 //! where both the regions are anonymous.
 
-use infer::error_reporting::nice_region_error::NiceRegionError;
-use infer::error_reporting::nice_region_error::util::AnonymousArgInfo;
-use util::common::ErrorReported;
+use crate::infer::error_reporting::nice_region_error::NiceRegionError;
+use crate::infer::error_reporting::nice_region_error::util::AnonymousArgInfo;
+use crate::util::common::ErrorReported;
 
 impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
     /// Print the error message for lifetime errors when both the concerned regions are anonymous.
diff --git a/src/librustc/infer/error_reporting/nice_region_error/find_anon_type.rs b/src/librustc/infer/error_reporting/nice_region_error/find_anon_type.rs
index ebaef4977f400..ea748874fc4e2 100644
--- a/src/librustc/infer/error_reporting/nice_region_error/find_anon_type.rs
+++ b/src/librustc/infer/error_reporting/nice_region_error/find_anon_type.rs
@@ -1,9 +1,9 @@
-use hir;
-use ty::{self, Region, TyCtxt};
-use hir::Node;
-use middle::resolve_lifetime as rl;
-use hir::intravisit::{self, NestedVisitorMap, Visitor};
-use infer::error_reporting::nice_region_error::NiceRegionError;
+use crate::hir;
+use crate::ty::{self, Region, TyCtxt};
+use crate::hir::Node;
+use crate::middle::resolve_lifetime as rl;
+use crate::hir::intravisit::{self, NestedVisitorMap, Visitor};
+use crate::infer::error_reporting::nice_region_error::NiceRegionError;
 
 impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
     /// This function calls the `visit_ty` method for the parameters
diff --git a/src/librustc/infer/error_reporting/nice_region_error/mod.rs b/src/librustc/infer/error_reporting/nice_region_error/mod.rs
index d34b71c33f4b4..dad1e3ba80da3 100644
--- a/src/librustc/infer/error_reporting/nice_region_error/mod.rs
+++ b/src/librustc/infer/error_reporting/nice_region_error/mod.rs
@@ -1,9 +1,9 @@
-use infer::InferCtxt;
-use infer::lexical_region_resolve::RegionResolutionError;
-use infer::lexical_region_resolve::RegionResolutionError::*;
+use crate::infer::InferCtxt;
+use crate::infer::lexical_region_resolve::RegionResolutionError;
+use crate::infer::lexical_region_resolve::RegionResolutionError::*;
 use syntax::source_map::Span;
-use ty::{self, TyCtxt};
-use util::common::ErrorReported;
+use crate::ty::{self, TyCtxt};
+use crate::util::common::ErrorReported;
 
 mod different_lifetimes;
 mod find_anon_type;
diff --git a/src/librustc/infer/error_reporting/nice_region_error/named_anon_conflict.rs b/src/librustc/infer/error_reporting/nice_region_error/named_anon_conflict.rs
index 05333f4337336..d66bb274b34ce 100644
--- a/src/librustc/infer/error_reporting/nice_region_error/named_anon_conflict.rs
+++ b/src/librustc/infer/error_reporting/nice_region_error/named_anon_conflict.rs
@@ -1,9 +1,9 @@
 //! Error Reporting for Anonymous Region Lifetime Errors
 //! where one region is named and the other is anonymous.
-use infer::error_reporting::nice_region_error::NiceRegionError;
-use ty;
-use util::common::ErrorReported;
-use errors::Applicability;
+use crate::infer::error_reporting::nice_region_error::NiceRegionError;
+use crate::ty;
+use crate::util::common::ErrorReported;
+use crate::errors::Applicability;
 
 impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
     /// When given a `ConcreteFailure` for a function with arguments containing a named region and
diff --git a/src/librustc/infer/error_reporting/nice_region_error/outlives_closure.rs b/src/librustc/infer/error_reporting/nice_region_error/outlives_closure.rs
index cbd36a8b2db8a..6432780de0670 100644
--- a/src/librustc/infer/error_reporting/nice_region_error/outlives_closure.rs
+++ b/src/librustc/infer/error_reporting/nice_region_error/outlives_closure.rs
@@ -1,13 +1,13 @@
 //! Error Reporting for Anonymous Region Lifetime Errors
 //! where both the regions are anonymous.
 
-use infer::error_reporting::nice_region_error::NiceRegionError;
-use infer::SubregionOrigin;
-use ty::RegionKind;
-use hir::{Expr, ExprKind::Closure};
-use hir::Node;
-use util::common::ErrorReported;
-use infer::lexical_region_resolve::RegionResolutionError::SubSupConflict;
+use crate::infer::error_reporting::nice_region_error::NiceRegionError;
+use crate::infer::SubregionOrigin;
+use crate::ty::RegionKind;
+use crate::hir::{Expr, ExprKind::Closure};
+use crate::hir::Node;
+use crate::util::common::ErrorReported;
+use crate::infer::lexical_region_resolve::RegionResolutionError::SubSupConflict;
 
 impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
     /// Print the error message for lifetime errors when binding escapes a closure.
diff --git a/src/librustc/infer/error_reporting/nice_region_error/placeholder_error.rs b/src/librustc/infer/error_reporting/nice_region_error/placeholder_error.rs
index ebac5a0c2a69e..6893a1fb168b8 100644
--- a/src/librustc/infer/error_reporting/nice_region_error/placeholder_error.rs
+++ b/src/librustc/infer/error_reporting/nice_region_error/placeholder_error.rs
@@ -1,15 +1,15 @@
-use errors::DiagnosticBuilder;
-use hir::def_id::DefId;
-use infer::error_reporting::nice_region_error::NiceRegionError;
-use infer::lexical_region_resolve::RegionResolutionError;
-use infer::ValuePairs;
-use infer::{SubregionOrigin, TypeTrace};
-use traits::{ObligationCause, ObligationCauseCode};
-use ty;
-use ty::error::ExpectedFound;
-use ty::subst::Substs;
-use util::common::ErrorReported;
-use util::ppaux::RegionHighlightMode;
+use crate::errors::DiagnosticBuilder;
+use crate::hir::def_id::DefId;
+use crate::infer::error_reporting::nice_region_error::NiceRegionError;
+use crate::infer::lexical_region_resolve::RegionResolutionError;
+use crate::infer::ValuePairs;
+use crate::infer::{SubregionOrigin, TypeTrace};
+use crate::traits::{ObligationCause, ObligationCauseCode};
+use crate::ty;
+use crate::ty::error::ExpectedFound;
+use crate::ty::subst::Substs;
+use crate::util::common::ErrorReported;
+use crate::util::ppaux::RegionHighlightMode;
 
 impl NiceRegionError<'me, 'gcx, 'tcx> {
     /// When given a `ConcreteFailure` for a function with arguments containing a named region and
diff --git a/src/librustc/infer/error_reporting/nice_region_error/static_impl_trait.rs b/src/librustc/infer/error_reporting/nice_region_error/static_impl_trait.rs
index 4331518d403dd..3f0297952278a 100644
--- a/src/librustc/infer/error_reporting/nice_region_error/static_impl_trait.rs
+++ b/src/librustc/infer/error_reporting/nice_region_error/static_impl_trait.rs
@@ -1,10 +1,10 @@
 //! Error Reporting for static impl Traits.
 
-use infer::error_reporting::nice_region_error::NiceRegionError;
-use infer::lexical_region_resolve::RegionResolutionError;
-use ty::{BoundRegion, FreeRegion, RegionKind};
-use util::common::ErrorReported;
-use errors::Applicability;
+use crate::infer::error_reporting::nice_region_error::NiceRegionError;
+use crate::infer::lexical_region_resolve::RegionResolutionError;
+use crate::ty::{BoundRegion, FreeRegion, RegionKind};
+use crate::util::common::ErrorReported;
+use crate::errors::Applicability;
 
 impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
     /// Print the error message for lifetime errors when the return type is a static impl Trait.
diff --git a/src/librustc/infer/error_reporting/nice_region_error/util.rs b/src/librustc/infer/error_reporting/nice_region_error/util.rs
index dd8a33829eb53..f73f8d8bb82be 100644
--- a/src/librustc/infer/error_reporting/nice_region_error/util.rs
+++ b/src/librustc/infer/error_reporting/nice_region_error/util.rs
@@ -1,10 +1,10 @@
 //! Helper functions corresponding to lifetime errors due to
 //! anonymous regions.
 
-use hir;
-use infer::error_reporting::nice_region_error::NiceRegionError;
-use ty::{self, Region, Ty};
-use hir::def_id::DefId;
+use crate::hir;
+use crate::infer::error_reporting::nice_region_error::NiceRegionError;
+use crate::ty::{self, Region, Ty};
+use crate::hir::def_id::DefId;
 use syntax_pos::Span;
 
 // The struct contains the information about the anonymous region
diff --git a/src/librustc/infer/error_reporting/note.rs b/src/librustc/infer/error_reporting/note.rs
index e45a4b17cdd9c..efd7f3c55e900 100644
--- a/src/librustc/infer/error_reporting/note.rs
+++ b/src/librustc/infer/error_reporting/note.rs
@@ -1,8 +1,8 @@
-use infer::{self, InferCtxt, SubregionOrigin};
-use middle::region;
-use ty::{self, Region};
-use ty::error::TypeError;
-use errors::DiagnosticBuilder;
+use crate::infer::{self, InferCtxt, SubregionOrigin};
+use crate::middle::region;
+use crate::ty::{self, Region};
+use crate::ty::error::TypeError;
+use crate::errors::DiagnosticBuilder;
 
 impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
     pub(super) fn note_region_origin(&self,
diff --git a/src/librustc/infer/freshen.rs b/src/librustc/infer/freshen.rs
index 74abcf82529cb..201717b34ee41 100644
--- a/src/librustc/infer/freshen.rs
+++ b/src/librustc/infer/freshen.rs
@@ -31,9 +31,9 @@
 //! variable only once, and it does so as soon as it can, so it is reasonable to ask what the type
 //! inferencer knows "so far".
 
-use ty::{self, Ty, TyCtxt, TypeFoldable};
-use ty::fold::TypeFolder;
-use util::nodemap::FxHashMap;
+use crate::ty::{self, Ty, TyCtxt, TypeFoldable};
+use crate::ty::fold::TypeFolder;
+use crate::util::nodemap::FxHashMap;
 
 use std::collections::hash_map::Entry;
 
diff --git a/src/librustc/infer/fudge.rs b/src/librustc/infer/fudge.rs
index a38db5d210f7b..d205cfcf73b7e 100644
--- a/src/librustc/infer/fudge.rs
+++ b/src/librustc/infer/fudge.rs
@@ -1,6 +1,6 @@
-use infer::type_variable::TypeVariableMap;
-use ty::{self, Ty, TyCtxt};
-use ty::fold::{TypeFoldable, TypeFolder};
+use crate::infer::type_variable::TypeVariableMap;
+use crate::ty::{self, Ty, TyCtxt};
+use crate::ty::fold::{TypeFoldable, TypeFolder};
 
 use super::InferCtxt;
 use super::RegionVariableOrigin;
diff --git a/src/librustc/infer/glb.rs b/src/librustc/infer/glb.rs
index 635a6d00270b7..910c6571853dc 100644
--- a/src/librustc/infer/glb.rs
+++ b/src/librustc/infer/glb.rs
@@ -3,9 +3,9 @@ use super::InferCtxt;
 use super::lattice::{self, LatticeDir};
 use super::Subtype;
 
-use traits::ObligationCause;
-use ty::{self, Ty, TyCtxt};
-use ty::relate::{Relate, RelateResult, TypeRelation};
+use crate::traits::ObligationCause;
+use crate::ty::{self, Ty, TyCtxt};
+use crate::ty::relate::{Relate, RelateResult, TypeRelation};
 
 /// "Greatest lower bound" (common subtype)
 pub struct Glb<'combine, 'infcx: 'combine, 'gcx: 'infcx+'tcx, 'tcx: 'infcx> {
diff --git a/src/librustc/infer/higher_ranked/mod.rs b/src/librustc/infer/higher_ranked/mod.rs
index 709e8c0ba9b24..c7fc446b9787b 100644
--- a/src/librustc/infer/higher_ranked/mod.rs
+++ b/src/librustc/infer/higher_ranked/mod.rs
@@ -4,8 +4,8 @@
 use super::combine::CombineFields;
 use super::{HigherRankedType, InferCtxt, PlaceholderMap};
 
-use ty::relate::{Relate, RelateResult, TypeRelation};
-use ty::{self, Binder, TypeFoldable};
+use crate::ty::relate::{Relate, RelateResult, TypeRelation};
+use crate::ty::{self, Binder, TypeFoldable};
 
 impl<'a, 'gcx, 'tcx> CombineFields<'a, 'gcx, 'tcx> {
     pub fn higher_ranked_sub<T>(
diff --git a/src/librustc/infer/lattice.rs b/src/librustc/infer/lattice.rs
index a8794b4076a9d..dfa086a64de61 100644
--- a/src/librustc/infer/lattice.rs
+++ b/src/librustc/infer/lattice.rs
@@ -22,10 +22,10 @@
 use super::InferCtxt;
 use super::type_variable::TypeVariableOrigin;
 
-use traits::ObligationCause;
-use ty::TyVar;
-use ty::{self, Ty};
-use ty::relate::{RelateResult, TypeRelation};
+use crate::traits::ObligationCause;
+use crate::ty::TyVar;
+use crate::ty::{self, Ty};
+use crate::ty::relate::{RelateResult, TypeRelation};
 
 pub trait LatticeDir<'f, 'gcx: 'f+'tcx, 'tcx: 'f> : TypeRelation<'f, 'gcx, 'tcx> {
     fn infcx(&self) -> &'f InferCtxt<'f, 'gcx, 'tcx>;
diff --git a/src/librustc/infer/lexical_region_resolve/graphviz.rs b/src/librustc/infer/lexical_region_resolve/graphviz.rs
index 7ce2aba54f5cc..073a3f74422c6 100644
--- a/src/librustc/infer/lexical_region_resolve/graphviz.rs
+++ b/src/librustc/infer/lexical_region_resolve/graphviz.rs
@@ -8,14 +8,14 @@
 /// For clarity, rename the graphviz crate locally to dot.
 use graphviz as dot;
 
-use hir::def_id::DefIndex;
-use ty;
-use middle::free_region::RegionRelations;
-use middle::region;
+use crate::hir::def_id::DefIndex;
+use crate::ty;
+use crate::middle::free_region::RegionRelations;
+use crate::middle::region;
 use super::Constraint;
-use infer::SubregionOrigin;
-use infer::region_constraints::RegionConstraintData;
-use util::nodemap::{FxHashMap, FxHashSet};
+use crate::infer::SubregionOrigin;
+use crate::infer::region_constraints::RegionConstraintData;
+use crate::util::nodemap::{FxHashMap, FxHashSet};
 
 use std::borrow::Cow;
 use std::collections::hash_map::Entry::Vacant;
diff --git a/src/librustc/infer/lexical_region_resolve/mod.rs b/src/librustc/infer/lexical_region_resolve/mod.rs
index c0952fefac0e1..7add8a26ede09 100644
--- a/src/librustc/infer/lexical_region_resolve/mod.rs
+++ b/src/librustc/infer/lexical_region_resolve/mod.rs
@@ -1,13 +1,13 @@
 //! The code to do lexical region resolution.
 
-use infer::region_constraints::Constraint;
-use infer::region_constraints::GenericKind;
-use infer::region_constraints::RegionConstraintData;
-use infer::region_constraints::VarInfos;
-use infer::region_constraints::VerifyBound;
-use infer::RegionVariableOrigin;
-use infer::SubregionOrigin;
-use middle::free_region::RegionRelations;
+use crate::infer::region_constraints::Constraint;
+use crate::infer::region_constraints::GenericKind;
+use crate::infer::region_constraints::RegionConstraintData;
+use crate::infer::region_constraints::VarInfos;
+use crate::infer::region_constraints::VerifyBound;
+use crate::infer::RegionVariableOrigin;
+use crate::infer::SubregionOrigin;
+use crate::middle::free_region::RegionRelations;
 use rustc_data_structures::fx::FxHashSet;
 use rustc_data_structures::graph::implementation::{
     Direction, Graph, NodeIndex, INCOMING, OUTGOING,
@@ -16,11 +16,11 @@ use rustc_data_structures::indexed_vec::{Idx, IndexVec};
 use smallvec::SmallVec;
 use std::fmt;
 use std::u32;
-use ty::fold::TypeFoldable;
-use ty::{self, Ty, TyCtxt};
-use ty::{ReEarlyBound, ReEmpty, ReErased, ReFree, ReStatic};
-use ty::{ReLateBound, ReScope, RePlaceholder, ReVar};
-use ty::{Region, RegionVid};
+use crate::ty::fold::TypeFoldable;
+use crate::ty::{self, Ty, TyCtxt};
+use crate::ty::{ReEarlyBound, ReEmpty, ReErased, ReFree, ReStatic};
+use crate::ty::{ReLateBound, ReScope, RePlaceholder, ReVar};
+use crate::ty::{Region, RegionVid};
 
 mod graphviz;
 
diff --git a/src/librustc/infer/lub.rs b/src/librustc/infer/lub.rs
index 0b9839f69fa2a..f9eb60d82d17b 100644
--- a/src/librustc/infer/lub.rs
+++ b/src/librustc/infer/lub.rs
@@ -3,9 +3,9 @@ use super::InferCtxt;
 use super::lattice::{self, LatticeDir};
 use super::Subtype;
 
-use traits::ObligationCause;
-use ty::{self, Ty, TyCtxt};
-use ty::relate::{Relate, RelateResult, TypeRelation};
+use crate::traits::ObligationCause;
+use crate::ty::{self, Ty, TyCtxt};
+use crate::ty::relate::{Relate, RelateResult, TypeRelation};
 
 /// "Least upper bound" (common supertype)
 pub struct Lub<'combine, 'infcx: 'combine, 'gcx: 'infcx+'tcx, 'tcx: 'infcx> {
diff --git a/src/librustc/infer/mod.rs b/src/librustc/infer/mod.rs
index 958982545750f..06c94d133344c 100644
--- a/src/librustc/infer/mod.rs
+++ b/src/librustc/infer/mod.rs
@@ -5,31 +5,31 @@ pub use self::LateBoundRegionConversionTime::*;
 pub use self::RegionVariableOrigin::*;
 pub use self::SubregionOrigin::*;
 pub use self::ValuePairs::*;
-pub use ty::IntVarValue;
+pub use crate::ty::IntVarValue;
 
 use arena::SyncDroplessArena;
-use errors::DiagnosticBuilder;
-use hir::def_id::DefId;
-use infer::canonical::{Canonical, CanonicalVarValues};
-use middle::free_region::RegionRelations;
-use middle::lang_items;
-use middle::region;
+use crate::errors::DiagnosticBuilder;
+use crate::hir::def_id::DefId;
+use crate::infer::canonical::{Canonical, CanonicalVarValues};
+use crate::middle::free_region::RegionRelations;
+use crate::middle::lang_items;
+use crate::middle::region;
 use rustc_data_structures::unify as ut;
-use session::config::BorrowckMode;
+use crate::session::config::BorrowckMode;
 use std::cell::{Cell, Ref, RefCell, RefMut};
 use std::collections::BTreeMap;
 use std::fmt;
 use syntax::ast;
 use syntax_pos::symbol::InternedString;
 use syntax_pos::{self, Span};
-use traits::{self, ObligationCause, PredicateObligations, TraitEngine};
-use ty::error::{ExpectedFound, TypeError, UnconstrainedNumeric};
-use ty::fold::TypeFoldable;
-use ty::relate::RelateResult;
-use ty::subst::{Kind, Substs};
-use ty::{self, GenericParamDefKind, Ty, TyCtxt, CtxtInterners};
-use ty::{FloatVid, IntVid, TyVid};
-use util::nodemap::FxHashMap;
+use crate::traits::{self, ObligationCause, PredicateObligations, TraitEngine};
+use crate::ty::error::{ExpectedFound, TypeError, UnconstrainedNumeric};
+use crate::ty::fold::TypeFoldable;
+use crate::ty::relate::RelateResult;
+use crate::ty::subst::{Kind, Substs};
+use crate::ty::{self, GenericParamDefKind, Ty, TyCtxt, CtxtInterners};
+use crate::ty::{FloatVid, IntVid, TyVid};
+use crate::util::nodemap::FxHashMap;
 
 use self::combine::CombineFields;
 use self::lexical_region_resolve::LexicalRegionResolutions;
@@ -617,8 +617,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
     }
 
     pub fn type_is_unconstrained_numeric(&'a self, ty: Ty<'_>) -> UnconstrainedNumeric {
-        use ty::error::UnconstrainedNumeric::Neither;
-        use ty::error::UnconstrainedNumeric::{UnconstrainedFloat, UnconstrainedInt};
+        use crate::ty::error::UnconstrainedNumeric::Neither;
+        use crate::ty::error::UnconstrainedNumeric::{UnconstrainedFloat, UnconstrainedInt};
         match ty.sty {
             ty::Infer(ty::IntVar(vid)) => {
                 if self.int_unification_table
diff --git a/src/librustc/infer/opaque_types/mod.rs b/src/librustc/infer/opaque_types/mod.rs
index 5e94bb1f877fb..e28157f05f15f 100644
--- a/src/librustc/infer/opaque_types/mod.rs
+++ b/src/librustc/infer/opaque_types/mod.rs
@@ -1,16 +1,16 @@
-use hir::def_id::DefId;
-use hir;
-use hir::Node;
-use infer::{self, InferCtxt, InferOk, TypeVariableOrigin};
-use infer::outlives::free_region_map::FreeRegionRelations;
+use crate::hir::def_id::DefId;
+use crate::hir;
+use crate::hir::Node;
+use crate::infer::{self, InferCtxt, InferOk, TypeVariableOrigin};
+use crate::infer::outlives::free_region_map::FreeRegionRelations;
 use rustc_data_structures::fx::FxHashMap;
 use syntax::ast;
-use traits::{self, PredicateObligation};
-use ty::{self, Ty, TyCtxt, GenericParamDefKind};
-use ty::fold::{BottomUpFolder, TypeFoldable, TypeFolder};
-use ty::outlives::Component;
-use ty::subst::{Kind, Substs, UnpackedKind};
-use util::nodemap::DefIdMap;
+use crate::traits::{self, PredicateObligation};
+use crate::ty::{self, Ty, TyCtxt, GenericParamDefKind};
+use crate::ty::fold::{BottomUpFolder, TypeFoldable, TypeFolder};
+use crate::ty::outlives::Component;
+use crate::ty::subst::{Kind, Substs, UnpackedKind};
+use crate::util::nodemap::DefIdMap;
 
 pub type OpaqueTypeMap<'tcx> = DefIdMap<OpaqueTypeDecl<'tcx>>;
 
diff --git a/src/librustc/infer/outlives/env.rs b/src/librustc/infer/outlives/env.rs
index 677b6136ea03b..20d03f3c6edb5 100644
--- a/src/librustc/infer/outlives/env.rs
+++ b/src/librustc/infer/outlives/env.rs
@@ -1,10 +1,10 @@
-use infer::outlives::free_region_map::FreeRegionMap;
-use infer::{GenericKind, InferCtxt};
+use crate::infer::outlives::free_region_map::FreeRegionMap;
+use crate::infer::{GenericKind, InferCtxt};
 use rustc_data_structures::fx::FxHashMap;
 use syntax::ast;
 use syntax_pos::Span;
-use traits::query::outlives_bounds::{self, OutlivesBound};
-use ty::{self, Ty};
+use crate::traits::query::outlives_bounds::{self, OutlivesBound};
+use crate::ty::{self, Ty};
 
 /// The `OutlivesEnvironment` collects information about what outlives
 /// what in a given type-checking setting. For example, if we have a
diff --git a/src/librustc/infer/outlives/free_region_map.rs b/src/librustc/infer/outlives/free_region_map.rs
index a6703c9d679da..7daf6d71980f6 100644
--- a/src/librustc/infer/outlives/free_region_map.rs
+++ b/src/librustc/infer/outlives/free_region_map.rs
@@ -1,4 +1,4 @@
-use ty::{self, Lift, TyCtxt, Region};
+use crate::ty::{self, Lift, TyCtxt, Region};
 use rustc_data_structures::transitive_relation::TransitiveRelation;
 
 #[derive(Clone, RustcEncodable, RustcDecodable, Debug, Default)]
diff --git a/src/librustc/infer/outlives/obligations.rs b/src/librustc/infer/outlives/obligations.rs
index abe835c9211a5..884bd58b4023b 100644
--- a/src/librustc/infer/outlives/obligations.rs
+++ b/src/librustc/infer/outlives/obligations.rs
@@ -59,14 +59,14 @@
 //! might later infer `?U` to something like `&'b u32`, which would
 //! imply that `'b: 'a`.
 
-use infer::outlives::env::RegionBoundPairs;
-use infer::outlives::verify::VerifyBoundCx;
-use infer::{self, GenericKind, InferCtxt, RegionObligation, SubregionOrigin, VerifyBound};
+use crate::infer::outlives::env::RegionBoundPairs;
+use crate::infer::outlives::verify::VerifyBoundCx;
+use crate::infer::{self, GenericKind, InferCtxt, RegionObligation, SubregionOrigin, VerifyBound};
 use rustc_data_structures::fx::FxHashMap;
 use syntax::ast;
-use traits::ObligationCause;
-use ty::outlives::Component;
-use ty::{self, Region, Ty, TyCtxt, TypeFoldable};
+use crate::traits::ObligationCause;
+use crate::ty::outlives::Component;
+use crate::ty::{self, Region, Ty, TyCtxt, TypeFoldable};
 
 impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
     /// Registers that the given region obligation must be resolved
diff --git a/src/librustc/infer/outlives/verify.rs b/src/librustc/infer/outlives/verify.rs
index 4e9a8e9ded899..0457e7179461c 100644
--- a/src/librustc/infer/outlives/verify.rs
+++ b/src/librustc/infer/outlives/verify.rs
@@ -1,10 +1,10 @@
-use hir::def_id::DefId;
-use infer::outlives::env::RegionBoundPairs;
-use infer::{GenericKind, VerifyBound};
-use traits;
-use ty::subst::{Subst, Substs};
-use ty::{self, Ty, TyCtxt};
-use util::captures::Captures;
+use crate::hir::def_id::DefId;
+use crate::infer::outlives::env::RegionBoundPairs;
+use crate::infer::{GenericKind, VerifyBound};
+use crate::traits;
+use crate::ty::subst::{Subst, Substs};
+use crate::ty::{self, Ty, TyCtxt};
+use crate::util::captures::Captures;
 
 /// The `TypeOutlives` struct has the job of "lowering" a `T: 'a`
 /// obligation into a series of `'a: 'b` constraints and "verifys", as
diff --git a/src/librustc/infer/region_constraints/mod.rs b/src/librustc/infer/region_constraints/mod.rs
index 56ae850226c91..500497dc011e1 100644
--- a/src/librustc/infer/region_constraints/mod.rs
+++ b/src/librustc/infer/region_constraints/mod.rs
@@ -9,10 +9,10 @@ use super::{MiscVariable, RegionVariableOrigin, SubregionOrigin};
 use rustc_data_structures::fx::{FxHashMap, FxHashSet};
 use rustc_data_structures::indexed_vec::IndexVec;
 use rustc_data_structures::unify as ut;
-use ty::ReStatic;
-use ty::{self, Ty, TyCtxt};
-use ty::{BrFresh, ReLateBound, ReVar};
-use ty::{Region, RegionVid};
+use crate::ty::ReStatic;
+use crate::ty::{self, Ty, TyCtxt};
+use crate::ty::{BrFresh, ReLateBound, ReVar};
+use crate::ty::{Region, RegionVid};
 
 use std::collections::BTreeMap;
 use std::{cmp, fmt, mem, u32};
diff --git a/src/librustc/infer/resolve.rs b/src/librustc/infer/resolve.rs
index f6131c01b372f..4a8f0c34ead11 100644
--- a/src/librustc/infer/resolve.rs
+++ b/src/librustc/infer/resolve.rs
@@ -1,6 +1,6 @@
 use super::{InferCtxt, FixupError, FixupResult};
-use ty::{self, Ty, TyCtxt, TypeFoldable};
-use ty::fold::{TypeFolder, TypeVisitor};
+use crate::ty::{self, Ty, TyCtxt, TypeFoldable};
+use crate::ty::fold::{TypeFolder, TypeVisitor};
 
 ///////////////////////////////////////////////////////////////////////////
 // OPPORTUNISTIC TYPE RESOLVER
diff --git a/src/librustc/infer/sub.rs b/src/librustc/infer/sub.rs
index df76d1d3afb34..0cff42742c30a 100644
--- a/src/librustc/infer/sub.rs
+++ b/src/librustc/infer/sub.rs
@@ -1,11 +1,11 @@
 use super::SubregionOrigin;
 use super::combine::{CombineFields, RelationDir};
 
-use traits::Obligation;
-use ty::{self, Ty, TyCtxt};
-use ty::TyVar;
-use ty::fold::TypeFoldable;
-use ty::relate::{Cause, Relate, RelateResult, TypeRelation};
+use crate::traits::Obligation;
+use crate::ty::{self, Ty, TyCtxt};
+use crate::ty::TyVar;
+use crate::ty::fold::TypeFoldable;
+use crate::ty::relate::{Cause, Relate, RelateResult, TypeRelation};
 use std::mem;
 
 /// Ensures `a` is made a subtype of `b`. Returns `a` on success.
diff --git a/src/librustc/infer/type_variable.rs b/src/librustc/infer/type_variable.rs
index 3ec27bdcf1bcd..14f3261bfc203 100644
--- a/src/librustc/infer/type_variable.rs
+++ b/src/librustc/infer/type_variable.rs
@@ -1,6 +1,6 @@
 use syntax::symbol::InternedString;
 use syntax_pos::Span;
-use ty::{self, Ty};
+use crate::ty::{self, Ty};
 
 use std::cmp;
 use std::marker::PhantomData;
diff --git a/src/librustc/infer/unify_key.rs b/src/librustc/infer/unify_key.rs
index 068ff0c90e7fc..09f800d9f9bfc 100644
--- a/src/librustc/infer/unify_key.rs
+++ b/src/librustc/infer/unify_key.rs
@@ -1,4 +1,4 @@
-use ty::{self, FloatVarValue, IntVarValue, Ty, TyCtxt};
+use crate::ty::{self, FloatVarValue, IntVarValue, Ty, TyCtxt};
 use rustc_data_structures::unify::{NoError, EqUnifyValue, UnifyKey, UnifyValue};
 
 pub trait ToType {
diff --git a/src/librustc/lib.rs b/src/librustc/lib.rs
index f886e50246ac0..d19513515201e 100644
--- a/src/librustc/lib.rs
+++ b/src/librustc/lib.rs
@@ -30,6 +30,9 @@
        html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
        html_root_url = "https://doc.rust-lang.org/nightly/")]
 
+#![deny(rust_2018_idioms)]
+#![allow(explicit_outlives_requirements)]
+
 #![feature(box_patterns)]
 #![feature(box_syntax)]
 #![feature(core_intrinsics)]
@@ -64,41 +67,24 @@
 
 #![warn(elided_lifetimes_in_paths)]
 
-extern crate arena;
 #[macro_use] extern crate bitflags;
-extern crate core;
-extern crate fmt_macros;
 extern crate getopts;
-extern crate graphviz;
-extern crate num_cpus;
 #[macro_use] extern crate lazy_static;
 #[macro_use] extern crate scoped_tls;
 #[cfg(windows)]
 extern crate libc;
-extern crate polonius_engine;
-extern crate rustc_target;
 #[macro_use] extern crate rustc_data_structures;
-extern crate serialize;
-extern crate parking_lot;
-extern crate rustc_errors as errors;
-extern crate rustc_rayon as rayon;
-extern crate rustc_rayon_core as rayon_core;
+
 #[macro_use] extern crate log;
 #[macro_use] extern crate syntax;
-extern crate syntax_pos;
-extern crate jobserver;
-extern crate proc_macro;
-extern crate chalk_engine;
-extern crate rustc_fs_util;
 
-extern crate serialize as rustc_serialize; // used by deriving
+// FIXME: This import is used by deriving `RustcDecodable` and `RustcEncodable`. Removing this
+// results in a bunch of "failed to resolve" errors. Hopefully, the compiler moves to serde or
+// something, and we can get rid of this.
+#[allow(rust_2018_idioms)]
+extern crate serialize as rustc_serialize;
 
-extern crate rustc_apfloat;
-extern crate byteorder;
-extern crate backtrace;
-
-#[macro_use]
-extern crate smallvec;
+#[macro_use] extern crate smallvec;
 
 // Note that librustc doesn't actually depend on these crates, see the note in
 // `Cargo.toml` for this crate about why these are here.
@@ -166,9 +152,11 @@ pub mod util {
 // `libstd` uses the same trick.
 #[doc(hidden)]
 mod rustc {
-    pub use lint;
+    pub use crate::lint;
 }
 
+use rustc_errors as errors;
+
 // FIXME(#27438): right now the unit tests of librustc don't refer to any actual
 //                functions generated in librustc_data_structures (all
 //                references are through generic functions), but statics are
diff --git a/src/librustc/lint/builtin.rs b/src/librustc/lint/builtin.rs
index 3fe544d690640..6ae7448645a20 100644
--- a/src/librustc/lint/builtin.rs
+++ b/src/librustc/lint/builtin.rs
@@ -4,9 +4,9 @@
 //! compiler code, rather than using their own custom pass. Those
 //! lints are all available in `rustc_lint::builtin`.
 
-use errors::{Applicability, DiagnosticBuilder};
-use lint::{LintPass, LateLintPass, LintArray};
-use session::Session;
+use crate::errors::{Applicability, DiagnosticBuilder};
+use crate::lint::{LintPass, LateLintPass, LintArray};
+use crate::session::Session;
 use syntax::ast;
 use syntax::source_map::Span;
 
diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs
index 394e404fb881f..27ead805d5dbd 100644
--- a/src/librustc/lint/context.rs
+++ b/src/librustc/lint/context.rs
@@ -18,26 +18,26 @@ use self::TargetLint::*;
 
 use std::slice;
 use rustc_data_structures::sync::ReadGuard;
-use lint::{EarlyLintPass, EarlyLintPassObject, LateLintPassObject};
-use lint::{LintArray, Level, Lint, LintId, LintPass, LintBuffer};
-use lint::builtin::BuiltinLintDiagnostics;
-use lint::levels::{LintLevelSets, LintLevelsBuilder};
-use middle::privacy::AccessLevels;
-use rustc_serialize::{Decoder, Decodable, Encoder, Encodable};
-use session::{config, early_error, Session};
-use ty::{self, TyCtxt, Ty};
-use ty::layout::{LayoutError, LayoutOf, TyLayout};
-use util::nodemap::FxHashMap;
-use util::common::time;
+use crate::lint::{EarlyLintPass, EarlyLintPassObject, LateLintPassObject};
+use crate::lint::{LintArray, Level, Lint, LintId, LintPass, LintBuffer};
+use crate::lint::builtin::BuiltinLintDiagnostics;
+use crate::lint::levels::{LintLevelSets, LintLevelsBuilder};
+use crate::middle::privacy::AccessLevels;
+use crate::rustc_serialize::{Decoder, Decodable, Encoder, Encodable};
+use crate::session::{config, early_error, Session};
+use crate::ty::{self, TyCtxt, Ty};
+use crate::ty::layout::{LayoutError, LayoutOf, TyLayout};
+use crate::util::nodemap::FxHashMap;
+use crate::util::common::time;
 
 use std::default::Default as StdDefault;
 use syntax::ast;
 use syntax::edition;
 use syntax_pos::{MultiSpan, Span, symbol::{LocalInternedString, Symbol}};
-use errors::DiagnosticBuilder;
-use hir;
-use hir::def_id::LOCAL_CRATE;
-use hir::intravisit as hir_visit;
+use crate::errors::DiagnosticBuilder;
+use crate::hir;
+use crate::hir::def_id::LOCAL_CRATE;
+use crate::hir::intravisit as hir_visit;
 use syntax::util::lev_distance::find_best_match_for_name;
 use syntax::visit as ast_visit;
 
diff --git a/src/librustc/lint/levels.rs b/src/librustc/lint/levels.rs
index 616915769435d..62bd54de7c929 100644
--- a/src/librustc/lint/levels.rs
+++ b/src/librustc/lint/levels.rs
@@ -1,20 +1,20 @@
 use std::cmp;
 
-use errors::{Applicability, DiagnosticBuilder};
-use hir::HirId;
-use ich::StableHashingContext;
-use lint::builtin;
-use lint::context::CheckLintNameResult;
-use lint::{self, Lint, LintId, Level, LintSource};
+use crate::errors::{Applicability, DiagnosticBuilder};
+use crate::hir::HirId;
+use crate::ich::StableHashingContext;
+use crate::lint::builtin;
+use crate::lint::context::CheckLintNameResult;
+use crate::lint::{self, Lint, LintId, Level, LintSource};
 use rustc_data_structures::stable_hasher::{HashStable, ToStableHashKey,
                                            StableHasher, StableHasherResult};
-use session::Session;
+use crate::session::Session;
 use syntax::ast;
 use syntax::attr;
 use syntax::feature_gate;
 use syntax::source_map::MultiSpan;
 use syntax::symbol::Symbol;
-use util::nodemap::FxHashMap;
+use crate::util::nodemap::FxHashMap;
 
 pub struct LintLevelSets {
     list: Vec<LintSet>,
diff --git a/src/librustc/lint/mod.rs b/src/librustc/lint/mod.rs
index a95fa350bf1c3..4e6bf753b01aa 100644
--- a/src/librustc/lint/mod.rs
+++ b/src/librustc/lint/mod.rs
@@ -23,13 +23,13 @@ pub use self::LintSource::*;
 
 use rustc_data_structures::sync::{self, Lrc};
 
-use errors::{DiagnosticBuilder, DiagnosticId};
-use hir::def_id::{CrateNum, LOCAL_CRATE};
-use hir::intravisit;
-use hir;
-use lint::builtin::BuiltinLintDiagnostics;
-use lint::builtin::parser::{QUESTION_MARK_MACRO_SEP, ILL_FORMED_ATTRIBUTE_INPUT};
-use session::{Session, DiagnosticMessageId};
+use crate::errors::{DiagnosticBuilder, DiagnosticId};
+use crate::hir::def_id::{CrateNum, LOCAL_CRATE};
+use crate::hir::intravisit;
+use crate::hir;
+use crate::lint::builtin::BuiltinLintDiagnostics;
+use crate::lint::builtin::parser::{QUESTION_MARK_MACRO_SEP, ILL_FORMED_ATTRIBUTE_INPUT};
+use crate::session::{Session, DiagnosticMessageId};
 use std::{hash, ptr};
 use syntax::ast;
 use syntax::source_map::{MultiSpan, ExpnFormat};
@@ -37,11 +37,11 @@ use syntax::early_buffered_lints::BufferedEarlyLintId;
 use syntax::edition::Edition;
 use syntax::symbol::Symbol;
 use syntax_pos::Span;
-use ty::TyCtxt;
-use ty::query::Providers;
-use util::nodemap::NodeMap;
+use crate::ty::TyCtxt;
+use crate::ty::query::Providers;
+use crate::util::nodemap::NodeMap;
 
-pub use lint::context::{LateContext, EarlyContext, LintContext, LintStore,
+pub use crate::lint::context::{LateContext, EarlyContext, LintContext, LintStore,
                         check_crate, check_ast_crate, CheckLintNameResult,
                         FutureIncompatibleInfo, BufferedEarlyLint};
 
@@ -678,7 +678,7 @@ pub fn struct_lint_level<'a>(sess: &'a Session,
             "this was previously accepted by the compiler but is being phased out; \
              it will become a hard error";
 
-        let explanation = if lint_id == LintId::of(::lint::builtin::UNSTABLE_NAME_COLLISIONS) {
+        let explanation = if lint_id == LintId::of(crate::lint::builtin::UNSTABLE_NAME_COLLISIONS) {
             "once this method is added to the standard library, \
              the ambiguity may cause an error or change in behavior!"
                 .to_owned()
diff --git a/src/librustc/middle/borrowck.rs b/src/librustc/middle/borrowck.rs
index 120ba6b1d4e9f..2799f9424d919 100644
--- a/src/librustc/middle/borrowck.rs
+++ b/src/librustc/middle/borrowck.rs
@@ -1,6 +1,6 @@
-use ich::StableHashingContext;
-use hir::HirId;
-use util::nodemap::FxHashSet;
+use crate::ich::StableHashingContext;
+use crate::hir::HirId;
+use crate::util::nodemap::FxHashSet;
 
 use rustc_data_structures::stable_hasher::{HashStable, StableHasher,
                                            StableHasherResult};
diff --git a/src/librustc/middle/cstore.rs b/src/librustc/middle/cstore.rs
index 9168bbf907f1e..6e9552a1e9209 100644
--- a/src/librustc/middle/cstore.rs
+++ b/src/librustc/middle/cstore.rs
@@ -2,13 +2,13 @@
 //! are *mostly* used as a part of that interface, but these should
 //! probably get a better home if someone can find one.
 
-use hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
-use hir::map as hir_map;
-use hir::map::definitions::{DefKey, DefPathTable};
+use crate::hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
+use crate::hir::map as hir_map;
+use crate::hir::map::definitions::{DefKey, DefPathTable};
 use rustc_data_structures::svh::Svh;
-use ty::{self, TyCtxt};
-use session::{Session, CrateDisambiguator};
-use session::search_paths::PathKind;
+use crate::ty::{self, TyCtxt};
+use crate::session::{Session, CrateDisambiguator};
+use crate::session::search_paths::PathKind;
 
 use std::any::Any;
 use std::path::{Path, PathBuf};
diff --git a/src/librustc/middle/dead.rs b/src/librustc/middle/dead.rs
index abbf0ae210c25..6dffe8efba612 100644
--- a/src/librustc/middle/dead.rs
+++ b/src/librustc/middle/dead.rs
@@ -2,18 +2,18 @@
 // closely. The idea is that all reachable symbols are live, codes called
 // from live codes are live, and everything else is dead.
 
-use hir::Node;
-use hir::{self, PatKind};
-use hir::intravisit::{self, Visitor, NestedVisitorMap};
-use hir::itemlikevisit::ItemLikeVisitor;
-
-use hir::def::Def;
-use hir::CodegenFnAttrFlags;
-use hir::def_id::{DefId, LOCAL_CRATE};
-use lint;
-use middle::privacy;
-use ty::{self, TyCtxt};
-use util::nodemap::FxHashSet;
+use crate::hir::Node;
+use crate::hir::{self, PatKind};
+use crate::hir::intravisit::{self, Visitor, NestedVisitorMap};
+use crate::hir::itemlikevisit::ItemLikeVisitor;
+
+use crate::hir::def::Def;
+use crate::hir::CodegenFnAttrFlags;
+use crate::hir::def_id::{DefId, LOCAL_CRATE};
+use crate::lint;
+use crate::middle::privacy;
+use crate::ty::{self, TyCtxt};
+use crate::util::nodemap::FxHashSet;
 
 use rustc_data_structures::fx::FxHashMap;
 
diff --git a/src/librustc/middle/dependency_format.rs b/src/librustc/middle/dependency_format.rs
index 16c9344a03722..a24d25cba1184 100644
--- a/src/librustc/middle/dependency_format.rs
+++ b/src/librustc/middle/dependency_format.rs
@@ -51,13 +51,13 @@
 //! Additionally, the algorithm is geared towards finding *any* solution rather
 //! than finding a number of solutions (there are normally quite a few).
 
-use hir::def_id::CrateNum;
+use crate::hir::def_id::CrateNum;
 
-use session::config;
-use ty::TyCtxt;
-use middle::cstore::{self, DepKind};
-use middle::cstore::LinkagePreference::{self, RequireStatic, RequireDynamic};
-use util::nodemap::FxHashMap;
+use crate::session::config;
+use crate::ty::TyCtxt;
+use crate::middle::cstore::{self, DepKind};
+use crate::middle::cstore::LinkagePreference::{self, RequireStatic, RequireDynamic};
+use crate::util::nodemap::FxHashMap;
 use rustc_target::spec::PanicStrategy;
 
 /// A list of dependencies for a certain crate type.
diff --git a/src/librustc/middle/entry.rs b/src/librustc/middle/entry.rs
index 218ca3b7553c0..2d0e6c3917bb8 100644
--- a/src/librustc/middle/entry.rs
+++ b/src/librustc/middle/entry.rs
@@ -1,15 +1,15 @@
-use hir::map as hir_map;
-use hir::def_id::{CrateNum, CRATE_DEF_INDEX, DefId, LOCAL_CRATE};
-use session::{config, Session};
-use session::config::EntryFnType;
+use crate::hir::map as hir_map;
+use crate::hir::def_id::{CrateNum, CRATE_DEF_INDEX, DefId, LOCAL_CRATE};
+use crate::session::{config, Session};
+use crate::session::config::EntryFnType;
 use syntax::ast::NodeId;
 use syntax::attr;
 use syntax::entry::EntryPointType;
 use syntax_pos::Span;
-use hir::{Item, ItemKind, ImplItem, TraitItem};
-use hir::itemlikevisit::ItemLikeVisitor;
-use ty::TyCtxt;
-use ty::query::Providers;
+use crate::hir::{Item, ItemKind, ImplItem, TraitItem};
+use crate::hir::itemlikevisit::ItemLikeVisitor;
+use crate::ty::TyCtxt;
+use crate::ty::query::Providers;
 
 struct EntryContext<'a, 'tcx: 'a> {
     session: &'a Session,
diff --git a/src/librustc/middle/exported_symbols.rs b/src/librustc/middle/exported_symbols.rs
index a0a73ea0b81fb..6c43068a22772 100644
--- a/src/librustc/middle/exported_symbols.rs
+++ b/src/librustc/middle/exported_symbols.rs
@@ -1,11 +1,11 @@
-use hir::def_id::{DefId, LOCAL_CRATE};
-use ich::StableHashingContext;
+use crate::hir::def_id::{DefId, LOCAL_CRATE};
+use crate::ich::StableHashingContext;
 use rustc_data_structures::stable_hasher::{StableHasher, HashStable,
                                            StableHasherResult};
 use std::cmp;
 use std::mem;
-use ty;
-use ty::subst::Substs;
+use crate::ty;
+use crate::ty::subst::Substs;
 
 /// The SymbolExportLevel of a symbols specifies from which kinds of crates
 /// the symbol will be exported. `C` symbols will be exported from any
diff --git a/src/librustc/middle/expr_use_visitor.rs b/src/librustc/middle/expr_use_visitor.rs
index 08210c3f075ce..0939f07f43bb3 100644
--- a/src/librustc/middle/expr_use_visitor.rs
+++ b/src/librustc/middle/expr_use_visitor.rs
@@ -9,20 +9,20 @@ pub use self::MatchMode::*;
 use self::TrackMatchMode::*;
 use self::OverloadedCallType::*;
 
-use hir::def::Def;
-use hir::def_id::DefId;
-use infer::InferCtxt;
-use middle::mem_categorization as mc;
-use middle::region;
-use ty::{self, TyCtxt, adjustment};
-
-use hir::{self, PatKind};
+use crate::hir::def::Def;
+use crate::hir::def_id::DefId;
+use crate::infer::InferCtxt;
+use crate::middle::mem_categorization as mc;
+use crate::middle::region;
+use crate::ty::{self, TyCtxt, adjustment};
+
+use crate::hir::{self, PatKind};
 use rustc_data_structures::sync::Lrc;
 use std::rc::Rc;
 use syntax::ast;
 use syntax::ptr::P;
 use syntax_pos::Span;
-use util::nodemap::ItemLocalSet;
+use crate::util::nodemap::ItemLocalSet;
 
 ///////////////////////////////////////////////////////////////////////////
 // The Delegate trait
diff --git a/src/librustc/middle/free_region.rs b/src/librustc/middle/free_region.rs
index 6e9eadca6a521..e752643e842aa 100644
--- a/src/librustc/middle/free_region.rs
+++ b/src/librustc/middle/free_region.rs
@@ -5,10 +5,10 @@
 //! `TransitiveRelation` type and use that to decide when one free
 //! region outlives another and so forth.
 
-use infer::outlives::free_region_map::{FreeRegionMap, FreeRegionRelations};
-use hir::def_id::DefId;
-use middle::region;
-use ty::{self, TyCtxt, Region};
+use crate::infer::outlives::free_region_map::{FreeRegionMap, FreeRegionRelations};
+use crate::hir::def_id::DefId;
+use crate::middle::region;
+use crate::ty::{self, TyCtxt, Region};
 
 /// Combines a `region::ScopeTree` (which governs relationships between
 /// scopes) and a `FreeRegionMap` (which governs relationships between
diff --git a/src/librustc/middle/intrinsicck.rs b/src/librustc/middle/intrinsicck.rs
index 29d3713900ad9..ee361e9776313 100644
--- a/src/librustc/middle/intrinsicck.rs
+++ b/src/librustc/middle/intrinsicck.rs
@@ -1,14 +1,14 @@
-use hir::def::Def;
-use hir::def_id::DefId;
-use ty::{self, Ty, TyCtxt};
-use ty::layout::{LayoutError, Pointer, SizeSkeleton, VariantIdx};
-use ty::query::Providers;
+use crate::hir::def::Def;
+use crate::hir::def_id::DefId;
+use crate::ty::{self, Ty, TyCtxt};
+use crate::ty::layout::{LayoutError, Pointer, SizeSkeleton, VariantIdx};
+use crate::ty::query::Providers;
 
 use rustc_target::spec::abi::Abi::RustIntrinsic;
 use rustc_data_structures::indexed_vec::Idx;
 use syntax_pos::Span;
-use hir::intravisit::{self, Visitor, NestedVisitorMap};
-use hir;
+use crate::hir::intravisit::{self, Visitor, NestedVisitorMap};
+use crate::hir;
 
 pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
     for &module in tcx.hir().krate().modules.keys() {
diff --git a/src/librustc/middle/lang_items.rs b/src/librustc/middle/lang_items.rs
index 87107f727a05d..3f9230ab551d5 100644
--- a/src/librustc/middle/lang_items.rs
+++ b/src/librustc/middle/lang_items.rs
@@ -11,17 +11,17 @@
 
 pub use self::LangItem::*;
 
-use hir::def_id::DefId;
-use hir::check_attr::Target;
-use ty::{self, TyCtxt};
-use middle::weak_lang_items;
-use util::nodemap::FxHashMap;
+use crate::hir::def_id::DefId;
+use crate::hir::check_attr::Target;
+use crate::ty::{self, TyCtxt};
+use crate::middle::weak_lang_items;
+use crate::util::nodemap::FxHashMap;
 
 use syntax::ast;
 use syntax::symbol::Symbol;
 use syntax_pos::Span;
-use hir::itemlikevisit::ItemLikeVisitor;
-use hir;
+use crate::hir::itemlikevisit::ItemLikeVisitor;
+use crate::hir;
 
 // The actual lang items defined come at the end of this file in one handy table.
 // So you probably just want to nip down to the end.
diff --git a/src/librustc/middle/lib_features.rs b/src/librustc/middle/lib_features.rs
index 8c23377324f1f..45095d9bc986b 100644
--- a/src/librustc/middle/lib_features.rs
+++ b/src/librustc/middle/lib_features.rs
@@ -4,13 +4,13 @@
 // and `#[unstable (..)]`), but are not declared in one single location
 // (unlike lang features), which means we need to collect them instead.
 
-use ty::TyCtxt;
+use crate::ty::TyCtxt;
 use syntax::symbol::Symbol;
 use syntax::ast::{Attribute, MetaItem, MetaItemKind};
 use syntax_pos::Span;
-use hir::intravisit::{self, NestedVisitorMap, Visitor};
+use crate::hir::intravisit::{self, NestedVisitorMap, Visitor};
 use rustc_data_structures::fx::{FxHashSet, FxHashMap};
-use errors::DiagnosticId;
+use crate::errors::DiagnosticId;
 
 pub struct LibFeatures {
     // A map from feature to stabilisation version.
diff --git a/src/librustc/middle/liveness.rs b/src/librustc/middle/liveness.rs
index d47ad009c1db6..ce4a0f69c2864 100644
--- a/src/librustc/middle/liveness.rs
+++ b/src/librustc/middle/liveness.rs
@@ -97,13 +97,13 @@ use self::LoopKind::*;
 use self::LiveNodeKind::*;
 use self::VarKind::*;
 
-use hir::def::*;
-use hir::Node;
-use ty::{self, TyCtxt};
-use ty::query::Providers;
-use lint;
-use errors::Applicability;
-use util::nodemap::{NodeMap, HirIdMap, HirIdSet};
+use crate::hir::def::*;
+use crate::hir::Node;
+use crate::ty::{self, TyCtxt};
+use crate::ty::query::Providers;
+use crate::lint;
+use crate::errors::Applicability;
+use crate::util::nodemap::{NodeMap, HirIdMap, HirIdSet};
 
 use std::collections::{BTreeMap, VecDeque};
 use std::{fmt, u32};
@@ -115,10 +115,10 @@ use syntax::ptr::P;
 use syntax::symbol::keywords;
 use syntax_pos::Span;
 
-use hir;
-use hir::{Expr, HirId};
-use hir::def_id::DefId;
-use hir::intravisit::{self, Visitor, FnKind, NestedVisitorMap};
+use crate::hir;
+use crate::hir::{Expr, HirId};
+use crate::hir::def_id::DefId;
+use crate::hir::intravisit::{self, Visitor, FnKind, NestedVisitorMap};
 
 /// For use with `propagate_through_loop`.
 enum LoopKind<'a> {
@@ -406,7 +406,7 @@ fn add_from_pat<'a, 'tcx>(ir: &mut IrMaps<'a, 'tcx>, pat: &P<hir::Pat>) {
     let mut pats = VecDeque::new();
     pats.push_back(pat);
     while let Some(pat) = pats.pop_front() {
-        use hir::PatKind::*;
+        use crate::hir::PatKind::*;
         match pat.node {
             Binding(_, _, _, _, ref inner_pat) => {
                 pats.extend(inner_pat.iter());
diff --git a/src/librustc/middle/mem_categorization.rs b/src/librustc/middle/mem_categorization.rs
index 370f0d1a6c6d7..04e4a0b39a2ca 100644
--- a/src/librustc/middle/mem_categorization.rs
+++ b/src/librustc/middle/mem_categorization.rs
@@ -58,19 +58,19 @@ pub use self::Note::*;
 
 use self::Aliasability::*;
 
-use middle::region;
-use hir::def_id::{DefId, LocalDefId};
-use hir::Node;
-use infer::InferCtxt;
-use hir::def::{Def, CtorKind};
-use ty::adjustment;
-use ty::{self, Ty, TyCtxt};
-use ty::fold::TypeFoldable;
-use ty::layout::VariantIdx;
-
-use hir::{MutImmutable, MutMutable, PatKind};
-use hir::pat_util::EnumerateAndAdjustIterator;
-use hir;
+use crate::middle::region;
+use crate::hir::def_id::{DefId, LocalDefId};
+use crate::hir::Node;
+use crate::infer::InferCtxt;
+use crate::hir::def::{Def, CtorKind};
+use crate::ty::adjustment;
+use crate::ty::{self, Ty, TyCtxt};
+use crate::ty::fold::TypeFoldable;
+use crate::ty::layout::VariantIdx;
+
+use crate::hir::{MutImmutable, MutMutable, PatKind};
+use crate::hir::pat_util::EnumerateAndAdjustIterator;
+use crate::hir;
 use syntax::ast::{self, Name};
 use syntax_pos::Span;
 
@@ -80,7 +80,7 @@ use std::hash::{Hash, Hasher};
 use rustc_data_structures::sync::Lrc;
 use rustc_data_structures::indexed_vec::Idx;
 use std::rc::Rc;
-use util::nodemap::ItemLocalSet;
+use crate::util::nodemap::ItemLocalSet;
 
 #[derive(Clone, Debug, PartialEq)]
 pub enum Categorization<'tcx> {
diff --git a/src/librustc/middle/privacy.rs b/src/librustc/middle/privacy.rs
index 3baf0f0ea39ff..1655d8356a5a7 100644
--- a/src/librustc/middle/privacy.rs
+++ b/src/librustc/middle/privacy.rs
@@ -2,7 +2,7 @@
 //! outside their scopes. This pass will also generate a set of exported items
 //! which are available for use externally when compiled as a library.
 
-use util::nodemap::{DefIdSet, FxHashMap};
+use crate::util::nodemap::{DefIdSet, FxHashMap};
 
 use std::hash::Hash;
 use std::fmt;
diff --git a/src/librustc/middle/reachable.rs b/src/librustc/middle/reachable.rs
index 10deca836fff3..73ba47d411915 100644
--- a/src/librustc/middle/reachable.rs
+++ b/src/librustc/middle/reachable.rs
@@ -5,24 +5,24 @@
 // makes all other generics or inline functions that it references
 // reachable as well.
 
-use hir::{CodegenFnAttrs, CodegenFnAttrFlags};
-use hir::Node;
-use hir::def::Def;
-use hir::def_id::{DefId, CrateNum};
+use crate::hir::{CodegenFnAttrs, CodegenFnAttrFlags};
+use crate::hir::Node;
+use crate::hir::def::Def;
+use crate::hir::def_id::{DefId, CrateNum};
 use rustc_data_structures::sync::Lrc;
-use ty::{self, TyCtxt};
-use ty::query::Providers;
-use middle::privacy;
-use session::config;
-use util::nodemap::{NodeSet, FxHashSet};
+use crate::ty::{self, TyCtxt};
+use crate::ty::query::Providers;
+use crate::middle::privacy;
+use crate::session::config;
+use crate::util::nodemap::{NodeSet, FxHashSet};
 
 use rustc_target::spec::abi::Abi;
 use syntax::ast;
-use hir;
-use hir::def_id::LOCAL_CRATE;
-use hir::intravisit::{Visitor, NestedVisitorMap};
-use hir::itemlikevisit::ItemLikeVisitor;
-use hir::intravisit;
+use crate::hir;
+use crate::hir::def_id::LOCAL_CRATE;
+use crate::hir::intravisit::{Visitor, NestedVisitorMap};
+use crate::hir::itemlikevisit::ItemLikeVisitor;
+use crate::hir::intravisit;
 
 // Returns true if the given item must be inlined because it may be
 // monomorphized or it was marked with `#[inline]`. This will only return
diff --git a/src/librustc/middle/recursion_limit.rs b/src/librustc/middle/recursion_limit.rs
index 1eabd7f59e689..ea077220e0be3 100644
--- a/src/librustc/middle/recursion_limit.rs
+++ b/src/librustc/middle/recursion_limit.rs
@@ -5,7 +5,7 @@
 // this via an attribute on the crate like `#![recursion_limit="22"]`. This pass
 // just peeks and looks for that attribute.
 
-use session::Session;
+use crate::session::Session;
 use syntax::ast;
 
 use rustc_data_structures::sync::Once;
diff --git a/src/librustc/middle/region.rs b/src/librustc/middle/region.rs
index db52cc3074b9a..788d2185d6da2 100644
--- a/src/librustc/middle/region.rs
+++ b/src/librustc/middle/region.rs
@@ -6,9 +6,9 @@
 //!
 //! [rustc guide]: https://rust-lang.github.io/rustc-guide/mir/borrowck.html
 
-use ich::{StableHashingContext, NodeIdHashingMode};
-use util::nodemap::{FxHashMap, FxHashSet};
-use ty;
+use crate::ich::{StableHashingContext, NodeIdHashingMode};
+use crate::util::nodemap::{FxHashMap, FxHashSet};
+use crate::ty;
 
 use std::mem;
 use std::fmt;
@@ -16,14 +16,14 @@ use rustc_data_structures::sync::Lrc;
 use syntax::source_map;
 use syntax::ast;
 use syntax_pos::{Span, DUMMY_SP};
-use ty::TyCtxt;
-use ty::query::Providers;
-
-use hir;
-use hir::Node;
-use hir::def_id::DefId;
-use hir::intravisit::{self, Visitor, NestedVisitorMap};
-use hir::{Block, Arm, Pat, PatKind, Stmt, Expr, Local};
+use crate::ty::TyCtxt;
+use crate::ty::query::Providers;
+
+use crate::hir;
+use crate::hir::Node;
+use crate::hir::def_id::DefId;
+use crate::hir::intravisit::{self, Visitor, NestedVisitorMap};
+use crate::hir::{Block, Arm, Pat, PatKind, Stmt, Expr, Local};
 use rustc_data_structures::indexed_vec::Idx;
 use rustc_data_structures::stable_hasher::{HashStable, StableHasher,
                                            StableHasherResult};
@@ -154,7 +154,7 @@ newtype_index! {
     pub struct FirstStatementIndex { .. }
 }
 
-impl_stable_hash_for!(struct ::middle::region::FirstStatementIndex { private });
+impl_stable_hash_for!(struct crate::middle::region::FirstStatementIndex { private });
 
 // compilation error if size of `ScopeData` is not the same as a `u32`
 static_assert!(ASSERT_SCOPE_DATA: mem::size_of::<ScopeData>() == 4);
diff --git a/src/librustc/middle/resolve_lifetime.rs b/src/librustc/middle/resolve_lifetime.rs
index 34db30a1706b9..f7cd241236498 100644
--- a/src/librustc/middle/resolve_lifetime.rs
+++ b/src/librustc/middle/resolve_lifetime.rs
@@ -5,16 +5,16 @@
 //! used between functions, and they operate in a purely top-down
 //! way. Therefore we break lifetime name resolution into a separate pass.
 
-use hir::def::Def;
-use hir::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE};
-use hir::map::Map;
-use hir::{GenericArg, GenericParam, ItemLocalId, LifetimeName, Node, ParamName};
-use ty::{self, DefIdTree, GenericParamDefKind, TyCtxt};
-
-use errors::{Applicability, DiagnosticBuilder};
-use rustc::lint;
+use crate::hir::def::Def;
+use crate::hir::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE};
+use crate::hir::map::Map;
+use crate::hir::{GenericArg, GenericParam, ItemLocalId, LifetimeName, Node, ParamName};
+use crate::ty::{self, DefIdTree, GenericParamDefKind, TyCtxt};
+
+use crate::errors::{Applicability, DiagnosticBuilder};
+use crate::rustc::lint;
 use rustc_data_structures::sync::Lrc;
-use session::Session;
+use crate::session::Session;
 use std::borrow::Cow;
 use std::cell::Cell;
 use std::mem::replace;
@@ -23,10 +23,10 @@ use syntax::attr;
 use syntax::ptr::P;
 use syntax::symbol::keywords;
 use syntax_pos::Span;
-use util::nodemap::{DefIdMap, FxHashMap, FxHashSet, NodeMap, NodeSet};
+use crate::util::nodemap::{DefIdMap, FxHashMap, FxHashSet, NodeMap, NodeSet};
 
-use hir::intravisit::{self, NestedVisitorMap, Visitor};
-use hir::{self, GenericParamKind, LifetimeParamKind};
+use crate::hir::intravisit::{self, NestedVisitorMap, Visitor};
+use crate::hir::{self, GenericParamKind, LifetimeParamKind};
 
 /// The origin of a named lifetime definition.
 ///
@@ -216,7 +216,7 @@ pub struct ResolveLifetimes {
         FxHashMap<LocalDefId, Lrc<FxHashMap<ItemLocalId, Lrc<Vec<ObjectLifetimeDefault>>>>>,
 }
 
-impl_stable_hash_for!(struct ::middle::resolve_lifetime::ResolveLifetimes {
+impl_stable_hash_for!(struct crate::middle::resolve_lifetime::ResolveLifetimes {
     defs,
     late_bound,
     object_lifetime_defaults
diff --git a/src/librustc/middle/stability.rs b/src/librustc/middle/stability.rs
index 3717ee7143c55..85b5409465a8d 100644
--- a/src/librustc/middle/stability.rs
+++ b/src/librustc/middle/stability.rs
@@ -3,14 +3,14 @@
 
 pub use self::StabilityLevel::*;
 
-use lint::{self, Lint};
-use hir::{self, Item, Generics, StructField, Variant, HirId};
-use hir::def::Def;
-use hir::def_id::{CrateNum, CRATE_DEF_INDEX, DefId, LOCAL_CRATE};
-use hir::intravisit::{self, Visitor, NestedVisitorMap};
-use ty::query::Providers;
-use middle::privacy::AccessLevels;
-use session::{DiagnosticMessageId, Session};
+use crate::lint::{self, Lint};
+use crate::hir::{self, Item, Generics, StructField, Variant, HirId};
+use crate::hir::def::Def;
+use crate::hir::def_id::{CrateNum, CRATE_DEF_INDEX, DefId, LOCAL_CRATE};
+use crate::hir::intravisit::{self, Visitor, NestedVisitorMap};
+use crate::ty::query::Providers;
+use crate::middle::privacy::AccessLevels;
+use crate::session::{DiagnosticMessageId, Session};
 use syntax::symbol::Symbol;
 use syntax_pos::{Span, MultiSpan};
 use syntax::ast;
@@ -18,8 +18,8 @@ use syntax::ast::{NodeId, Attribute};
 use syntax::errors::Applicability;
 use syntax::feature_gate::{GateIssue, emit_feature_err};
 use syntax::attr::{self, Stability, Deprecation};
-use ty::{self, TyCtxt};
-use util::nodemap::{FxHashSet, FxHashMap};
+use crate::ty::{self, TyCtxt};
+use crate::util::nodemap::{FxHashSet, FxHashMap};
 
 use std::mem::replace;
 use std::cmp::Ordering;
diff --git a/src/librustc/middle/weak_lang_items.rs b/src/librustc/middle/weak_lang_items.rs
index 82f19cbb82a19..119e855c58551 100644
--- a/src/librustc/middle/weak_lang_items.rs
+++ b/src/librustc/middle/weak_lang_items.rs
@@ -1,18 +1,18 @@
 //! Validity checking for weak lang items
 
-use session::config;
-use middle::lang_items;
+use crate::session::config;
+use crate::middle::lang_items;
 
 use rustc_data_structures::fx::FxHashSet;
 use rustc_target::spec::PanicStrategy;
 use syntax::ast;
 use syntax::symbol::Symbol;
 use syntax_pos::Span;
-use hir::def_id::DefId;
-use hir::intravisit::{Visitor, NestedVisitorMap};
-use hir::intravisit;
-use hir;
-use ty::TyCtxt;
+use crate::hir::def_id::DefId;
+use crate::hir::intravisit::{Visitor, NestedVisitorMap};
+use crate::hir::intravisit;
+use crate::hir;
+use crate::ty::TyCtxt;
 
 macro_rules! weak_lang_items {
     ($($name:ident, $item:ident, $sym:ident;)*) => (
diff --git a/src/librustc/mir/cache.rs b/src/librustc/mir/cache.rs
index 56ab263c47740..1cc927b1f720f 100644
--- a/src/librustc/mir/cache.rs
+++ b/src/librustc/mir/cache.rs
@@ -2,10 +2,10 @@ use rustc_data_structures::indexed_vec::IndexVec;
 use rustc_data_structures::sync::{RwLock, MappedReadGuard, ReadGuard};
 use rustc_data_structures::stable_hasher::{HashStable, StableHasher,
                                            StableHasherResult};
-use ich::StableHashingContext;
-use mir::{Mir, BasicBlock};
+use crate::ich::StableHashingContext;
+use crate::mir::{Mir, BasicBlock};
 
-use rustc_serialize as serialize;
+use crate::rustc_serialize as serialize;
 
 #[derive(Clone, Debug)]
 pub struct Cache {
diff --git a/src/librustc/mir/interpret/allocation.rs b/src/librustc/mir/interpret/allocation.rs
index 7ed29c5afd03f..7761e1fdafac5 100644
--- a/src/librustc/mir/interpret/allocation.rs
+++ b/src/librustc/mir/interpret/allocation.rs
@@ -5,10 +5,10 @@ use super::{
     truncate,
 };
 
-use ty::layout::{Size, Align};
+use crate::ty::layout::{Size, Align};
 use syntax::ast::Mutability;
 use std::iter;
-use mir;
+use crate::mir;
 use std::ops::{Deref, DerefMut};
 use rustc_data_structures::sorted_map::SortedMap;
 use rustc_target::abi::HasDataLayout;
diff --git a/src/librustc/mir/interpret/error.rs b/src/librustc/mir/interpret/error.rs
index c3fe5d773ab16..870a51f95df1c 100644
--- a/src/librustc/mir/interpret/error.rs
+++ b/src/librustc/mir/interpret/error.rs
@@ -1,17 +1,17 @@
 use std::{fmt, env};
 
-use hir::map::definitions::DefPathData;
-use mir;
-use ty::{self, Ty, layout};
-use ty::layout::{Size, Align, LayoutError};
+use crate::hir::map::definitions::DefPathData;
+use crate::mir;
+use crate::ty::{self, Ty, layout};
+use crate::ty::layout::{Size, Align, LayoutError};
 use rustc_target::spec::abi::Abi;
 
 use super::{RawConst, Pointer, InboundsCheck, ScalarMaybeUndef};
 
 use backtrace::Backtrace;
 
-use ty::query::TyCtxtAt;
-use errors::DiagnosticBuilder;
+use crate::ty::query::TyCtxtAt;
+use crate::errors::DiagnosticBuilder;
 
 use syntax_pos::{Pos, Span};
 use syntax::ast;
@@ -42,7 +42,7 @@ pub type ConstEvalResult<'tcx> = Result<ty::Const<'tcx>, ErrorHandled>;
 #[derive(Clone, Debug, RustcEncodable, RustcDecodable)]
 pub struct ConstEvalErr<'tcx> {
     pub span: Span,
-    pub error: ::mir::interpret::EvalErrorKind<'tcx, u64>,
+    pub error: crate::mir::interpret::EvalErrorKind<'tcx, u64>,
     pub stacktrace: Vec<FrameInfo<'tcx>>,
 }
 
@@ -136,7 +136,7 @@ impl<'a, 'gcx, 'tcx> ConstEvalErr<'tcx> {
                 .next()
                 .unwrap_or(lint_root);
             tcx.struct_span_lint_node(
-                ::rustc::lint::builtin::CONST_ERR,
+                crate::rustc::lint::builtin::CONST_ERR,
                 node_id,
                 tcx.span,
                 message,
diff --git a/src/librustc/mir/interpret/mod.rs b/src/librustc/mir/interpret/mod.rs
index e6a560b2ad7b6..efd233f1f3854 100644
--- a/src/librustc/mir/interpret/mod.rs
+++ b/src/librustc/mir/interpret/mod.rs
@@ -25,17 +25,17 @@ pub use self::allocation::{
 pub use self::pointer::{Pointer, PointerArithmetic};
 
 use std::fmt;
-use mir;
-use hir::def_id::DefId;
-use ty::{self, TyCtxt, Instance};
-use ty::layout::{self, Size};
+use crate::mir;
+use crate::hir::def_id::DefId;
+use crate::ty::{self, TyCtxt, Instance};
+use crate::ty::layout::{self, Size};
 use std::io;
-use rustc_serialize::{Encoder, Decodable, Encodable};
+use crate::rustc_serialize::{Encoder, Decodable, Encodable};
 use rustc_data_structures::fx::FxHashMap;
 use rustc_data_structures::sync::{Lock as Mutex, HashMapExt};
 use rustc_data_structures::tiny_list::TinyList;
 use byteorder::{WriteBytesExt, ReadBytesExt, LittleEndian, BigEndian};
-use ty::codec::TyDecoder;
+use crate::ty::codec::TyDecoder;
 use std::sync::atomic::{AtomicU32, Ordering};
 use std::num::NonZeroU32;
 
@@ -53,8 +53,8 @@ pub struct GlobalId<'tcx> {
 #[derive(Copy, Clone, Eq, Hash, Ord, PartialEq, PartialOrd, Debug)]
 pub struct AllocId(pub u64);
 
-impl ::rustc_serialize::UseSpecializedEncodable for AllocId {}
-impl ::rustc_serialize::UseSpecializedDecodable for AllocId {}
+impl crate::rustc_serialize::UseSpecializedEncodable for AllocId {}
+impl crate::rustc_serialize::UseSpecializedDecodable for AllocId {}
 
 #[derive(RustcDecodable, RustcEncodable)]
 enum AllocDiscriminant {
diff --git a/src/librustc/mir/interpret/pointer.rs b/src/librustc/mir/interpret/pointer.rs
index 498c0b5b917e9..551e7b2fd41ec 100644
--- a/src/librustc/mir/interpret/pointer.rs
+++ b/src/librustc/mir/interpret/pointer.rs
@@ -1,5 +1,5 @@
-use mir;
-use ty::layout::{self, HasDataLayout, Size};
+use crate::mir;
+use crate::ty::layout::{self, HasDataLayout, Size};
 
 use super::{
     AllocId, EvalResult, InboundsCheck,
diff --git a/src/librustc/mir/interpret/value.rs b/src/librustc/mir/interpret/value.rs
index 1328a1aeeab96..73917342814de 100644
--- a/src/librustc/mir/interpret/value.rs
+++ b/src/librustc/mir/interpret/value.rs
@@ -515,7 +515,7 @@ impl<'tcx, Tag> ScalarMaybeUndef<Tag> {
     }
 }
 
-impl_stable_hash_for!(enum ::mir::interpret::ScalarMaybeUndef {
+impl_stable_hash_for!(enum crate::mir::interpret::ScalarMaybeUndef {
     Scalar(v),
     Undef
 });
diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs
index 82083b4f69964..009997bfcf2c4 100644
--- a/src/librustc/mir/mod.rs
+++ b/src/librustc/mir/mod.rs
@@ -2,11 +2,11 @@
 //!
 //! [rustc guide]: https://rust-lang.github.io/rustc-guide/mir/index.html
 
-use hir::def::CtorKind;
-use hir::def_id::DefId;
-use hir::{self, HirId, InlineAsm};
-use mir::interpret::{ConstValue, EvalErrorKind, Scalar};
-use mir::visit::MirVisitable;
+use crate::hir::def::CtorKind;
+use crate::hir::def_id::DefId;
+use crate::hir::{self, HirId, InlineAsm};
+use crate::mir::interpret::{ConstValue, EvalErrorKind, Scalar};
+use crate::mir::visit::MirVisitable;
 use rustc_apfloat::ieee::{Double, Single};
 use rustc_apfloat::Float;
 use rustc_data_structures::fx::FxHashSet;
@@ -15,7 +15,7 @@ use rustc_data_structures::graph::{self, GraphPredecessors, GraphSuccessors};
 use rustc_data_structures::indexed_vec::{Idx, IndexVec};
 use rustc_data_structures::sync::Lrc;
 use rustc_data_structures::sync::MappedReadGuard;
-use rustc_serialize::{self as serialize};
+use crate::rustc_serialize::{self as serialize};
 use smallvec::SmallVec;
 use std::borrow::Cow;
 use std::fmt::{self, Debug, Formatter, Write};
@@ -26,16 +26,16 @@ use std::{iter, mem, option, u32};
 use syntax::ast::{self, Name};
 use syntax::symbol::InternedString;
 use syntax_pos::{Span, DUMMY_SP};
-use ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
-use ty::subst::{Subst, Substs};
-use ty::layout::VariantIdx;
-use ty::{
+use crate::ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
+use crate::ty::subst::{Subst, Substs};
+use crate::ty::layout::VariantIdx;
+use crate::ty::{
     self, AdtDef, CanonicalUserTypeAnnotations, ClosureSubsts, GeneratorSubsts, Region, Ty, TyCtxt,
     UserTypeAnnotationIndex,
 };
-use util::ppaux;
+use crate::util::ppaux;
 
-pub use mir::interpret::AssertMessage;
+pub use crate::mir::interpret::AssertMessage;
 
 mod cache;
 pub mod interpret;
@@ -676,7 +676,7 @@ impl_stable_hash_for!(enum self::MirPhase {
 });
 
 mod binding_form_impl {
-    use ich::StableHashingContext;
+    use crate::ich::StableHashingContext;
     use rustc_data_structures::stable_hasher::{HashStable, StableHasher, StableHasherResult};
 
     impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for super::BindingForm<'tcx> {
@@ -2625,7 +2625,7 @@ CloneTypeFoldableAndLiftImpls! { ProjectionKind<'tcx>, }
 
 impl<'tcx> TypeFoldable<'tcx> for UserTypeProjection<'tcx> {
     fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
-        use mir::ProjectionElem::*;
+        use crate::mir::ProjectionElem::*;
 
         let base = self.base.fold_with(folder);
         let projs: Vec<_> = self.projs
@@ -2671,7 +2671,7 @@ pub fn fmt_lazy_const_val(f: &mut impl Write, const_val: &ty::LazyConst<'_>) ->
 
 /// Write a `ConstValue` in a way closer to the original source code than the `Debug` output.
 pub fn fmt_const_val(f: &mut impl Write, const_val: ty::Const<'_>) -> fmt::Result {
-    use ty::TyKind::*;
+    use crate::ty::TyKind::*;
     let value = const_val.val;
     let ty = const_val.ty;
     // print some primitives
@@ -3116,7 +3116,7 @@ EnumTypeFoldableImpl! {
 
 impl<'tcx> TypeFoldable<'tcx> for Terminator<'tcx> {
     fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
-        use mir::TerminatorKind::*;
+        use crate::mir::TerminatorKind::*;
 
         let kind = match self.kind {
             Goto { target } => Goto { target },
@@ -3229,7 +3229,7 @@ impl<'tcx> TypeFoldable<'tcx> for Terminator<'tcx> {
     }
 
     fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
-        use mir::TerminatorKind::*;
+        use crate::mir::TerminatorKind::*;
 
         match self.kind {
             SwitchInt {
@@ -3301,7 +3301,7 @@ impl<'tcx> TypeFoldable<'tcx> for Place<'tcx> {
 
 impl<'tcx> TypeFoldable<'tcx> for Rvalue<'tcx> {
     fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
-        use mir::Rvalue::*;
+        use crate::mir::Rvalue::*;
         match *self {
             Use(ref op) => Use(op.fold_with(folder)),
             Repeat(ref op, len) => Repeat(op.fold_with(folder), len),
@@ -3343,7 +3343,7 @@ impl<'tcx> TypeFoldable<'tcx> for Rvalue<'tcx> {
     }
 
     fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
-        use mir::Rvalue::*;
+        use crate::mir::Rvalue::*;
         match *self {
             Use(ref op) => op.visit_with(visitor),
             Repeat(ref op, _) => op.visit_with(visitor),
@@ -3395,7 +3395,7 @@ where
     T: TypeFoldable<'tcx>,
 {
     fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
-        use mir::ProjectionElem::*;
+        use crate::mir::ProjectionElem::*;
 
         let base = self.base.fold_with(folder);
         let elem = match self.elem {
@@ -3409,7 +3409,7 @@ where
     }
 
     fn super_visit_with<Vs: TypeVisitor<'tcx>>(&self, visitor: &mut Vs) -> bool {
-        use mir::ProjectionElem::*;
+        use crate::mir::ProjectionElem::*;
 
         self.base.visit_with(visitor) || match self.elem {
             Field(_, ref ty) => ty.visit_with(visitor),
diff --git a/src/librustc/mir/mono.rs b/src/librustc/mir/mono.rs
index 55f5c36cde66d..affa9f9fdd4d7 100644
--- a/src/librustc/mir/mono.rs
+++ b/src/librustc/mir/mono.rs
@@ -1,12 +1,12 @@
-use hir::def_id::{DefId, CrateNum, LOCAL_CRATE};
+use crate::hir::def_id::{DefId, CrateNum, LOCAL_CRATE};
 use syntax::ast::NodeId;
 use syntax::symbol::{Symbol, InternedString};
-use ty::{Instance, TyCtxt};
-use util::nodemap::FxHashMap;
+use crate::ty::{Instance, TyCtxt};
+use crate::util::nodemap::FxHashMap;
 use rustc_data_structures::base_n;
 use rustc_data_structures::stable_hasher::{HashStable, StableHasherResult,
                                            StableHasher};
-use ich::{Fingerprint, StableHashingContext, NodeIdHashingMode};
+use crate::ich::{Fingerprint, StableHashingContext, NodeIdHashingMode};
 use std::fmt;
 use std::hash::Hash;
 
diff --git a/src/librustc/mir/tcx.rs b/src/librustc/mir/tcx.rs
index 649370059f0ea..ac3a97898b405 100644
--- a/src/librustc/mir/tcx.rs
+++ b/src/librustc/mir/tcx.rs
@@ -3,12 +3,12 @@
  * building is complete.
  */
 
-use mir::*;
-use ty::subst::{Subst, Substs};
-use ty::{self, AdtDef, Ty, TyCtxt};
-use ty::layout::VariantIdx;
-use hir;
-use ty::util::IntTypeExt;
+use crate::mir::*;
+use crate::ty::subst::{Subst, Substs};
+use crate::ty::{self, AdtDef, Ty, TyCtxt};
+use crate::ty::layout::VariantIdx;
+use crate::hir;
+use crate::ty::util::IntTypeExt;
 
 #[derive(Copy, Clone, Debug)]
 pub enum PlaceTy<'tcx> {
diff --git a/src/librustc/mir/visit.rs b/src/librustc/mir/visit.rs
index 598303f29328f..0180256661630 100644
--- a/src/librustc/mir/visit.rs
+++ b/src/librustc/mir/visit.rs
@@ -1,7 +1,7 @@
-use hir::def_id::DefId;
-use ty::subst::Substs;
-use ty::{CanonicalUserTypeAnnotation, ClosureSubsts, GeneratorSubsts, Region, Ty};
-use mir::*;
+use crate::hir::def_id::DefId;
+use crate::ty::subst::Substs;
+use crate::ty::{CanonicalUserTypeAnnotation, ClosureSubsts, GeneratorSubsts, Region, Ty};
+use crate::mir::*;
 use syntax_pos::Span;
 
 // # The MIR Visitor
@@ -567,7 +567,7 @@ macro_rules! make_mir_visitor {
             fn super_assert_message(&mut self,
                                     msg: & $($mutability)* AssertMessage<'tcx>,
                                     location: Location) {
-                use mir::interpret::EvalErrorKind::*;
+                use crate::mir::interpret::EvalErrorKind::*;
                 if let BoundsCheck {
                         ref $($mutability)* len,
                         ref $($mutability)* index
diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs
index 86f676fbf888a..f8de61f146337 100644
--- a/src/librustc/session/config.rs
+++ b/src/librustc/session/config.rs
@@ -3,13 +3,13 @@
 
 use std::str::FromStr;
 
-use session::{early_error, early_warn, Session};
-use session::search_paths::SearchPath;
+use crate::session::{early_error, early_warn, Session};
+use crate::session::search_paths::SearchPath;
 
 use rustc_target::spec::{LinkerFlavor, MergeFunctions, PanicStrategy, RelroLevel};
 use rustc_target::spec::{Target, TargetTriple};
-use lint;
-use middle::cstore;
+use crate::lint;
+use crate::middle::cstore;
 
 use syntax::ast::{self, IntTy, UintTy, MetaItemKind};
 use syntax::source_map::{FileName, FilePathMapping};
@@ -19,7 +19,7 @@ use syntax::parse;
 use syntax::symbol::Symbol;
 use syntax::feature_gate::UnstableFeatures;
 
-use errors::{ColorConfig, FatalError, Handler};
+use crate::errors::{ColorConfig, FatalError, Handler};
 
 use getopts;
 use std::collections::{BTreeMap, BTreeSet};
@@ -2342,7 +2342,7 @@ pub mod nightly_options {
     use getopts;
     use syntax::feature_gate::UnstableFeatures;
     use super::{ErrorOutputType, OptionStability, RustcOptGroup};
-    use session::early_error;
+    use crate::session::early_error;
 
     pub fn is_unstable_enabled(matches: &getopts::Matches) -> bool {
         is_nightly_build()
@@ -2431,8 +2431,8 @@ impl fmt::Display for CrateType {
 /// we have an opt-in scheme here, so one is hopefully forced to think about
 /// how the hash should be calculated when adding a new command-line argument.
 mod dep_tracking {
-    use lint;
-    use middle::cstore;
+    use crate::lint;
+    use crate::middle::cstore;
     use std::collections::BTreeMap;
     use std::hash::Hash;
     use std::path::PathBuf;
@@ -2565,14 +2565,14 @@ mod dep_tracking {
 
 #[cfg(test)]
 mod tests {
-    use errors;
+    use crate::errors;
     use getopts;
-    use lint;
-    use middle::cstore;
-    use session::config::{build_configuration, build_session_options_and_crate_config};
-    use session::config::{LtoCli, CrossLangLto};
-    use session::build_session;
-    use session::search_paths::SearchPath;
+    use crate::lint;
+    use crate::middle::cstore;
+    use crate::session::config::{build_configuration, build_session_options_and_crate_config};
+    use crate::session::config::{LtoCli, CrossLangLto};
+    use crate::session::build_session;
+    use crate::session::search_paths::SearchPath;
     use std::collections::{BTreeMap, BTreeSet};
     use std::iter::FromIterator;
     use std::path::PathBuf;
diff --git a/src/librustc/session/filesearch.rs b/src/librustc/session/filesearch.rs
index 19f1c7a18fad1..77f190e281229 100644
--- a/src/librustc/session/filesearch.rs
+++ b/src/librustc/session/filesearch.rs
@@ -7,7 +7,7 @@ use std::env;
 use std::fs;
 use std::path::{Path, PathBuf};
 
-use session::search_paths::{SearchPath, PathKind};
+use crate::session::search_paths::{SearchPath, PathKind};
 use rustc_fs_util::fix_windows_verbatim_for_gcc;
 
 #[derive(Copy, Clone)]
diff --git a/src/librustc/session/mod.rs b/src/librustc/session/mod.rs
index c5034415d6ffb..d2beb64b38861 100644
--- a/src/librustc/session/mod.rs
+++ b/src/librustc/session/mod.rs
@@ -1,19 +1,19 @@
 pub use self::code_stats::{DataTypeKind, SizeKind, FieldInfo, VariantInfo};
 use self::code_stats::CodeStats;
 
-use dep_graph::cgu_reuse_tracker::CguReuseTracker;
-use hir::def_id::CrateNum;
+use crate::dep_graph::cgu_reuse_tracker::CguReuseTracker;
+use crate::hir::def_id::CrateNum;
 use rustc_data_structures::fingerprint::Fingerprint;
 
-use lint;
-use lint::builtin::BuiltinLintDiagnostics;
-use middle::allocator::AllocatorKind;
-use middle::dependency_format;
-use session::config::{OutputType, Lto};
-use session::search_paths::{PathKind, SearchPath};
-use util::nodemap::{FxHashMap, FxHashSet};
-use util::common::{duration_to_secs_str, ErrorReported};
-use util::common::ProfileQueriesMsg;
+use crate::lint;
+use crate::lint::builtin::BuiltinLintDiagnostics;
+use crate::middle::allocator::AllocatorKind;
+use crate::middle::dependency_format;
+use crate::session::config::{OutputType, Lto};
+use crate::session::search_paths::{PathKind, SearchPath};
+use crate::util::nodemap::{FxHashMap, FxHashSet};
+use crate::util::common::{duration_to_secs_str, ErrorReported};
+use crate::util::common::ProfileQueriesMsg;
 
 use rustc_data_structures::base_n;
 use rustc_data_structures::sync::{
@@ -21,8 +21,8 @@ use rustc_data_structures::sync::{
     Ordering::SeqCst,
 };
 
-use errors::{self, DiagnosticBuilder, DiagnosticId, Applicability};
-use errors::emitter::{Emitter, EmitterWriter};
+use crate::errors::{self, DiagnosticBuilder, DiagnosticId, Applicability};
+use crate::errors::emitter::{Emitter, EmitterWriter};
 use syntax::ast::{self, NodeId};
 use syntax::edition::Edition;
 use syntax::feature_gate::{self, AttributeType};
@@ -30,7 +30,7 @@ use syntax::json::JsonEmitter;
 use syntax::source_map;
 use syntax::parse::{self, ParseSess};
 use syntax_pos::{MultiSpan, Span};
-use util::profiling::SelfProfiler;
+use crate::util::profiling::SelfProfiler;
 
 use rustc_target::spec::{PanicStrategy, RelroLevel, Target, TargetTriple};
 use rustc_data_structures::flock;
diff --git a/src/librustc/session/search_paths.rs b/src/librustc/session/search_paths.rs
index 85d64b1571266..a950258cefd0c 100644
--- a/src/librustc/session/search_paths.rs
+++ b/src/librustc/session/search_paths.rs
@@ -1,6 +1,6 @@
 use std::path::{Path, PathBuf};
-use session::{early_error, config};
-use session::filesearch::make_target_lib_path;
+use crate::session::{early_error, config};
+use crate::session::filesearch::make_target_lib_path;
 
 #[derive(Clone, Debug)]
 pub struct SearchPath {
diff --git a/src/librustc/traits/auto_trait.rs b/src/librustc/traits/auto_trait.rs
index 92004ece26d00..d1db49e05f190 100644
--- a/src/librustc/traits/auto_trait.rs
+++ b/src/librustc/traits/auto_trait.rs
@@ -6,12 +6,12 @@ use super::*;
 use std::collections::hash_map::Entry;
 use std::collections::VecDeque;
 
-use infer::region_constraints::{Constraint, RegionConstraintData};
-use infer::InferCtxt;
+use crate::infer::region_constraints::{Constraint, RegionConstraintData};
+use crate::infer::InferCtxt;
 use rustc_data_structures::fx::{FxHashMap, FxHashSet};
 
-use ty::fold::TypeFolder;
-use ty::{Region, RegionVid};
+use crate::ty::fold::TypeFolder;
+use crate::ty::{Region, RegionVid};
 
 // FIXME(twk): this is obviously not nice to duplicate like that
 #[derive(Eq, PartialEq, Hash, Copy, Clone, Debug)]
diff --git a/src/librustc/traits/chalk_fulfill.rs b/src/librustc/traits/chalk_fulfill.rs
index df4e08e0eb5f3..d9eb6d8157dfb 100644
--- a/src/librustc/traits/chalk_fulfill.rs
+++ b/src/librustc/traits/chalk_fulfill.rs
@@ -1,4 +1,4 @@
-use traits::{
+use crate::traits::{
     Environment,
     InEnvironment,
     TraitEngine,
@@ -8,10 +8,10 @@ use traits::{
     FulfillmentErrorCode,
     SelectionError,
 };
-use traits::query::NoSolution;
-use infer::InferCtxt;
-use infer::canonical::{Canonical, OriginalQueryValues};
-use ty::{self, Ty};
+use crate::traits::query::NoSolution;
+use crate::infer::InferCtxt;
+use crate::infer::canonical::{Canonical, OriginalQueryValues};
+use crate::ty::{self, Ty};
 use rustc_data_structures::fx::FxHashSet;
 
 pub type CanonicalGoal<'tcx> = Canonical<'tcx, InEnvironment<'tcx, ty::Predicate<'tcx>>>;
diff --git a/src/librustc/traits/codegen/mod.rs b/src/librustc/traits/codegen/mod.rs
index 94d56c2cbfc88..eed9345afae16 100644
--- a/src/librustc/traits/codegen/mod.rs
+++ b/src/librustc/traits/codegen/mod.rs
@@ -3,16 +3,16 @@
 // seems likely that they should eventually be merged into more
 // general routines.
 
-use dep_graph::{DepKind, DepTrackingMapConfig};
+use crate::dep_graph::{DepKind, DepTrackingMapConfig};
 use std::marker::PhantomData;
 use syntax_pos::DUMMY_SP;
-use infer::InferCtxt;
+use crate::infer::InferCtxt;
 use syntax_pos::Span;
-use traits::{FulfillmentContext, Obligation, ObligationCause, SelectionContext,
+use crate::traits::{FulfillmentContext, Obligation, ObligationCause, SelectionContext,
              TraitEngine, Vtable};
-use ty::{self, Ty, TyCtxt};
-use ty::subst::{Subst, Substs};
-use ty::fold::TypeFoldable;
+use crate::ty::{self, Ty, TyCtxt};
+use crate::ty::subst::{Subst, Substs};
+use crate::ty::fold::TypeFoldable;
 
 /// Attempts to resolve an obligation to a vtable.. The result is
 /// a shallow vtable resolution -- meaning that we do not
diff --git a/src/librustc/traits/coherence.rs b/src/librustc/traits/coherence.rs
index 4c7049c366207..4fe7a1507f737 100644
--- a/src/librustc/traits/coherence.rs
+++ b/src/librustc/traits/coherence.rs
@@ -4,17 +4,17 @@
 //! [trait-resolution]: https://rust-lang.github.io/rustc-guide/traits/resolution.html
 //! [trait-specialization]: https://rust-lang.github.io/rustc-guide/traits/specialization.html
 
-use infer::CombinedSnapshot;
-use hir::def_id::{DefId, LOCAL_CRATE};
+use crate::infer::CombinedSnapshot;
+use crate::hir::def_id::{DefId, LOCAL_CRATE};
 use syntax_pos::DUMMY_SP;
-use traits::{self, Normalized, SelectionContext, Obligation, ObligationCause};
-use traits::IntercrateMode;
-use traits::select::IntercrateAmbiguityCause;
-use ty::{self, Ty, TyCtxt};
-use ty::fold::TypeFoldable;
-use ty::subst::Subst;
+use crate::traits::{self, Normalized, SelectionContext, Obligation, ObligationCause};
+use crate::traits::IntercrateMode;
+use crate::traits::select::IntercrateAmbiguityCause;
+use crate::ty::{self, Ty, TyCtxt};
+use crate::ty::fold::TypeFoldable;
+use crate::ty::subst::Subst;
 
-use infer::{InferOk};
+use crate::infer::{InferOk};
 
 /// Whether we do the orphan check relative to this crate or
 /// to some remote crate.
@@ -39,7 +39,7 @@ pub struct OverlapResult<'tcx> {
     pub involves_placeholder: bool,
 }
 
-pub fn add_placeholder_note(err: &mut ::errors::DiagnosticBuilder<'_>) {
+pub fn add_placeholder_note(err: &mut crate::errors::DiagnosticBuilder<'_>) {
     err.note(&format!(
         "this behavior recently changed as a result of a bug fix; \
          see rust-lang/rust#56105 for details"
diff --git a/src/librustc/traits/engine.rs b/src/librustc/traits/engine.rs
index c759a9ddf2ce6..2f019d823ff5d 100644
--- a/src/librustc/traits/engine.rs
+++ b/src/librustc/traits/engine.rs
@@ -1,7 +1,7 @@
-use infer::InferCtxt;
-use ty::{self, Ty, TyCtxt, ToPredicate};
-use traits::Obligation;
-use hir::def_id::DefId;
+use crate::infer::InferCtxt;
+use crate::ty::{self, Ty, TyCtxt, ToPredicate};
+use crate::traits::Obligation;
+use crate::hir::def_id::DefId;
 
 use super::{ChalkFulfillmentContext, FulfillmentContext, FulfillmentError};
 use super::{ObligationCause, PredicateObligation};
diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs
index ea3ea59c7613f..79afc593a4676 100644
--- a/src/librustc/traits/error_reporting.rs
+++ b/src/librustc/traits/error_reporting.rs
@@ -17,23 +17,23 @@ use super::{
     Overflow,
 };
 
-use errors::{Applicability, DiagnosticBuilder};
-use hir;
-use hir::Node;
-use hir::def_id::DefId;
-use infer::{self, InferCtxt};
-use infer::type_variable::TypeVariableOrigin;
+use crate::errors::{Applicability, DiagnosticBuilder};
+use crate::hir;
+use crate::hir::Node;
+use crate::hir::def_id::DefId;
+use crate::infer::{self, InferCtxt};
+use crate::infer::type_variable::TypeVariableOrigin;
 use std::fmt;
 use syntax::ast;
-use session::DiagnosticMessageId;
-use ty::{self, AdtKind, ToPredicate, ToPolyTraitRef, Ty, TyCtxt, TypeFoldable};
-use ty::GenericParamDefKind;
-use ty::error::ExpectedFound;
-use ty::fast_reject;
-use ty::fold::TypeFolder;
-use ty::subst::Subst;
-use ty::SubtypePredicate;
-use util::nodemap::{FxHashMap, FxHashSet};
+use crate::session::DiagnosticMessageId;
+use crate::ty::{self, AdtKind, ToPredicate, ToPolyTraitRef, Ty, TyCtxt, TypeFoldable};
+use crate::ty::GenericParamDefKind;
+use crate::ty::error::ExpectedFound;
+use crate::ty::fast_reject;
+use crate::ty::fold::TypeFolder;
+use crate::ty::subst::Subst;
+use crate::ty::SubtypePredicate;
+use crate::util::nodemap::{FxHashMap, FxHashSet};
 
 use syntax_pos::{DUMMY_SP, Span, ExpnInfo, ExpnFormat};
 
diff --git a/src/librustc/traits/fulfill.rs b/src/librustc/traits/fulfill.rs
index 2e00d4d4b7c3b..98784bccb6f82 100644
--- a/src/librustc/traits/fulfill.rs
+++ b/src/librustc/traits/fulfill.rs
@@ -1,7 +1,7 @@
-use infer::InferCtxt;
-use mir::interpret::{GlobalId, ErrorHandled};
-use ty::{self, Ty, TypeFoldable, ToPolyTraitRef};
-use ty::error::ExpectedFound;
+use crate::infer::InferCtxt;
+use crate::mir::interpret::{GlobalId, ErrorHandled};
+use crate::ty::{self, Ty, TypeFoldable, ToPolyTraitRef};
+use crate::ty::error::ExpectedFound;
 use rustc_data_structures::obligation_forest::{DoCompleted, Error, ForestObligation};
 use rustc_data_structures::obligation_forest::{ObligationForest, ObligationProcessor};
 use rustc_data_structures::obligation_forest::{ProcessResult};
diff --git a/src/librustc/traits/mod.rs b/src/librustc/traits/mod.rs
index 68383bef37a6a..d1be8d377a84d 100644
--- a/src/librustc/traits/mod.rs
+++ b/src/librustc/traits/mod.rs
@@ -20,20 +20,20 @@ mod util;
 pub mod query;
 
 use chalk_engine;
-use hir;
-use hir::def_id::DefId;
-use infer::{InferCtxt, SuppressRegionErrors};
-use infer::outlives::env::OutlivesEnvironment;
-use middle::region;
-use mir::interpret::ErrorHandled;
+use crate::hir;
+use crate::hir::def_id::DefId;
+use crate::infer::{InferCtxt, SuppressRegionErrors};
+use crate::infer::outlives::env::OutlivesEnvironment;
+use crate::middle::region;
+use crate::mir::interpret::ErrorHandled;
 use rustc_data_structures::sync::Lrc;
 use syntax::ast;
 use syntax_pos::{Span, DUMMY_SP};
-use ty::subst::Substs;
-use ty::{self, AdtKind, List, Ty, TyCtxt, GenericParamDefKind, ToPredicate};
-use ty::error::{ExpectedFound, TypeError};
-use ty::fold::{TypeFolder, TypeFoldable, TypeVisitor};
-use util::common::ErrorReported;
+use crate::ty::subst::Substs;
+use crate::ty::{self, AdtKind, List, Ty, TyCtxt, GenericParamDefKind, ToPredicate};
+use crate::ty::error::{ExpectedFound, TypeError};
+use crate::ty::fold::{TypeFolder, TypeFoldable, TypeVisitor};
+use crate::util::common::ErrorReported;
 
 use std::fmt::Debug;
 use std::rc::Rc;
diff --git a/src/librustc/traits/object_safety.rs b/src/librustc/traits/object_safety.rs
index c37dc2a855ed0..75eaa67e767c2 100644
--- a/src/librustc/traits/object_safety.rs
+++ b/src/librustc/traits/object_safety.rs
@@ -10,11 +10,11 @@
 
 use super::elaborate_predicates;
 
-use hir::def_id::DefId;
-use lint;
-use traits::{self, Obligation, ObligationCause};
-use ty::{self, Ty, TyCtxt, TypeFoldable, Predicate, ToPredicate};
-use ty::subst::{Subst, Substs};
+use crate::hir::def_id::DefId;
+use crate::lint;
+use crate::traits::{self, Obligation, ObligationCause};
+use crate::ty::{self, Ty, TyCtxt, TypeFoldable, Predicate, ToPredicate};
+use crate::ty::subst::{Subst, Substs};
 use std::borrow::Cow;
 use std::iter::{self};
 use syntax::ast::{self, Name};
@@ -341,7 +341,7 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
             } else {
                 // sanity check to make sure the receiver actually has the layout of a pointer
 
-                use ty::layout::Abi;
+                use crate::ty::layout::Abi;
 
                 let param_env = self.param_env(method.def_id);
 
diff --git a/src/librustc/traits/on_unimplemented.rs b/src/librustc/traits/on_unimplemented.rs
index 3ec901f50e4cc..f61c32614cc93 100644
--- a/src/librustc/traits/on_unimplemented.rs
+++ b/src/librustc/traits/on_unimplemented.rs
@@ -1,9 +1,9 @@
 use fmt_macros::{Parser, Piece, Position};
 
-use hir::def_id::DefId;
-use ty::{self, TyCtxt, GenericParamDefKind};
-use util::common::ErrorReported;
-use util::nodemap::FxHashMap;
+use crate::hir::def_id::DefId;
+use crate::ty::{self, TyCtxt, GenericParamDefKind};
+use crate::util::common::ErrorReported;
+use crate::util::nodemap::FxHashMap;
 
 use syntax::ast::{MetaItem, NestedMetaItem};
 use syntax::attr;
diff --git a/src/librustc/traits/project.rs b/src/librustc/traits/project.rs
index bec45046cb93e..99107a1a6d4e1 100644
--- a/src/librustc/traits/project.rs
+++ b/src/librustc/traits/project.rs
@@ -12,16 +12,16 @@ use super::SelectionError;
 use super::{VtableImplData, VtableClosureData, VtableGeneratorData, VtableFnPointerData};
 use super::util;
 
-use hir::def_id::DefId;
-use infer::{InferCtxt, InferOk, LateBoundRegionConversionTime};
-use infer::type_variable::TypeVariableOrigin;
-use mir::interpret::{GlobalId};
+use crate::hir::def_id::DefId;
+use crate::infer::{InferCtxt, InferOk, LateBoundRegionConversionTime};
+use crate::infer::type_variable::TypeVariableOrigin;
+use crate::mir::interpret::{GlobalId};
 use rustc_data_structures::snapshot_map::{Snapshot, SnapshotMap};
 use syntax::ast::Ident;
-use ty::subst::{Subst, Substs};
-use ty::{self, ToPredicate, ToPolyTraitRef, Ty, TyCtxt};
-use ty::fold::{TypeFoldable, TypeFolder};
-use util::common::FN_OUTPUT_NAME;
+use crate::ty::subst::{Subst, Substs};
+use crate::ty::{self, ToPredicate, ToPolyTraitRef, Ty, TyCtxt};
+use crate::ty::fold::{TypeFoldable, TypeFolder};
+use crate::util::common::FN_OUTPUT_NAME;
 
 /// Depending on the stage of compilation, we want projection to be
 /// more or less conservative.
diff --git a/src/librustc/traits/query/dropck_outlives.rs b/src/librustc/traits/query/dropck_outlives.rs
index 1fd2172212d3c..47ca416e6b5aa 100644
--- a/src/librustc/traits/query/dropck_outlives.rs
+++ b/src/librustc/traits/query/dropck_outlives.rs
@@ -1,10 +1,10 @@
-use infer::at::At;
-use infer::InferOk;
-use infer::canonical::OriginalQueryValues;
+use crate::infer::at::At;
+use crate::infer::InferOk;
+use crate::infer::canonical::OriginalQueryValues;
 use std::iter::FromIterator;
 use syntax::source_map::Span;
-use ty::subst::Kind;
-use ty::{self, Ty, TyCtxt};
+use crate::ty::subst::Kind;
+use crate::ty::{self, Ty, TyCtxt};
 
 impl<'cx, 'gcx, 'tcx> At<'cx, 'gcx, 'tcx> {
     /// Given a type `ty` of some value being dropped, computes a set
diff --git a/src/librustc/traits/query/evaluate_obligation.rs b/src/librustc/traits/query/evaluate_obligation.rs
index fdae7d833734e..d5230f15c2565 100644
--- a/src/librustc/traits/query/evaluate_obligation.rs
+++ b/src/librustc/traits/query/evaluate_obligation.rs
@@ -1,6 +1,6 @@
-use infer::InferCtxt;
-use infer::canonical::OriginalQueryValues;
-use traits::{EvaluationResult, PredicateObligation, SelectionContext,
+use crate::infer::InferCtxt;
+use crate::infer::canonical::OriginalQueryValues;
+use crate::traits::{EvaluationResult, PredicateObligation, SelectionContext,
              TraitQueryMode, OverflowError};
 
 impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
diff --git a/src/librustc/traits/query/method_autoderef.rs b/src/librustc/traits/query/method_autoderef.rs
index b4984e1237857..6b9bdfd63f4d0 100644
--- a/src/librustc/traits/query/method_autoderef.rs
+++ b/src/librustc/traits/query/method_autoderef.rs
@@ -1,6 +1,6 @@
 use rustc_data_structures::sync::Lrc;
-use infer::canonical::{Canonical, QueryResponse};
-use ty::Ty;
+use crate::infer::canonical::{Canonical, QueryResponse};
+use crate::ty::Ty;
 
 #[derive(Debug)]
 pub struct CandidateStep<'tcx> {
diff --git a/src/librustc/traits/query/mod.rs b/src/librustc/traits/query/mod.rs
index 59f786025b224..112a1d0e09c94 100644
--- a/src/librustc/traits/query/mod.rs
+++ b/src/librustc/traits/query/mod.rs
@@ -5,9 +5,9 @@
 //! The providers for the queries defined here can be found in
 //! `librustc_traits`.
 
-use infer::canonical::Canonical;
-use ty::error::TypeError;
-use ty::{self, Ty};
+use crate::infer::canonical::Canonical;
+use crate::ty::error::TypeError;
+use crate::ty::{self, Ty};
 
 pub mod dropck_outlives;
 pub mod evaluate_obligation;
diff --git a/src/librustc/traits/query/normalize.rs b/src/librustc/traits/query/normalize.rs
index be05445cfc61a..f477f161bbb32 100644
--- a/src/librustc/traits/query/normalize.rs
+++ b/src/librustc/traits/query/normalize.rs
@@ -2,15 +2,15 @@
 //! which folds deeply, invoking the underlying
 //! `normalize_projection_ty` query when it encounters projections.
 
-use infer::at::At;
-use infer::canonical::OriginalQueryValues;
-use infer::{InferCtxt, InferOk};
-use mir::interpret::GlobalId;
-use traits::project::Normalized;
-use traits::{Obligation, ObligationCause, PredicateObligation, Reveal};
-use ty::fold::{TypeFoldable, TypeFolder};
-use ty::subst::{Subst, Substs};
-use ty::{self, Ty, TyCtxt};
+use crate::infer::at::At;
+use crate::infer::canonical::OriginalQueryValues;
+use crate::infer::{InferCtxt, InferOk};
+use crate::mir::interpret::GlobalId;
+use crate::traits::project::Normalized;
+use crate::traits::{Obligation, ObligationCause, PredicateObligation, Reveal};
+use crate::ty::fold::{TypeFoldable, TypeFolder};
+use crate::ty::subst::{Subst, Substs};
+use crate::ty::{self, Ty, TyCtxt};
 
 use super::NoSolution;
 
diff --git a/src/librustc/traits/query/normalize_erasing_regions.rs b/src/librustc/traits/query/normalize_erasing_regions.rs
index e7034065bdf2e..4fc61077e268a 100644
--- a/src/librustc/traits/query/normalize_erasing_regions.rs
+++ b/src/librustc/traits/query/normalize_erasing_regions.rs
@@ -7,8 +7,8 @@
 //! `normalize_ty_after_erasing_regions` query for each type found
 //! within. (This underlying query is what is cached.)
 
-use ty::{self, Ty, TyCtxt};
-use ty::fold::{TypeFoldable, TypeFolder};
+use crate::ty::{self, Ty, TyCtxt};
+use crate::ty::fold::{TypeFoldable, TypeFolder};
 
 impl<'cx, 'tcx> TyCtxt<'cx, 'tcx, 'tcx> {
     /// Erase the regions in `value` and then fully normalize all the
diff --git a/src/librustc/traits/query/outlives_bounds.rs b/src/librustc/traits/query/outlives_bounds.rs
index 1134cb1b2f5d0..e57236b999bab 100644
--- a/src/librustc/traits/query/outlives_bounds.rs
+++ b/src/librustc/traits/query/outlives_bounds.rs
@@ -1,12 +1,12 @@
-use infer::InferCtxt;
-use infer::canonical::OriginalQueryValues;
+use crate::infer::InferCtxt;
+use crate::infer::canonical::OriginalQueryValues;
 use syntax::ast;
 use syntax::source_map::Span;
-use traits::{FulfillmentContext, ObligationCause, TraitEngine, TraitEngineExt};
-use traits::query::NoSolution;
-use ty::{self, Ty, TyCtxt};
+use crate::traits::{FulfillmentContext, ObligationCause, TraitEngine, TraitEngineExt};
+use crate::traits::query::NoSolution;
+use crate::ty::{self, Ty, TyCtxt};
 
-use ich::StableHashingContext;
+use crate::ich::StableHashingContext;
 use rustc_data_structures::stable_hasher::{HashStable, StableHasher,
                                            StableHasherResult};
 use std::mem;
diff --git a/src/librustc/traits/query/type_op/ascribe_user_type.rs b/src/librustc/traits/query/type_op/ascribe_user_type.rs
index 15f627b3ee8c4..d9f573eb7e291 100644
--- a/src/librustc/traits/query/type_op/ascribe_user_type.rs
+++ b/src/librustc/traits/query/type_op/ascribe_user_type.rs
@@ -1,8 +1,8 @@
-use infer::canonical::{Canonical, Canonicalized, CanonicalizedQueryResponse, QueryResponse};
-use traits::query::Fallible;
-use hir::def_id::DefId;
-use ty::{ParamEnvAnd, Ty, TyCtxt};
-use ty::subst::UserSubsts;
+use crate::infer::canonical::{Canonical, Canonicalized, CanonicalizedQueryResponse, QueryResponse};
+use crate::traits::query::Fallible;
+use crate::hir::def_id::DefId;
+use crate::ty::{ParamEnvAnd, Ty, TyCtxt};
+use crate::ty::subst::UserSubsts;
 
 #[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
 pub struct AscribeUserType<'tcx> {
diff --git a/src/librustc/traits/query/type_op/custom.rs b/src/librustc/traits/query/type_op/custom.rs
index 0756d2eed8aea..7e38282cc1adc 100644
--- a/src/librustc/traits/query/type_op/custom.rs
+++ b/src/librustc/traits/query/type_op/custom.rs
@@ -1,12 +1,12 @@
-use infer::{InferCtxt, InferOk};
+use crate::infer::{InferCtxt, InferOk};
 use std::fmt;
-use traits::query::Fallible;
+use crate::traits::query::Fallible;
 
-use infer::canonical::query_response;
-use infer::canonical::QueryRegionConstraint;
+use crate::infer::canonical::query_response;
+use crate::infer::canonical::QueryRegionConstraint;
 use std::rc::Rc;
 use syntax::source_map::DUMMY_SP;
-use traits::{ObligationCause, TraitEngine, TraitEngineExt};
+use crate::traits::{ObligationCause, TraitEngine, TraitEngineExt};
 
 pub struct CustomTypeOp<F, G> {
     closure: F,
diff --git a/src/librustc/traits/query/type_op/eq.rs b/src/librustc/traits/query/type_op/eq.rs
index 7acb8ccb0d319..5c3ccc9a99537 100644
--- a/src/librustc/traits/query/type_op/eq.rs
+++ b/src/librustc/traits/query/type_op/eq.rs
@@ -1,6 +1,6 @@
-use infer::canonical::{Canonical, Canonicalized, CanonicalizedQueryResponse, QueryResponse};
-use traits::query::Fallible;
-use ty::{ParamEnvAnd, Ty, TyCtxt};
+use crate::infer::canonical::{Canonical, Canonicalized, CanonicalizedQueryResponse, QueryResponse};
+use crate::traits::query::Fallible;
+use crate::ty::{ParamEnvAnd, Ty, TyCtxt};
 
 #[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
 pub struct Eq<'tcx> {
diff --git a/src/librustc/traits/query/type_op/implied_outlives_bounds.rs b/src/librustc/traits/query/type_op/implied_outlives_bounds.rs
index f4a825a669b48..c48ca33b13fbc 100644
--- a/src/librustc/traits/query/type_op/implied_outlives_bounds.rs
+++ b/src/librustc/traits/query/type_op/implied_outlives_bounds.rs
@@ -1,7 +1,7 @@
-use infer::canonical::{Canonical, Canonicalized, CanonicalizedQueryResponse, QueryResponse};
-use traits::query::outlives_bounds::OutlivesBound;
-use traits::query::Fallible;
-use ty::{ParamEnvAnd, Ty, TyCtxt};
+use crate::infer::canonical::{Canonical, Canonicalized, CanonicalizedQueryResponse, QueryResponse};
+use crate::traits::query::outlives_bounds::OutlivesBound;
+use crate::traits::query::Fallible;
+use crate::ty::{ParamEnvAnd, Ty, TyCtxt};
 
 #[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
 pub struct ImpliedOutlivesBounds<'tcx> {
diff --git a/src/librustc/traits/query/type_op/mod.rs b/src/librustc/traits/query/type_op/mod.rs
index 6e5a6080976c0..fd13acc7796f8 100644
--- a/src/librustc/traits/query/type_op/mod.rs
+++ b/src/librustc/traits/query/type_op/mod.rs
@@ -1,14 +1,14 @@
-use infer::canonical::{
+use crate::infer::canonical::{
     Canonical, Canonicalized, CanonicalizedQueryResponse, OriginalQueryValues,
     QueryRegionConstraint, QueryResponse,
 };
-use infer::{InferCtxt, InferOk};
+use crate::infer::{InferCtxt, InferOk};
 use std::fmt;
 use std::rc::Rc;
-use traits::query::Fallible;
-use traits::ObligationCause;
-use ty::fold::TypeFoldable;
-use ty::{Lift, ParamEnvAnd, TyCtxt};
+use crate::traits::query::Fallible;
+use crate::traits::ObligationCause;
+use crate::ty::fold::TypeFoldable;
+use crate::ty::{Lift, ParamEnvAnd, TyCtxt};
 
 pub mod ascribe_user_type;
 pub mod custom;
diff --git a/src/librustc/traits/query/type_op/normalize.rs b/src/librustc/traits/query/type_op/normalize.rs
index 98afe2abdbf05..346c18516234c 100644
--- a/src/librustc/traits/query/type_op/normalize.rs
+++ b/src/librustc/traits/query/type_op/normalize.rs
@@ -1,8 +1,8 @@
-use infer::canonical::{Canonical, Canonicalized, CanonicalizedQueryResponse, QueryResponse};
+use crate::infer::canonical::{Canonical, Canonicalized, CanonicalizedQueryResponse, QueryResponse};
 use std::fmt;
-use traits::query::Fallible;
-use ty::fold::TypeFoldable;
-use ty::{self, Lift, ParamEnvAnd, Ty, TyCtxt};
+use crate::traits::query::Fallible;
+use crate::ty::fold::TypeFoldable;
+use crate::ty::{self, Lift, ParamEnvAnd, Ty, TyCtxt};
 
 #[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
 pub struct Normalize<T> {
diff --git a/src/librustc/traits/query/type_op/outlives.rs b/src/librustc/traits/query/type_op/outlives.rs
index 108aa373e039c..fc0c1c022fc80 100644
--- a/src/librustc/traits/query/type_op/outlives.rs
+++ b/src/librustc/traits/query/type_op/outlives.rs
@@ -1,8 +1,8 @@
-use infer::canonical::{Canonical, Canonicalized, CanonicalizedQueryResponse, QueryResponse};
-use traits::query::dropck_outlives::trivial_dropck_outlives;
-use traits::query::dropck_outlives::DropckOutlivesResult;
-use traits::query::Fallible;
-use ty::{ParamEnvAnd, Ty, TyCtxt};
+use crate::infer::canonical::{Canonical, Canonicalized, CanonicalizedQueryResponse, QueryResponse};
+use crate::traits::query::dropck_outlives::trivial_dropck_outlives;
+use crate::traits::query::dropck_outlives::DropckOutlivesResult;
+use crate::traits::query::Fallible;
+use crate::ty::{ParamEnvAnd, Ty, TyCtxt};
 
 #[derive(Copy, Clone, Debug)]
 pub struct DropckOutlives<'tcx> {
diff --git a/src/librustc/traits/query/type_op/prove_predicate.rs b/src/librustc/traits/query/type_op/prove_predicate.rs
index d9eb89c9fc7c8..50dedf6e87f40 100644
--- a/src/librustc/traits/query/type_op/prove_predicate.rs
+++ b/src/librustc/traits/query/type_op/prove_predicate.rs
@@ -1,6 +1,6 @@
-use infer::canonical::{Canonical, Canonicalized, CanonicalizedQueryResponse, QueryResponse};
-use traits::query::Fallible;
-use ty::{ParamEnvAnd, Predicate, TyCtxt};
+use crate::infer::canonical::{Canonical, Canonicalized, CanonicalizedQueryResponse, QueryResponse};
+use crate::traits::query::Fallible;
+use crate::ty::{ParamEnvAnd, Predicate, TyCtxt};
 
 #[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
 pub struct ProvePredicate<'tcx> {
diff --git a/src/librustc/traits/query/type_op/subtype.rs b/src/librustc/traits/query/type_op/subtype.rs
index f001c7ea10a17..c45fb06313e16 100644
--- a/src/librustc/traits/query/type_op/subtype.rs
+++ b/src/librustc/traits/query/type_op/subtype.rs
@@ -1,6 +1,6 @@
-use infer::canonical::{Canonical, Canonicalized, CanonicalizedQueryResponse, QueryResponse};
-use traits::query::Fallible;
-use ty::{ParamEnvAnd, Ty, TyCtxt};
+use crate::infer::canonical::{Canonical, Canonicalized, CanonicalizedQueryResponse, QueryResponse};
+use crate::traits::query::Fallible;
+use crate::ty::{ParamEnvAnd, Ty, TyCtxt};
 
 #[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
 pub struct Subtype<'tcx> {
diff --git a/src/librustc/traits/select.rs b/src/librustc/traits/select.rs
index 6fe4a7a52be86..1e4cd145e1760 100644
--- a/src/librustc/traits/select.rs
+++ b/src/librustc/traits/select.rs
@@ -27,17 +27,17 @@ use super::{
     VtableGeneratorData, VtableImplData, VtableObjectData, VtableTraitAliasData,
 };
 
-use dep_graph::{DepKind, DepNodeIndex};
-use hir::def_id::DefId;
-use infer::{InferCtxt, InferOk, TypeFreshener};
-use middle::lang_items;
-use mir::interpret::GlobalId;
-use ty::fast_reject;
-use ty::relate::TypeRelation;
-use ty::subst::{Subst, Substs};
-use ty::{self, ToPolyTraitRef, ToPredicate, Ty, TyCtxt, TypeFoldable};
-
-use hir;
+use crate::dep_graph::{DepKind, DepNodeIndex};
+use crate::hir::def_id::DefId;
+use crate::infer::{InferCtxt, InferOk, TypeFreshener};
+use crate::middle::lang_items;
+use crate::mir::interpret::GlobalId;
+use crate::ty::fast_reject;
+use crate::ty::relate::TypeRelation;
+use crate::ty::subst::{Subst, Substs};
+use crate::ty::{self, ToPolyTraitRef, ToPredicate, Ty, TyCtxt, TypeFoldable};
+
+use crate::hir;
 use rustc_data_structures::bit_set::GrowableBitSet;
 use rustc_data_structures::sync::Lock;
 use rustc_target::spec::abi::Abi;
@@ -45,7 +45,7 @@ use std::cmp;
 use std::fmt::{self, Display};
 use std::iter;
 use std::rc::Rc;
-use util::nodemap::{FxHashMap, FxHashSet};
+use crate::util::nodemap::{FxHashMap, FxHashSet};
 
 pub struct SelectionContext<'cx, 'gcx: 'cx + 'tcx, 'tcx: 'cx> {
     infcx: &'cx InferCtxt<'cx, 'gcx, 'tcx>,
@@ -103,7 +103,7 @@ impl IntercrateAmbiguityCause {
     /// See #23980 for details.
     pub fn add_intercrate_ambiguity_hint<'a, 'tcx>(
         &self,
-        err: &mut ::errors::DiagnosticBuilder<'_>,
+        err: &mut crate::errors::DiagnosticBuilder<'_>,
     ) {
         err.note(&self.intercrate_ambiguity_hint());
     }
diff --git a/src/librustc/traits/specialize/mod.rs b/src/librustc/traits/specialize/mod.rs
index e5ed16e755860..e7187005c132a 100644
--- a/src/librustc/traits/specialize/mod.rs
+++ b/src/librustc/traits/specialize/mod.rs
@@ -11,16 +11,16 @@
 
 pub mod specialization_graph;
 
-use hir::def_id::DefId;
-use infer::{InferCtxt, InferOk};
-use lint;
-use traits::{self, coherence, FutureCompatOverlapErrorKind, ObligationCause, TraitEngine};
+use crate::hir::def_id::DefId;
+use crate::infer::{InferCtxt, InferOk};
+use crate::lint;
+use crate::traits::{self, coherence, FutureCompatOverlapErrorKind, ObligationCause, TraitEngine};
 use rustc_data_structures::fx::FxHashSet;
 use rustc_data_structures::sync::Lrc;
 use syntax_pos::DUMMY_SP;
-use traits::select::IntercrateAmbiguityCause;
-use ty::{self, TyCtxt, TypeFoldable};
-use ty::subst::{Subst, Substs};
+use crate::traits::select::IntercrateAmbiguityCause;
+use crate::ty::{self, TyCtxt, TypeFoldable};
+use crate::ty::subst::{Subst, Substs};
 
 use super::{SelectionContext, FulfillmentContext};
 use super::util::impl_trait_ref_and_oblig;
diff --git a/src/librustc/traits/specialize/specialization_graph.rs b/src/librustc/traits/specialize/specialization_graph.rs
index e5780a26a1918..010555744b6c3 100644
--- a/src/librustc/traits/specialize/specialization_graph.rs
+++ b/src/librustc/traits/specialize/specialization_graph.rs
@@ -1,16 +1,16 @@
 use super::OverlapError;
 
-use hir::def_id::DefId;
-use ich::{self, StableHashingContext};
+use crate::hir::def_id::DefId;
+use crate::ich::{self, StableHashingContext};
 use rustc_data_structures::stable_hasher::{HashStable, StableHasher,
                                            StableHasherResult};
-use traits;
-use ty::{self, TyCtxt, TypeFoldable};
-use ty::fast_reject::{self, SimplifiedType};
+use crate::traits;
+use crate::ty::{self, TyCtxt, TypeFoldable};
+use crate::ty::fast_reject::{self, SimplifiedType};
 use rustc_data_structures::sync::Lrc;
 use syntax::ast::Ident;
-use util::captures::Captures;
-use util::nodemap::{DefIdMap, FxHashMap};
+use crate::util::captures::Captures;
+use crate::util::nodemap::{DefIdMap, FxHashMap};
 
 /// A per-trait graph of impls in specialization order. At the moment, this
 /// graph forms a tree rooted with the trait itself, with all other nodes
@@ -489,7 +489,7 @@ impl<'a, 'gcx, 'tcx> Ancestors {
         trait_def_id: DefId,
     ) -> impl Iterator<Item = NodeItem<ty::AssociatedItem>> + Captures<'gcx> + Captures<'tcx> + 'a {
         self.flat_map(move |node| {
-            use ty::AssociatedKind::*;
+            use crate::ty::AssociatedKind::*;
             node.items(tcx).filter(move |impl_item| match (trait_item_kind, impl_item.kind) {
                 | (Const, Const)
                 | (Method, Method)
diff --git a/src/librustc/traits/structural_impls.rs b/src/librustc/traits/structural_impls.rs
index 2f5df022218fe..c5cc9e8b40182 100644
--- a/src/librustc/traits/structural_impls.rs
+++ b/src/librustc/traits/structural_impls.rs
@@ -1,9 +1,9 @@
 use chalk_engine;
 use smallvec::SmallVec;
-use traits;
-use traits::project::Normalized;
-use ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
-use ty::{self, Lift, TyCtxt};
+use crate::traits;
+use crate::traits::project::Normalized;
+use crate::ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
+use crate::ty::{self, Lift, TyCtxt};
 use syntax::symbol::InternedString;
 
 use std::fmt;
@@ -163,7 +163,7 @@ impl<'tcx> fmt::Debug for traits::MismatchedProjectionTypes<'tcx> {
 
 impl<'tcx> fmt::Display for traits::WhereClause<'tcx> {
     fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
-        use traits::WhereClause::*;
+        use crate::traits::WhereClause::*;
 
         // Bypass ppaux because it does not print out anonymous regions.
         fn write_region_name<'tcx>(
@@ -206,7 +206,7 @@ impl<'tcx> fmt::Display for traits::WhereClause<'tcx> {
 
 impl<'tcx> fmt::Display for traits::WellFormed<'tcx> {
     fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
-        use traits::WellFormed::*;
+        use crate::traits::WellFormed::*;
 
         match self {
             Trait(trait_ref) => write!(fmt, "WellFormed({})", trait_ref),
@@ -217,7 +217,7 @@ impl<'tcx> fmt::Display for traits::WellFormed<'tcx> {
 
 impl<'tcx> fmt::Display for traits::FromEnv<'tcx> {
     fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
-        use traits::FromEnv::*;
+        use crate::traits::FromEnv::*;
 
         match self {
             Trait(trait_ref) => write!(fmt, "FromEnv({})", trait_ref),
@@ -228,7 +228,7 @@ impl<'tcx> fmt::Display for traits::FromEnv<'tcx> {
 
 impl<'tcx> fmt::Display for traits::DomainGoal<'tcx> {
     fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
-        use traits::DomainGoal::*;
+        use crate::traits::DomainGoal::*;
 
         match self {
             Holds(wc) => write!(fmt, "{}", wc),
@@ -246,7 +246,7 @@ impl<'tcx> fmt::Display for traits::DomainGoal<'tcx> {
 
 impl fmt::Display for traits::QuantifierKind {
     fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
-        use traits::QuantifierKind::*;
+        use crate::traits::QuantifierKind::*;
 
         match self {
             Universal => write!(fmt, "forall"),
@@ -361,7 +361,7 @@ impl<'tcx> TypeVisitor<'tcx> for BoundNamesCollector {
 
 impl<'tcx> fmt::Display for traits::Goal<'tcx> {
     fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
-        use traits::GoalKind::*;
+        use crate::traits::GoalKind::*;
 
         match self {
             Implies(hypotheses, goal) => {
@@ -420,7 +420,7 @@ impl<'tcx> fmt::Display for traits::ProgramClause<'tcx> {
 
 impl<'tcx> fmt::Display for traits::Clause<'tcx> {
     fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
-        use traits::Clause::*;
+        use crate::traits::Clause::*;
 
         match self {
             Implies(clause) => write!(fmt, "{}", clause),
diff --git a/src/librustc/traits/util.rs b/src/librustc/traits/util.rs
index 5b7ba5386725e..67c919ac91610 100644
--- a/src/librustc/traits/util.rs
+++ b/src/librustc/traits/util.rs
@@ -1,10 +1,10 @@
-use hir;
-use hir::def_id::DefId;
-use traits::specialize::specialization_graph::NodeItem;
-use ty::{self, Ty, TyCtxt, ToPredicate, ToPolyTraitRef};
-use ty::outlives::Component;
-use ty::subst::{Kind, Subst, Substs};
-use util::nodemap::FxHashSet;
+use crate::hir;
+use crate::hir::def_id::DefId;
+use crate::traits::specialize::specialization_graph::NodeItem;
+use crate::ty::{self, Ty, TyCtxt, ToPredicate, ToPolyTraitRef};
+use crate::ty::outlives::Component;
+use crate::ty::subst::{Kind, Subst, Substs};
+use crate::util::nodemap::FxHashSet;
 
 use super::{Obligation, ObligationCause, PredicateObligation, SelectionContext, Normalized};
 
diff --git a/src/librustc/ty/_match.rs b/src/librustc/ty/_match.rs
index 34b94d4217d8b..07fa441bb8076 100644
--- a/src/librustc/ty/_match.rs
+++ b/src/librustc/ty/_match.rs
@@ -1,6 +1,6 @@
-use ty::{self, Ty, TyCtxt};
-use ty::error::TypeError;
-use ty::relate::{self, Relate, TypeRelation, RelateResult};
+use crate::ty::{self, Ty, TyCtxt};
+use crate::ty::error::TypeError;
+use crate::ty::relate::{self, Relate, TypeRelation, RelateResult};
 
 /// A type "A" *matches* "B" if the fresh types in B could be
 /// substituted with values so as to make it equal to A. Matching is
diff --git a/src/librustc/ty/adjustment.rs b/src/librustc/ty/adjustment.rs
index 117112c0c75f4..68e7bd6e16abe 100644
--- a/src/librustc/ty/adjustment.rs
+++ b/src/librustc/ty/adjustment.rs
@@ -1,7 +1,7 @@
-use hir;
-use hir::def_id::DefId;
-use ty::{self, Ty, TyCtxt};
-use ty::subst::Substs;
+use crate::hir;
+use crate::hir::def_id::DefId;
+use crate::ty::{self, Ty, TyCtxt};
+use crate::ty::subst::Substs;
 
 
 /// Represents coercing a value to a different type of value.
diff --git a/src/librustc/ty/binding.rs b/src/librustc/ty/binding.rs
index 2ab14642406b1..1290141b0a6b0 100644
--- a/src/librustc/ty/binding.rs
+++ b/src/librustc/ty/binding.rs
@@ -1,6 +1,6 @@
-use hir::BindingAnnotation::*;
-use hir::BindingAnnotation;
-use hir::Mutability;
+use crate::hir::BindingAnnotation::*;
+use crate::hir::BindingAnnotation;
+use crate::hir::Mutability;
 
 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
 pub enum BindingMode {
diff --git a/src/librustc/ty/cast.rs b/src/librustc/ty/cast.rs
index 0f067de3649bf..0b2112f42d595 100644
--- a/src/librustc/ty/cast.rs
+++ b/src/librustc/ty/cast.rs
@@ -1,7 +1,7 @@
 // Helpers for handling cast expressions, used in both
 // typeck and codegen.
 
-use ty::{self, Ty};
+use crate::ty::{self, Ty};
 
 use syntax::ast;
 
diff --git a/src/librustc/ty/codec.rs b/src/librustc/ty/codec.rs
index e0e4d9c362a6c..c9775b1029315 100644
--- a/src/librustc/ty/codec.rs
+++ b/src/librustc/ty/codec.rs
@@ -6,15 +6,15 @@
 // The functionality in here is shared between persisting to crate metadata and
 // persisting to incr. comp. caches.
 
-use hir::def_id::{DefId, CrateNum};
-use infer::canonical::{CanonicalVarInfo, CanonicalVarInfos};
+use crate::hir::def_id::{DefId, CrateNum};
+use crate::infer::canonical::{CanonicalVarInfo, CanonicalVarInfos};
 use rustc_data_structures::fx::FxHashMap;
-use rustc_serialize::{Decodable, Decoder, Encoder, Encodable, opaque};
+use crate::rustc_serialize::{Decodable, Decoder, Encoder, Encodable, opaque};
 use std::hash::Hash;
 use std::intrinsics;
-use ty::{self, Ty, TyCtxt};
-use ty::subst::Substs;
-use mir::interpret::Allocation;
+use crate::ty::{self, Ty, TyCtxt};
+use crate::ty::subst::Substs;
+use crate::mir::interpret::Allocation;
 
 /// The shorthand encoding uses an enum's variant index `usize`
 /// and is offset by this value so it never matches a real variant.
@@ -283,7 +283,7 @@ macro_rules! implement_ty_decoder {
             use $crate::ty::codec::*;
             use $crate::ty::subst::Substs;
             use $crate::hir::def_id::{CrateNum};
-            use rustc_serialize::{Decoder, SpecializedDecoder};
+            use crate::rustc_serialize::{Decoder, SpecializedDecoder};
             use std::borrow::Cow;
 
             impl<$($typaram ),*> Decoder for $DecoderName<$($typaram),*> {
diff --git a/src/librustc/ty/constness.rs b/src/librustc/ty/constness.rs
index 3741f4051b896..1bb6386728917 100644
--- a/src/librustc/ty/constness.rs
+++ b/src/librustc/ty/constness.rs
@@ -1,9 +1,9 @@
-use ty::query::Providers;
-use hir::def_id::DefId;
-use hir;
-use ty::TyCtxt;
+use crate::ty::query::Providers;
+use crate::hir::def_id::DefId;
+use crate::hir;
+use crate::ty::TyCtxt;
 use syntax_pos::symbol::Symbol;
-use hir::map::blocks::FnLikeNode;
+use crate::hir::map::blocks::FnLikeNode;
 use syntax::attr;
 
 impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs
index b379b5ba02494..140c772256d3f 100644
--- a/src/librustc/ty/context.rs
+++ b/src/librustc/ty/context.rs
@@ -1,48 +1,48 @@
 //! type context book-keeping
 
-use dep_graph::DepGraph;
-use dep_graph::{DepNode, DepConstructor};
-use errors::DiagnosticBuilder;
-use session::Session;
-use session::config::{BorrowckMode, OutputFilenames};
-use session::config::CrateType;
-use middle;
-use hir::{TraitCandidate, HirId, ItemKind, ItemLocalId, Node};
-use hir::def::{Def, Export};
-use hir::def_id::{CrateNum, DefId, DefIndex, LOCAL_CRATE};
-use hir::map as hir_map;
-use hir::map::DefPathHash;
-use lint::{self, Lint};
-use ich::{StableHashingContext, NodeIdHashingMode};
-use infer::canonical::{Canonical, CanonicalVarInfo, CanonicalVarInfos};
-use infer::outlives::free_region_map::FreeRegionMap;
-use middle::cstore::CrateStoreDyn;
-use middle::cstore::EncodedMetadata;
-use middle::lang_items;
-use middle::resolve_lifetime::{self, ObjectLifetimeDefault};
-use middle::stability;
-use mir::{self, Mir, interpret, ProjectionKind};
-use mir::interpret::Allocation;
-use ty::subst::{Kind, Substs, Subst};
-use ty::ReprOptions;
-use traits;
-use traits::{Clause, Clauses, GoalKind, Goal, Goals};
-use ty::{self, Ty, TypeAndMut};
-use ty::{TyS, TyKind, List};
-use ty::{AdtKind, AdtDef, ClosureSubsts, GeneratorSubsts, Region, Const, LazyConst};
-use ty::{PolyFnSig, InferTy, ParamTy, ProjectionTy, ExistentialPredicate, Predicate};
-use ty::RegionKind;
-use ty::{TyVar, TyVid, IntVar, IntVid, FloatVar, FloatVid};
-use ty::TyKind::*;
-use ty::GenericParamDefKind;
-use ty::layout::{LayoutDetails, TargetDataLayout, VariantIdx};
-use ty::query;
-use ty::steal::Steal;
-use ty::subst::{UserSubsts, UnpackedKind};
-use ty::{BoundVar, BindingMode};
-use ty::CanonicalPolyFnSig;
-use util::nodemap::{DefIdMap, DefIdSet, ItemLocalMap};
-use util::nodemap::{FxHashMap, FxHashSet};
+use crate::dep_graph::DepGraph;
+use crate::dep_graph::{DepNode, DepConstructor};
+use crate::errors::DiagnosticBuilder;
+use crate::session::Session;
+use crate::session::config::{BorrowckMode, OutputFilenames};
+use crate::session::config::CrateType;
+use crate::middle;
+use crate::hir::{TraitCandidate, HirId, ItemKind, ItemLocalId, Node};
+use crate::hir::def::{Def, Export};
+use crate::hir::def_id::{CrateNum, DefId, DefIndex, LOCAL_CRATE};
+use crate::hir::map as hir_map;
+use crate::hir::map::DefPathHash;
+use crate::lint::{self, Lint};
+use crate::ich::{StableHashingContext, NodeIdHashingMode};
+use crate::infer::canonical::{Canonical, CanonicalVarInfo, CanonicalVarInfos};
+use crate::infer::outlives::free_region_map::FreeRegionMap;
+use crate::middle::cstore::CrateStoreDyn;
+use crate::middle::cstore::EncodedMetadata;
+use crate::middle::lang_items;
+use crate::middle::resolve_lifetime::{self, ObjectLifetimeDefault};
+use crate::middle::stability;
+use crate::mir::{self, Mir, interpret, ProjectionKind};
+use crate::mir::interpret::Allocation;
+use crate::ty::subst::{Kind, Substs, Subst};
+use crate::ty::ReprOptions;
+use crate::traits;
+use crate::traits::{Clause, Clauses, GoalKind, Goal, Goals};
+use crate::ty::{self, Ty, TypeAndMut};
+use crate::ty::{TyS, TyKind, List};
+use crate::ty::{AdtKind, AdtDef, ClosureSubsts, GeneratorSubsts, Region, Const, LazyConst};
+use crate::ty::{PolyFnSig, InferTy, ParamTy, ProjectionTy, ExistentialPredicate, Predicate};
+use crate::ty::RegionKind;
+use crate::ty::{TyVar, TyVid, IntVar, IntVid, FloatVar, FloatVid};
+use crate::ty::TyKind::*;
+use crate::ty::GenericParamDefKind;
+use crate::ty::layout::{LayoutDetails, TargetDataLayout, VariantIdx};
+use crate::ty::query;
+use crate::ty::steal::Steal;
+use crate::ty::subst::{UserSubsts, UnpackedKind};
+use crate::ty::{BoundVar, BindingMode};
+use crate::ty::CanonicalPolyFnSig;
+use crate::util::nodemap::{DefIdMap, DefIdSet, ItemLocalMap};
+use crate::util::nodemap::{FxHashMap, FxHashSet};
 use rustc_data_structures::interner::HashInterner;
 use smallvec::SmallVec;
 use rustc_data_structures::stable_hasher::{HashStable, hash_stable_hashmap,
@@ -73,7 +73,7 @@ use syntax::feature_gate;
 use syntax::symbol::{Symbol, keywords, InternedString};
 use syntax_pos::Span;
 
-use hir;
+use crate::hir;
 
 pub struct AllArenas<'tcx> {
     pub global: WorkerLocal<GlobalArenas<'tcx>>,
@@ -1822,18 +1822,18 @@ pub mod tls {
     use std::marker::PhantomData;
     use std::ptr;
     use syntax_pos;
-    use ty::query;
-    use errors::{Diagnostic, TRACK_DIAGNOSTICS};
+    use crate::ty::query;
+    use crate::errors::{Diagnostic, TRACK_DIAGNOSTICS};
     use rustc_data_structures::OnDrop;
     use rustc_data_structures::sync::{self, Lrc, Lock};
     use rustc_data_structures::thin_vec::ThinVec;
-    use dep_graph::TaskDeps;
+    use crate::dep_graph::TaskDeps;
 
     #[cfg(not(parallel_compiler))]
     use std::cell::Cell;
 
     #[cfg(parallel_compiler)]
-    use rayon_core;
+    use rustc_rayon_core as rayon_core;
 
     /// This is the implicit state of rustc. It contains the current
     /// TyCtxt and query. It is updated when creating a local interner or
@@ -2114,8 +2114,8 @@ macro_rules! sty_debug_print {
         // variable names.
         #[allow(non_snake_case)]
         mod inner {
-            use ty::{self, TyCtxt};
-            use ty::context::Interned;
+            use crate::ty::{self, TyCtxt};
+            use crate::ty::context::Interned;
 
             #[derive(Copy, Clone)]
             struct DebugStat {
diff --git a/src/librustc/ty/erase_regions.rs b/src/librustc/ty/erase_regions.rs
index da7e021b2d54b..0431afcc76c9e 100644
--- a/src/librustc/ty/erase_regions.rs
+++ b/src/librustc/ty/erase_regions.rs
@@ -1,5 +1,5 @@
-use ty::{self, Ty, TyCtxt, TypeFlags};
-use ty::fold::{TypeFolder, TypeFoldable};
+use crate::ty::{self, Ty, TyCtxt, TypeFlags};
+use crate::ty::fold::{TypeFolder, TypeFoldable};
 
 pub(super) fn provide(providers: &mut ty::query::Providers<'_>) {
     *providers = ty::query::Providers {
diff --git a/src/librustc/ty/error.rs b/src/librustc/ty/error.rs
index f444013e2a3bd..d0c9677ea6ecb 100644
--- a/src/librustc/ty/error.rs
+++ b/src/librustc/ty/error.rs
@@ -1,13 +1,13 @@
-use hir::def_id::DefId;
-use ty::{self, Region, Ty, TyCtxt};
+use crate::hir::def_id::DefId;
+use crate::ty::{self, Region, Ty, TyCtxt};
 use std::borrow::Cow;
 use std::fmt;
 use rustc_target::spec::abi;
 use syntax::ast;
-use errors::{Applicability, DiagnosticBuilder};
+use crate::errors::{Applicability, DiagnosticBuilder};
 use syntax_pos::Span;
 
-use hir;
+use crate::hir;
 
 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
 pub struct ExpectedFound<T> {
diff --git a/src/librustc/ty/fast_reject.rs b/src/librustc/ty/fast_reject.rs
index 2b41fc4fe341f..59ab4561f2c87 100644
--- a/src/librustc/ty/fast_reject.rs
+++ b/src/librustc/ty/fast_reject.rs
@@ -1,12 +1,12 @@
-use hir::def_id::DefId;
-use ich::StableHashingContext;
+use crate::hir::def_id::DefId;
+use crate::ich::StableHashingContext;
 use rustc_data_structures::stable_hasher::{StableHasher, StableHasherResult,
                                            HashStable};
 use std::fmt::Debug;
 use std::hash::Hash;
 use std::mem;
 use syntax::ast;
-use ty::{self, Ty, TyCtxt};
+use crate::ty::{self, Ty, TyCtxt};
 
 use self::SimplifiedTypeGen::*;
 
diff --git a/src/librustc/ty/flags.rs b/src/librustc/ty/flags.rs
index 4fa13a01d5a92..25ec3e49cdf67 100644
--- a/src/librustc/ty/flags.rs
+++ b/src/librustc/ty/flags.rs
@@ -1,5 +1,5 @@
-use ty::subst::Substs;
-use ty::{self, Ty, TypeFlags, TypeFoldable};
+use crate::ty::subst::Substs;
+use crate::ty::{self, Ty, TypeFlags, TypeFoldable};
 
 #[derive(Debug)]
 pub struct FlagComputation {
diff --git a/src/librustc/ty/fold.rs b/src/librustc/ty/fold.rs
index 28b6f010ce09c..306c69666e596 100644
--- a/src/librustc/ty/fold.rs
+++ b/src/librustc/ty/fold.rs
@@ -29,12 +29,12 @@
 //! These methods return true to indicate that the visitor has found what it is looking for
 //! and does not need to visit anything else.
 
-use hir::def_id::DefId;
-use ty::{self, Binder, Ty, TyCtxt, TypeFlags};
+use crate::hir::def_id::DefId;
+use crate::ty::{self, Binder, Ty, TyCtxt, TypeFlags};
 
 use std::collections::BTreeMap;
 use std::fmt;
-use util::nodemap::FxHashSet;
+use crate::util::nodemap::FxHashSet;
 
 /// The TypeFoldable trait is implemented for every type that can be folded.
 /// Basically, every type that has a corresponding method in TypeFolder.
diff --git a/src/librustc/ty/inhabitedness/def_id_forest.rs b/src/librustc/ty/inhabitedness/def_id_forest.rs
index 41fd88607e893..73b7d74d9dafe 100644
--- a/src/librustc/ty/inhabitedness/def_id_forest.rs
+++ b/src/librustc/ty/inhabitedness/def_id_forest.rs
@@ -1,8 +1,8 @@
 use std::mem;
 use smallvec::SmallVec;
 use syntax::ast::CRATE_NODE_ID;
-use ty::context::TyCtxt;
-use ty::{DefId, DefIdTree};
+use crate::ty::context::TyCtxt;
+use crate::ty::{DefId, DefIdTree};
 
 /// Represents a forest of DefIds closed under the ancestor relation. That is,
 /// if a DefId representing a module is contained in the forest then all
diff --git a/src/librustc/ty/inhabitedness/mod.rs b/src/librustc/ty/inhabitedness/mod.rs
index 6dfc9681cfd86..601ffe70eec18 100644
--- a/src/librustc/ty/inhabitedness/mod.rs
+++ b/src/librustc/ty/inhabitedness/mod.rs
@@ -1,8 +1,8 @@
-use ty::context::TyCtxt;
-use ty::{AdtDef, VariantDef, FieldDef, Ty, TyS};
-use ty::{self, DefId, Substs};
-use ty::{AdtKind, Visibility};
-use ty::TyKind::*;
+use crate::ty::context::TyCtxt;
+use crate::ty::{AdtDef, VariantDef, FieldDef, Ty, TyS};
+use crate::ty::{self, DefId, Substs};
+use crate::ty::{AdtKind, Visibility};
+use crate::ty::TyKind::*;
 
 pub use self::def_id_forest::DefIdForest;
 
diff --git a/src/librustc/ty/instance.rs b/src/librustc/ty/instance.rs
index bc43fedef0f34..e4fe93d5deaea 100644
--- a/src/librustc/ty/instance.rs
+++ b/src/librustc/ty/instance.rs
@@ -1,9 +1,9 @@
-use hir::Unsafety;
-use hir::def_id::DefId;
-use ty::{self, Ty, PolyFnSig, TypeFoldable, Substs, TyCtxt};
-use traits;
+use crate::hir::Unsafety;
+use crate::hir::def_id::DefId;
+use crate::ty::{self, Ty, PolyFnSig, TypeFoldable, Substs, TyCtxt};
+use crate::traits;
 use rustc_target::spec::abi::Abi;
-use util::ppaux;
+use crate::util::ppaux;
 
 use std::fmt;
 use std::iter;
@@ -141,7 +141,7 @@ impl<'tcx> InstanceDef<'tcx> {
         &self,
         tcx: TyCtxt<'a, 'tcx, 'tcx>
     ) -> bool {
-        use hir::map::DefPathData;
+        use crate::hir::map::DefPathData;
         let def_id = match *self {
             ty::InstanceDef::Item(def_id) => def_id,
             ty::InstanceDef::DropGlue(_, Some(_)) => return false,
diff --git a/src/librustc/ty/item_path.rs b/src/librustc/ty/item_path.rs
index adb7e1fb3e322..f89e50d696945 100644
--- a/src/librustc/ty/item_path.rs
+++ b/src/librustc/ty/item_path.rs
@@ -1,8 +1,8 @@
-use hir;
-use hir::map::DefPathData;
-use hir::def_id::{CrateNum, DefId, CRATE_DEF_INDEX, LOCAL_CRATE};
-use ty::{self, DefIdTree, Ty, TyCtxt};
-use middle::cstore::{ExternCrate, ExternCrateSource};
+use crate::hir;
+use crate::hir::map::DefPathData;
+use crate::hir::def_id::{CrateNum, DefId, CRATE_DEF_INDEX, LOCAL_CRATE};
+use crate::ty::{self, DefIdTree, Ty, TyCtxt};
+use crate::middle::cstore::{ExternCrate, ExternCrateSource};
 use syntax::ast;
 use syntax::symbol::{keywords, LocalInternedString, Symbol};
 
diff --git a/src/librustc/ty/layout.rs b/src/librustc/ty/layout.rs
index 1162bff852cbb..8401d0861cad2 100644
--- a/src/librustc/ty/layout.rs
+++ b/src/librustc/ty/layout.rs
@@ -1,5 +1,5 @@
-use session::{self, DataTypeKind};
-use ty::{self, Ty, TyCtxt, TypeFoldable, ReprOptions};
+use crate::session::{self, DataTypeKind};
+use crate::ty::{self, Ty, TyCtxt, TypeFoldable, ReprOptions};
 
 use syntax::ast::{self, Ident, IntTy, UintTy};
 use syntax::attr;
@@ -12,7 +12,7 @@ use std::iter;
 use std::mem;
 use std::ops::Bound;
 
-use ich::StableHashingContext;
+use crate::ich::StableHashingContext;
 use rustc_data_structures::indexed_vec::{IndexVec, Idx};
 use rustc_data_structures::stable_hasher::{HashStable, StableHasher,
                                            StableHasherResult};
@@ -1872,7 +1872,7 @@ impl<'a> HashStable<StableHashingContext<'a>> for Variants {
     fn hash_stable<W: StableHasherResult>(&self,
                                           hcx: &mut StableHashingContext<'a>,
                                           hasher: &mut StableHasher<W>) {
-        use ty::layout::Variants::*;
+        use crate::ty::layout::Variants::*;
         mem::discriminant(self).hash_stable(hcx, hasher);
 
         match *self {
@@ -1908,7 +1908,7 @@ impl<'a> HashStable<StableHashingContext<'a>> for FieldPlacement {
     fn hash_stable<W: StableHasherResult>(&self,
                                           hcx: &mut StableHashingContext<'a>,
                                           hasher: &mut StableHasher<W>) {
-        use ty::layout::FieldPlacement::*;
+        use crate::ty::layout::FieldPlacement::*;
         mem::discriminant(self).hash_stable(hcx, hasher);
 
         match *self {
@@ -1941,7 +1941,7 @@ impl<'a> HashStable<StableHashingContext<'a>> for Abi {
     fn hash_stable<W: StableHasherResult>(&self,
                                           hcx: &mut StableHashingContext<'a>,
                                           hasher: &mut StableHasher<W>) {
-        use ty::layout::Abi::*;
+        use crate::ty::layout::Abi::*;
         mem::discriminant(self).hash_stable(hcx, hasher);
 
         match *self {
@@ -1975,7 +1975,7 @@ impl<'a> HashStable<StableHashingContext<'a>> for Scalar {
     }
 }
 
-impl_stable_hash_for!(struct ::ty::layout::LayoutDetails {
+impl_stable_hash_for!(struct crate::ty::layout::LayoutDetails {
     variants,
     fields,
     abi,
@@ -1983,7 +1983,7 @@ impl_stable_hash_for!(struct ::ty::layout::LayoutDetails {
     align
 });
 
-impl_stable_hash_for!(enum ::ty::layout::Integer {
+impl_stable_hash_for!(enum crate::ty::layout::Integer {
     I8,
     I16,
     I32,
@@ -1991,13 +1991,13 @@ impl_stable_hash_for!(enum ::ty::layout::Integer {
     I128
 });
 
-impl_stable_hash_for!(enum ::ty::layout::Primitive {
+impl_stable_hash_for!(enum crate::ty::layout::Primitive {
     Int(integer, signed),
     Float(fty),
     Pointer
 });
 
-impl_stable_hash_for!(struct ::ty::layout::AbiAndPrefAlign {
+impl_stable_hash_for!(struct crate::ty::layout::AbiAndPrefAlign {
     abi,
     pref
 });
@@ -2023,7 +2023,7 @@ impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for LayoutError<'gcx>
     fn hash_stable<W: StableHasherResult>(&self,
                                           hcx: &mut StableHashingContext<'a>,
                                           hasher: &mut StableHasher<W>) {
-        use ty::layout::LayoutError::*;
+        use crate::ty::layout::LayoutError::*;
         mem::discriminant(self).hash_stable(hcx, hasher);
 
         match *self {
diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs
index c9089428b2324..60e3ac673a0a0 100644
--- a/src/librustc/ty/mod.rs
+++ b/src/librustc/ty/mod.rs
@@ -4,31 +4,31 @@ pub use self::BorrowKind::*;
 pub use self::IntVarValue::*;
 pub use self::fold::TypeFoldable;
 
-use hir::{map as hir_map, FreevarMap, GlobMap, TraitMap};
-use hir::Node;
-use hir::def::{Def, CtorKind, ExportMap};
-use hir::def_id::{CrateNum, DefId, LocalDefId, CRATE_DEF_INDEX, LOCAL_CRATE};
-use hir::map::DefPathData;
+use crate::hir::{map as hir_map, FreevarMap, GlobMap, TraitMap};
+use crate::hir::Node;
+use crate::hir::def::{Def, CtorKind, ExportMap};
+use crate::hir::def_id::{CrateNum, DefId, LocalDefId, CRATE_DEF_INDEX, LOCAL_CRATE};
+use crate::hir::map::DefPathData;
 use rustc_data_structures::svh::Svh;
-use ich::Fingerprint;
-use ich::StableHashingContext;
-use infer::canonical::Canonical;
-use middle::lang_items::{FnTraitLangItem, FnMutTraitLangItem, FnOnceTraitLangItem};
-use middle::resolve_lifetime::ObjectLifetimeDefault;
-use mir::Mir;
-use mir::interpret::{GlobalId, ErrorHandled};
-use mir::GeneratorLayout;
-use session::CrateDisambiguator;
-use traits::{self, Reveal};
-use ty;
-use ty::layout::VariantIdx;
-use ty::subst::{Subst, Substs};
-use ty::util::{IntTypeExt, Discr};
-use ty::walk::TypeWalker;
-use util::captures::Captures;
-use util::nodemap::{NodeSet, DefIdMap, FxHashMap};
+use crate::ich::Fingerprint;
+use crate::ich::StableHashingContext;
+use crate::infer::canonical::Canonical;
+use crate::middle::lang_items::{FnTraitLangItem, FnMutTraitLangItem, FnOnceTraitLangItem};
+use crate::middle::resolve_lifetime::ObjectLifetimeDefault;
+use crate::mir::Mir;
+use crate::mir::interpret::{GlobalId, ErrorHandled};
+use crate::mir::GeneratorLayout;
+use crate::session::CrateDisambiguator;
+use crate::traits::{self, Reveal};
+use crate::ty;
+use crate::ty::layout::VariantIdx;
+use crate::ty::subst::{Subst, Substs};
+use crate::ty::util::{IntTypeExt, Discr};
+use crate::ty::walk::TypeWalker;
+use crate::util::captures::Captures;
+use crate::util::nodemap::{NodeSet, DefIdMap, FxHashMap};
 use arena::SyncDroplessArena;
-use session::DataTypeKind;
+use crate::session::DataTypeKind;
 
 use serialize::{self, Encodable, Encoder};
 use std::cell::RefCell;
@@ -50,7 +50,7 @@ use rustc_data_structures::indexed_vec::{Idx, IndexVec};
 use rustc_data_structures::stable_hasher::{StableHasher, StableHasherResult,
                                            HashStable};
 
-use hir;
+use crate::hir;
 
 pub use self::sty::{Binder, BoundTy, BoundTyKind, BoundVar, DebruijnIndex, INNERMOST};
 pub use self::sty::{FnSig, GenSig, CanonicalPolyFnSig, PolyFnSig, PolyGenSig};
@@ -2277,7 +2277,7 @@ impl<'a, 'gcx, 'tcx> AdtDef {
                     })
                 } else {
                     info!("invalid enum discriminant: {:#?}", val);
-                    ::mir::interpret::struct_error(
+                    crate::mir::interpret::struct_error(
                         tcx.at(tcx.def_span(expr_did)),
                         "constant evaluation of enum discriminant resulted in non-integer",
                     ).emit();
diff --git a/src/librustc/ty/outlives.rs b/src/librustc/ty/outlives.rs
index ca2d5cd718c64..5b21ed5abd77b 100644
--- a/src/librustc/ty/outlives.rs
+++ b/src/librustc/ty/outlives.rs
@@ -3,7 +3,7 @@
 // RFC for reference.
 
 use smallvec::SmallVec;
-use ty::{self, Ty, TyCtxt, TypeFoldable};
+use crate::ty::{self, Ty, TyCtxt, TypeFoldable};
 
 #[derive(Debug)]
 pub enum Component<'tcx> {
diff --git a/src/librustc/ty/query/config.rs b/src/librustc/ty/query/config.rs
index 495cce4d2feac..255e39eaccd6d 100644
--- a/src/librustc/ty/query/config.rs
+++ b/src/librustc/ty/query/config.rs
@@ -1,19 +1,19 @@
-use dep_graph::SerializedDepNodeIndex;
-use dep_graph::DepNode;
-use hir::def_id::{CrateNum, DefId, DefIndex};
-use mir::interpret::GlobalId;
-use traits;
-use traits::query::{
+use crate::dep_graph::SerializedDepNodeIndex;
+use crate::dep_graph::DepNode;
+use crate::hir::def_id::{CrateNum, DefId, DefIndex};
+use crate::mir::interpret::GlobalId;
+use crate::traits;
+use crate::traits::query::{
     CanonicalPredicateGoal, CanonicalProjectionGoal, CanonicalTyGoal,
     CanonicalTypeOpAscribeUserTypeGoal, CanonicalTypeOpEqGoal, CanonicalTypeOpNormalizeGoal,
     CanonicalTypeOpProvePredicateGoal, CanonicalTypeOpSubtypeGoal,
 };
-use ty::{self, ParamEnvAnd, Ty, TyCtxt};
-use ty::subst::Substs;
-use ty::query::queries;
-use ty::query::Query;
-use ty::query::QueryCache;
-use util::profiling::ProfileCategory;
+use crate::ty::{self, ParamEnvAnd, Ty, TyCtxt};
+use crate::ty::subst::Substs;
+use crate::ty::query::queries;
+use crate::ty::query::Query;
+use crate::ty::query::QueryCache;
+use crate::util::profiling::ProfileCategory;
 
 use std::borrow::Cow;
 use std::hash::Hash;
@@ -21,7 +21,7 @@ use std::fmt::Debug;
 use syntax_pos::symbol::InternedString;
 use rustc_data_structures::sync::Lock;
 use rustc_data_structures::stable_hasher::HashStable;
-use ich::StableHashingContext;
+use crate::ich::StableHashingContext;
 
 // Query configuration and description traits.
 
@@ -901,7 +901,7 @@ impl<'tcx> QueryDescription<'tcx> for queries::optimized_mir<'tcx> {
     fn try_load_from_disk<'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
                               id: SerializedDepNodeIndex)
                               -> Option<Self::Value> {
-        let mir: Option<::mir::Mir<'tcx>> = tcx.queries.on_disk_cache
+        let mir: Option<crate::mir::Mir<'tcx>> = tcx.queries.on_disk_cache
                                                .try_load_query_result(tcx, id);
         mir.map(|x| tcx.alloc_mir(x))
     }
diff --git a/src/librustc/ty/query/job.rs b/src/librustc/ty/query/job.rs
index abbf74a7761ef..0793366e6d479 100644
--- a/src/librustc/ty/query/job.rs
+++ b/src/librustc/ty/query/job.rs
@@ -1,25 +1,27 @@
 #![allow(warnings)]
 
 use std::mem;
+use std::process;
+use std::{fmt, ptr};
+
 use rustc_data_structures::fx::FxHashSet;
 use rustc_data_structures::sync::{Lock, LockGuard, Lrc, Weak};
 use rustc_data_structures::OnDrop;
 use syntax_pos::Span;
-use ty::tls;
-use ty::query::Query;
-use ty::query::plumbing::CycleError;
+
+use crate::ty::tls;
+use crate::ty::query::Query;
+use crate::ty::query::plumbing::CycleError;
 #[cfg(not(parallel_compiler))]
-use ty::query::{
+use crate::ty::query::{
     plumbing::TryGetJob,
     config::QueryDescription,
 };
-use ty::context::TyCtxt;
-use std::process;
-use std::{fmt, ptr};
+use crate::ty::context::TyCtxt;
 
 #[cfg(parallel_compiler)]
 use {
-    rayon_core,
+    rustc_rayon_core as rayon_core,
     parking_lot::{Mutex, Condvar},
     std::sync::atomic::Ordering,
     std::thread,
@@ -89,7 +91,7 @@ impl<'tcx> QueryJob<'tcx> {
     /// For single threaded rustc there's no concurrent jobs running, so if we are waiting for any
     /// query that means that there is a query cycle, thus this always running a cycle error.
     #[cfg(parallel_compiler)]
-    pub(super) fn await<'lcx>(
+    pub(super) fn r#await<'lcx>(
         &self,
         tcx: TyCtxt<'_, 'tcx, 'lcx>,
         span: Span,
@@ -101,7 +103,7 @@ impl<'tcx> QueryJob<'tcx> {
                 cycle: Lock::new(None),
                 condvar: Condvar::new(),
             });
-            self.latch.await(&waiter);
+            self.latch.r#await(&waiter);
             // FIXME: Get rid of this lock. We have ownership of the QueryWaiter
             // although another thread may still have a Lrc reference so we cannot
             // use Lrc::get_mut
@@ -200,7 +202,7 @@ impl<'tcx> QueryLatch<'tcx> {
     }
 
     /// Awaits the caller on this latch by blocking the current thread.
-    fn await(&self, waiter: &Lrc<QueryWaiter<'tcx>>) {
+    fn r#await(&self, waiter: &Lrc<QueryWaiter<'tcx>>) {
         let mut info = self.info.lock();
         if !info.complete {
             // We push the waiter on to the `waiters` list. It can be accessed inside
diff --git a/src/librustc/ty/query/keys.rs b/src/librustc/ty/query/keys.rs
index af6f5a00dee5c..f5eb7374cc19b 100644
--- a/src/librustc/ty/query/keys.rs
+++ b/src/librustc/ty/query/keys.rs
@@ -1,12 +1,12 @@
 //! Defines the set of legal keys that can be used in queries.
 
-use infer::canonical::Canonical;
-use hir::def_id::{CrateNum, DefId, LOCAL_CRATE, DefIndex};
-use traits;
-use ty::{self, Ty, TyCtxt};
-use ty::subst::Substs;
-use ty::fast_reject::SimplifiedType;
-use mir;
+use crate::infer::canonical::Canonical;
+use crate::hir::def_id::{CrateNum, DefId, LOCAL_CRATE, DefIndex};
+use crate::traits;
+use crate::ty::{self, Ty, TyCtxt};
+use crate::ty::subst::Substs;
+use crate::ty::fast_reject::SimplifiedType;
+use crate::mir;
 
 use std::fmt::Debug;
 use std::hash::Hash;
diff --git a/src/librustc/ty/query/mod.rs b/src/librustc/ty/query/mod.rs
index d4884e712b860..20a700bb58dd1 100644
--- a/src/librustc/ty/query/mod.rs
+++ b/src/librustc/ty/query/mod.rs
@@ -1,48 +1,48 @@
-use dep_graph::{DepConstructor, DepNode};
-use errors::DiagnosticBuilder;
-use hir::def_id::{CrateNum, DefId, DefIndex};
-use hir::def::{Def, Export};
-use hir::{self, TraitCandidate, ItemLocalId, CodegenFnAttrs};
+use crate::dep_graph::{DepConstructor, DepNode};
+use crate::errors::DiagnosticBuilder;
+use crate::hir::def_id::{CrateNum, DefId, DefIndex};
+use crate::hir::def::{Def, Export};
+use crate::hir::{self, TraitCandidate, ItemLocalId, CodegenFnAttrs};
 use rustc_data_structures::svh::Svh;
-use infer::canonical::{self, Canonical};
-use lint;
-use middle::borrowck::BorrowCheckResult;
-use middle::cstore::{ExternCrate, LinkagePreference, NativeLibrary, ForeignModule};
-use middle::cstore::{NativeLibraryKind, DepKind, CrateSource};
-use middle::privacy::AccessLevels;
-use middle::reachable::ReachableSet;
-use middle::region;
-use middle::resolve_lifetime::{ResolveLifetimes, Region, ObjectLifetimeDefault};
-use middle::stability::{self, DeprecationEntry};
-use middle::lib_features::LibFeatures;
-use middle::lang_items::{LanguageItems, LangItem};
-use middle::exported_symbols::{SymbolExportLevel, ExportedSymbol};
-use mir::interpret::{ConstEvalRawResult, ConstEvalResult};
-use mir::mono::CodegenUnit;
-use mir;
-use mir::interpret::GlobalId;
-use session::{CompileResult, CrateDisambiguator};
-use session::config::{EntryFnType, OutputFilenames, OptLevel};
-use traits::{self, Vtable};
-use traits::query::{
+use crate::infer::canonical::{self, Canonical};
+use crate::lint;
+use crate::middle::borrowck::BorrowCheckResult;
+use crate::middle::cstore::{ExternCrate, LinkagePreference, NativeLibrary, ForeignModule};
+use crate::middle::cstore::{NativeLibraryKind, DepKind, CrateSource};
+use crate::middle::privacy::AccessLevels;
+use crate::middle::reachable::ReachableSet;
+use crate::middle::region;
+use crate::middle::resolve_lifetime::{ResolveLifetimes, Region, ObjectLifetimeDefault};
+use crate::middle::stability::{self, DeprecationEntry};
+use crate::middle::lib_features::LibFeatures;
+use crate::middle::lang_items::{LanguageItems, LangItem};
+use crate::middle::exported_symbols::{SymbolExportLevel, ExportedSymbol};
+use crate::mir::interpret::{ConstEvalRawResult, ConstEvalResult};
+use crate::mir::mono::CodegenUnit;
+use crate::mir;
+use crate::mir::interpret::GlobalId;
+use crate::session::{CompileResult, CrateDisambiguator};
+use crate::session::config::{EntryFnType, OutputFilenames, OptLevel};
+use crate::traits::{self, Vtable};
+use crate::traits::query::{
     CanonicalPredicateGoal, CanonicalProjectionGoal,
     CanonicalTyGoal, CanonicalTypeOpAscribeUserTypeGoal,
     CanonicalTypeOpEqGoal, CanonicalTypeOpSubtypeGoal, CanonicalTypeOpProvePredicateGoal,
     CanonicalTypeOpNormalizeGoal, NoSolution,
 };
-use traits::query::method_autoderef::MethodAutoderefStepsResult;
-use traits::query::dropck_outlives::{DtorckConstraint, DropckOutlivesResult};
-use traits::query::normalize::NormalizationResult;
-use traits::query::outlives_bounds::OutlivesBound;
-use traits::specialization_graph;
-use traits::Clauses;
-use ty::{self, CrateInherentImpls, ParamEnvAnd, Ty, TyCtxt};
-use ty::steal::Steal;
-use ty::subst::Substs;
-use util::nodemap::{DefIdSet, DefIdMap, ItemLocalSet};
-use util::common::{ErrorReported};
-use util::profiling::ProfileCategory::*;
-use session::Session;
+use crate::traits::query::method_autoderef::MethodAutoderefStepsResult;
+use crate::traits::query::dropck_outlives::{DtorckConstraint, DropckOutlivesResult};
+use crate::traits::query::normalize::NormalizationResult;
+use crate::traits::query::outlives_bounds::OutlivesBound;
+use crate::traits::specialization_graph;
+use crate::traits::Clauses;
+use crate::ty::{self, CrateInherentImpls, ParamEnvAnd, Ty, TyCtxt};
+use crate::ty::steal::Steal;
+use crate::ty::subst::Substs;
+use crate::util::nodemap::{DefIdSet, DefIdMap, ItemLocalSet};
+use crate::util::common::{ErrorReported};
+use crate::util::profiling::ProfileCategory::*;
+use crate::session::Session;
 
 use rustc_data_structures::bit_set::BitSet;
 use rustc_data_structures::indexed_vec::IndexVec;
diff --git a/src/librustc/ty/query/on_disk_cache.rs b/src/librustc/ty/query/on_disk_cache.rs
index a3f49de0d078b..9c9bc0f6aa11c 100644
--- a/src/librustc/ty/query/on_disk_cache.rs
+++ b/src/librustc/ty/query/on_disk_cache.rs
@@ -1,28 +1,28 @@
-use dep_graph::{DepNodeIndex, SerializedDepNodeIndex};
-use errors::Diagnostic;
-use hir;
-use hir::def_id::{CrateNum, DefIndex, DefId, LocalDefId, LOCAL_CRATE};
-use hir::map::definitions::DefPathHash;
-use ich::{CachingSourceMapView, Fingerprint};
-use mir::{self, interpret};
-use mir::interpret::{AllocDecodingSession, AllocDecodingState};
+use crate::dep_graph::{DepNodeIndex, SerializedDepNodeIndex};
+use crate::errors::Diagnostic;
+use crate::hir;
+use crate::hir::def_id::{CrateNum, DefIndex, DefId, LocalDefId, LOCAL_CRATE};
+use crate::hir::map::definitions::DefPathHash;
+use crate::ich::{CachingSourceMapView, Fingerprint};
+use crate::mir::{self, interpret};
+use crate::mir::interpret::{AllocDecodingSession, AllocDecodingState};
 use rustc_data_structures::fx::FxHashMap;
 use rustc_data_structures::thin_vec::ThinVec;
 use rustc_data_structures::sync::{Lrc, Lock, HashMapExt, Once};
 use rustc_data_structures::indexed_vec::{IndexVec, Idx};
-use rustc_serialize::{Decodable, Decoder, Encodable, Encoder, opaque,
+use crate::rustc_serialize::{Decodable, Decoder, Encodable, Encoder, opaque,
                       SpecializedDecoder, SpecializedEncoder,
                       UseSpecializedDecodable, UseSpecializedEncodable};
-use session::{CrateDisambiguator, Session};
+use crate::session::{CrateDisambiguator, Session};
 use std::mem;
 use syntax::ast::NodeId;
 use syntax::source_map::{SourceMap, StableSourceFileId};
 use syntax_pos::{BytePos, Span, DUMMY_SP, SourceFile};
 use syntax_pos::hygiene::{Mark, SyntaxContext, ExpnInfo};
-use ty;
-use ty::codec::{self as ty_codec, TyDecoder, TyEncoder};
-use ty::context::TyCtxt;
-use util::common::time;
+use crate::ty;
+use crate::ty::codec::{self as ty_codec, TyDecoder, TyEncoder};
+use crate::ty::context::TyCtxt;
+use crate::util::common::time;
 
 const TAG_FILE_FOOTER: u128 = 0xC0FFEE_C0FFEE_C0FFEE_C0FFEE_C0FFEE;
 
@@ -202,7 +202,7 @@ impl<'sess> OnDiskCache<'sess> {
             let mut query_result_index = EncodedQueryResultIndex::new();
 
             time(tcx.sess, "encode query results", || {
-                use ty::query::queries::*;
+                use crate::ty::query::queries::*;
                 let enc = &mut encoder;
                 let qri = &mut query_result_index;
 
@@ -225,11 +225,11 @@ impl<'sess> OnDiskCache<'sess> {
                 encode_query_results::<specialization_graph_of<'_>, _>(tcx, enc, qri)?;
 
                 // const eval is special, it only encodes successfully evaluated constants
-                use ty::query::QueryAccessors;
+                use crate::ty::query::QueryAccessors;
                 let cache = const_eval::query_cache(tcx).borrow();
                 assert!(cache.active.is_empty());
                 for (key, entry) in cache.results.iter() {
-                    use ty::query::config::QueryDescription;
+                    use crate::ty::query::config::QueryDescription;
                     if const_eval::cache_on_disk(tcx, key.clone()) {
                         if let Ok(ref value) = entry.value {
                             let dep_node = SerializedDepNodeIndex::new(entry.index.index());
@@ -777,7 +777,7 @@ impl<'enc, 'a, 'tcx, E> CacheEncoder<'enc, 'a, 'tcx, E>
                                                  value: &V)
                                                  -> Result<(), E::Error>
     {
-        use ty::codec::TyEncoder;
+        use crate::ty::codec::TyEncoder;
         let start_pos = self.position();
 
         tag.encode(self)?;
diff --git a/src/librustc/ty/query/plumbing.rs b/src/librustc/ty/query/plumbing.rs
index 69bff8d25b024..a26b21a1059fe 100644
--- a/src/librustc/ty/query/plumbing.rs
+++ b/src/librustc/ty/query/plumbing.rs
@@ -2,19 +2,19 @@
 //! that generate the actual methods on tcx which find and execute the
 //! provider, manage the caches, and so forth.
 
-use dep_graph::{DepNodeIndex, DepNode, DepKind, SerializedDepNodeIndex};
-use errors::DiagnosticBuilder;
-use errors::Level;
-use errors::Diagnostic;
-use errors::FatalError;
-use ty::tls;
-use ty::{TyCtxt};
-use ty::query::Query;
-use ty::query::config::{QueryConfig, QueryDescription};
-use ty::query::job::{QueryJob, QueryResult, QueryInfo};
-use ty::item_path;
-
-use util::common::{profq_msg, ProfileQueriesMsg, QueryMsg};
+use crate::dep_graph::{DepNodeIndex, DepNode, DepKind, SerializedDepNodeIndex};
+use crate::errors::DiagnosticBuilder;
+use crate::errors::Level;
+use crate::errors::Diagnostic;
+use crate::errors::FatalError;
+use crate::ty::tls;
+use crate::ty::{TyCtxt};
+use crate::ty::query::Query;
+use crate::ty::query::config::{QueryConfig, QueryDescription};
+use crate::ty::query::job::{QueryJob, QueryResult, QueryInfo};
+use crate::ty::item_path;
+
+use crate::util::common::{profq_msg, ProfileQueriesMsg, QueryMsg};
 
 use rustc_data_structures::fx::{FxHashMap};
 use rustc_data_structures::sync::{Lrc, Lock};
@@ -160,7 +160,7 @@ impl<'a, 'tcx, Q: QueryDescription<'tcx>> JobOwner<'a, 'tcx, Q> {
             // thread
             #[cfg(parallel_compiler)]
             {
-                if let Err(cycle) = job.await(tcx, span) {
+                if let Err(cycle) = job.r#await(tcx, span) {
                     return TryGetJob::JobCompleted(Err(cycle));
                 }
             }
@@ -367,7 +367,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
         // Fast path for when incr. comp. is off. `to_dep_node` is
         // expensive for some DepKinds.
         if !self.dep_graph.is_fully_enabled() {
-            let null_dep_node = DepNode::new_no_params(::dep_graph::DepKind::Null);
+            let null_dep_node = DepNode::new_no_params(crate::dep_graph::DepKind::Null);
             return Ok(self.force_query_with_job::<Q>(key, job, null_dep_node).0);
         }
 
@@ -500,7 +500,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
         dep_node_index: DepNodeIndex,
     ) {
         use rustc_data_structures::stable_hasher::{StableHasher, HashStable};
-        use ich::Fingerprint;
+        use crate::ich::Fingerprint;
 
         assert!(Some(self.dep_graph.fingerprint_of(dep_node_index)) ==
                 self.dep_graph.prev_fingerprint_of(dep_node),
@@ -566,7 +566,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
             self.dep_graph.mark_loaded_from_cache(dep_node_index, false);
         }
 
-        if dep_node.kind != ::dep_graph::DepKind::Null {
+        if dep_node.kind != crate::dep_graph::DepKind::Null {
             if unlikely!(!diagnostics.is_empty()) {
                 self.queries.on_disk_cache
                     .store_diagnostics(dep_node_index, diagnostics);
@@ -698,13 +698,13 @@ macro_rules! define_queries_inner {
         #[cfg(parallel_compiler)]
         use ty::query::job::QueryResult;
         use rustc_data_structures::sync::Lock;
-        use {
+        use crate::{
             rustc_data_structures::stable_hasher::HashStable,
             rustc_data_structures::stable_hasher::StableHasherResult,
             rustc_data_structures::stable_hasher::StableHasher,
             ich::StableHashingContext
         };
-        use util::profiling::ProfileCategory;
+        use crate::util::profiling::ProfileCategory;
 
         define_queries_struct! {
             tcx: $tcx,
@@ -947,7 +947,7 @@ macro_rules! define_queries_inner {
             #[allow(unused)]
             #[inline(always)]
             fn to_dep_node(tcx: TyCtxt<'_, $tcx, '_>, key: &Self::Key) -> DepNode {
-                use dep_graph::DepConstructor::*;
+                use crate::dep_graph::DepConstructor::*;
 
                 DepNode::new(tcx, $node(*key))
             }
@@ -1127,7 +1127,7 @@ macro_rules! define_provider_struct {
 pub fn force_from_dep_node<'a, 'gcx, 'lcx>(tcx: TyCtxt<'a, 'gcx, 'lcx>,
                                            dep_node: &DepNode)
                                            -> bool {
-    use hir::def_id::LOCAL_CRATE;
+    use crate::hir::def_id::LOCAL_CRATE;
 
     // We must avoid ever having to call force_from_dep_node() for a
     // DepNode::CodegenUnit:
@@ -1167,7 +1167,7 @@ pub fn force_from_dep_node<'a, 'gcx, 'lcx>(tcx: TyCtxt<'a, 'gcx, 'lcx>,
     macro_rules! force {
         ($query:ident, $key:expr) => {
             {
-                tcx.force_query::<::ty::query::queries::$query<'_>>($key, DUMMY_SP, *dep_node);
+                tcx.force_query::<crate::ty::query::queries::$query<'_>>($key, DUMMY_SP, *dep_node);
             }
         }
     };
@@ -1437,8 +1437,8 @@ macro_rules! impl_load_from_cache {
             // Check whether the query invocation corresponding to the given
             // DepNode is eligible for on-disk-caching.
             pub fn cache_on_disk(&self, tcx: TyCtxt<'_, '_, '_>) -> bool {
-                use ty::query::queries;
-                use ty::query::QueryDescription;
+                use crate::ty::query::queries;
+                use crate::ty::query::QueryDescription;
 
                 match self.kind {
                     $(DepKind::$dep_kind => {
diff --git a/src/librustc/ty/query/values.rs b/src/librustc/ty/query/values.rs
index 3f84f1bc78972..11f55208d6e48 100644
--- a/src/librustc/ty/query/values.rs
+++ b/src/librustc/ty/query/values.rs
@@ -1,4 +1,4 @@
-use ty::{self, Ty, TyCtxt};
+use crate::ty::{self, Ty, TyCtxt};
 
 use syntax::symbol::Symbol;
 
diff --git a/src/librustc/ty/relate.rs b/src/librustc/ty/relate.rs
index a16d6fea74c0b..3dbd0dc1d97f7 100644
--- a/src/librustc/ty/relate.rs
+++ b/src/librustc/ty/relate.rs
@@ -4,18 +4,18 @@
 //! types or regions but can be other things. Examples of type relations are
 //! subtyping, type equality, etc.
 
-use hir::def_id::DefId;
-use ty::subst::{Kind, UnpackedKind, Substs};
-use ty::{self, Ty, TyCtxt, TypeFoldable};
-use ty::error::{ExpectedFound, TypeError};
-use mir::interpret::GlobalId;
-use util::common::ErrorReported;
+use crate::hir::def_id::DefId;
+use crate::ty::subst::{Kind, UnpackedKind, Substs};
+use crate::ty::{self, Ty, TyCtxt, TypeFoldable};
+use crate::ty::error::{ExpectedFound, TypeError};
+use crate::mir::interpret::GlobalId;
+use crate::util::common::ErrorReported;
 use syntax_pos::DUMMY_SP;
 use std::rc::Rc;
 use std::iter;
 use rustc_target::spec::abi;
-use hir as ast;
-use traits;
+use crate::hir as ast;
+use crate::traits;
 
 pub type RelateResult<'tcx, T> = Result<T, TypeError<'tcx>>;
 
@@ -588,7 +588,7 @@ impl<'tcx> Relate<'tcx> for &'tcx ty::List<ty::ExistentialPredicate<'tcx>> {
 
         let tcx = relation.tcx();
         let v = a.iter().zip(b.iter()).map(|(ep_a, ep_b)| {
-            use ty::ExistentialPredicate::*;
+            use crate::ty::ExistentialPredicate::*;
             match (*ep_a, *ep_b) {
                 (Trait(ref a), Trait(ref b)) => Ok(Trait(relation.relate(a, b)?)),
                 (Projection(ref a), Projection(ref b)) => Ok(Projection(relation.relate(a, b)?)),
@@ -746,7 +746,7 @@ impl<'tcx> Relate<'tcx> for traits::WhereClause<'tcx> {
     ) -> RelateResult<'tcx, traits::WhereClause<'tcx>>
         where R: TypeRelation<'a, 'gcx, 'tcx>, 'gcx: 'tcx, 'tcx: 'a
     {
-        use traits::WhereClause::*;
+        use crate::traits::WhereClause::*;
         match (a, b) {
             (Implemented(a_pred), Implemented(b_pred)) => {
                 Ok(Implemented(relation.relate(a_pred, b_pred)?))
@@ -783,7 +783,7 @@ impl<'tcx> Relate<'tcx> for traits::WellFormed<'tcx> {
     ) -> RelateResult<'tcx, traits::WellFormed<'tcx>>
         where R: TypeRelation<'a, 'gcx, 'tcx>, 'gcx: 'tcx, 'tcx: 'a
     {
-        use traits::WellFormed::*;
+        use crate::traits::WellFormed::*;
         match (a, b) {
             (Trait(a_pred), Trait(b_pred)) => Ok(Trait(relation.relate(a_pred, b_pred)?)),
             (Ty(a_ty), Ty(b_ty)) => Ok(Ty(relation.relate(a_ty, b_ty)?)),
@@ -800,7 +800,7 @@ impl<'tcx> Relate<'tcx> for traits::FromEnv<'tcx> {
     ) -> RelateResult<'tcx, traits::FromEnv<'tcx>>
         where R: TypeRelation<'a, 'gcx, 'tcx>, 'gcx: 'tcx, 'tcx: 'a
     {
-        use traits::FromEnv::*;
+        use crate::traits::FromEnv::*;
         match (a, b) {
             (Trait(a_pred), Trait(b_pred)) => Ok(Trait(relation.relate(a_pred, b_pred)?)),
             (Ty(a_ty), Ty(b_ty)) => Ok(Ty(relation.relate(a_ty, b_ty)?)),
@@ -817,7 +817,7 @@ impl<'tcx> Relate<'tcx> for traits::DomainGoal<'tcx> {
     ) -> RelateResult<'tcx, traits::DomainGoal<'tcx>>
         where R: TypeRelation<'a, 'gcx, 'tcx>, 'gcx: 'tcx, 'tcx: 'a
     {
-        use traits::DomainGoal::*;
+        use crate::traits::DomainGoal::*;
         match (a, b) {
             (Holds(a_wc), Holds(b_wc)) => Ok(Holds(relation.relate(a_wc, b_wc)?)),
             (WellFormed(a_wf), WellFormed(b_wf)) => Ok(WellFormed(relation.relate(a_wf, b_wf)?)),
@@ -840,7 +840,7 @@ impl<'tcx> Relate<'tcx> for traits::Goal<'tcx> {
     ) -> RelateResult<'tcx, traits::Goal<'tcx>>
         where R: TypeRelation<'a, 'gcx, 'tcx>, 'gcx: 'tcx, 'tcx: 'a
     {
-        use traits::GoalKind::*;
+        use crate::traits::GoalKind::*;
         match (a, b) {
             (Implies(a_clauses, a_goal), Implies(b_clauses, b_goal)) => {
                 let clauses = relation.relate(a_clauses, b_clauses)?;
@@ -904,7 +904,7 @@ impl<'tcx> Relate<'tcx> for traits::Clause<'tcx> {
     ) -> RelateResult<'tcx, traits::Clause<'tcx>>
         where R: TypeRelation<'a, 'gcx, 'tcx>, 'gcx: 'tcx, 'tcx: 'a
     {
-        use traits::Clause::*;
+        use crate::traits::Clause::*;
         match (a, b) {
             (Implies(a_clause), Implies(b_clause)) => {
                 let clause = relation.relate(a_clause, b_clause)?;
diff --git a/src/librustc/ty/structural_impls.rs b/src/librustc/ty/structural_impls.rs
index 28f5a65374d98..62a49238ebf3d 100644
--- a/src/librustc/ty/structural_impls.rs
+++ b/src/librustc/ty/structural_impls.rs
@@ -3,13 +3,13 @@
 //! hand, though we've recently added some macros (e.g.,
 //! `BraceStructLiftImpl!`) to help with the tedium.
 
-use mir::ProjectionKind;
-use mir::interpret::ConstValue;
-use ty::{self, Lift, Ty, TyCtxt};
-use ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
+use crate::mir::ProjectionKind;
+use crate::mir::interpret::ConstValue;
+use crate::ty::{self, Lift, Ty, TyCtxt};
+use crate::ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
 use rustc_data_structures::indexed_vec::{IndexVec, Idx};
 use smallvec::SmallVec;
-use mir::interpret;
+use crate::mir::interpret;
 
 use std::rc::Rc;
 
@@ -23,35 +23,35 @@ CloneTypeFoldableAndLiftImpls! {
     (),
     bool,
     usize,
-    ::ty::layout::VariantIdx,
+    crate::ty::layout::VariantIdx,
     u64,
     String,
-    ::middle::region::Scope,
+    crate::middle::region::Scope,
     ::syntax::ast::FloatTy,
     ::syntax::ast::NodeId,
     ::syntax_pos::symbol::Symbol,
-    ::hir::def::Def,
-    ::hir::def_id::DefId,
-    ::hir::InlineAsm,
-    ::hir::MatchSource,
-    ::hir::Mutability,
-    ::hir::Unsafety,
+    crate::hir::def::Def,
+    crate::hir::def_id::DefId,
+    crate::hir::InlineAsm,
+    crate::hir::MatchSource,
+    crate::hir::Mutability,
+    crate::hir::Unsafety,
     ::rustc_target::spec::abi::Abi,
-    ::mir::Local,
-    ::mir::Promoted,
-    ::traits::Reveal,
-    ::ty::adjustment::AutoBorrowMutability,
-    ::ty::AdtKind,
+    crate::mir::Local,
+    crate::mir::Promoted,
+    crate::traits::Reveal,
+    crate::ty::adjustment::AutoBorrowMutability,
+    crate::ty::AdtKind,
     // Including `BoundRegion` is a *bit* dubious, but direct
     // references to bound region appear in `ty::Error`, and aren't
     // really meant to be folded. In general, we can only fold a fully
     // general `Region`.
-    ::ty::BoundRegion,
-    ::ty::ClosureKind,
-    ::ty::IntVarValue,
-    ::ty::ParamTy,
-    ::ty::UniverseIndex,
-    ::ty::Variance,
+    crate::ty::BoundRegion,
+    crate::ty::ClosureKind,
+    crate::ty::IntVarValue,
+    crate::ty::ParamTy,
+    crate::ty::UniverseIndex,
+    crate::ty::Variance,
     ::syntax_pos::Span,
 }
 
@@ -421,7 +421,7 @@ impl<'tcx, T: Lift<'tcx>> Lift<'tcx> for ty::error::ExpectedFound<T> {
 impl<'a, 'tcx> Lift<'tcx> for ty::error::TypeError<'a> {
     type Lifted = ty::error::TypeError<'tcx>;
     fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
-        use ty::error::TypeError::*;
+        use crate::ty::error::TypeError::*;
 
         Some(match *self {
             Mismatch => Mismatch,
@@ -651,7 +651,7 @@ impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<ProjectionKind<'tcx>> {
 
 impl<'tcx> TypeFoldable<'tcx> for ty::instance::Instance<'tcx> {
     fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
-        use ty::InstanceDef::*;
+        use crate::ty::InstanceDef::*;
         Self {
             substs: self.substs.fold_with(folder),
             def: match self.def {
@@ -682,7 +682,7 @@ impl<'tcx> TypeFoldable<'tcx> for ty::instance::Instance<'tcx> {
     }
 
     fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
-        use ty::InstanceDef::*;
+        use crate::ty::InstanceDef::*;
         self.substs.visit_with(visitor) ||
         match self.def {
             Item(did) | VtableShim(did) | Intrinsic(did) | Virtual(did, _) => {
diff --git a/src/librustc/ty/sty.rs b/src/librustc/ty/sty.rs
index 671a0fc2d5d7a..790cc15ca17b6 100644
--- a/src/librustc/ty/sty.rs
+++ b/src/librustc/ty/sty.rs
@@ -1,17 +1,17 @@
 //! This module contains `TyKind` and its major components.
 
-use hir;
-use hir::def_id::DefId;
-use infer::canonical::Canonical;
-use mir::interpret::ConstValue;
-use middle::region;
+use crate::hir;
+use crate::hir::def_id::DefId;
+use crate::infer::canonical::Canonical;
+use crate::mir::interpret::ConstValue;
+use crate::middle::region;
 use polonius_engine::Atom;
 use rustc_data_structures::indexed_vec::Idx;
-use ty::subst::{Substs, Subst, Kind, UnpackedKind};
-use ty::{self, AdtDef, TypeFlags, Ty, TyCtxt, TypeFoldable};
-use ty::{List, TyS, ParamEnvAnd, ParamEnv};
-use util::captures::Captures;
-use mir::interpret::{Scalar, Pointer};
+use crate::ty::subst::{Substs, Subst, Kind, UnpackedKind};
+use crate::ty::{self, AdtDef, TypeFlags, Ty, TyCtxt, TypeFoldable};
+use crate::ty::{List, TyS, ParamEnvAnd, ParamEnv};
+use crate::util::captures::Captures;
+use crate::mir::interpret::{Scalar, Pointer};
 
 use smallvec::SmallVec;
 use std::iter;
@@ -550,7 +550,7 @@ impl<'a, 'gcx, 'tcx> ExistentialPredicate<'tcx> {
 impl<'a, 'gcx, 'tcx> Binder<ExistentialPredicate<'tcx>> {
     pub fn with_self_ty(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>, self_ty: Ty<'tcx>)
         -> ty::Predicate<'tcx> {
-        use ty::ToPredicate;
+        use crate::ty::ToPredicate;
         match *self.skip_binder() {
             ExistentialPredicate::Trait(tr) => Binder(tr).with_self_ty(tcx, self_ty).to_predicate(),
             ExistentialPredicate::Projection(p) =>
diff --git a/src/librustc/ty/subst.rs b/src/librustc/ty/subst.rs
index 64e7af815b4bf..d7c322d0f8402 100644
--- a/src/librustc/ty/subst.rs
+++ b/src/librustc/ty/subst.rs
@@ -1,9 +1,9 @@
 // Type substitutions.
 
-use hir::def_id::DefId;
-use infer::canonical::Canonical;
-use ty::{self, Lift, List, Ty, TyCtxt};
-use ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
+use crate::hir::def_id::DefId;
+use crate::infer::canonical::Canonical;
+use crate::ty::{self, Lift, List, Ty, TyCtxt};
+use crate::ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
 
 use serialize::{self, Encodable, Encoder, Decodable, Decoder};
 use syntax_pos::{Span, DUMMY_SP};
diff --git a/src/librustc/ty/trait_def.rs b/src/librustc/ty/trait_def.rs
index 37ec560d6c19f..5429a2504b97b 100644
--- a/src/librustc/ty/trait_def.rs
+++ b/src/librustc/ty/trait_def.rs
@@ -1,11 +1,11 @@
-use hir;
-use hir::def_id::DefId;
-use hir::map::DefPathHash;
-use ich::{self, StableHashingContext};
-use traits::specialization_graph;
-use ty::fast_reject;
-use ty::fold::TypeFoldable;
-use ty::{Ty, TyCtxt};
+use crate::hir;
+use crate::hir::def_id::DefId;
+use crate::hir::map::DefPathHash;
+use crate::ich::{self, StableHashingContext};
+use crate::traits::specialization_graph;
+use crate::ty::fast_reject;
+use crate::ty::fold::TypeFoldable;
+use crate::ty::{Ty, TyCtxt};
 
 use rustc_data_structures::fx::FxHashMap;
 use rustc_data_structures::stable_hasher::{HashStable, StableHasher,
diff --git a/src/librustc/ty/util.rs b/src/librustc/ty/util.rs
index 2fe47b2f032f8..61544932b4329 100644
--- a/src/librustc/ty/util.rs
+++ b/src/librustc/ty/util.rs
@@ -1,18 +1,18 @@
 //! misc. type-system utilities too small to deserve their own file
 
-use hir::def::Def;
-use hir::def_id::DefId;
-use hir::map::DefPathData;
-use hir::{self, Node};
-use ich::NodeIdHashingMode;
-use traits::{self, ObligationCause};
-use ty::{self, Ty, TyCtxt, GenericParamDefKind, TypeFoldable};
-use ty::subst::{Subst, Substs, UnpackedKind};
-use ty::query::TyCtxtAt;
-use ty::TyKind::*;
-use ty::layout::{Integer, IntegerExt};
-use util::common::ErrorReported;
-use middle::lang_items;
+use crate::hir::def::Def;
+use crate::hir::def_id::DefId;
+use crate::hir::map::DefPathData;
+use crate::hir::{self, Node};
+use crate::ich::NodeIdHashingMode;
+use crate::traits::{self, ObligationCause};
+use crate::ty::{self, Ty, TyCtxt, GenericParamDefKind, TypeFoldable};
+use crate::ty::subst::{Subst, Substs, UnpackedKind};
+use crate::ty::query::TyCtxtAt;
+use crate::ty::TyKind::*;
+use crate::ty::layout::{Integer, IntegerExt};
+use crate::util::common::ErrorReported;
+use crate::middle::lang_items;
 
 use rustc_data_structures::stable_hasher::{StableHasher, HashStable};
 use rustc_data_structures::fx::{FxHashMap, FxHashSet};
diff --git a/src/librustc/ty/walk.rs b/src/librustc/ty/walk.rs
index 6887d092fcd62..126f5290af513 100644
--- a/src/librustc/ty/walk.rs
+++ b/src/librustc/ty/walk.rs
@@ -1,7 +1,7 @@
 //! An iterator over the type substructure.
 //! WARNING: this does not keep track of the region depth.
 
-use ty::{self, Ty};
+use crate::ty::{self, Ty};
 use smallvec::{self, SmallVec};
 
 // The TypeWalker's stack is hot enough that it's worth going to some effort to
diff --git a/src/librustc/ty/wf.rs b/src/librustc/ty/wf.rs
index ef68394029680..2aae953c1c40a 100644
--- a/src/librustc/ty/wf.rs
+++ b/src/librustc/ty/wf.rs
@@ -1,12 +1,12 @@
-use hir::def_id::DefId;
-use infer::InferCtxt;
-use ty::subst::Substs;
-use traits;
-use ty::{self, ToPredicate, Ty, TyCtxt, TypeFoldable};
+use crate::hir::def_id::DefId;
+use crate::infer::InferCtxt;
+use crate::ty::subst::Substs;
+use crate::traits;
+use crate::ty::{self, ToPredicate, Ty, TyCtxt, TypeFoldable};
 use std::iter::once;
 use syntax::ast;
 use syntax_pos::Span;
-use middle::lang_items;
+use crate::middle::lang_items;
 
 /// Returns the set of obligations needed to make `ty` well-formed.
 /// If `ty` contains unresolved inference variables, this may include
diff --git a/src/librustc/util/bug.rs b/src/librustc/util/bug.rs
index 7698f5ece98cc..02ddfab6d826e 100644
--- a/src/librustc/util/bug.rs
+++ b/src/librustc/util/bug.rs
@@ -1,6 +1,6 @@
 // These functions are used by macro expansion for bug! and span_bug!
 
-use ty::tls;
+use crate::ty::tls;
 use std::fmt;
 use syntax_pos::{Span, MultiSpan};
 
diff --git a/src/librustc/util/common.rs b/src/librustc/util/common.rs
index cc0ca165053d3..f6743ed75d92e 100644
--- a/src/librustc/util/common.rs
+++ b/src/librustc/util/common.rs
@@ -12,10 +12,10 @@ use std::time::{Duration, Instant};
 
 use std::sync::mpsc::{Sender};
 use syntax_pos::{SpanData};
-use ty::TyCtxt;
-use dep_graph::{DepNode};
+use crate::ty::TyCtxt;
+use crate::dep_graph::{DepNode};
 use lazy_static;
-use session::Session;
+use crate::session::Session;
 
 // The name of the associated type for `Fn` return types
 pub const FN_OUTPUT_NAME: &str = "Output";
diff --git a/src/librustc/util/nodemap.rs b/src/librustc/util/nodemap.rs
index fe6ab075a1a8a..6969b2f872ade 100644
--- a/src/librustc/util/nodemap.rs
+++ b/src/librustc/util/nodemap.rs
@@ -1,7 +1,7 @@
 //! An efficient hash map for node IDs
 
-use hir::def_id::DefId;
-use hir::{HirId, ItemLocalId};
+use crate::hir::def_id::DefId;
+use crate::hir::{HirId, ItemLocalId};
 use syntax::ast;
 
 pub use rustc_data_structures::fx::FxHashMap;
diff --git a/src/librustc/util/ppaux.rs b/src/librustc/util/ppaux.rs
index 51e9192cd290d..2cd82d44af3aa 100644
--- a/src/librustc/util/ppaux.rs
+++ b/src/librustc/util/ppaux.rs
@@ -1,15 +1,15 @@
-use hir::def_id::DefId;
-use hir::map::definitions::DefPathData;
-use middle::region;
-use ty::subst::{self, Subst};
-use ty::{BrAnon, BrEnv, BrFresh, BrNamed};
-use ty::{Bool, Char, Adt};
-use ty::{Error, Str, Array, Slice, Float, FnDef, FnPtr};
-use ty::{Param, Bound, RawPtr, Ref, Never, Tuple};
-use ty::{Closure, Generator, GeneratorWitness, Foreign, Projection, Opaque};
-use ty::{Placeholder, UnnormalizedProjection, Dynamic, Int, Uint, Infer};
-use ty::{self, Ty, TyCtxt, TypeFoldable, GenericParamCount, GenericParamDefKind};
-use util::nodemap::FxHashSet;
+use crate::hir::def_id::DefId;
+use crate::hir::map::definitions::DefPathData;
+use crate::middle::region;
+use crate::ty::subst::{self, Subst};
+use crate::ty::{BrAnon, BrEnv, BrFresh, BrNamed};
+use crate::ty::{Bool, Char, Adt};
+use crate::ty::{Error, Str, Array, Slice, Float, FnDef, FnPtr};
+use crate::ty::{Param, Bound, RawPtr, Ref, Never, Tuple};
+use crate::ty::{Closure, Generator, GeneratorWitness, Foreign, Projection, Opaque};
+use crate::ty::{Placeholder, UnnormalizedProjection, Dynamic, Int, Uint, Infer};
+use crate::ty::{self, Ty, TyCtxt, TypeFoldable, GenericParamCount, GenericParamDefKind};
+use crate::util::nodemap::FxHashSet;
 
 use std::cell::Cell;
 use std::fmt;
@@ -18,7 +18,7 @@ use std::usize;
 use rustc_target::spec::abi::Abi;
 use syntax::ast::CRATE_NODE_ID;
 use syntax::symbol::{Symbol, InternedString};
-use hir;
+use crate::hir;
 
 /// The "region highlights" are used to control region printing during
 /// specific error messages. When a "region highlight" is enabled, it
diff --git a/src/librustc/util/profiling.rs b/src/librustc/util/profiling.rs
index d31a06d6cb82d..0e03946f82a5c 100644
--- a/src/librustc/util/profiling.rs
+++ b/src/librustc/util/profiling.rs
@@ -1,4 +1,4 @@
-use session::config::Options;
+use crate::session::config::Options;
 
 use std::fs;
 use std::io::{self, StderrLock, Write};

From 80c052bed76d7b7406e956747012bc8a929fe909 Mon Sep 17 00:00:00 2001
From: Dan Robertson <dan@dlrobertson.com>
Date: Tue, 5 Feb 2019 15:52:54 +0000
Subject: [PATCH 10/24] Do not ICE in codegen given a extern_type static

The layout of a extern_type static is unsized, but may pass the
Well-Formed check in typeck. As a result, we cannot assume that
a static is sized when generating the `Place` for an r-value.
---
 src/librustc_codegen_ssa/mir/place.rs         | 19 ++++++++++++++++++-
 .../static-extern-type/Makefile               |  5 +++++
 .../static-extern-type/define-foo.c           | 11 +++++++++++
 .../static-extern-type/use-foo.rs             | 14 ++++++++++++++
 4 files changed, 48 insertions(+), 1 deletion(-)
 create mode 100644 src/test/run-make-fulldeps/static-extern-type/Makefile
 create mode 100644 src/test/run-make-fulldeps/static-extern-type/define-foo.c
 create mode 100644 src/test/run-make-fulldeps/static-extern-type/use-foo.rs

diff --git a/src/librustc_codegen_ssa/mir/place.rs b/src/librustc_codegen_ssa/mir/place.rs
index b10611e5ac797..596f97a038892 100644
--- a/src/librustc_codegen_ssa/mir/place.rs
+++ b/src/librustc_codegen_ssa/mir/place.rs
@@ -41,6 +41,21 @@ impl<'a, 'tcx: 'a, V: CodegenObject> PlaceRef<'tcx, V> {
         }
     }
 
+    fn new_thin_place<Bx: BuilderMethods<'a, 'tcx, Value = V>>(
+        bx: &mut Bx,
+        llval: V,
+        layout: TyLayout<'tcx>,
+        align: Align,
+    ) -> PlaceRef<'tcx, V> {
+        assert!(!bx.cx().type_has_metadata(layout.ty));
+        PlaceRef {
+            llval,
+            llextra: None,
+            layout,
+            align
+        }
+    }
+
     pub fn alloca<Bx: BuilderMethods<'a, 'tcx, Value = V>>(
         bx: &mut Bx,
         layout: TyLayout<'tcx>,
@@ -421,8 +436,10 @@ impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
                 }
             }
             mir::Place::Static(box mir::Static { def_id, ty }) => {
+                // NB: The layout of a static may be unsized as is the case when working
+                // with a static that is an extern_type.
                 let layout = cx.layout_of(self.monomorphize(&ty));
-                PlaceRef::new_sized(bx.get_static(def_id), layout, layout.align.abi)
+                PlaceRef::new_thin_place(bx, bx.get_static(def_id), layout, layout.align.abi)
             },
             mir::Place::Projection(box mir::Projection {
                 ref base,
diff --git a/src/test/run-make-fulldeps/static-extern-type/Makefile b/src/test/run-make-fulldeps/static-extern-type/Makefile
new file mode 100644
index 0000000000000..5879fc0ce7781
--- /dev/null
+++ b/src/test/run-make-fulldeps/static-extern-type/Makefile
@@ -0,0 +1,5 @@
+-include ../tools.mk
+
+all: $(call NATIVE_STATICLIB,define-foo)
+	$(RUSTC) -ldefine-foo use-foo.rs
+	$(call RUN,use-foo) || exit 1
diff --git a/src/test/run-make-fulldeps/static-extern-type/define-foo.c b/src/test/run-make-fulldeps/static-extern-type/define-foo.c
new file mode 100644
index 0000000000000..39be5acfa1118
--- /dev/null
+++ b/src/test/run-make-fulldeps/static-extern-type/define-foo.c
@@ -0,0 +1,11 @@
+#include <stdint.h>
+
+struct Foo {
+    uint8_t x;
+};
+
+struct Foo FOO = { 42 };
+
+uint8_t bar(const struct Foo* foo) {
+    return foo->x;
+}
diff --git a/src/test/run-make-fulldeps/static-extern-type/use-foo.rs b/src/test/run-make-fulldeps/static-extern-type/use-foo.rs
new file mode 100644
index 0000000000000..932b5b5944bc7
--- /dev/null
+++ b/src/test/run-make-fulldeps/static-extern-type/use-foo.rs
@@ -0,0 +1,14 @@
+#![feature(extern_types)]
+
+extern "C" {
+    type Foo;
+    static FOO: Foo;
+    fn bar(foo: *const Foo) -> u8;
+}
+
+fn main() {
+    unsafe {
+        let foo = &FOO;
+        assert_eq!(bar(foo), 42);
+    }
+}

From f7ed6e18160bc8fccf27a73c05f3935c9e8f672e Mon Sep 17 00:00:00 2001
From: Nicholas Nethercote <nnethercote@mozilla.com>
Date: Wed, 6 Feb 2019 18:02:32 +1100
Subject: [PATCH 11/24] Make an assert debug-only in
 `find_constraint_paths_between_regions`.

This reduces instruction counts for NLL builds of `wg-grammar` by over
20%.
---
 .../borrow_check/nll/region_infer/error_reporting/mod.rs        | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/mod.rs b/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/mod.rs
index ec68ddaf3c852..550668a7ceece 100644
--- a/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/mod.rs
+++ b/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/mod.rs
@@ -205,7 +205,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
             for constraint in self.constraint_graph
                 .outgoing_edges(r, &self.constraints, fr_static)
             {
-                assert_eq!(constraint.sup, r);
+                debug_assert_eq!(constraint.sup, r);
                 let sub_region = constraint.sub;
                 if let Trace::NotVisited = context[sub_region] {
                     context[sub_region] = Trace::FromOutlivesConstraint(constraint);

From 20022f8b912f26cea45ae2dc1ed15e14d5f6b996 Mon Sep 17 00:00:00 2001
From: Taiki Endo <te316e89@gmail.com>
Date: Wed, 6 Feb 2019 22:28:47 +0900
Subject: [PATCH 12/24] librustc_tsan => 2018

---
 src/librustc_tsan/Cargo.toml | 1 +
 src/librustc_tsan/build.rs   | 3 ---
 src/librustc_tsan/lib.rs     | 3 ++-
 3 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/src/librustc_tsan/Cargo.toml b/src/librustc_tsan/Cargo.toml
index f0618275f2f6a..d805833a7efc1 100644
--- a/src/librustc_tsan/Cargo.toml
+++ b/src/librustc_tsan/Cargo.toml
@@ -3,6 +3,7 @@ authors = ["The Rust Project Developers"]
 build = "build.rs"
 name = "rustc_tsan"
 version = "0.0.0"
+edition = "2018"
 
 [lib]
 name = "rustc_tsan"
diff --git a/src/librustc_tsan/build.rs b/src/librustc_tsan/build.rs
index 0db3db392dddc..ed9c37087c7e5 100644
--- a/src/librustc_tsan/build.rs
+++ b/src/librustc_tsan/build.rs
@@ -1,6 +1,3 @@
-extern crate build_helper;
-extern crate cmake;
-
 use std::env;
 use build_helper::sanitizer_lib_boilerplate;
 
diff --git a/src/librustc_tsan/lib.rs b/src/librustc_tsan/lib.rs
index d6c8e54c18db7..568bb540c4719 100644
--- a/src/librustc_tsan/lib.rs
+++ b/src/librustc_tsan/lib.rs
@@ -1,8 +1,9 @@
 #![sanitizer_runtime]
-#![feature(nll)]
 #![feature(sanitizer_runtime)]
 #![feature(staged_api)]
 #![no_std]
 #![unstable(feature = "sanitizer_runtime_lib",
             reason = "internal implementation detail of sanitizers",
             issue = "0")]
+
+#![deny(rust_2018_idioms)]

From fb0f0bfea6a9123ebfd057e10b87fad013ffd6ed Mon Sep 17 00:00:00 2001
From: Taiki Endo <te316e89@gmail.com>
Date: Wed, 6 Feb 2019 22:36:25 +0900
Subject: [PATCH 13/24] librustc_msan => 2018

---
 src/librustc_msan/Cargo.toml | 1 +
 src/librustc_msan/build.rs   | 3 ---
 src/librustc_msan/lib.rs     | 3 ++-
 3 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/src/librustc_msan/Cargo.toml b/src/librustc_msan/Cargo.toml
index 78c39d03e45a9..7d88aa59b3adb 100644
--- a/src/librustc_msan/Cargo.toml
+++ b/src/librustc_msan/Cargo.toml
@@ -3,6 +3,7 @@ authors = ["The Rust Project Developers"]
 build = "build.rs"
 name = "rustc_msan"
 version = "0.0.0"
+edition = "2018"
 
 [lib]
 name = "rustc_msan"
diff --git a/src/librustc_msan/build.rs b/src/librustc_msan/build.rs
index 085514b5a0108..1c66b0a9cd3cf 100644
--- a/src/librustc_msan/build.rs
+++ b/src/librustc_msan/build.rs
@@ -1,6 +1,3 @@
-extern crate build_helper;
-extern crate cmake;
-
 use std::env;
 use build_helper::sanitizer_lib_boilerplate;
 
diff --git a/src/librustc_msan/lib.rs b/src/librustc_msan/lib.rs
index d6c8e54c18db7..568bb540c4719 100644
--- a/src/librustc_msan/lib.rs
+++ b/src/librustc_msan/lib.rs
@@ -1,8 +1,9 @@
 #![sanitizer_runtime]
-#![feature(nll)]
 #![feature(sanitizer_runtime)]
 #![feature(staged_api)]
 #![no_std]
 #![unstable(feature = "sanitizer_runtime_lib",
             reason = "internal implementation detail of sanitizers",
             issue = "0")]
+
+#![deny(rust_2018_idioms)]

From 30fab05bed13c497182e0cf3cf18ea2ea12af997 Mon Sep 17 00:00:00 2001
From: Taiki Endo <te316e89@gmail.com>
Date: Wed, 6 Feb 2019 22:40:09 +0900
Subject: [PATCH 14/24] librustc_asan => 2018

---
 src/librustc_asan/Cargo.toml | 1 +
 src/librustc_asan/build.rs   | 3 ---
 src/librustc_asan/lib.rs     | 3 ++-
 3 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/src/librustc_asan/Cargo.toml b/src/librustc_asan/Cargo.toml
index 836caf22abfa5..7d9641c83ee7d 100644
--- a/src/librustc_asan/Cargo.toml
+++ b/src/librustc_asan/Cargo.toml
@@ -3,6 +3,7 @@ authors = ["The Rust Project Developers"]
 build = "build.rs"
 name = "rustc_asan"
 version = "0.0.0"
+edition = "2018"
 
 [lib]
 name = "rustc_asan"
diff --git a/src/librustc_asan/build.rs b/src/librustc_asan/build.rs
index b42d775deb393..a2b4b090efb4f 100644
--- a/src/librustc_asan/build.rs
+++ b/src/librustc_asan/build.rs
@@ -1,6 +1,3 @@
-extern crate build_helper;
-extern crate cmake;
-
 use std::env;
 use build_helper::sanitizer_lib_boilerplate;
 
diff --git a/src/librustc_asan/lib.rs b/src/librustc_asan/lib.rs
index d6c8e54c18db7..568bb540c4719 100644
--- a/src/librustc_asan/lib.rs
+++ b/src/librustc_asan/lib.rs
@@ -1,8 +1,9 @@
 #![sanitizer_runtime]
-#![feature(nll)]
 #![feature(sanitizer_runtime)]
 #![feature(staged_api)]
 #![no_std]
 #![unstable(feature = "sanitizer_runtime_lib",
             reason = "internal implementation detail of sanitizers",
             issue = "0")]
+
+#![deny(rust_2018_idioms)]

From 3893b2f04e90366a9ebad4d90b05ac51600992c7 Mon Sep 17 00:00:00 2001
From: Taiki Endo <te316e89@gmail.com>
Date: Wed, 6 Feb 2019 22:46:01 +0900
Subject: [PATCH 15/24] libprofiler_builtins => 2018

---
 src/libprofiler_builtins/Cargo.toml | 1 +
 src/libprofiler_builtins/build.rs   | 2 --
 src/libprofiler_builtins/lib.rs     | 2 +-
 3 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/src/libprofiler_builtins/Cargo.toml b/src/libprofiler_builtins/Cargo.toml
index 7c95cf0a0542a..0d36bd0b39d76 100644
--- a/src/libprofiler_builtins/Cargo.toml
+++ b/src/libprofiler_builtins/Cargo.toml
@@ -3,6 +3,7 @@ authors = ["The Rust Project Developers"]
 build = "build.rs"
 name = "profiler_builtins"
 version = "0.0.0"
+edition = "2018"
 
 [lib]
 name = "profiler_builtins"
diff --git a/src/libprofiler_builtins/build.rs b/src/libprofiler_builtins/build.rs
index b66cd66448748..ff52a03d9dd97 100644
--- a/src/libprofiler_builtins/build.rs
+++ b/src/libprofiler_builtins/build.rs
@@ -2,8 +2,6 @@
 //!
 //! See the build.rs for libcompiler_builtins crate for details.
 
-extern crate cc;
-
 use std::env;
 use std::path::Path;
 
diff --git a/src/libprofiler_builtins/lib.rs b/src/libprofiler_builtins/lib.rs
index 0d12ba01c87a2..9c8d3a13b0812 100644
--- a/src/libprofiler_builtins/lib.rs
+++ b/src/libprofiler_builtins/lib.rs
@@ -5,5 +5,5 @@
             reason = "internal implementation detail of rustc right now",
             issue = "0")]
 #![allow(unused_features)]
-#![feature(nll)]
 #![feature(staged_api)]
+#![deny(rust_2018_idioms)]

From ea46f5b2d06bd4f106d67245cf2260ca33526f2b Mon Sep 17 00:00:00 2001
From: Taiki Endo <te316e89@gmail.com>
Date: Wed, 6 Feb 2019 23:12:47 +0900
Subject: [PATCH 16/24] librustc_lsan => 2018

---
 src/librustc_lsan/Cargo.toml | 1 +
 src/librustc_lsan/build.rs   | 3 ---
 src/librustc_lsan/lib.rs     | 3 ++-
 3 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/src/librustc_lsan/Cargo.toml b/src/librustc_lsan/Cargo.toml
index a8e11df7670cf..9ad53ee6d0958 100644
--- a/src/librustc_lsan/Cargo.toml
+++ b/src/librustc_lsan/Cargo.toml
@@ -3,6 +3,7 @@ authors = ["The Rust Project Developers"]
 build = "build.rs"
 name = "rustc_lsan"
 version = "0.0.0"
+edition = "2018"
 
 [lib]
 name = "rustc_lsan"
diff --git a/src/librustc_lsan/build.rs b/src/librustc_lsan/build.rs
index ad528bb03902c..b8c7b7c2d5537 100644
--- a/src/librustc_lsan/build.rs
+++ b/src/librustc_lsan/build.rs
@@ -1,6 +1,3 @@
-extern crate build_helper;
-extern crate cmake;
-
 use std::env;
 use build_helper::sanitizer_lib_boilerplate;
 
diff --git a/src/librustc_lsan/lib.rs b/src/librustc_lsan/lib.rs
index d6c8e54c18db7..568bb540c4719 100644
--- a/src/librustc_lsan/lib.rs
+++ b/src/librustc_lsan/lib.rs
@@ -1,8 +1,9 @@
 #![sanitizer_runtime]
-#![feature(nll)]
 #![feature(sanitizer_runtime)]
 #![feature(staged_api)]
 #![no_std]
 #![unstable(feature = "sanitizer_runtime_lib",
             reason = "internal implementation detail of sanitizers",
             issue = "0")]
+
+#![deny(rust_2018_idioms)]

From d4a60e01d158d508b50427167c399ef2a964bddd Mon Sep 17 00:00:00 2001
From: Taiki Endo <te316e89@gmail.com>
Date: Wed, 6 Feb 2019 23:18:33 +0900
Subject: [PATCH 17/24] librustc_fs_util => 2018

---
 src/librustc_fs_util/Cargo.toml | 1 +
 src/librustc_fs_util/lib.rs     | 2 ++
 2 files changed, 3 insertions(+)

diff --git a/src/librustc_fs_util/Cargo.toml b/src/librustc_fs_util/Cargo.toml
index e40b44204b349..47918643f31fe 100644
--- a/src/librustc_fs_util/Cargo.toml
+++ b/src/librustc_fs_util/Cargo.toml
@@ -2,6 +2,7 @@
 authors = ["The Rust Project Developers"]
 name = "rustc_fs_util"
 version = "0.0.0"
+edition = "2018"
 
 [lib]
 name = "rustc_fs_util"
diff --git a/src/librustc_fs_util/lib.rs b/src/librustc_fs_util/lib.rs
index 74ff121f80385..340681d65c383 100644
--- a/src/librustc_fs_util/lib.rs
+++ b/src/librustc_fs_util/lib.rs
@@ -1,3 +1,5 @@
+#![deny(rust_2018_idioms)]
+
 use std::path::{Path, PathBuf};
 use std::ffi::CString;
 use std::fs;

From 9f4a11c63732c2bdc623b4e66ee9bcc3f0159e95 Mon Sep 17 00:00:00 2001
From: Taiki Endo <te316e89@gmail.com>
Date: Wed, 6 Feb 2019 23:56:39 +0900
Subject: [PATCH 18/24] librustc_plugin => 2018

---
 src/librustc_plugin/Cargo.toml     |  1 +
 src/librustc_plugin/diagnostics.rs |  2 ++
 src/librustc_plugin/lib.rs         | 10 ++--------
 src/librustc_plugin/load.rs        |  5 +++--
 4 files changed, 8 insertions(+), 10 deletions(-)

diff --git a/src/librustc_plugin/Cargo.toml b/src/librustc_plugin/Cargo.toml
index d8fa1da1ce219..5e23aa0d7f74e 100644
--- a/src/librustc_plugin/Cargo.toml
+++ b/src/librustc_plugin/Cargo.toml
@@ -3,6 +3,7 @@ authors = ["The Rust Project Developers"]
 name = "rustc_plugin"
 version = "0.0.0"
 build = false
+edition = "2018"
 
 [lib]
 name = "rustc_plugin"
diff --git a/src/librustc_plugin/diagnostics.rs b/src/librustc_plugin/diagnostics.rs
index 382a1edb43c4a..68462bd83ef60 100644
--- a/src/librustc_plugin/diagnostics.rs
+++ b/src/librustc_plugin/diagnostics.rs
@@ -1,5 +1,7 @@
 #![allow(non_snake_case)]
 
+use syntax::{register_diagnostic, register_diagnostics, register_long_diagnostics};
+
 register_long_diagnostics! {
 
 }
diff --git a/src/librustc_plugin/lib.rs b/src/librustc_plugin/lib.rs
index 7bdeae3e97854..9a31bddc1eded 100644
--- a/src/librustc_plugin/lib.rs
+++ b/src/librustc_plugin/lib.rs
@@ -54,19 +54,13 @@
        html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
        html_root_url = "https://doc.rust-lang.org/nightly/")]
 
-#![feature(nll)]
 #![feature(rustc_diagnostic_macros)]
 
 #![recursion_limit="256"]
 
-#[macro_use] extern crate syntax;
+#![deny(rust_2018_idioms)]
 
-extern crate rustc;
-extern crate rustc_metadata;
-extern crate syntax_pos;
-extern crate rustc_errors as errors;
-
-pub use self::registry::Registry;
+pub use registry::Registry;
 
 mod diagnostics;
 pub mod registry;
diff --git a/src/librustc_plugin/load.rs b/src/librustc_plugin/load.rs
index 39f580420cf03..1b88cf05f40d5 100644
--- a/src/librustc_plugin/load.rs
+++ b/src/librustc_plugin/load.rs
@@ -3,18 +3,19 @@
 use rustc::session::Session;
 use rustc_metadata::creader::CrateLoader;
 use rustc_metadata::cstore::CStore;
-use registry::Registry;
+use crate::registry::Registry;
 
 use std::borrow::ToOwned;
 use std::env;
 use std::mem;
 use std::path::PathBuf;
 use syntax::ast;
+use syntax::span_err;
 use syntax_pos::{Span, DUMMY_SP};
 
 /// Pointer to a registrar function.
 pub type PluginRegistrarFun =
-    fn(&mut Registry);
+    fn(&mut Registry<'_>);
 
 pub struct PluginRegistrar {
     pub fun: PluginRegistrarFun,

From edbd8a36c8820fb8a128675859c1fa76feab2bea Mon Sep 17 00:00:00 2001
From: Taiki Endo <te316e89@gmail.com>
Date: Thu, 7 Feb 2019 02:15:23 +0900
Subject: [PATCH 19/24] librustc_resolve => 2018

---
 src/librustc_resolve/Cargo.toml             |  1 +
 src/librustc_resolve/build_reduced_graph.rs | 22 +++--
 src/librustc_resolve/check_unused.rs        |  6 +-
 src/librustc_resolve/diagnostics.rs         |  2 +
 src/librustc_resolve/error_reporting.rs     |  8 +-
 src/librustc_resolve/lib.rs                 | 93 ++++++++++-----------
 src/librustc_resolve/macros.rs              | 23 ++---
 src/librustc_resolve/resolve_imports.rs     | 30 ++++---
 8 files changed, 96 insertions(+), 89 deletions(-)

diff --git a/src/librustc_resolve/Cargo.toml b/src/librustc_resolve/Cargo.toml
index 3a8e84a3280c6..0ce82f2ce521b 100644
--- a/src/librustc_resolve/Cargo.toml
+++ b/src/librustc_resolve/Cargo.toml
@@ -2,6 +2,7 @@
 authors = ["The Rust Project Developers"]
 name = "rustc_resolve"
 version = "0.0.0"
+edition = "2018"
 
 [lib]
 name = "rustc_resolve"
diff --git a/src/librustc_resolve/build_reduced_graph.rs b/src/librustc_resolve/build_reduced_graph.rs
index c5401ac3f5560..750eb35a98854 100644
--- a/src/librustc_resolve/build_reduced_graph.rs
+++ b/src/librustc_resolve/build_reduced_graph.rs
@@ -3,14 +3,15 @@
 //! Here we build the "reduced graph": the graph of the module tree without
 //! any imports resolved.
 
-use macros::{InvocationData, ParentScope, LegacyScope};
-use resolve_imports::ImportDirective;
-use resolve_imports::ImportDirectiveSubclass::{self, GlobImport, SingleImport};
-use {Module, ModuleData, ModuleKind, NameBinding, NameBindingKind, Segment, ToNameBinding};
-use {ModuleOrUniformRoot, PerNS, Resolver, ResolverArenas, ExternPreludeEntry};
-use Namespace::{self, TypeNS, ValueNS, MacroNS};
-use {resolve_error, resolve_struct_error, ResolutionError};
-
+use crate::macros::{InvocationData, ParentScope, LegacyScope};
+use crate::resolve_imports::ImportDirective;
+use crate::resolve_imports::ImportDirectiveSubclass::{self, GlobImport, SingleImport};
+use crate::{Module, ModuleData, ModuleKind, NameBinding, NameBindingKind, Segment, ToNameBinding};
+use crate::{ModuleOrUniformRoot, PerNS, Resolver, ResolverArenas, ExternPreludeEntry};
+use crate::Namespace::{self, TypeNS, ValueNS, MacroNS};
+use crate::{resolve_error, resolve_struct_error, ResolutionError};
+
+use rustc::bug;
 use rustc::hir::def::*;
 use rustc::hir::def_id::{CrateNum, CRATE_DEF_INDEX, LOCAL_CRATE, DefId};
 use rustc::ty;
@@ -21,7 +22,7 @@ use std::cell::Cell;
 use std::ptr;
 use rustc_data_structures::sync::Lrc;
 
-use errors::Applicability;
+use crate::errors::Applicability;
 
 use syntax::ast::{Name, Ident};
 use syntax::attr;
@@ -34,12 +35,15 @@ use syntax::ext::hygiene::Mark;
 use syntax::ext::tt::macro_rules;
 use syntax::feature_gate::is_builtin_attr;
 use syntax::parse::token::{self, Token};
+use syntax::span_err;
 use syntax::std_inject::injected_crate_name;
 use syntax::symbol::keywords;
 use syntax::visit::{self, Visitor};
 
 use syntax_pos::{Span, DUMMY_SP};
 
+use log::debug;
+
 impl<'a> ToNameBinding<'a> for (Module<'a>, ty::Visibility, Span, Mark) {
     fn to_name_binding(self, arenas: &'a ResolverArenas<'a>) -> &'a NameBinding<'a> {
         arenas.alloc_name_binding(NameBinding {
diff --git a/src/librustc_resolve/check_unused.rs b/src/librustc_resolve/check_unused.rs
index 16d8a95c003f7..639960827c996 100644
--- a/src/librustc_resolve/check_unused.rs
+++ b/src/librustc_resolve/check_unused.rs
@@ -10,8 +10,8 @@
 
 use std::ops::{Deref, DerefMut};
 
-use Resolver;
-use resolve_imports::ImportDirectiveSubclass;
+use crate::Resolver;
+use crate::resolve_imports::ImportDirectiveSubclass;
 
 use rustc::{lint, ty};
 use rustc::util::nodemap::NodeMap;
@@ -113,7 +113,7 @@ impl<'a, 'b> Visitor<'a> for UnusedImportCheckVisitor<'a, 'b> {
     }
 }
 
-pub fn check_crate(resolver: &mut Resolver, krate: &ast::Crate) {
+pub fn check_crate(resolver: &mut Resolver<'_>, krate: &ast::Crate) {
     for directive in resolver.potentially_unused_imports.iter() {
         match directive.subclass {
             _ if directive.used.get() ||
diff --git a/src/librustc_resolve/diagnostics.rs b/src/librustc_resolve/diagnostics.rs
index 3f9c5f4fd273c..0db8689c0c17c 100644
--- a/src/librustc_resolve/diagnostics.rs
+++ b/src/librustc_resolve/diagnostics.rs
@@ -1,5 +1,7 @@
 #![allow(non_snake_case)]
 
+use syntax::{register_diagnostic, register_diagnostics, register_long_diagnostics};
+
 // Error messages for EXXXX errors.  Each message should start and end with a
 // new line, and be wrapped to 80 characters.  In vim you can `:set tw=80` and
 // use `gq` to wrap paragraphs. Use `:set tw=0` to disable.
diff --git a/src/librustc_resolve/error_reporting.rs b/src/librustc_resolve/error_reporting.rs
index 2a8e95536b8c7..b131a6b62f9bf 100644
--- a/src/librustc_resolve/error_reporting.rs
+++ b/src/librustc_resolve/error_reporting.rs
@@ -1,10 +1,12 @@
-use {CrateLint, PathResult, Segment};
-use macros::ParentScope;
+use crate::{CrateLint, PathResult, Segment};
+use crate::macros::ParentScope;
+use crate::resolve_imports::ImportResolver;
 
 use syntax::symbol::keywords;
 use syntax_pos::Span;
 
-use resolve_imports::ImportResolver;
+use log::debug;
+
 use std::cmp::Reverse;
 
 impl<'a, 'b:'a> ImportResolver<'a, 'b> {
diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs
index 3973bc2ad62de..b166b1be02f45 100644
--- a/src/librustc_resolve/lib.rs
+++ b/src/librustc_resolve/lib.rs
@@ -4,30 +4,19 @@
 
 #![feature(crate_visibility_modifier)]
 #![feature(label_break_value)]
-#![feature(nll)]
 #![feature(rustc_diagnostic_macros)]
 #![feature(slice_sort_by_cached_key)]
 
 #![recursion_limit="256"]
 
-#[macro_use]
-extern crate bitflags;
-#[macro_use]
-extern crate log;
-#[macro_use]
-extern crate syntax;
-extern crate syntax_pos;
-extern crate rustc_errors as errors;
-extern crate arena;
-#[macro_use]
-extern crate rustc;
-extern crate rustc_data_structures;
-extern crate rustc_metadata;
+#![deny(rust_2018_idioms)]
+
+use rustc_errors as errors;
 
 pub use rustc::hir::def::{Namespace, PerNS};
 
-use self::TypeParameters::*;
-use self::RibKind::*;
+use TypeParameters::*;
+use RibKind::*;
 
 use rustc::hir::map::{Definitions, DefCollector};
 use rustc::hir::{self, PrimTy, Bool, Char, Float, Int, Uint, Str};
@@ -41,6 +30,7 @@ use rustc::hir::{Freevar, FreevarMap, TraitCandidate, TraitMap, GlobMap};
 use rustc::session::config::nightly_options;
 use rustc::ty;
 use rustc::util::nodemap::{NodeMap, NodeSet, FxHashMap, FxHashSet, DefIdMap};
+use rustc::{bug, span_bug};
 
 use rustc_metadata::creader::CrateLoader;
 use rustc_metadata::cstore::CStore;
@@ -62,10 +52,13 @@ use syntax::ast::{Item, ItemKind, ImplItem, ImplItemKind};
 use syntax::ast::{Label, Local, Mutability, Pat, PatKind, Path};
 use syntax::ast::{QSelf, TraitItemKind, TraitRef, Ty, TyKind};
 use syntax::ptr::P;
+use syntax::{span_err, struct_span_err, unwrap_or, walk_list};
 
 use syntax_pos::{BytePos, Span, DUMMY_SP, MultiSpan};
 use errors::{Applicability, DiagnosticBuilder, DiagnosticId};
 
+use log::debug;
+
 use std::cell::{Cell, RefCell};
 use std::{cmp, fmt, iter, mem, ptr};
 use std::collections::BTreeSet;
@@ -191,13 +184,13 @@ enum ResolutionError<'a> {
 ///
 /// This takes the error provided, combines it with the span and any additional spans inside the
 /// error and emits it.
-fn resolve_error<'sess, 'a>(resolver: &'sess Resolver,
+fn resolve_error<'sess, 'a>(resolver: &'sess Resolver<'_>,
                             span: Span,
                             resolution_error: ResolutionError<'a>) {
     resolve_struct_error(resolver, span, resolution_error).emit();
 }
 
-fn resolve_struct_error<'sess, 'a>(resolver: &'sess Resolver,
+fn resolve_struct_error<'sess, 'a>(resolver: &'sess Resolver<'_>,
                                    span: Span,
                                    resolution_error: ResolutionError<'a>)
                                    -> DiagnosticBuilder<'sess> {
@@ -1192,7 +1185,7 @@ impl<'a> ModuleData<'a> {
 }
 
 impl<'a> fmt::Debug for ModuleData<'a> {
-    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         write!(f, "{:?}", self.def())
     }
 }
@@ -1416,7 +1409,7 @@ impl<'a> NameBinding<'a> {
     // in some later round and screw up our previously found resolution.
     // See more detailed explanation in
     // https://github.com/rust-lang/rust/pull/53778#issuecomment-419224049
-    fn may_appear_after(&self, invoc_parent_expansion: Mark, binding: &NameBinding) -> bool {
+    fn may_appear_after(&self, invoc_parent_expansion: Mark, binding: &NameBinding<'_>) -> bool {
         // self > max(invoc, binding) => !(self <= invoc || self <= binding)
         // Expansions are partially ordered, so "may appear after" is an inversion of
         // "certainly appears before or simultaneously" and includes unordered cases.
@@ -1630,14 +1623,14 @@ impl<'a> ResolverArenas<'a> {
         }
         module
     }
-    fn local_modules(&'a self) -> ::std::cell::Ref<'a, Vec<Module<'a>>> {
+    fn local_modules(&'a self) -> std::cell::Ref<'a, Vec<Module<'a>>> {
         self.local_modules.borrow()
     }
     fn alloc_name_binding(&'a self, name_binding: NameBinding<'a>) -> &'a NameBinding<'a> {
         self.name_bindings.alloc(name_binding)
     }
     fn alloc_import_directive(&'a self, import_directive: ImportDirective<'a>)
-                              -> &'a ImportDirective {
+                              -> &'a ImportDirective<'_> {
         self.import_directives.alloc(import_directive)
     }
     fn alloc_name_resolution(&'a self) -> &'a RefCell<NameResolution<'a>> {
@@ -1754,7 +1747,7 @@ impl<'a> Resolver<'a> {
         is_value: bool,
         error_callback: F,
     ) -> hir::Path
-        where F: for<'c, 'b> FnOnce(&'c mut Resolver, Span, ResolutionError<'b>)
+        where F: for<'c, 'b> FnOnce(&'c mut Resolver<'_>, Span, ResolutionError<'b>)
     {
         let namespace = if is_value { ValueNS } else { TypeNS };
         let span = path.span;
@@ -1819,7 +1812,7 @@ impl<'a> Resolver<'a> {
         DefCollector::new(&mut definitions, Mark::root())
             .collect_root(crate_name, session.local_crate_disambiguator());
 
-        let mut extern_prelude: FxHashMap<Ident, ExternPreludeEntry> =
+        let mut extern_prelude: FxHashMap<Ident, ExternPreludeEntry<'_>> =
             session.opts.externs.iter().map(|kv| (Ident::from_str(kv.0), Default::default()))
                                        .collect();
 
@@ -2315,7 +2308,7 @@ impl<'a> Resolver<'a> {
     // implementations thus found, for compatibility with old resolve pass.
 
     pub fn with_scope<F, T>(&mut self, id: NodeId, f: F) -> T
-        where F: FnOnce(&mut Resolver) -> T
+        where F: FnOnce(&mut Resolver<'_>) -> T
     {
         let id = self.definitions.local_def_id(id);
         let module = self.module_map.get(&id).cloned(); // clones a reference
@@ -2342,7 +2335,7 @@ impl<'a> Resolver<'a> {
     ///
     /// Stops after meeting a closure.
     fn search_label<P, R>(&self, mut ident: Ident, pred: P) -> Option<R>
-        where P: Fn(&Rib, Ident) -> Option<R>
+        where P: Fn(&Rib<'_>, Ident) -> Option<R>
     {
         for rib in self.label_ribs.iter().rev() {
             match rib.kind {
@@ -2527,7 +2520,7 @@ impl<'a> Resolver<'a> {
     }
 
     fn with_type_parameter_rib<'b, F>(&'b mut self, type_parameters: TypeParameters<'a, 'b>, f: F)
-        where F: FnOnce(&mut Resolver)
+        where F: FnOnce(&mut Resolver<'_>)
     {
         match type_parameters {
             HasTypeParameters(generics, rib_kind) => {
@@ -2573,7 +2566,7 @@ impl<'a> Resolver<'a> {
     }
 
     fn with_label_rib<F>(&mut self, f: F)
-        where F: FnOnce(&mut Resolver)
+        where F: FnOnce(&mut Resolver<'_>)
     {
         self.label_ribs.push(Rib::new(NormalRibKind));
         f(self);
@@ -2581,7 +2574,7 @@ impl<'a> Resolver<'a> {
     }
 
     fn with_item_rib<F>(&mut self, f: F)
-        where F: FnOnce(&mut Resolver)
+        where F: FnOnce(&mut Resolver<'_>)
     {
         self.ribs[ValueNS].push(Rib::new(ItemRibKind));
         self.ribs[TypeNS].push(Rib::new(ItemRibKind));
@@ -2591,7 +2584,7 @@ impl<'a> Resolver<'a> {
     }
 
     fn with_constant_rib<F>(&mut self, f: F)
-        where F: FnOnce(&mut Resolver)
+        where F: FnOnce(&mut Resolver<'_>)
     {
         self.ribs[ValueNS].push(Rib::new(ConstantItemRibKind));
         self.label_ribs.push(Rib::new(ConstantItemRibKind));
@@ -2601,7 +2594,7 @@ impl<'a> Resolver<'a> {
     }
 
     fn with_current_self_type<T, F>(&mut self, self_type: &Ty, f: F) -> T
-        where F: FnOnce(&mut Resolver) -> T
+        where F: FnOnce(&mut Resolver<'_>) -> T
     {
         // Handle nested impls (inside fn bodies)
         let previous_value = replace(&mut self.current_self_type, Some(self_type.clone()));
@@ -2611,7 +2604,7 @@ impl<'a> Resolver<'a> {
     }
 
     fn with_current_self_item<T, F>(&mut self, self_item: &Item, f: F) -> T
-        where F: FnOnce(&mut Resolver) -> T
+        where F: FnOnce(&mut Resolver<'_>) -> T
     {
         let previous_value = replace(&mut self.current_self_item, Some(self_item.id));
         let result = f(self);
@@ -2621,7 +2614,7 @@ impl<'a> Resolver<'a> {
 
     /// This is called to resolve a trait reference from an `impl` (i.e., `impl Trait for Foo`)
     fn with_optional_trait_ref<T, F>(&mut self, opt_trait_ref: Option<&TraitRef>, f: F) -> T
-        where F: FnOnce(&mut Resolver, Option<DefId>) -> T
+        where F: FnOnce(&mut Resolver<'_>, Option<DefId>) -> T
     {
         let mut new_val = None;
         let mut new_id = None;
@@ -2658,7 +2651,7 @@ impl<'a> Resolver<'a> {
     }
 
     fn with_self_rib<F>(&mut self, self_def: Def, f: F)
-        where F: FnOnce(&mut Resolver)
+        where F: FnOnce(&mut Resolver<'_>)
     {
         let mut self_type_rib = Rib::new(NormalRibKind);
 
@@ -2670,7 +2663,7 @@ impl<'a> Resolver<'a> {
     }
 
     fn with_self_struct_ctor_rib<F>(&mut self, impl_id: DefId, f: F)
-        where F: FnOnce(&mut Resolver)
+        where F: FnOnce(&mut Resolver<'_>)
     {
         let self_def = Def::SelfCtor(impl_id);
         let mut self_type_rib = Rib::new(NormalRibKind);
@@ -2771,7 +2764,7 @@ impl<'a> Resolver<'a> {
     }
 
     fn check_trait_item<F>(&mut self, ident: Ident, ns: Namespace, span: Span, err: F)
-        where F: FnOnce(Name, &str) -> ResolutionError
+        where F: FnOnce(Name, &str) -> ResolutionError<'_>
     {
         // If there is a TraitRef in scope for an impl, then the method must be in the
         // trait.
@@ -3102,7 +3095,7 @@ impl<'a> Resolver<'a> {
                           id: NodeId,
                           qself: Option<&QSelf>,
                           path: &Path,
-                          source: PathSource)
+                          source: PathSource<'_>)
                           -> PathResolution {
         self.smart_resolve_path_with_crate_lint(id, qself, path, source, CrateLint::SimplePath(id))
     }
@@ -3120,7 +3113,7 @@ impl<'a> Resolver<'a> {
         id: NodeId,
         qself: Option<&QSelf>,
         path: &Path,
-        source: PathSource,
+        source: PathSource<'_>,
         crate_lint: CrateLint
     ) -> PathResolution {
         self.smart_resolve_path_fragment(
@@ -3138,7 +3131,7 @@ impl<'a> Resolver<'a> {
                                    qself: Option<&QSelf>,
                                    path: &[Segment],
                                    span: Span,
-                                   source: PathSource,
+                                   source: PathSource<'_>,
                                    crate_lint: CrateLint)
                                    -> PathResolution {
         let ident_span = path.last().map_or(span, |ident| ident.ident.span);
@@ -3581,7 +3574,7 @@ impl<'a> Resolver<'a> {
     }
 
     fn type_ascription_suggestion(&self,
-                                  err: &mut DiagnosticBuilder,
+                                  err: &mut DiagnosticBuilder<'_>,
                                   base_span: Span) {
         debug!("type_ascription_suggetion {:?}", base_span);
         let cm = self.session.source_map();
@@ -4040,7 +4033,7 @@ impl<'a> Resolver<'a> {
         crate_lint: CrateLint,
         path: &[Segment],
         path_span: Span,
-        second_binding: Option<&NameBinding>,
+        second_binding: Option<&NameBinding<'_>>,
     ) {
         let (diag_id, diag_span) = match crate_lint {
             CrateLint::No => return,
@@ -4266,7 +4259,7 @@ impl<'a> Resolver<'a> {
     where
         FilterFn: Fn(Def) -> bool,
     {
-        let add_module_candidates = |module: Module, names: &mut Vec<TypoSuggestion>| {
+        let add_module_candidates = |module: Module<'_>, names: &mut Vec<TypoSuggestion>| {
             for (&(ident, _), resolution) in module.resolutions.borrow().iter() {
                 if let Some(binding) = resolution.borrow().binding {
                     if filter_fn(binding.def()) {
@@ -4361,7 +4354,7 @@ impl<'a> Resolver<'a> {
     }
 
     fn with_resolved_label<F>(&mut self, label: Option<Label>, id: NodeId, f: F)
-        where F: FnOnce(&mut Resolver)
+        where F: FnOnce(&mut Resolver<'_>)
     {
         if let Some(label) = label {
             self.unused_labels.insert(id, label.ident.span);
@@ -4950,7 +4943,7 @@ impl<'a> Resolver<'a> {
         }
     }
 
-    fn binding_description(&self, b: &NameBinding, ident: Ident, from_prelude: bool) -> String {
+    fn binding_description(&self, b: &NameBinding<'_>, ident: Ident, from_prelude: bool) -> String {
         if b.span.is_dummy() {
             let add_built_in = match b.def() {
                 // These already contain the "built-in" prefix or look bad with it.
@@ -4978,7 +4971,7 @@ impl<'a> Resolver<'a> {
         }
     }
 
-    fn report_ambiguity_error(&self, ambiguity_error: &AmbiguityError) {
+    fn report_ambiguity_error(&self, ambiguity_error: &AmbiguityError<'_>) {
         let AmbiguityError { kind, ident, b1, b2, misc1, misc2 } = *ambiguity_error;
         let (b1, b2, misc1, misc2, swapped) = if b2.span.is_dummy() && !b1.span.is_dummy() {
             // We have to print the span-less alternative first, otherwise formatting looks bad.
@@ -4992,7 +4985,7 @@ impl<'a> Resolver<'a> {
                                        ident = ident, why = kind.descr());
         err.span_label(ident.span, "ambiguous name");
 
-        let mut could_refer_to = |b: &NameBinding, misc: AmbiguityErrorMisc, also: &str| {
+        let mut could_refer_to = |b: &NameBinding<'_>, misc: AmbiguityErrorMisc, also: &str| {
             let what = self.binding_description(b, ident, misc == AmbiguityErrorMisc::FromPrelude);
             let note_msg = format!("`{ident}` could{also} refer to {what}",
                                    ident = ident, also = also, what = what);
@@ -5073,7 +5066,7 @@ impl<'a> Resolver<'a> {
     }
 
     fn report_conflict<'b>(&mut self,
-                       parent: Module,
+                       parent: Module<'_>,
                        ident: Ident,
                        ns: Namespace,
                        new_binding: &NameBinding<'b>,
@@ -5451,7 +5444,7 @@ fn import_candidate_to_enum_paths(suggestion: &ImportSuggestion) -> (String, Str
 /// When an entity with a given name is not available in scope, we search for
 /// entities with that name in all crates. This method allows outputting the
 /// results of this search in a programmer-friendly way
-fn show_candidates(err: &mut DiagnosticBuilder,
+fn show_candidates(err: &mut DiagnosticBuilder<'_>,
                    // This is `None` if all placement locations are inside expansions
                    span: Option<Span>,
                    candidates: &[ImportSuggestion],
@@ -5500,10 +5493,10 @@ fn show_candidates(err: &mut DiagnosticBuilder,
 }
 
 /// A somewhat inefficient routine to obtain the name of a module.
-fn module_to_string(module: Module) -> Option<String> {
+fn module_to_string(module: Module<'_>) -> Option<String> {
     let mut names = Vec::new();
 
-    fn collect_mod(names: &mut Vec<Ident>, module: Module) {
+    fn collect_mod(names: &mut Vec<Ident>, module: Module<'_>) {
         if let ModuleKind::Def(_, name) = module.kind {
             if let Some(parent) = module.parent {
                 names.push(Ident::with_empty_ctxt(name));
diff --git a/src/librustc_resolve/macros.rs b/src/librustc_resolve/macros.rs
index abf575aed6725..c8c0847a28eac 100644
--- a/src/librustc_resolve/macros.rs
+++ b/src/librustc_resolve/macros.rs
@@ -1,16 +1,17 @@
-use {AmbiguityError, AmbiguityKind, AmbiguityErrorMisc};
-use {CrateLint, Resolver, ResolutionError, ScopeSet, Weak};
-use {Module, ModuleKind, NameBinding, NameBindingKind, PathResult, Segment, ToNameBinding};
-use {is_known_tool, resolve_error};
-use ModuleOrUniformRoot;
-use Namespace::*;
-use build_reduced_graph::{BuildReducedGraphVisitor, IsMacroExport};
-use resolve_imports::ImportResolver;
+use crate::{AmbiguityError, AmbiguityKind, AmbiguityErrorMisc};
+use crate::{CrateLint, Resolver, ResolutionError, ScopeSet, Weak};
+use crate::{Module, ModuleKind, NameBinding, NameBindingKind, PathResult, Segment, ToNameBinding};
+use crate::{is_known_tool, resolve_error};
+use crate::ModuleOrUniformRoot;
+use crate::Namespace::*;
+use crate::build_reduced_graph::{BuildReducedGraphVisitor, IsMacroExport};
+use crate::resolve_imports::ImportResolver;
 use rustc::hir::def_id::{DefId, CRATE_DEF_INDEX, DefIndex,
                          CrateNum, DefIndexAddressSpace};
 use rustc::hir::def::{Def, NonMacroAttrKind};
 use rustc::hir::map::{self, DefCollector};
 use rustc::{ty, lint};
+use rustc::{bug, span_bug};
 use syntax::ast::{self, Ident};
 use syntax::attr;
 use syntax::errors::DiagnosticBuilder;
@@ -26,7 +27,7 @@ use syntax::symbol::{Symbol, keywords};
 use syntax::visit::Visitor;
 use syntax::util::lev_distance::find_best_match_for_name;
 use syntax_pos::{Span, DUMMY_SP};
-use errors::Applicability;
+use crate::errors::Applicability;
 
 use std::cell::Cell;
 use std::{mem, ptr};
@@ -530,7 +531,7 @@ impl<'a> Resolver<'a> {
             BuiltinTypes,
         }
 
-        bitflags! {
+        bitflags::bitflags! {
             struct Flags: u8 {
                 const MACRO_RULES        = 1 << 0;
                 const MODULE             = 1 << 1;
@@ -560,7 +561,7 @@ impl<'a> Resolver<'a> {
         // }
         // So we have to save the innermost solution and continue searching in outer scopes
         // to detect potential ambiguities.
-        let mut innermost_result: Option<(&NameBinding, Flags)> = None;
+        let mut innermost_result: Option<(&NameBinding<'_>, Flags)> = None;
 
         // Go through all the scopes and try to resolve the name.
         let rust_2015 = orig_ident.span.rust_2015();
diff --git a/src/librustc_resolve/resolve_imports.rs b/src/librustc_resolve/resolve_imports.rs
index 197cf7014db3d..712871408fa04 100644
--- a/src/librustc_resolve/resolve_imports.rs
+++ b/src/librustc_resolve/resolve_imports.rs
@@ -1,13 +1,13 @@
-use self::ImportDirectiveSubclass::*;
+use ImportDirectiveSubclass::*;
 
-use {AmbiguityError, AmbiguityKind, AmbiguityErrorMisc};
-use {CrateLint, Module, ModuleOrUniformRoot, PerNS, ScopeSet, Weak};
-use Namespace::{self, TypeNS, MacroNS};
-use {NameBinding, NameBindingKind, ToNameBinding, PathResult, PrivacyError};
-use {Resolver, Segment};
-use {names_to_string, module_to_string};
-use {resolve_error, ResolutionError};
-use macros::ParentScope;
+use crate::{AmbiguityError, AmbiguityKind, AmbiguityErrorMisc};
+use crate::{CrateLint, Module, ModuleOrUniformRoot, PerNS, ScopeSet, Weak};
+use crate::Namespace::{self, TypeNS, MacroNS};
+use crate::{NameBinding, NameBindingKind, ToNameBinding, PathResult, PrivacyError};
+use crate::{Resolver, Segment};
+use crate::{names_to_string, module_to_string};
+use crate::{resolve_error, ResolutionError};
+use crate::macros::ParentScope;
 
 use rustc_data_structures::ptr_key::PtrKey;
 use rustc::ty;
@@ -17,14 +17,18 @@ use rustc::hir::def_id::{CrateNum, DefId};
 use rustc::hir::def::*;
 use rustc::session::DiagnosticMessageId;
 use rustc::util::nodemap::FxHashSet;
+use rustc::{bug, span_bug};
 
 use syntax::ast::{self, Ident, Name, NodeId, CRATE_NODE_ID};
 use syntax::ext::base::Determinacy::{self, Determined, Undetermined};
 use syntax::ext::hygiene::Mark;
 use syntax::symbol::keywords;
 use syntax::util::lev_distance::find_best_match_for_name;
+use syntax::{struct_span_err, unwrap_or};
 use syntax_pos::{MultiSpan, Span};
 
+use log::debug;
+
 use std::cell::{Cell, RefCell};
 use std::{mem, ptr};
 
@@ -623,14 +627,14 @@ pub struct ImportResolver<'a, 'b: 'a> {
     pub resolver: &'a mut Resolver<'b>,
 }
 
-impl<'a, 'b: 'a> ::std::ops::Deref for ImportResolver<'a, 'b> {
+impl<'a, 'b: 'a> std::ops::Deref for ImportResolver<'a, 'b> {
     type Target = Resolver<'b>;
     fn deref(&self) -> &Resolver<'b> {
         self.resolver
     }
 }
 
-impl<'a, 'b: 'a> ::std::ops::DerefMut for ImportResolver<'a, 'b> {
+impl<'a, 'b: 'a> std::ops::DerefMut for ImportResolver<'a, 'b> {
     fn deref_mut(&mut self) -> &mut Resolver<'b> {
         self.resolver
     }
@@ -1316,7 +1320,7 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
 }
 
 fn import_path_to_string(names: &[Ident],
-                         subclass: &ImportDirectiveSubclass,
+                         subclass: &ImportDirectiveSubclass<'_>,
                          span: Span) -> String {
     let pos = names.iter()
         .position(|p| span == p.span && p.name != keywords::PathRoot.name());
@@ -1336,7 +1340,7 @@ fn import_path_to_string(names: &[Ident],
     }
 }
 
-fn import_directive_subclass_to_string(subclass: &ImportDirectiveSubclass) -> String {
+fn import_directive_subclass_to_string(subclass: &ImportDirectiveSubclass<'_>) -> String {
     match *subclass {
         SingleImport { source, .. } => source.to_string(),
         GlobImport { .. } => "*".to_string(),

From 86d8e47c11ade35ab706ca462f36eb5cfd3bf24b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= <sebastian@centricular.com>
Date: Wed, 6 Feb 2019 19:24:20 +0200
Subject: [PATCH 20/24] Fix broken grammar in iter::from_fn() docs

---
 src/libcore/iter/sources.rs | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/src/libcore/iter/sources.rs b/src/libcore/iter/sources.rs
index 2b741e66170aa..6f45f082d6a37 100644
--- a/src/libcore/iter/sources.rs
+++ b/src/libcore/iter/sources.rs
@@ -504,10 +504,8 @@ pub fn once_with<A, F: FnOnce() -> A>(gen: F) -> OnceWith<F> {
 /// [`FusedIterator`]: trait.FusedIterator.html
 /// [`Iterator::size_hint`]: trait.Iterator.html#method.size_hint
 ///
-/// The closure can use its its captures and environment
-/// to track state across iterations.
-/// Depending on how the iterator is used,
-/// this may require specifying the `move` keyword on the closure.
+/// The closure can use captures and its environment to track state across iterations. Depending on
+/// how the iterator is used, this may require specifying the `move` keyword on the closure.
 ///
 /// # Examples
 ///

From 0d3e17864e54edb6b041d39a145f2eec522090da Mon Sep 17 00:00:00 2001
From: Taiki Endo <te316e89@gmail.com>
Date: Thu, 7 Feb 2019 03:04:35 +0900
Subject: [PATCH 21/24] librustc_apfloat => 2018

---
 src/librustc_apfloat/Cargo.toml    | 1 +
 src/librustc_apfloat/ieee.rs       | 8 ++++----
 src/librustc_apfloat/lib.rs        | 8 ++------
 src/librustc_apfloat/ppc.rs        | 6 +++---
 src/librustc_apfloat/tests/ieee.rs | 4 +---
 src/librustc_apfloat/tests/ppc.rs  | 2 --
 6 files changed, 11 insertions(+), 18 deletions(-)

diff --git a/src/librustc_apfloat/Cargo.toml b/src/librustc_apfloat/Cargo.toml
index 248f2d71f41e5..c7496a9547ea6 100644
--- a/src/librustc_apfloat/Cargo.toml
+++ b/src/librustc_apfloat/Cargo.toml
@@ -2,6 +2,7 @@
 authors = ["The Rust Project Developers"]
 name = "rustc_apfloat"
 version = "0.0.0"
+edition = "2018"
 
 [lib]
 name = "rustc_apfloat"
diff --git a/src/librustc_apfloat/ieee.rs b/src/librustc_apfloat/ieee.rs
index 7ad34bec899f4..58066a9cada47 100644
--- a/src/librustc_apfloat/ieee.rs
+++ b/src/librustc_apfloat/ieee.rs
@@ -1,5 +1,5 @@
-use {Category, ExpInt, IEK_INF, IEK_NAN, IEK_ZERO};
-use {Float, FloatConvert, ParseError, Round, Status, StatusAnd};
+use crate::{Category, ExpInt, IEK_INF, IEK_NAN, IEK_ZERO};
+use crate::{Float, FloatConvert, ParseError, Round, Status, StatusAnd};
 
 use smallvec::{SmallVec, smallvec};
 use std::cmp::{self, Ordering};
@@ -325,7 +325,7 @@ impl<S> Neg for IeeeFloat<S> {
 /// 1.01E-2              4        2       0.0101
 /// 1.01E-2              4        1       1.01E-2
 impl<S: Semantics> fmt::Display for IeeeFloat<S> {
-    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         let width = f.width().unwrap_or(3);
         let alternate = f.alternate();
 
@@ -614,7 +614,7 @@ impl<S: Semantics> fmt::Display for IeeeFloat<S> {
 }
 
 impl<S: Semantics> fmt::Debug for IeeeFloat<S> {
-    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         write!(f, "{}({:?} | {}{:?} * 2^{})",
                self, self.category,
                if self.sign { "-" } else { "+" },
diff --git a/src/librustc_apfloat/lib.rs b/src/librustc_apfloat/lib.rs
index 6d2c54ca9ffe9..17311f0688fe6 100644
--- a/src/librustc_apfloat/lib.rs
+++ b/src/librustc_apfloat/lib.rs
@@ -34,24 +34,20 @@
       html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
       html_root_url = "https://doc.rust-lang.org/nightly/")]
 #![forbid(unsafe_code)]
+#![deny(rust_2018_idioms)]
 
-#![feature(nll)]
 #![feature(try_from)]
 // See librustc_cratesio_shim/Cargo.toml for a comment explaining this.
 #[allow(unused_extern_crates)]
 extern crate rustc_cratesio_shim;
 
-#[macro_use]
-extern crate bitflags;
-extern crate smallvec;
-
 use std::cmp::Ordering;
 use std::fmt;
 use std::ops::{Neg, Add, Sub, Mul, Div, Rem};
 use std::ops::{AddAssign, SubAssign, MulAssign, DivAssign, RemAssign};
 use std::str::FromStr;
 
-bitflags! {
+bitflags::bitflags! {
     /// IEEE-754R 7: Default exception handling.
     ///
     /// UNDERFLOW or OVERFLOW are always returned or-ed with INEXACT.
diff --git a/src/librustc_apfloat/ppc.rs b/src/librustc_apfloat/ppc.rs
index 839e88cf34039..ddccfd6ca623b 100644
--- a/src/librustc_apfloat/ppc.rs
+++ b/src/librustc_apfloat/ppc.rs
@@ -1,5 +1,5 @@
-use {Category, ExpInt, Float, FloatConvert, Round, ParseError, Status, StatusAnd};
-use ieee;
+use crate::{Category, ExpInt, Float, FloatConvert, Round, ParseError, Status, StatusAnd};
+use crate::ieee;
 
 use std::cmp::Ordering;
 use std::fmt;
@@ -124,7 +124,7 @@ impl<F: Float> Neg for DoubleFloat<F> {
 }
 
 impl<F: FloatConvert<Fallback<F>>> fmt::Display for DoubleFloat<F> {
-    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         fmt::Display::fmt(&Fallback::from(*self), f)
     }
 }
diff --git a/src/librustc_apfloat/tests/ieee.rs b/src/librustc_apfloat/tests/ieee.rs
index 96249020c1a6f..108b2114439d4 100644
--- a/src/librustc_apfloat/tests/ieee.rs
+++ b/src/librustc_apfloat/tests/ieee.rs
@@ -1,9 +1,7 @@
-#[macro_use]
-extern crate rustc_apfloat;
-
 use rustc_apfloat::{Category, ExpInt, IEK_INF, IEK_NAN, IEK_ZERO};
 use rustc_apfloat::{Float, FloatConvert, ParseError, Round, Status};
 use rustc_apfloat::ieee::{Half, Single, Double, Quad, X87DoubleExtended};
+use rustc_apfloat::unpack;
 
 trait SingleExt {
     fn from_f32(input: f32) -> Self;
diff --git a/src/librustc_apfloat/tests/ppc.rs b/src/librustc_apfloat/tests/ppc.rs
index cfb453bd0617a..02cdeb90a12be 100644
--- a/src/librustc_apfloat/tests/ppc.rs
+++ b/src/librustc_apfloat/tests/ppc.rs
@@ -1,5 +1,3 @@
-extern crate rustc_apfloat;
-
 use rustc_apfloat::{Category, Float, Round};
 use rustc_apfloat::ppc::DoubleDouble;
 

From a07dc4e43c8f3d7c79114b257997b4ce37ddeab1 Mon Sep 17 00:00:00 2001
From: Taiki Endo <te316e89@gmail.com>
Date: Thu, 7 Feb 2019 03:46:54 +0900
Subject: [PATCH 22/24] librustc_llvm => 2018

---
 src/librustc_llvm/Cargo.toml | 1 +
 src/librustc_llvm/build.rs   | 3 ---
 src/librustc_llvm/lib.rs     | 2 +-
 3 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/src/librustc_llvm/Cargo.toml b/src/librustc_llvm/Cargo.toml
index 013badb71cc5a..0fe327d5deeeb 100644
--- a/src/librustc_llvm/Cargo.toml
+++ b/src/librustc_llvm/Cargo.toml
@@ -3,6 +3,7 @@ authors = ["The Rust Project Developers"]
 name = "rustc_llvm"
 version = "0.0.0"
 build = "build.rs"
+edition = "2018"
 
 [lib]
 name = "rustc_llvm"
diff --git a/src/librustc_llvm/build.rs b/src/librustc_llvm/build.rs
index cd91fcb2995ee..7fa83dd977950 100644
--- a/src/librustc_llvm/build.rs
+++ b/src/librustc_llvm/build.rs
@@ -1,6 +1,3 @@
-extern crate cc;
-extern crate build_helper;
-
 use std::process::Command;
 use std::env;
 use std::path::{PathBuf, Path};
diff --git a/src/librustc_llvm/lib.rs b/src/librustc_llvm/lib.rs
index ca66540fa25f7..99c5e2493edec 100644
--- a/src/librustc_llvm/lib.rs
+++ b/src/librustc_llvm/lib.rs
@@ -1,4 +1,4 @@
-#![feature(nll)]
+#![deny(rust_2018_idioms)]
 #![feature(static_nobundle)]
 
 #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",

From 950fe6686da1fdbaf25341cc5fafe1bb9fb1b180 Mon Sep 17 00:00:00 2001
From: Taiki Endo <te316e89@gmail.com>
Date: Thu, 7 Feb 2019 03:53:01 +0900
Subject: [PATCH 23/24] librustc_errors => 2018

---
 src/librustc_errors/Cargo.toml            |  1 +
 src/librustc_errors/diagnostic.rs         | 12 ++++-----
 src/librustc_errors/diagnostic_builder.rs | 19 +++++++-------
 src/librustc_errors/emitter.rs            | 16 ++++++------
 src/librustc_errors/lib.rs                | 30 +++++++++--------------
 src/librustc_errors/snippet.rs            |  2 +-
 src/librustc_errors/styled_buffer.rs      |  2 +-
 7 files changed, 37 insertions(+), 45 deletions(-)

diff --git a/src/librustc_errors/Cargo.toml b/src/librustc_errors/Cargo.toml
index b24f8ddf4d9f7..02c011857bd2a 100644
--- a/src/librustc_errors/Cargo.toml
+++ b/src/librustc_errors/Cargo.toml
@@ -2,6 +2,7 @@
 authors = ["The Rust Project Developers"]
 name = "rustc_errors"
 version = "0.0.0"
+edition = "2018"
 
 [lib]
 name = "rustc_errors"
diff --git a/src/librustc_errors/diagnostic.rs b/src/librustc_errors/diagnostic.rs
index 06a1761a1e76f..aefe296ad0fa7 100644
--- a/src/librustc_errors/diagnostic.rs
+++ b/src/librustc_errors/diagnostic.rs
@@ -1,11 +1,11 @@
-use CodeSuggestion;
-use SubstitutionPart;
-use Substitution;
-use Applicability;
-use Level;
+use crate::CodeSuggestion;
+use crate::SubstitutionPart;
+use crate::Substitution;
+use crate::Applicability;
+use crate::Level;
+use crate::snippet::Style;
 use std::fmt;
 use syntax_pos::{MultiSpan, Span};
-use snippet::Style;
 
 #[must_use]
 #[derive(Clone, Debug, PartialEq, Hash, RustcEncodable, RustcDecodable)]
diff --git a/src/librustc_errors/diagnostic_builder.rs b/src/librustc_errors/diagnostic_builder.rs
index f423a4cd1a7bf..fd4ea7f2d823f 100644
--- a/src/librustc_errors/diagnostic_builder.rs
+++ b/src/librustc_errors/diagnostic_builder.rs
@@ -1,14 +1,15 @@
-use Diagnostic;
-use DiagnosticId;
-use DiagnosticStyledString;
-use Applicability;
+use crate::Diagnostic;
+use crate::DiagnosticId;
+use crate::DiagnosticStyledString;
+use crate::Applicability;
 
-use Level;
-use Handler;
+use crate::Level;
+use crate::Handler;
 use std::fmt::{self, Debug};
 use std::ops::{Deref, DerefMut};
 use std::thread::panicking;
 use syntax_pos::{MultiSpan, Span};
+use log::debug;
 
 /// Used for emitting structured error messages and other diagnostic information.
 ///
@@ -111,8 +112,8 @@ impl<'a> DiagnosticBuilder<'a> {
         // implements `Drop`.
         let diagnostic;
         unsafe {
-            diagnostic = ::std::ptr::read(&self.diagnostic);
-            ::std::mem::forget(self);
+            diagnostic = std::ptr::read(&self.diagnostic);
+            std::mem::forget(self);
         };
         // Logging here is useful to help track down where in logs an error was
         // actually emitted.
@@ -298,7 +299,7 @@ impl<'a> DiagnosticBuilder<'a> {
 }
 
 impl<'a> Debug for DiagnosticBuilder<'a> {
-    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         self.diagnostic.fmt(f)
     }
 }
diff --git a/src/librustc_errors/emitter.rs b/src/librustc_errors/emitter.rs
index 25d09a33c154f..061d23697fa3a 100644
--- a/src/librustc_errors/emitter.rs
+++ b/src/librustc_errors/emitter.rs
@@ -1,28 +1,26 @@
-use self::Destination::*;
+use Destination::*;
 
 use syntax_pos::{SourceFile, Span, MultiSpan};
 
-use {Level, CodeSuggestion, DiagnosticBuilder, SubDiagnostic, SourceMapperDyn, DiagnosticId};
-use snippet::{Annotation, AnnotationType, Line, MultilineAnnotation, StyledString, Style};
-use styled_buffer::StyledBuffer;
+use crate::{Level, CodeSuggestion, DiagnosticBuilder, SubDiagnostic, SourceMapperDyn, DiagnosticId};
+use crate::snippet::{Annotation, AnnotationType, Line, MultilineAnnotation, StyledString, Style};
+use crate::styled_buffer::StyledBuffer;
 
 use rustc_data_structures::fx::FxHashMap;
 use rustc_data_structures::sync::Lrc;
-use atty;
 use std::borrow::Cow;
 use std::io::prelude::*;
 use std::io;
 use std::cmp::{min, Reverse};
 use termcolor::{StandardStream, ColorChoice, ColorSpec, BufferWriter};
 use termcolor::{WriteColor, Color, Buffer};
-use unicode_width;
 
 const ANONYMIZED_LINE_NUM: &str = "LL";
 
 /// Emitter trait for emitting errors.
 pub trait Emitter {
     /// Emit a structured diagnostic.
-    fn emit(&mut self, db: &DiagnosticBuilder);
+    fn emit(&mut self, db: &DiagnosticBuilder<'_>);
 
     /// Check if should show explanations about "rustc --explain"
     fn should_show_explain(&self) -> bool {
@@ -31,7 +29,7 @@ pub trait Emitter {
 }
 
 impl Emitter for EmitterWriter {
-    fn emit(&mut self, db: &DiagnosticBuilder) {
+    fn emit(&mut self, db: &DiagnosticBuilder<'_>) {
         let mut primary_span = db.span.clone();
         let mut children = db.children.clone();
         let mut suggestions: &[_] = &[];
@@ -1431,7 +1429,7 @@ fn emit_to_destination(rendered_buffer: &[Vec<StyledString>],
                        dst: &mut Destination,
                        short_message: bool)
                        -> io::Result<()> {
-    use lock;
+    use crate::lock;
 
     let mut dst = dst.writable();
 
diff --git a/src/librustc_errors/lib.rs b/src/librustc_errors/lib.rs
index 64d5ca0c2a742..831415ed0bb8c 100644
--- a/src/librustc_errors/lib.rs
+++ b/src/librustc_errors/lib.rs
@@ -6,23 +6,15 @@
 #![allow(unused_attributes)]
 #![feature(range_contains)]
 #![cfg_attr(unix, feature(libc))]
-#![feature(nll)]
 #![feature(optin_builtin_traits)]
+#![deny(rust_2018_idioms)]
 
-extern crate atty;
-extern crate termcolor;
-#[cfg(unix)]
-extern crate libc;
-#[macro_use]
-extern crate log;
-extern crate rustc_data_structures;
-extern crate serialize as rustc_serialize;
-extern crate syntax_pos;
-extern crate unicode_width;
+#[allow(unused_extern_crates)]
+extern crate serialize as rustc_serialize; // used by deriving
 
 pub use emitter::ColorConfig;
 
-use self::Level::*;
+use Level::*;
 
 use emitter::{Emitter, EmitterWriter};
 
@@ -144,7 +136,7 @@ impl CodeSuggestion {
         use syntax_pos::{CharPos, Loc, Pos};
 
         fn push_trailing(buf: &mut String,
-                         line_opt: Option<&Cow<str>>,
+                         line_opt: Option<&Cow<'_, str>>,
                          lo: &Loc,
                          hi_opt: Option<&Loc>) {
             let (lo, hi_opt) = (lo.col.to_usize(), hi_opt.map(|hi| hi.col.to_usize()));
@@ -247,7 +239,7 @@ impl FatalError {
 }
 
 impl fmt::Display for FatalError {
-    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         write!(f, "parser fatal error")
     }
 }
@@ -264,7 +256,7 @@ impl error::Error for FatalError {
 pub struct ExplicitBug;
 
 impl fmt::Display for ExplicitBug {
-    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         write!(f, "parser internal bug")
     }
 }
@@ -496,7 +488,7 @@ impl Handler {
         DiagnosticBuilder::new(self, Level::Fatal, msg)
     }
 
-    pub fn cancel(&self, err: &mut DiagnosticBuilder) {
+    pub fn cancel(&self, err: &mut DiagnosticBuilder<'_>) {
         err.cancel();
     }
 
@@ -698,12 +690,12 @@ impl Handler {
         self.taught_diagnostics.borrow_mut().insert(code.clone())
     }
 
-    pub fn force_print_db(&self, mut db: DiagnosticBuilder) {
+    pub fn force_print_db(&self, mut db: DiagnosticBuilder<'_>) {
         self.emitter.borrow_mut().emit(&db);
         db.cancel();
     }
 
-    fn emit_db(&self, db: &DiagnosticBuilder) {
+    fn emit_db(&self, db: &DiagnosticBuilder<'_>) {
         let diagnostic = &**db;
 
         TRACK_DIAGNOSTICS.with(|track_diagnostics| {
@@ -749,7 +741,7 @@ pub enum Level {
 }
 
 impl fmt::Display for Level {
-    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         self.to_str().fmt(f)
     }
 }
diff --git a/src/librustc_errors/snippet.rs b/src/librustc_errors/snippet.rs
index da1da77f398a9..0c62ff0ff89b2 100644
--- a/src/librustc_errors/snippet.rs
+++ b/src/librustc_errors/snippet.rs
@@ -1,6 +1,6 @@
 // Code for annotating snippets.
 
-use Level;
+use crate::Level;
 
 #[derive(Clone, Debug, PartialOrd, Ord, PartialEq, Eq)]
 pub struct Line {
diff --git a/src/librustc_errors/styled_buffer.rs b/src/librustc_errors/styled_buffer.rs
index 880f09e75e32e..6e03618d2b0b5 100644
--- a/src/librustc_errors/styled_buffer.rs
+++ b/src/librustc_errors/styled_buffer.rs
@@ -1,6 +1,6 @@
 // Code for creating styled buffers
 
-use snippet::{Style, StyledString};
+use crate::snippet::{Style, StyledString};
 
 #[derive(Debug)]
 pub struct StyledBuffer {

From 5db385064e26202d71dc3801dee8a41a6ce28a9b Mon Sep 17 00:00:00 2001
From: Michael Howell <michael@notriddle.com>
Date: Wed, 6 Feb 2019 12:27:01 -0700
Subject: [PATCH 24/24] Document the one TyKind that isn't documented

This is especially confusing since the name `Foreign`
and the name `extern type` are so different. I deduced
that they're the same by consulting git-blame.
---
 src/librustc/ty/sty.rs | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/librustc/ty/sty.rs b/src/librustc/ty/sty.rs
index 671a0fc2d5d7a..6d49da5d002ba 100644
--- a/src/librustc/ty/sty.rs
+++ b/src/librustc/ty/sty.rs
@@ -107,6 +107,7 @@ pub enum TyKind<'tcx> {
     /// definition and not a concrete use of it.
     Adt(&'tcx AdtDef, &'tcx Substs<'tcx>),
 
+    /// An unsized FFI type that is opaque to Rust. Written as `extern type T`.
     Foreign(DefId),
 
     /// The pointee of a string slice. Written as `str`.