diff --git a/src/librustc/error_codes.rs b/src/librustc/error_codes.rs
index f6564f1fcd4c1..968b0b9f2f2b7 100644
--- a/src/librustc/error_codes.rs
+++ b/src/librustc/error_codes.rs
@@ -2217,6 +2217,23 @@ Examples of erroneous code:
 static X: u32 = 42;
 ```
 "##,
+
+E0734: r##"
+A stability attribute has been used outside of the standard library.
+
+Erroneous code examples:
+
+```compile_fail,E0734
+#[rustc_deprecated(since = "b", reason = "text")] // invalid
+#[stable(feature = "a", since = "b")] // invalid
+#[unstable(feature = "b", issue = "0")] // invalid
+fn foo(){}
+```
+
+These attributes are meant to only be used by the standard library and are
+rejected in your own crates.
+"##,
+
 ;
 //  E0006, // merged with E0005
 //  E0101, // replaced with E0282
diff --git a/src/librustc/middle/stability.rs b/src/librustc/middle/stability.rs
index 9e053ce4e69c2..30a88d155f5f8 100644
--- a/src/librustc/middle/stability.rs
+++ b/src/librustc/middle/stability.rs
@@ -199,8 +199,12 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
                 let name = attr.name_or_empty();
                 if [sym::unstable, sym::stable, sym::rustc_deprecated].contains(&name) {
                     attr::mark_used(attr);
-                    self.tcx.sess.span_err(attr.span, "stability attributes may not be used \
-                                                        outside of the standard library");
+                    struct_span_err!(
+                        self.tcx.sess,
+                        attr.span,
+                        E0734,
+                        "stability attributes may not be used outside of the standard library",
+                    ).emit();
                 }
             }
 
diff --git a/src/librustc/mir/interpret/error.rs b/src/librustc/mir/interpret/error.rs
index ac99ccd45eafe..71967b513a049 100644
--- a/src/librustc/mir/interpret/error.rs
+++ b/src/librustc/mir/interpret/error.rs
@@ -389,6 +389,10 @@ pub enum UnsupportedOpInfo<'tcx> {
     /// Free-form case. Only for errors that are never caught!
     Unsupported(String),
 
+    /// FIXME(#64506) Error used to work around accessing projections of
+    /// uninhabited types.
+    UninhabitedValue,
+
     // -- Everything below is not categorized yet --
     FunctionAbiMismatch(Abi, Abi),
     FunctionArgMismatch(Ty<'tcx>, Ty<'tcx>),
@@ -552,6 +556,8 @@ impl fmt::Debug for UnsupportedOpInfo<'tcx> {
                     not a power of two"),
             Unsupported(ref msg) =>
                 write!(f, "{}", msg),
+            UninhabitedValue =>
+                write!(f, "tried to use an uninhabited value"),
         }
     }
 }
diff --git a/src/librustc/traits/coherence.rs b/src/librustc/traits/coherence.rs
index 039973d80dbf1..4696d4da58ec0 100644
--- a/src/librustc/traits/coherence.rs
+++ b/src/librustc/traits/coherence.rs
@@ -378,7 +378,15 @@ fn orphan_check_trait_ref<'tcx>(
         //      Let Ti be the first such type.
         //     - No uncovered type parameters P1..=Pn may appear in T0..Ti (excluding Ti)
         //
-        for input_ty in trait_ref.input_types() {
+        fn uncover_fundamental_ty(ty: Ty<'_>) -> Vec<Ty<'_>> {
+            if fundamental_ty(ty) {
+                ty.walk_shallow().flat_map(|ty| uncover_fundamental_ty(ty)).collect()
+            } else {
+                vec![ty]
+            }
+        }
+
+        for input_ty in trait_ref.input_types().flat_map(uncover_fundamental_ty) {
             debug!("orphan_check_trait_ref: check ty `{:?}`", input_ty);
             if ty_is_local(tcx, input_ty, in_crate) {
                 debug!("orphan_check_trait_ref: ty_is_local `{:?}`", input_ty);
diff --git a/src/librustc_mir/const_eval.rs b/src/librustc_mir/const_eval.rs
index ca238867421ab..bb02b99dd8d87 100644
--- a/src/librustc_mir/const_eval.rs
+++ b/src/librustc_mir/const_eval.rs
@@ -21,7 +21,7 @@ use syntax::source_map::{Span, DUMMY_SP};
 
 use crate::interpret::{self,
     PlaceTy, MPlaceTy, OpTy, ImmTy, Immediate, Scalar, Pointer,
-    RawConst, ConstValue,
+    RawConst, ConstValue, Machine,
     InterpResult, InterpErrorInfo, GlobalId, InterpCx, StackPopCleanup,
     Allocation, AllocId, MemoryKind, Memory,
     snapshot, RefTracking, intern_const_alloc_recursive,
@@ -41,7 +41,7 @@ const DETECTOR_SNAPSHOT_PERIOD: isize = 256;
 /// that inform us about the generic bounds of the constant. E.g., using an associated constant
 /// of a function's generic parameter will require knowledge about the bounds on the generic
 /// parameter. These bounds are passed to `mk_eval_cx` via the `ParamEnv` argument.
-pub(crate) fn mk_eval_cx<'mir, 'tcx>(
+fn mk_eval_cx<'mir, 'tcx>(
     tcx: TyCtxt<'tcx>,
     span: Span,
     param_env: ty::ParamEnv<'tcx>,
@@ -169,7 +169,7 @@ fn eval_body_using_ecx<'mir, 'tcx>(
 }
 
 #[derive(Clone, Debug)]
-enum ConstEvalError {
+pub enum ConstEvalError {
     NeedsRfc(String),
 }
 
@@ -521,8 +521,8 @@ pub fn const_variant_index<'tcx>(
 /// Turn an interpreter error into something to report to the user.
 /// As a side-effect, if RUSTC_CTFE_BACKTRACE is set, this prints the backtrace.
 /// Should be called only if the error is actually going to to be reported!
-pub fn error_to_const_error<'mir, 'tcx>(
-    ecx: &InterpCx<'mir, 'tcx, CompileTimeInterpreter<'mir, 'tcx>>,
+pub fn error_to_const_error<'mir, 'tcx, M: Machine<'mir, 'tcx>>(
+    ecx: &InterpCx<'mir, 'tcx, M>,
     mut error: InterpErrorInfo<'tcx>,
 ) -> ConstEvalErr<'tcx> {
     error.print_backtrace();
diff --git a/src/librustc_mir/interpret/machine.rs b/src/librustc_mir/interpret/machine.rs
index bb74a50156e56..c30c59bbf10c8 100644
--- a/src/librustc_mir/interpret/machine.rs
+++ b/src/librustc_mir/interpret/machine.rs
@@ -12,6 +12,7 @@ use rustc::ty::{self, Ty, TyCtxt};
 use super::{
     Allocation, AllocId, InterpResult, Scalar, AllocationExtra,
     InterpCx, PlaceTy, OpTy, ImmTy, MemoryKind, Pointer, Memory,
+    Frame, Operand,
 };
 
 /// Whether this kind of memory is allowed to leak
@@ -184,6 +185,22 @@ pub trait Machine<'mir, 'tcx>: Sized {
         dest: PlaceTy<'tcx, Self::PointerTag>,
     ) -> InterpResult<'tcx>;
 
+    /// Called to read the specified `local` from the `frame`.
+    fn access_local(
+        _ecx: &InterpCx<'mir, 'tcx, Self>,
+        frame: &Frame<'mir, 'tcx, Self::PointerTag, Self::FrameExtra>,
+        local: mir::Local,
+    ) -> InterpResult<'tcx, Operand<Self::PointerTag>> {
+        frame.locals[local].access()
+    }
+
+    /// Called before a `StaticKind::Static` value is accessed.
+    fn before_access_static(
+        _allocation: &Allocation,
+    ) -> InterpResult<'tcx> {
+        Ok(())
+    }
+
     /// Called to initialize the "extra" state of an allocation and make the pointers
     /// it contains (in relocations) tagged.  The way we construct allocations is
     /// to always first construct it without extra and then add the extra.
diff --git a/src/librustc_mir/interpret/memory.rs b/src/librustc_mir/interpret/memory.rs
index 62b1760508b4c..924474c53175c 100644
--- a/src/librustc_mir/interpret/memory.rs
+++ b/src/librustc_mir/interpret/memory.rs
@@ -462,6 +462,8 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
                     // Make sure we use the ID of the resolved memory, not the lazy one!
                     let id = raw_const.alloc_id;
                     let allocation = tcx.alloc_map.lock().unwrap_memory(id);
+
+                    M::before_access_static(allocation)?;
                     Cow::Borrowed(allocation)
                 }
             }
diff --git a/src/librustc_mir/interpret/operand.rs b/src/librustc_mir/interpret/operand.rs
index f5d1ec3eb7556..861e5ebef877d 100644
--- a/src/librustc_mir/interpret/operand.rs
+++ b/src/librustc_mir/interpret/operand.rs
@@ -458,7 +458,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
             // Do not read from ZST, they might not be initialized
             Operand::Immediate(Scalar::zst().into())
         } else {
-            frame.locals[local].access()?
+            M::access_local(&self, frame, local)?
         };
         Ok(OpTy { op, layout })
     }
@@ -481,7 +481,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
 
     // Evaluate a place with the goal of reading from it.  This lets us sometimes
     // avoid allocations.
-    pub(super) fn eval_place_to_op(
+    pub fn eval_place_to_op(
         &self,
         place: &mir::Place<'tcx>,
         layout: Option<TyLayout<'tcx>>,
diff --git a/src/librustc_mir/interpret/place.rs b/src/librustc_mir/interpret/place.rs
index 2f1b35757fe9c..1166ca9bf2444 100644
--- a/src/librustc_mir/interpret/place.rs
+++ b/src/librustc_mir/interpret/place.rs
@@ -9,7 +9,7 @@ use rustc::mir;
 use rustc::mir::interpret::truncate;
 use rustc::ty::{self, Ty};
 use rustc::ty::layout::{
-    self, Size, Align, LayoutOf, TyLayout, HasDataLayout, VariantIdx, PrimitiveExt
+    self, Size, Abi, Align, LayoutOf, TyLayout, HasDataLayout, VariantIdx, PrimitiveExt
 };
 use rustc::ty::TypeFoldable;
 
@@ -385,6 +385,10 @@ where
                 stride * field
             }
             layout::FieldPlacement::Union(count) => {
+                // FIXME(#64506) `UninhabitedValue` can be removed when this issue is resolved
+                if base.layout.abi == Abi::Uninhabited {
+                    throw_unsup!(UninhabitedValue);
+                }
                 assert!(field < count as u64,
                         "Tried to access field {} of union with {} fields", field, count);
                 // Offset is always 0
diff --git a/src/librustc_mir/interpret/step.rs b/src/librustc_mir/interpret/step.rs
index affca10bf5265..daca7a25787ca 100644
--- a/src/librustc_mir/interpret/step.rs
+++ b/src/librustc_mir/interpret/step.rs
@@ -132,7 +132,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
     ///
     /// There is no separate `eval_rvalue` function. Instead, the code for handling each rvalue
     /// type writes its results directly into the memory specified by the place.
-    fn eval_rvalue_into_place(
+    pub fn eval_rvalue_into_place(
         &mut self,
         rvalue: &mir::Rvalue<'tcx>,
         place: &mir::Place<'tcx>,
diff --git a/src/librustc_mir/transform/const_prop.rs b/src/librustc_mir/transform/const_prop.rs
index 857757ada53b7..612822b6d9d34 100644
--- a/src/librustc_mir/transform/const_prop.rs
+++ b/src/librustc_mir/transform/const_prop.rs
@@ -1,22 +1,26 @@
 //! Propagates constants for early reporting of statically known
 //! assertion failures
 
+use std::borrow::Cow;
 use std::cell::Cell;
 
 use rustc::hir::def::DefKind;
+use rustc::hir::def_id::DefId;
 use rustc::mir::{
     AggregateKind, Constant, Location, Place, PlaceBase, Body, Operand, Rvalue,
-    Local, NullOp, UnOp, StatementKind, Statement, LocalKind, Static, StaticKind,
-    TerminatorKind, Terminator,  ClearCrossCrate, SourceInfo, BinOp, ProjectionElem,
-    SourceScope, SourceScopeLocalData, LocalDecl,
+    Local, NullOp, UnOp, StatementKind, Statement, LocalKind,
+    TerminatorKind, Terminator,  ClearCrossCrate, SourceInfo, BinOp,
+    SourceScope, SourceScopeLocalData, LocalDecl, BasicBlock,
 };
 use rustc::mir::visit::{
     Visitor, PlaceContext, MutatingUseContext, MutVisitor, NonMutatingUseContext,
 };
-use rustc::mir::interpret::{Scalar, GlobalId, InterpResult, PanicInfo};
+use rustc::mir::interpret::{Scalar, InterpResult, PanicInfo};
 use rustc::ty::{self, Instance, ParamEnv, Ty, TyCtxt};
+use syntax::ast::Mutability;
 use syntax_pos::{Span, DUMMY_SP};
 use rustc::ty::subst::InternalSubsts;
+use rustc_data_structures::fx::FxHashMap;
 use rustc_data_structures::indexed_vec::IndexVec;
 use rustc::ty::layout::{
     LayoutOf, TyLayout, LayoutError, HasTyCtxt, TargetDataLayout, HasDataLayout,
@@ -24,11 +28,11 @@ use rustc::ty::layout::{
 
 use crate::interpret::{
     self, InterpCx, ScalarMaybeUndef, Immediate, OpTy,
-    ImmTy, MemoryKind, StackPopCleanup, LocalValue, LocalState,
-};
-use crate::const_eval::{
-    CompileTimeInterpreter, error_to_const_error, mk_eval_cx,
+    StackPopCleanup, LocalValue, LocalState, AllocId, Frame,
+    Allocation, MemoryKind, ImmTy, Pointer, Memory, PlaceTy,
+    Operand as InterpOperand,
 };
+use crate::const_eval::error_to_const_error;
 use crate::transform::{MirPass, MirSource};
 
 pub struct ConstProp;
@@ -57,6 +61,14 @@ impl<'tcx> MirPass<'tcx> for ConstProp {
             return
         }
 
+        let is_generator = tcx.type_of(source.def_id()).is_generator();
+        // FIXME(welseywiser) const prop doesn't work on generators because of query cycles
+        // computing their layout.
+        if is_generator {
+            trace!("ConstProp skipped for generator {:?}", source.def_id());
+            return
+        }
+
         trace!("ConstProp starting for {:?}", source.def_id());
 
         // Steal some data we need from `body`.
@@ -103,11 +115,154 @@ impl<'tcx> MirPass<'tcx> for ConstProp {
     }
 }
 
+struct ConstPropMachine;
+
+impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for ConstPropMachine {
+    type MemoryKinds= !;
+    type PointerTag = ();
+    type ExtraFnVal = !;
+
+    type FrameExtra = ();
+    type MemoryExtra = ();
+    type AllocExtra = ();
+
+    type MemoryMap = FxHashMap<AllocId, (MemoryKind<!>, Allocation)>;
+
+    const STATIC_KIND: Option<!> = None;
+
+    const CHECK_ALIGN: bool = false;
+
+    #[inline(always)]
+    fn enforce_validity(_ecx: &InterpCx<'mir, 'tcx, Self>) -> bool {
+        false
+    }
+
+    fn find_fn(
+        _ecx: &mut InterpCx<'mir, 'tcx, Self>,
+        _instance: ty::Instance<'tcx>,
+        _args: &[OpTy<'tcx>],
+        _dest: Option<PlaceTy<'tcx>>,
+        _ret: Option<BasicBlock>,
+    ) -> InterpResult<'tcx, Option<&'mir Body<'tcx>>> {
+        Ok(None)
+    }
+
+    fn call_extra_fn(
+        _ecx: &mut InterpCx<'mir, 'tcx, Self>,
+        fn_val: !,
+        _args: &[OpTy<'tcx>],
+        _dest: Option<PlaceTy<'tcx>>,
+        _ret: Option<BasicBlock>,
+    ) -> InterpResult<'tcx> {
+        match fn_val {}
+    }
+
+    fn call_intrinsic(
+        _ecx: &mut InterpCx<'mir, 'tcx, Self>,
+        _instance: ty::Instance<'tcx>,
+        _args: &[OpTy<'tcx>],
+        _dest: PlaceTy<'tcx>,
+    ) -> InterpResult<'tcx> {
+        throw_unsup_format!("calling intrinsics isn't supported in ConstProp");
+    }
+
+    fn ptr_to_int(
+        _mem: &Memory<'mir, 'tcx, Self>,
+        _ptr: Pointer,
+    ) -> InterpResult<'tcx, u64> {
+        throw_unsup_format!("ptr-to-int casts aren't supported in ConstProp");
+    }
+
+    fn binary_ptr_op(
+        _ecx: &InterpCx<'mir, 'tcx, Self>,
+        _bin_op: BinOp,
+        _left: ImmTy<'tcx>,
+        _right: ImmTy<'tcx>,
+    ) -> InterpResult<'tcx, (Scalar, bool, Ty<'tcx>)> {
+        // We can't do this because aliasing of memory can differ between const eval and llvm
+        throw_unsup_format!("pointer arithmetic or comparisons aren't supported in ConstProp");
+    }
+
+    fn find_foreign_static(
+        _tcx: TyCtxt<'tcx>,
+        _def_id: DefId,
+    ) -> InterpResult<'tcx, Cow<'tcx, Allocation<Self::PointerTag>>> {
+        throw_unsup!(ReadForeignStatic)
+    }
+
+    #[inline(always)]
+    fn tag_allocation<'b>(
+        _memory_extra: &(),
+        _id: AllocId,
+        alloc: Cow<'b, Allocation>,
+        _kind: Option<MemoryKind<!>>,
+    ) -> (Cow<'b, Allocation<Self::PointerTag>>, Self::PointerTag) {
+        // We do not use a tag so we can just cheaply forward the allocation
+        (alloc, ())
+    }
+
+    #[inline(always)]
+    fn tag_static_base_pointer(
+        _memory_extra: &(),
+        _id: AllocId,
+    ) -> Self::PointerTag {
+        ()
+    }
+
+    fn box_alloc(
+        _ecx: &mut InterpCx<'mir, 'tcx, Self>,
+        _dest: PlaceTy<'tcx>,
+    ) -> InterpResult<'tcx> {
+        throw_unsup_format!("can't const prop `box` keyword");
+    }
+
+    fn access_local(
+        _ecx: &InterpCx<'mir, 'tcx, Self>,
+        frame: &Frame<'mir, 'tcx, Self::PointerTag, Self::FrameExtra>,
+        local: Local,
+    ) -> InterpResult<'tcx, InterpOperand<Self::PointerTag>> {
+        let l = &frame.locals[local];
+
+        if l.value == LocalValue::Uninitialized {
+            throw_unsup_format!("tried to access an uninitialized local");
+        }
+
+        l.access()
+    }
+
+    fn before_access_static(
+        allocation: &Allocation<Self::PointerTag, Self::AllocExtra>,
+    ) -> InterpResult<'tcx> {
+        // if the static allocation is mutable or if it has relocations (it may be legal to mutate
+        // the memory behind that in the future), then we can't const prop it
+        if allocation.mutability == Mutability::Mutable || allocation.relocations().len() > 0 {
+            throw_unsup_format!("can't eval mutable statics in ConstProp");
+        }
+
+        Ok(())
+    }
+
+    fn before_terminator(_ecx: &mut InterpCx<'mir, 'tcx, Self>) -> InterpResult<'tcx> {
+        Ok(())
+    }
+
+    #[inline(always)]
+    fn stack_push(_ecx: &mut InterpCx<'mir, 'tcx, Self>) -> InterpResult<'tcx> {
+        Ok(())
+    }
+
+    /// Called immediately before a stack frame gets popped.
+    #[inline(always)]
+    fn stack_pop(_ecx: &mut InterpCx<'mir, 'tcx, Self>, _extra: ()) -> InterpResult<'tcx> {
+        Ok(())
+    }
+}
+
 type Const<'tcx> = OpTy<'tcx>;
 
 /// Finds optimization opportunities on the MIR.
 struct ConstPropagator<'mir, 'tcx> {
-    ecx: InterpCx<'mir, 'tcx, CompileTimeInterpreter<'mir, 'tcx>>,
+    ecx: InterpCx<'mir, 'tcx, ConstPropMachine>,
     tcx: TyCtxt<'tcx>,
     source: MirSource<'tcx>,
     can_const_prop: IndexVec<Local, bool>,
@@ -150,7 +305,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
         let def_id = source.def_id();
         let param_env = tcx.param_env(def_id);
         let span = tcx.def_span(def_id);
-        let mut ecx = mk_eval_cx(tcx, span, param_env);
+        let mut ecx = InterpCx::new(tcx.at(span), param_env, ConstPropMachine, ());
         let can_const_prop = CanConstProp::check(body);
 
         ecx.push_stack_frame(
@@ -282,53 +437,9 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
 
     fn eval_place(&mut self, place: &Place<'tcx>, source_info: SourceInfo) -> Option<Const<'tcx>> {
         trace!("eval_place(place={:?})", place);
-        let mut eval = match place.base {
-            PlaceBase::Local(loc) => self.get_const(loc).clone()?,
-            PlaceBase::Static(box Static {kind: StaticKind::Promoted(promoted, _), ..}) => {
-                let generics = self.tcx.generics_of(self.source.def_id());
-                if generics.requires_monomorphization(self.tcx) {
-                    // FIXME: can't handle code with generics
-                    return None;
-                }
-                let substs = InternalSubsts::identity_for_item(self.tcx, self.source.def_id());
-                let instance = Instance::new(self.source.def_id(), substs);
-                let cid = GlobalId {
-                    instance,
-                    promoted: Some(promoted),
-                };
-                let res = self.use_ecx(source_info, |this| {
-                    this.ecx.const_eval_raw(cid)
-                })?;
-                trace!("evaluated promoted {:?} to {:?}", promoted, res);
-                res.into()
-            }
-            _ => return None,
-        };
-
-        for (i, elem) in place.projection.iter().enumerate() {
-            let proj_base = &place.projection[..i];
-
-            match elem {
-                ProjectionElem::Field(field, _) => {
-                    trace!("field proj on {:?}", proj_base);
-                    eval = self.use_ecx(source_info, |this| {
-                        this.ecx.operand_field(eval, field.index() as u64)
-                    })?;
-                },
-                ProjectionElem::Deref => {
-                    trace!("processing deref");
-                    eval = self.use_ecx(source_info, |this| {
-                        this.ecx.deref_operand(eval)
-                    })?.into();
-                }
-                // We could get more projections by using e.g., `operand_projection`,
-                // but we do not even have the stack frame set up properly so
-                // an `Index` projection would throw us off-track.
-                _ => return None,
-            }
-        }
-
-        Some(eval)
+        self.use_ecx(source_info, |this| {
+            this.ecx.eval_place_to_op(place, None)
+        })
     }
 
     fn eval_operand(&mut self, op: &Operand<'tcx>, source_info: SourceInfo) -> Option<Const<'tcx>> {
@@ -344,166 +455,118 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
         rvalue: &Rvalue<'tcx>,
         place_layout: TyLayout<'tcx>,
         source_info: SourceInfo,
+        place: &Place<'tcx>,
     ) -> Option<Const<'tcx>> {
         let span = source_info.span;
-        match *rvalue {
-            Rvalue::Use(ref op) => {
-                self.eval_operand(op, source_info)
-            },
-            Rvalue::Ref(_, _, ref place) => {
-                let src = self.eval_place(place, source_info)?;
-                let mplace = src.try_as_mplace().ok()?;
-                Some(ImmTy::from_scalar(mplace.ptr.into(), place_layout).into())
-            },
+
+        // if this isn't a supported operation, then return None
+        match rvalue {
             Rvalue::Repeat(..) |
             Rvalue::Aggregate(..) |
             Rvalue::NullaryOp(NullOp::Box, _) |
-            Rvalue::Discriminant(..) => None,
-
-            Rvalue::Cast(kind, ref operand, _) => {
-                let op = self.eval_operand(operand, source_info)?;
-                self.use_ecx(source_info, |this| {
-                    let dest = this.ecx.allocate(place_layout, MemoryKind::Stack);
-                    this.ecx.cast(op, kind, dest.into())?;
-                    Ok(dest.into())
-                })
-            },
-            Rvalue::Len(ref place) => {
-                let place = self.eval_place(&place, source_info)?;
-                let mplace = place.try_as_mplace().ok()?;
-
-                if let ty::Slice(_) = mplace.layout.ty.kind {
-                    let len = mplace.meta.unwrap().to_usize(&self.ecx).unwrap();
-
-                    Some(ImmTy::from_uint(
-                        len,
-                        self.tcx.layout_of(self.param_env.and(self.tcx.types.usize)).ok()?,
-                    ).into())
-                } else {
-                    trace!("not slice: {:?}", mplace.layout.ty.kind);
-                    None
-                }
-            },
-            Rvalue::NullaryOp(NullOp::SizeOf, ty) => {
-                type_size_of(self.tcx, self.param_env, ty).and_then(|n| Some(
-                    ImmTy::from_uint(
-                        n,
-                        self.tcx.layout_of(self.param_env.and(self.tcx.types.usize)).ok()?,
-                    ).into()
-                ))
-            }
-            Rvalue::UnaryOp(op, ref arg) => {
-                let def_id = if self.tcx.is_closure(self.source.def_id()) {
-                    self.tcx.closure_base_def_id(self.source.def_id())
-                } else {
-                    self.source.def_id()
-                };
-                let generics = self.tcx.generics_of(def_id);
-                if generics.requires_monomorphization(self.tcx) {
-                    // FIXME: can't handle code with generics
-                    return None;
-                }
+            Rvalue::Discriminant(..) => return None,
+
+            Rvalue::Use(_) |
+            Rvalue::Len(_) |
+            Rvalue::Cast(..) |
+            Rvalue::NullaryOp(..) |
+            Rvalue::CheckedBinaryOp(..) |
+            Rvalue::Ref(..) |
+            Rvalue::UnaryOp(..) |
+            Rvalue::BinaryOp(..) => { }
+        }
 
-                let arg = self.eval_operand(arg, source_info)?;
-                let oflo_check = self.tcx.sess.overflow_checks();
-                let val = self.use_ecx(source_info, |this| {
-                    let prim = this.ecx.read_immediate(arg)?;
-                    match op {
-                        UnOp::Neg => {
-                            // We check overflow in debug mode already
-                            // so should only check in release mode.
-                            if !oflo_check
-                            && prim.layout.ty.is_signed()
-                            && prim.to_bits()? == (1 << (prim.layout.size.bits() - 1)) {
-                                throw_panic!(OverflowNeg)
-                            }
-                        }
-                        UnOp::Not => {
-                            // Cannot overflow
+        // perform any special checking for specific Rvalue types
+        if let Rvalue::UnaryOp(op, arg) = rvalue {
+            trace!("checking UnaryOp(op = {:?}, arg = {:?})", op, arg);
+            let overflow_check = self.tcx.sess.overflow_checks();
+
+            self.use_ecx(source_info, |this| {
+                // We check overflow in debug mode already
+                // so should only check in release mode.
+                if *op == UnOp::Neg && !overflow_check {
+                    let ty = arg.ty(&this.local_decls, this.tcx);
+
+                    if ty.is_integral() {
+                        let arg = this.ecx.eval_operand(arg, None)?;
+                        let prim = this.ecx.read_immediate(arg)?;
+                        // Need to do overflow check here: For actual CTFE, MIR
+                        // generation emits code that does this before calling the op.
+                        if prim.to_bits()? == (1 << (prim.layout.size.bits() - 1)) {
+                            throw_panic!(OverflowNeg)
                         }
                     }
-                    // Now run the actual operation.
-                    this.ecx.unary_op(op, prim)
-                })?;
-                Some(val.into())
-            }
-            Rvalue::CheckedBinaryOp(op, ref left, ref right) |
-            Rvalue::BinaryOp(op, ref left, ref right) => {
-                trace!("rvalue binop {:?} for {:?} and {:?}", op, left, right);
-                let right = self.eval_operand(right, source_info)?;
-                let def_id = if self.tcx.is_closure(self.source.def_id()) {
-                    self.tcx.closure_base_def_id(self.source.def_id())
-                } else {
-                    self.source.def_id()
-                };
-                let generics = self.tcx.generics_of(def_id);
-                if generics.requires_monomorphization(self.tcx) {
-                    // FIXME: can't handle code with generics
+                }
+
+                Ok(())
+            })?;
+        } else if let Rvalue::BinaryOp(op, left, right) = rvalue {
+            trace!("checking BinaryOp(op = {:?}, left = {:?}, right = {:?})", op, left, right);
+
+            let r = self.use_ecx(source_info, |this| {
+                this.ecx.read_immediate(this.ecx.eval_operand(right, None)?)
+            })?;
+            if *op == BinOp::Shr || *op == BinOp::Shl {
+                let left_bits = place_layout.size.bits();
+                let right_size = r.layout.size;
+                let r_bits = r.to_scalar().and_then(|r| r.to_bits(right_size));
+                if r_bits.ok().map_or(false, |b| b >= left_bits as u128) {
+                    let source_scope_local_data = match self.source_scope_local_data {
+                        ClearCrossCrate::Set(ref data) => data,
+                        ClearCrossCrate::Clear => return None,
+                    };
+                    let dir = if *op == BinOp::Shr {
+                        "right"
+                    } else {
+                        "left"
+                    };
+                    let hir_id = source_scope_local_data[source_info.scope].lint_root;
+                    self.tcx.lint_hir(
+                        ::rustc::lint::builtin::EXCEEDING_BITSHIFTS,
+                        hir_id,
+                        span,
+                        &format!("attempt to shift {} with overflow", dir));
                     return None;
                 }
+            }
+            self.use_ecx(source_info, |this| {
+                let l = this.ecx.read_immediate(this.ecx.eval_operand(left, None)?)?;
+                let (_, overflow, _ty) = this.ecx.overflowing_binary_op(*op, l, r)?;
+
+                // We check overflow in debug mode already
+                // so should only check in release mode.
+                if !this.tcx.sess.overflow_checks() && overflow {
+                    let err = err_panic!(Overflow(*op)).into();
+                    return Err(err);
+                }
 
-                let r = self.use_ecx(source_info, |this| {
-                    this.ecx.read_immediate(right)
-                })?;
-                if op == BinOp::Shr || op == BinOp::Shl {
-                    let left_ty = left.ty(&self.local_decls, self.tcx);
-                    let left_bits = self
-                        .tcx
-                        .layout_of(self.param_env.and(left_ty))
-                        .unwrap()
-                        .size
-                        .bits();
-                    let right_size = right.layout.size;
-                    let r_bits = r.to_scalar().and_then(|r| r.to_bits(right_size));
-                    if r_bits.ok().map_or(false, |b| b >= left_bits as u128) {
-                        let source_scope_local_data = match self.source_scope_local_data {
-                            ClearCrossCrate::Set(ref data) => data,
-                            ClearCrossCrate::Clear => return None,
-                        };
-                        let dir = if op == BinOp::Shr {
-                            "right"
-                        } else {
-                            "left"
-                        };
-                        let hir_id = source_scope_local_data[source_info.scope].lint_root;
-                        self.tcx.lint_hir(
-                            ::rustc::lint::builtin::EXCEEDING_BITSHIFTS,
-                            hir_id,
-                            span,
-                            &format!("attempt to shift {} with overflow", dir));
-                        return None;
-                    }
+                Ok(())
+            })?;
+        } else if let Rvalue::Ref(_, _, place) = rvalue {
+            trace!("checking Ref({:?})", place);
+            // FIXME(wesleywiser) we don't currently handle the case where we try to make a ref
+            // from a function argument that hasn't been assigned to in this function.
+            if let Place {
+                base: PlaceBase::Local(local),
+                projection: box []
+            } = place {
+                let alive =
+                    if let LocalValue::Live(_) = self.ecx.frame().locals[*local].value {
+                        true
+                    } else { false };
+
+                if local.as_usize() <= self.ecx.frame().body.arg_count && !alive {
+                    trace!("skipping Ref({:?})", place);
+                    return None;
                 }
-                let left = self.eval_operand(left, source_info)?;
-                let l = self.use_ecx(source_info, |this| {
-                    this.ecx.read_immediate(left)
-                })?;
-                trace!("const evaluating {:?} for {:?} and {:?}", op, left, right);
-                let (val, overflow, _ty) = self.use_ecx(source_info, |this| {
-                    this.ecx.overflowing_binary_op(op, l, r)
-                })?;
-                let val = if let Rvalue::CheckedBinaryOp(..) = *rvalue {
-                    Immediate::ScalarPair(
-                        val.into(),
-                        Scalar::from_bool(overflow).into(),
-                    )
-                } else {
-                    // We check overflow in debug mode already
-                    // so should only check in release mode.
-                    if !self.tcx.sess.overflow_checks() && overflow {
-                        let err = err_panic!(Overflow(op)).into();
-                        let _: Option<()> = self.use_ecx(source_info, |_| Err(err));
-                        return None;
-                    }
-                    Immediate::Scalar(val.into())
-                };
-                let res = ImmTy {
-                    imm: val,
-                    layout: place_layout,
-                };
-                Some(res.into())
-            },
+            }
         }
+
+        self.use_ecx(source_info, |this| {
+            trace!("calling eval_rvalue_into_place(rvalue = {:?}, place = {:?})", rvalue, place);
+            this.ecx.eval_rvalue_into_place(rvalue, place)?;
+            this.ecx.eval_place_to_op(place, Some(place_layout))
+        })
     }
 
     fn operand_from_scalar(&self, scalar: Scalar, ty: Ty<'tcx>, span: Span) -> Operand<'tcx> {
@@ -577,14 +640,6 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
     }
 }
 
-fn type_size_of<'tcx>(
-    tcx: TyCtxt<'tcx>,
-    param_env: ty::ParamEnv<'tcx>,
-    ty: Ty<'tcx>,
-) -> Option<u64> {
-    tcx.layout_of(param_env.and(ty)).ok().map(|layout| layout.size.bytes())
-}
-
 struct CanConstProp {
     can_const_prop: IndexVec<Local, bool>,
     // false at the beginning, once set, there are not allowed to be any more assignments
@@ -670,15 +725,19 @@ impl<'mir, 'tcx> MutVisitor<'tcx> for ConstPropagator<'mir, 'tcx> {
                 .ty(&self.local_decls, self.tcx)
                 .ty;
             if let Ok(place_layout) = self.tcx.layout_of(self.param_env.and(place_ty)) {
-                if let Some(value) = self.const_prop(rval, place_layout, statement.source_info) {
-                    if let Place {
-                        base: PlaceBase::Local(local),
-                        projection: box [],
-                    } = *place {
+                if let Place {
+                    base: PlaceBase::Local(local),
+                    projection: box [],
+                } = *place {
+                    if let Some(value) = self.const_prop(rval,
+                                                         place_layout,
+                                                         statement.source_info,
+                                                         place) {
                         trace!("checking whether {:?} can be stored to {:?}", value, local);
                         if self.can_const_prop[local] {
                             trace!("storing {:?} to {:?}", value, local);
-                            assert!(self.get_const(local).is_none());
+                            assert!(self.get_const(local).is_none() ||
+                                    self.get_const(local) == Some(value));
                             self.set_const(local, value);
 
                             if self.should_const_prop() {
@@ -692,7 +751,22 @@ impl<'mir, 'tcx> MutVisitor<'tcx> for ConstPropagator<'mir, 'tcx> {
                     }
                 }
             }
+        } else {
+            match statement.kind {
+                StatementKind::StorageLive(local) |
+                StatementKind::StorageDead(local) if self.can_const_prop[local] => {
+                    let frame = self.ecx.frame_mut();
+                    frame.locals[local].value =
+                        if let StatementKind::StorageLive(_) = statement.kind {
+                            LocalValue::Uninitialized
+                        } else {
+                            LocalValue::Dead
+                        };
+                }
+                _ => {}
+            }
         }
+
         self.super_statement(statement, location);
     }
 
diff --git a/src/librustc_resolve/error_codes.rs b/src/librustc_resolve/error_codes.rs
index adbff67cc8dac..9a39fcf422393 100644
--- a/src/librustc_resolve/error_codes.rs
+++ b/src/librustc_resolve/error_codes.rs
@@ -1525,6 +1525,51 @@ match r {
 ```
 "##,
 
+E0531: r##"
+An unknown tuple struct/variant has been used.
+
+Erroneous code example:
+
+```compile_fail,E0531
+let Type(x) = Type(12); // error!
+match Bar(12) {
+    Bar(x) => {} // error!
+    _ => {}
+}
+```
+
+In most cases, it's either a forgotten import or a typo. However, let's look at
+how you can have such a type:
+
+```edition2018
+struct Type(u32); // this is a tuple struct
+
+enum Foo {
+    Bar(u32), // this is a tuple variant
+}
+
+use Foo::*; // To use Foo's variant directly, we need to import them in
+            // the scope.
+```
+
+Either way, it should work fine with our previous code:
+
+```edition2018
+struct Type(u32);
+
+enum Foo {
+    Bar(u32),
+}
+use Foo::*;
+
+let Type(x) = Type(12); // ok!
+match Type(12) {
+    Type(x) => {} // ok!
+    _ => {}
+}
+```
+"##,
+
 E0532: r##"
 Pattern arm did not match expected kind.
 
@@ -1675,7 +1720,6 @@ fn const_id<T, const N: T>() -> T { // error: const parameter
 //  E0419, merged into 531
 //  E0420, merged into 532
 //  E0421, merged into 531
-    E0531, // unresolved pattern path kind `name`
 //  E0427, merged into 530
 //  E0467, removed
 //  E0470, removed
diff --git a/src/librustc_target/spec/aarch64_unknown_none.rs b/src/librustc_target/spec/aarch64_unknown_none.rs
index 8c02bc61088b4..b9549ec2120dd 100644
--- a/src/librustc_target/spec/aarch64_unknown_none.rs
+++ b/src/librustc_target/spec/aarch64_unknown_none.rs
@@ -1,4 +1,4 @@
-// Generic AArch64 target for bare-metal code
+// Generic AArch64 target for bare-metal code - Floating point enabled
 //
 // Can be used in conjunction with the `target-feature` and
 // `target-cpu` compiler flags to opt-in more hardware-specific
@@ -11,7 +11,7 @@ use super::{LldFlavor, LinkerFlavor, Target, TargetOptions, PanicStrategy};
 pub fn target() -> Result<Target, String> {
     let opts = TargetOptions {
         linker: Some("rust-lld".to_owned()),
-        features: "+strict-align".to_string(),
+        features: "+strict-align,+neon,+fp-armv8".to_string(),
         executables: true,
         relocation_model: "static".to_string(),
         disable_redzone: true,
diff --git a/src/librustc_target/spec/aarch64_unknown_none_softfloat.rs b/src/librustc_target/spec/aarch64_unknown_none_softfloat.rs
new file mode 100644
index 0000000000000..b91f2af68ecb8
--- /dev/null
+++ b/src/librustc_target/spec/aarch64_unknown_none_softfloat.rs
@@ -0,0 +1,37 @@
+// Generic AArch64 target for bare-metal code - Floating point disabled
+//
+// Can be used in conjunction with the `target-feature` and
+// `target-cpu` compiler flags to opt-in more hardware-specific
+// features.
+//
+// For example, `-C target-cpu=cortex-a53`.
+
+use super::{LldFlavor, LinkerFlavor, Target, TargetOptions, PanicStrategy};
+
+pub fn target() -> Result<Target, String> {
+    let opts = TargetOptions {
+        linker: Some("rust-lld".to_owned()),
+        features: "+strict-align,-neon,-fp-armv8".to_string(),
+        executables: true,
+        relocation_model: "static".to_string(),
+        disable_redzone: true,
+        linker_is_gnu: true,
+        max_atomic_width: Some(128),
+        panic_strategy: PanicStrategy::Abort,
+        abi_blacklist: super::arm_base::abi_blacklist(),
+        .. Default::default()
+    };
+    Ok(Target {
+        llvm_target: "aarch64-unknown-none".to_string(),
+        target_endian: "little".to_string(),
+        target_pointer_width: "64".to_string(),
+        target_c_int_width: "32".to_string(),
+        target_os: "none".to_string(),
+        target_env: String::new(),
+        target_vendor: String::new(),
+        data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".to_string(),
+        arch: "aarch64".to_string(),
+        linker_flavor: LinkerFlavor::Lld(LldFlavor::Ld),
+        options: opts,
+    })
+}
diff --git a/src/librustc_target/spec/mod.rs b/src/librustc_target/spec/mod.rs
index 626fa374a1bd4..25add0cc6a4be 100644
--- a/src/librustc_target/spec/mod.rs
+++ b/src/librustc_target/spec/mod.rs
@@ -489,6 +489,7 @@ supported_targets! {
     ("riscv64gc-unknown-none-elf", riscv64gc_unknown_none_elf),
 
     ("aarch64-unknown-none", aarch64_unknown_none),
+    ("aarch64-unknown-none-softfloat", aarch64_unknown_none_softfloat),
 
     ("x86_64-fortanix-unknown-sgx", x86_64_fortanix_unknown_sgx),
 
diff --git a/src/test/mir-opt/const_prop/read_immutable_static.rs b/src/test/mir-opt/const_prop/read_immutable_static.rs
new file mode 100644
index 0000000000000..d16f812ad95db
--- /dev/null
+++ b/src/test/mir-opt/const_prop/read_immutable_static.rs
@@ -0,0 +1,27 @@
+static FOO: u8 = 2;
+
+fn main() {
+    let x = FOO + FOO;
+}
+
+// END RUST SOURCE
+// START rustc.main.ConstProp.before.mir
+//  bb0: {
+//      ...
+//      _2 = (FOO: u8);
+//      ...
+//      _3 = (FOO: u8);
+//      _1 = Add(move _2, move _3);
+//      ...
+//  }
+// END rustc.main.ConstProp.before.mir
+// START rustc.main.ConstProp.after.mir
+//  bb0: {
+//      ...
+//      _2 = const 2u8;
+//      ...
+//      _3 = const 2u8;
+//      _1 = Add(move _2, move _3);
+//      ...
+//  }
+// END rustc.main.ConstProp.after.mir
diff --git a/src/test/mir-opt/const_prop/reify_fn_ptr.rs b/src/test/mir-opt/const_prop/reify_fn_ptr.rs
index 7e36b2a6b1b39..e9b61690cf89e 100644
--- a/src/test/mir-opt/const_prop/reify_fn_ptr.rs
+++ b/src/test/mir-opt/const_prop/reify_fn_ptr.rs
@@ -16,7 +16,7 @@ fn main() {
 // START rustc.main.ConstProp.after.mir
 //  bb0: {
 //      ...
-//      _3 = const Scalar(AllocId(1).0x0) : fn();
+//      _3 = const Scalar(AllocId(0).0x0) : fn();
 //      _2 = move _3 as usize (Misc);
 //      ...
 //      _1 = move _2 as *const fn() (Misc);
diff --git a/src/test/mir-opt/const_prop/slice_len.rs b/src/test/mir-opt/const_prop/slice_len.rs
index 5babeb195a826..05595ce147c96 100644
--- a/src/test/mir-opt/const_prop/slice_len.rs
+++ b/src/test/mir-opt/const_prop/slice_len.rs
@@ -34,7 +34,7 @@ fn main() {
 //      assert(const true, "index out of bounds: the len is move _7 but the index is _6") -> bb1;
 //  }
 //  bb1: {
-//      _1 = (*_2)[_6];
+//      _1 = const 2u32;
 //      ...
 //      return;
 //  }
diff --git a/src/test/run-fail/overflowing-lsh-1.rs b/src/test/run-fail/overflowing-lsh-1.rs
index c69da0f49adf1..37fbf01e487dc 100644
--- a/src/test/run-fail/overflowing-lsh-1.rs
+++ b/src/test/run-fail/overflowing-lsh-1.rs
@@ -2,6 +2,7 @@
 // compile-flags: -C debug-assertions
 
 #![warn(exceeding_bitshifts)]
+#![warn(const_err)]
 
 fn main() {
     let _x = 1_i32 << 32;
diff --git a/src/test/run-fail/overflowing-lsh-2.rs b/src/test/run-fail/overflowing-lsh-2.rs
index 21659bd52393a..7b0b37dfed043 100644
--- a/src/test/run-fail/overflowing-lsh-2.rs
+++ b/src/test/run-fail/overflowing-lsh-2.rs
@@ -2,6 +2,7 @@
 // compile-flags: -C debug-assertions
 
 #![warn(exceeding_bitshifts)]
+#![warn(const_err)]
 
 fn main() {
     let _x = 1 << -1;
diff --git a/src/test/run-fail/overflowing-lsh-3.rs b/src/test/run-fail/overflowing-lsh-3.rs
index 8f06cd1153354..1768a8e6d3138 100644
--- a/src/test/run-fail/overflowing-lsh-3.rs
+++ b/src/test/run-fail/overflowing-lsh-3.rs
@@ -2,6 +2,7 @@
 // compile-flags: -C debug-assertions
 
 #![warn(exceeding_bitshifts)]
+#![warn(const_err)]
 
 fn main() {
     let _x = 1_u64 << 64;
diff --git a/src/test/run-fail/overflowing-lsh-4.rs b/src/test/run-fail/overflowing-lsh-4.rs
index 084c147094dee..ec304b4144e0f 100644
--- a/src/test/run-fail/overflowing-lsh-4.rs
+++ b/src/test/run-fail/overflowing-lsh-4.rs
@@ -5,6 +5,7 @@
 // sidestep the overflow checking.
 
 #![warn(exceeding_bitshifts)]
+#![warn(const_err)]
 
 fn main() {
     // this signals overflow when checking is on
diff --git a/src/test/run-fail/overflowing-rsh-1.rs b/src/test/run-fail/overflowing-rsh-1.rs
index 24a77da896d9e..14514540c06e1 100644
--- a/src/test/run-fail/overflowing-rsh-1.rs
+++ b/src/test/run-fail/overflowing-rsh-1.rs
@@ -2,6 +2,7 @@
 // compile-flags: -C debug-assertions
 
 #![warn(exceeding_bitshifts)]
+#![warn(const_err)]
 
 fn main() {
     let _x = -1_i32 >> 32;
diff --git a/src/test/run-fail/overflowing-rsh-2.rs b/src/test/run-fail/overflowing-rsh-2.rs
index b5615cacc2055..83dcbd13d2ad8 100644
--- a/src/test/run-fail/overflowing-rsh-2.rs
+++ b/src/test/run-fail/overflowing-rsh-2.rs
@@ -2,6 +2,7 @@
 // compile-flags: -C debug-assertions
 
 #![warn(exceeding_bitshifts)]
+#![warn(const_err)]
 
 fn main() {
     let _x = -1_i32 >> -1;
diff --git a/src/test/run-fail/overflowing-rsh-3.rs b/src/test/run-fail/overflowing-rsh-3.rs
index 7598e026d8139..3521c0506591c 100644
--- a/src/test/run-fail/overflowing-rsh-3.rs
+++ b/src/test/run-fail/overflowing-rsh-3.rs
@@ -2,6 +2,7 @@
 // compile-flags: -C debug-assertions
 
 #![warn(exceeding_bitshifts)]
+#![warn(const_err)]
 
 fn main() {
     let _x = -1_i64 >> 64;
diff --git a/src/test/run-fail/overflowing-rsh-4.rs b/src/test/run-fail/overflowing-rsh-4.rs
index a8d3b69392a97..ed1191849e57c 100644
--- a/src/test/run-fail/overflowing-rsh-4.rs
+++ b/src/test/run-fail/overflowing-rsh-4.rs
@@ -5,6 +5,7 @@
 // truncation does not sidestep the overflow checking.
 
 #![warn(exceeding_bitshifts)]
+#![warn(const_err)]
 
 fn main() {
     // this signals overflow when checking is on
diff --git a/src/test/ui/coherence/auxiliary/coherence_lib.rs b/src/test/ui/coherence/auxiliary/coherence_lib.rs
index 9a5ec82430639..c22819831ab24 100644
--- a/src/test/ui/coherence/auxiliary/coherence_lib.rs
+++ b/src/test/ui/coherence/auxiliary/coherence_lib.rs
@@ -5,11 +5,11 @@ pub trait Remote {
 }
 
 pub trait Remote1<T> {
-    fn foo(&self, t: T) { }
+    fn foo(&self, _t: T) { }
 }
 
 pub trait Remote2<T, U> {
-    fn foo(&self, t: T, u: U) { }
+    fn foo(&self, _t: T, _u: U) { }
 }
 
 pub struct Pair<T,U>(T,U);
diff --git a/src/test/ui/coherence/impl-foreign[foreign]-for-foreign.rs b/src/test/ui/coherence/impl-foreign[foreign]-for-foreign.rs
new file mode 100644
index 0000000000000..b08fedc5e11c2
--- /dev/null
+++ b/src/test/ui/coherence/impl-foreign[foreign]-for-foreign.rs
@@ -0,0 +1,17 @@
+#![feature(re_rebalance_coherence)]
+
+// compile-flags:--crate-name=test
+// aux-build:coherence_lib.rs
+
+extern crate coherence_lib as lib;
+use lib::*;
+use std::rc::Rc;
+
+struct Local;
+
+impl Remote1<u32> for f64 {
+    //~^ ERROR only traits defined in the current crate
+    // | can be implemented for arbitrary types [E0117]
+}
+
+fn main() {}
diff --git a/src/test/ui/coherence/impl-foreign[foreign]-for-foreign.stderr b/src/test/ui/coherence/impl-foreign[foreign]-for-foreign.stderr
new file mode 100644
index 0000000000000..04e96f29230fb
--- /dev/null
+++ b/src/test/ui/coherence/impl-foreign[foreign]-for-foreign.stderr
@@ -0,0 +1,12 @@
+error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
+  --> $DIR/impl-foreign[foreign]-for-foreign.rs:12:1
+   |
+LL | impl Remote1<u32> for f64 {
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate
+   |
+   = note: the impl does not reference only types defined in this crate
+   = note: define and implement a trait or new type instead
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0117`.
diff --git a/src/test/ui/coherence/impl-foreign[foreign]-for-local.rs b/src/test/ui/coherence/impl-foreign[foreign]-for-local.rs
new file mode 100644
index 0000000000000..33e85c164763e
--- /dev/null
+++ b/src/test/ui/coherence/impl-foreign[foreign]-for-local.rs
@@ -0,0 +1,16 @@
+#![feature(re_rebalance_coherence)]
+
+// compile-flags:--crate-name=test
+// aux-build:coherence_lib.rs
+// check-pass
+
+extern crate coherence_lib as lib;
+use lib::*;
+use std::rc::Rc;
+
+struct Local;
+
+impl Remote1<u32> for Local {
+}
+
+fn main() {}
diff --git a/src/test/ui/coherence/impl[t]-foreign[foreign[t]_local]-for-foreign.rs b/src/test/ui/coherence/impl[t]-foreign[foreign[t]_local]-for-foreign.rs
new file mode 100644
index 0000000000000..54d4bf04a583c
--- /dev/null
+++ b/src/test/ui/coherence/impl[t]-foreign[foreign[t]_local]-for-foreign.rs
@@ -0,0 +1,14 @@
+#![feature(re_rebalance_coherence)]
+
+// check-pass
+// compile-flags:--crate-name=test
+// aux-build:coherence_lib.rs
+
+extern crate coherence_lib as lib;
+use lib::*;
+use std::rc::Rc;
+
+struct Local;
+impl<T> Remote2<Rc<T>, Local> for usize { }
+
+fn main() {}
diff --git a/src/test/ui/coherence/impl[t]-foreign[foreign]-for-fundamental[t].rs b/src/test/ui/coherence/impl[t]-foreign[foreign]-for-fundamental[t].rs
new file mode 100644
index 0000000000000..66a4d9d273469
--- /dev/null
+++ b/src/test/ui/coherence/impl[t]-foreign[foreign]-for-fundamental[t].rs
@@ -0,0 +1,20 @@
+#![feature(re_rebalance_coherence)]
+
+// compile-flags:--crate-name=test
+// aux-build:coherence_lib.rs
+
+extern crate coherence_lib as lib;
+use lib::*;
+use std::rc::Rc;
+
+struct Local;
+
+impl<T> Remote1<u32> for Box<T> {
+    //~^ ERROR type parameter `T` must be used as the type parameter for some local type
+}
+
+impl<'a, T> Remote1<u32> for &'a T {
+    //~^ ERROR type parameter `T` must be used as the type parameter for some local type
+}
+
+fn main() {}
diff --git a/src/test/ui/coherence/impl[t]-foreign[foreign]-for-fundamental[t].stderr b/src/test/ui/coherence/impl[t]-foreign[foreign]-for-fundamental[t].stderr
new file mode 100644
index 0000000000000..2467097b1a8b3
--- /dev/null
+++ b/src/test/ui/coherence/impl[t]-foreign[foreign]-for-fundamental[t].stderr
@@ -0,0 +1,19 @@
+error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct<T>`)
+  --> $DIR/impl[t]-foreign[foreign]-for-fundamental[t].rs:12:1
+   |
+LL | impl<T> Remote1<u32> for Box<T> {
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type parameter `T` must be used as the type parameter for some local type
+   |
+   = note: only traits defined in the current crate can be implemented for a type parameter
+
+error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct<T>`)
+  --> $DIR/impl[t]-foreign[foreign]-for-fundamental[t].rs:16:1
+   |
+LL | impl<'a, T> Remote1<u32> for &'a T {
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type parameter `T` must be used as the type parameter for some local type
+   |
+   = note: only traits defined in the current crate can be implemented for a type parameter
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0210`.
diff --git a/src/test/ui/coherence/impl[t]-foreign[foreign]-for-t.rs b/src/test/ui/coherence/impl[t]-foreign[foreign]-for-t.rs
new file mode 100644
index 0000000000000..0a67ebcbba44c
--- /dev/null
+++ b/src/test/ui/coherence/impl[t]-foreign[foreign]-for-t.rs
@@ -0,0 +1,16 @@
+#![feature(re_rebalance_coherence)]
+
+// compile-flags:--crate-name=test
+// aux-build:coherence_lib.rs
+
+extern crate coherence_lib as lib;
+use lib::*;
+use std::rc::Rc;
+
+struct Local;
+
+impl<T> Remote1<u32> for T {
+    //~^ ERROR type parameter `T` must be used as the type parameter for some local type
+}
+
+fn main() {}
diff --git a/src/test/ui/coherence/impl[t]-foreign[foreign]-for-t.stderr b/src/test/ui/coherence/impl[t]-foreign[foreign]-for-t.stderr
new file mode 100644
index 0000000000000..5c28406f113fc
--- /dev/null
+++ b/src/test/ui/coherence/impl[t]-foreign[foreign]-for-t.stderr
@@ -0,0 +1,11 @@
+error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct<T>`)
+  --> $DIR/impl[t]-foreign[foreign]-for-t.rs:12:1
+   |
+LL | impl<T> Remote1<u32> for T {
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^ type parameter `T` must be used as the type parameter for some local type
+   |
+   = note: only traits defined in the current crate can be implemented for a type parameter
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0210`.
diff --git a/src/test/ui/coherence/impl[t]-foreign[fundamental[t]]-for-foreign.rs b/src/test/ui/coherence/impl[t]-foreign[fundamental[t]]-for-foreign.rs
new file mode 100644
index 0000000000000..71598dae96ab3
--- /dev/null
+++ b/src/test/ui/coherence/impl[t]-foreign[fundamental[t]]-for-foreign.rs
@@ -0,0 +1,20 @@
+#![feature(re_rebalance_coherence)]
+
+// compile-flags:--crate-name=test
+// aux-build:coherence_lib.rs
+
+extern crate coherence_lib as lib;
+use lib::*;
+use std::rc::Rc;
+
+struct Local;
+
+impl<T> Remote1<Box<T>> for u32 {
+    //~^ ERROR type parameter `T` must be used as the type parameter for some local type
+}
+
+impl<'a, T> Remote1<&'a T> for u32 {
+    //~^ ERROR type parameter `T` must be used as the type parameter for some local type
+}
+
+fn main() {}
diff --git a/src/test/ui/coherence/impl[t]-foreign[fundamental[t]]-for-foreign.stderr b/src/test/ui/coherence/impl[t]-foreign[fundamental[t]]-for-foreign.stderr
new file mode 100644
index 0000000000000..dd9702650795e
--- /dev/null
+++ b/src/test/ui/coherence/impl[t]-foreign[fundamental[t]]-for-foreign.stderr
@@ -0,0 +1,19 @@
+error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct<T>`)
+  --> $DIR/impl[t]-foreign[fundamental[t]]-for-foreign.rs:12:1
+   |
+LL | impl<T> Remote1<Box<T>> for u32 {
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type parameter `T` must be used as the type parameter for some local type
+   |
+   = note: only traits defined in the current crate can be implemented for a type parameter
+
+error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct<T>`)
+  --> $DIR/impl[t]-foreign[fundamental[t]]-for-foreign.rs:16:1
+   |
+LL | impl<'a, T> Remote1<&'a T> for u32 {
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type parameter `T` must be used as the type parameter for some local type
+   |
+   = note: only traits defined in the current crate can be implemented for a type parameter
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0210`.
diff --git a/src/test/ui/coherence/impl[t]-foreign[fundamental[t]]-for-fundamental[t].rs b/src/test/ui/coherence/impl[t]-foreign[fundamental[t]]-for-fundamental[t].rs
new file mode 100644
index 0000000000000..7bf0306f29ba4
--- /dev/null
+++ b/src/test/ui/coherence/impl[t]-foreign[fundamental[t]]-for-fundamental[t].rs
@@ -0,0 +1,19 @@
+#![feature(re_rebalance_coherence)]
+
+// compile-flags:--crate-name=test
+// aux-build:coherence_lib.rs
+
+extern crate coherence_lib as lib;
+use lib::*;
+use std::rc::Rc;
+
+struct Local;
+
+impl<'a, T> Remote1<Box<T>> for &'a T {
+    //~^ ERROR type parameter `T` must be used as the type parameter for some local type
+}
+impl<'a, T> Remote1<&'a T> for Box<T> {
+    //~^ ERROR type parameter `T` must be used as the type parameter for some local type
+}
+
+fn main() {}
diff --git a/src/test/ui/coherence/impl[t]-foreign[fundamental[t]]-for-fundamental[t].stderr b/src/test/ui/coherence/impl[t]-foreign[fundamental[t]]-for-fundamental[t].stderr
new file mode 100644
index 0000000000000..eec57fccea762
--- /dev/null
+++ b/src/test/ui/coherence/impl[t]-foreign[fundamental[t]]-for-fundamental[t].stderr
@@ -0,0 +1,19 @@
+error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct<T>`)
+  --> $DIR/impl[t]-foreign[fundamental[t]]-for-fundamental[t].rs:12:1
+   |
+LL | impl<'a, T> Remote1<Box<T>> for &'a T {
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type parameter `T` must be used as the type parameter for some local type
+   |
+   = note: only traits defined in the current crate can be implemented for a type parameter
+
+error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct<T>`)
+  --> $DIR/impl[t]-foreign[fundamental[t]]-for-fundamental[t].rs:15:1
+   |
+LL | impl<'a, T> Remote1<&'a T> for Box<T> {
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type parameter `T` must be used as the type parameter for some local type
+   |
+   = note: only traits defined in the current crate can be implemented for a type parameter
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0210`.
diff --git a/src/test/ui/coherence/impl[t]-foreign[fundamental[t]]-for-local.rs b/src/test/ui/coherence/impl[t]-foreign[fundamental[t]]-for-local.rs
new file mode 100644
index 0000000000000..54d577c749248
--- /dev/null
+++ b/src/test/ui/coherence/impl[t]-foreign[fundamental[t]]-for-local.rs
@@ -0,0 +1,17 @@
+#![feature(re_rebalance_coherence)]
+
+// compile-flags:--crate-name=test
+// aux-build:coherence_lib.rs
+// check-pass
+
+extern crate coherence_lib as lib;
+use lib::*;
+use std::rc::Rc;
+
+struct Local;
+
+impl<T> Remote1<Box<T>> for Local {}
+
+impl<'a, T> Remote1<&'a T> for Local {}
+
+fn main() {}
diff --git a/src/test/ui/coherence/impl[t]-foreign[fundamental[t]]-for-t.rs b/src/test/ui/coherence/impl[t]-foreign[fundamental[t]]-for-t.rs
new file mode 100644
index 0000000000000..7af929006ef7f
--- /dev/null
+++ b/src/test/ui/coherence/impl[t]-foreign[fundamental[t]]-for-t.rs
@@ -0,0 +1,19 @@
+#![feature(re_rebalance_coherence)]
+
+// compile-flags:--crate-name=test
+// aux-build:coherence_lib.rs
+
+extern crate coherence_lib as lib;
+use lib::*;
+use std::rc::Rc;
+
+struct Local;
+
+impl<T> Remote1<Box<T>> for T {
+    //~^ ERROR type parameter `T` must be used as the type parameter for some local type
+}
+impl<'a, T> Remote1<&'a T> for T {
+    //~^ ERROR type parameter `T` must be used as the type parameter for some local type
+}
+
+fn main() {}
diff --git a/src/test/ui/coherence/impl[t]-foreign[fundamental[t]]-for-t.stderr b/src/test/ui/coherence/impl[t]-foreign[fundamental[t]]-for-t.stderr
new file mode 100644
index 0000000000000..e017c3ffe6c05
--- /dev/null
+++ b/src/test/ui/coherence/impl[t]-foreign[fundamental[t]]-for-t.stderr
@@ -0,0 +1,19 @@
+error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct<T>`)
+  --> $DIR/impl[t]-foreign[fundamental[t]]-for-t.rs:12:1
+   |
+LL | impl<T> Remote1<Box<T>> for T {
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type parameter `T` must be used as the type parameter for some local type
+   |
+   = note: only traits defined in the current crate can be implemented for a type parameter
+
+error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct<T>`)
+  --> $DIR/impl[t]-foreign[fundamental[t]]-for-t.rs:15:1
+   |
+LL | impl<'a, T> Remote1<&'a T> for T {
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type parameter `T` must be used as the type parameter for some local type
+   |
+   = note: only traits defined in the current crate can be implemented for a type parameter
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0210`.
diff --git a/src/test/ui/coherence/impl[t]-foreign[fundamental[t]_local]-for-foreign.rs b/src/test/ui/coherence/impl[t]-foreign[fundamental[t]_local]-for-foreign.rs
new file mode 100644
index 0000000000000..24e0f309c4555
--- /dev/null
+++ b/src/test/ui/coherence/impl[t]-foreign[fundamental[t]_local]-for-foreign.rs
@@ -0,0 +1,20 @@
+#![feature(re_rebalance_coherence)]
+
+// compile-flags:--crate-name=test
+// aux-build:coherence_lib.rs
+
+extern crate coherence_lib as lib;
+use lib::*;
+use std::rc::Rc;
+
+struct Local;
+
+impl<T> Remote2<Box<T>, Local> for u32 {
+    //~^ ERROR type parameter `T` must be used as the type parameter for some local type
+}
+
+impl<'a, T> Remote2<&'a T, Local> for u32 {
+    //~^ ERROR type parameter `T` must be used as the type parameter for some local type
+}
+
+fn main() {}
diff --git a/src/test/ui/coherence/impl[t]-foreign[fundamental[t]_local]-for-foreign.stderr b/src/test/ui/coherence/impl[t]-foreign[fundamental[t]_local]-for-foreign.stderr
new file mode 100644
index 0000000000000..3d8561956ae7f
--- /dev/null
+++ b/src/test/ui/coherence/impl[t]-foreign[fundamental[t]_local]-for-foreign.stderr
@@ -0,0 +1,19 @@
+error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct<T>`)
+  --> $DIR/impl[t]-foreign[fundamental[t]_local]-for-foreign.rs:12:1
+   |
+LL | impl<T> Remote2<Box<T>, Local> for u32 {
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type parameter `T` must be used as the type parameter for some local type
+   |
+   = note: only traits defined in the current crate can be implemented for a type parameter
+
+error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct<T>`)
+  --> $DIR/impl[t]-foreign[fundamental[t]_local]-for-foreign.rs:16:1
+   |
+LL | impl<'a, T> Remote2<&'a T, Local> for u32 {
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type parameter `T` must be used as the type parameter for some local type
+   |
+   = note: only traits defined in the current crate can be implemented for a type parameter
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0210`.
diff --git a/src/test/ui/coherence/impl[t]-foreign[local]-for-foreign.rs b/src/test/ui/coherence/impl[t]-foreign[local]-for-foreign.rs
new file mode 100644
index 0000000000000..81cf3c3f6eca9
--- /dev/null
+++ b/src/test/ui/coherence/impl[t]-foreign[local]-for-foreign.rs
@@ -0,0 +1,16 @@
+#![feature(re_rebalance_coherence)]
+
+// compile-flags:--crate-name=test
+// aux-build:coherence_lib.rs
+// check-pass
+
+extern crate coherence_lib as lib;
+use lib::*;
+use std::rc::Rc;
+
+struct Local;
+
+impl<T> Remote1<Local> for Rc<T> {}
+impl<T> Remote1<Local> for Vec<Box<T>> {}
+
+fn main() {}
diff --git a/src/test/ui/coherence/impl[t]-foreign[local]-for-fundamental[t].rs b/src/test/ui/coherence/impl[t]-foreign[local]-for-fundamental[t].rs
new file mode 100644
index 0000000000000..54425b6d708aa
--- /dev/null
+++ b/src/test/ui/coherence/impl[t]-foreign[local]-for-fundamental[t].rs
@@ -0,0 +1,20 @@
+#![feature(re_rebalance_coherence)]
+
+// compile-flags:--crate-name=test
+// aux-build:coherence_lib.rs
+
+extern crate coherence_lib as lib;
+use lib::*;
+use std::rc::Rc;
+
+struct Local;
+
+impl<T> Remote1<Local> for Box<T> {
+    //~^ ERROR type parameter `T` must be used as the type parameter for some local type
+}
+
+impl<T> Remote1<Local> for &T {
+    //~^ ERROR type parameter `T` must be used as the type parameter for some local type
+}
+
+fn main() {}
diff --git a/src/test/ui/coherence/impl[t]-foreign[local]-for-fundamental[t].stderr b/src/test/ui/coherence/impl[t]-foreign[local]-for-fundamental[t].stderr
new file mode 100644
index 0000000000000..7859665a7bb58
--- /dev/null
+++ b/src/test/ui/coherence/impl[t]-foreign[local]-for-fundamental[t].stderr
@@ -0,0 +1,19 @@
+error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct<T>`)
+  --> $DIR/impl[t]-foreign[local]-for-fundamental[t].rs:12:1
+   |
+LL | impl<T> Remote1<Local> for Box<T> {
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type parameter `T` must be used as the type parameter for some local type
+   |
+   = note: only traits defined in the current crate can be implemented for a type parameter
+
+error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct<T>`)
+  --> $DIR/impl[t]-foreign[local]-for-fundamental[t].rs:16:1
+   |
+LL | impl<T> Remote1<Local> for &T {
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type parameter `T` must be used as the type parameter for some local type
+   |
+   = note: only traits defined in the current crate can be implemented for a type parameter
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0210`.
diff --git a/src/test/ui/coherence/impl[t]-foreign[local]-for-local.rs b/src/test/ui/coherence/impl[t]-foreign[local]-for-local.rs
new file mode 100644
index 0000000000000..6b1d93cd94442
--- /dev/null
+++ b/src/test/ui/coherence/impl[t]-foreign[local]-for-local.rs
@@ -0,0 +1,15 @@
+#![feature(re_rebalance_coherence)]
+
+// compile-flags:--crate-name=test
+// aux-build:coherence_lib.rs
+// check-pass
+
+extern crate coherence_lib as lib;
+use lib::*;
+use std::rc::Rc;
+
+struct Local;
+
+impl Remote1<Local> for Local {}
+
+fn main() {}
diff --git a/src/test/ui/coherence/impl[t]-foreign[local]-for-t.rs b/src/test/ui/coherence/impl[t]-foreign[local]-for-t.rs
new file mode 100644
index 0000000000000..6f35c6c9dbc88
--- /dev/null
+++ b/src/test/ui/coherence/impl[t]-foreign[local]-for-t.rs
@@ -0,0 +1,16 @@
+#![feature(re_rebalance_coherence)]
+
+// compile-flags:--crate-name=test
+// aux-build:coherence_lib.rs
+
+extern crate coherence_lib as lib;
+use lib::*;
+use std::rc::Rc;
+
+struct Local;
+
+impl<T> Remote1<Local> for T {
+    //~^ ERROR type parameter `T` must be used as the type parameter for some local type
+}
+
+fn main() {}
diff --git a/src/test/ui/coherence/impl[t]-foreign[local]-for-t.stderr b/src/test/ui/coherence/impl[t]-foreign[local]-for-t.stderr
new file mode 100644
index 0000000000000..be7de8cccb467
--- /dev/null
+++ b/src/test/ui/coherence/impl[t]-foreign[local]-for-t.stderr
@@ -0,0 +1,11 @@
+error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct<T>`)
+  --> $DIR/impl[t]-foreign[local]-for-t.rs:12:1
+   |
+LL | impl<T> Remote1<Local> for T {
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type parameter `T` must be used as the type parameter for some local type
+   |
+   = note: only traits defined in the current crate can be implemented for a type parameter
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0210`.
diff --git a/src/test/ui/coherence/impl[t]-foreign[local_fundamental[t]]-for-foreign.rs b/src/test/ui/coherence/impl[t]-foreign[local_fundamental[t]]-for-foreign.rs
new file mode 100644
index 0000000000000..be0875d0110fd
--- /dev/null
+++ b/src/test/ui/coherence/impl[t]-foreign[local_fundamental[t]]-for-foreign.rs
@@ -0,0 +1,19 @@
+#![feature(re_rebalance_coherence)]
+
+// compile-flags:--crate-name=test
+// aux-build:coherence_lib.rs
+// check-pass
+
+extern crate coherence_lib as lib;
+use lib::*;
+use std::rc::Rc;
+
+struct Local;
+struct Local2<T>(Rc<T>);
+
+impl<T> Remote2<Local, Box<T>> for u32 {}
+impl<'a, T> Remote2<Local, &'a T> for u32 {}
+impl<T> Remote2<Local2<T>, Box<T>> for u32 {}
+impl<'a, T> Remote2<Local2<T>, &'a T> for u32 {}
+
+fn main() {}
diff --git a/src/test/ui/coherence/impl[t]-foreign[t]-for-foreign.rs b/src/test/ui/coherence/impl[t]-foreign[t]-for-foreign.rs
new file mode 100644
index 0000000000000..5e89c2077330a
--- /dev/null
+++ b/src/test/ui/coherence/impl[t]-foreign[t]-for-foreign.rs
@@ -0,0 +1,16 @@
+#![feature(re_rebalance_coherence)]
+
+// compile-flags:--crate-name=test
+// aux-build:coherence_lib.rs
+
+extern crate coherence_lib as lib;
+use lib::*;
+use std::rc::Rc;
+
+struct Local;
+
+impl<T> Remote1<T> for u32 {
+    //~^ ERROR type parameter `T` must be used as the type parameter for some local type
+}
+
+fn main() {}
diff --git a/src/test/ui/coherence/impl[t]-foreign[t]-for-foreign.stderr b/src/test/ui/coherence/impl[t]-foreign[t]-for-foreign.stderr
new file mode 100644
index 0000000000000..5544729b5d640
--- /dev/null
+++ b/src/test/ui/coherence/impl[t]-foreign[t]-for-foreign.stderr
@@ -0,0 +1,11 @@
+error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct<T>`)
+  --> $DIR/impl[t]-foreign[t]-for-foreign.rs:12:1
+   |
+LL | impl<T> Remote1<T> for u32 {
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^ type parameter `T` must be used as the type parameter for some local type
+   |
+   = note: only traits defined in the current crate can be implemented for a type parameter
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0210`.
diff --git a/src/test/ui/coherence/impl[t]-foreign[t]-for-fundamental.rs b/src/test/ui/coherence/impl[t]-foreign[t]-for-fundamental.rs
new file mode 100644
index 0000000000000..300a2c4d48a9c
--- /dev/null
+++ b/src/test/ui/coherence/impl[t]-foreign[t]-for-fundamental.rs
@@ -0,0 +1,20 @@
+#![feature(re_rebalance_coherence)]
+
+// compile-flags:--crate-name=test
+// aux-build:coherence_lib.rs
+
+extern crate coherence_lib as lib;
+use lib::*;
+use std::rc::Rc;
+
+struct Local;
+
+impl<T> Remote1<T> for Box<T> {
+    //~^ ERROR type parameter `T` must be used as the type parameter for some local type
+}
+
+impl<'a, A, B> Remote1<A> for &'a B {
+    //~^ ERROR type parameter `B` must be used as the type parameter for some local type
+}
+
+fn main() {}
diff --git a/src/test/ui/coherence/impl[t]-foreign[t]-for-fundamental.stderr b/src/test/ui/coherence/impl[t]-foreign[t]-for-fundamental.stderr
new file mode 100644
index 0000000000000..be8cc29a6e5b0
--- /dev/null
+++ b/src/test/ui/coherence/impl[t]-foreign[t]-for-fundamental.stderr
@@ -0,0 +1,19 @@
+error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct<T>`)
+  --> $DIR/impl[t]-foreign[t]-for-fundamental.rs:12:1
+   |
+LL | impl<T> Remote1<T> for Box<T> {
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type parameter `T` must be used as the type parameter for some local type
+   |
+   = note: only traits defined in the current crate can be implemented for a type parameter
+
+error[E0210]: type parameter `B` must be used as the type parameter for some local type (e.g., `MyStruct<B>`)
+  --> $DIR/impl[t]-foreign[t]-for-fundamental.rs:16:1
+   |
+LL | impl<'a, A, B> Remote1<A> for &'a B {
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type parameter `B` must be used as the type parameter for some local type
+   |
+   = note: only traits defined in the current crate can be implemented for a type parameter
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0210`.
diff --git a/src/test/ui/coherence/impl[t]-foreign[t]-for-local.rs b/src/test/ui/coherence/impl[t]-foreign[t]-for-local.rs
new file mode 100644
index 0000000000000..769147ea7eabd
--- /dev/null
+++ b/src/test/ui/coherence/impl[t]-foreign[t]-for-local.rs
@@ -0,0 +1,15 @@
+#![feature(re_rebalance_coherence)]
+
+// compile-flags:--crate-name=test
+// aux-build:coherence_lib.rs
+// check-pass
+
+extern crate coherence_lib as lib;
+use lib::*;
+use std::rc::Rc;
+
+struct Local;
+
+impl<T> Remote1<T> for Local {}
+
+fn main() {}
diff --git a/src/test/ui/coherence/impl[t]-foreign[t]-for-t.rs b/src/test/ui/coherence/impl[t]-foreign[t]-for-t.rs
new file mode 100644
index 0000000000000..c8513380ff73e
--- /dev/null
+++ b/src/test/ui/coherence/impl[t]-foreign[t]-for-t.rs
@@ -0,0 +1,16 @@
+#![feature(re_rebalance_coherence)]
+
+// compile-flags:--crate-name=test
+// aux-build:coherence_lib.rs
+
+extern crate coherence_lib as lib;
+use lib::*;
+use std::rc::Rc;
+
+struct Local;
+
+impl<T> Remote1<T> for T {
+    //~^ ERROR type parameter `T` must be used as the type parameter for some local type
+}
+
+fn main() {}
diff --git a/src/test/ui/coherence/impl[t]-foreign[t]-for-t.stderr b/src/test/ui/coherence/impl[t]-foreign[t]-for-t.stderr
new file mode 100644
index 0000000000000..de857afd20b15
--- /dev/null
+++ b/src/test/ui/coherence/impl[t]-foreign[t]-for-t.stderr
@@ -0,0 +1,11 @@
+error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct<T>`)
+  --> $DIR/impl[t]-foreign[t]-for-t.rs:12:1
+   |
+LL | impl<T> Remote1<T> for T {
+   | ^^^^^^^^^^^^^^^^^^^^^^^^ type parameter `T` must be used as the type parameter for some local type
+   |
+   = note: only traits defined in the current crate can be implemented for a type parameter
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0210`.
diff --git a/src/test/ui/coherence/re-rebalance-coherence-rpass.rs b/src/test/ui/coherence/re-rebalance-coherence-rpass.rs
deleted file mode 100644
index bacd3b89fad29..0000000000000
--- a/src/test/ui/coherence/re-rebalance-coherence-rpass.rs
+++ /dev/null
@@ -1,14 +0,0 @@
-#![allow(dead_code)]
-#![feature(re_rebalance_coherence)]
-
-// run-pass
-// aux-build:re_rebalance_coherence_lib.rs
-
-extern crate re_rebalance_coherence_lib as lib;
-use lib::*;
-
-struct Oracle;
-impl Backend for Oracle {}
-impl<'a, T:'a, Tab> QueryFragment<Oracle> for BatchInsert<'a, T, Tab> {}
-
-fn main() {}
diff --git a/src/test/ui/consts/const-eval/issue-50814.rs b/src/test/ui/consts/const-eval/issue-50814.rs
index b85cecda16e95..274967ef60de5 100644
--- a/src/test/ui/consts/const-eval/issue-50814.rs
+++ b/src/test/ui/consts/const-eval/issue-50814.rs
@@ -11,6 +11,7 @@ struct Sum<A,B>(A,B);
 
 impl<A: Unsigned, B: Unsigned> Unsigned for Sum<A,B> {
     const MAX: u8 = A::MAX + B::MAX; //~ ERROR any use of this value will cause an error
+    //~| ERROR any use of this value will cause an error
 }
 
 fn foo<T>(_: T) -> &'static u8 {
diff --git a/src/test/ui/consts/const-eval/issue-50814.stderr b/src/test/ui/consts/const-eval/issue-50814.stderr
index 707dfee7cd5b8..de3459c72dd2b 100644
--- a/src/test/ui/consts/const-eval/issue-50814.stderr
+++ b/src/test/ui/consts/const-eval/issue-50814.stderr
@@ -9,13 +9,21 @@ LL |     const MAX: u8 = A::MAX + B::MAX;
    = note: `#[deny(const_err)]` on by default
 
 error[E0080]: evaluation of constant expression failed
-  --> $DIR/issue-50814.rs:17:5
+  --> $DIR/issue-50814.rs:18:5
    |
 LL |     &Sum::<U8,U8>::MAX
    |     ^-----------------
    |      |
    |      referenced constant has errors
 
-error: aborting due to 2 previous errors
+error: any use of this value will cause an error
+  --> $DIR/issue-50814.rs:13:21
+   |
+LL |     const MAX: u8 = A::MAX + B::MAX;
+   |     ----------------^^^^^^^^^^^^^^^-
+   |                     |
+   |                     attempt to add with overflow
+
+error: aborting due to 3 previous errors
 
 For more information about this error, try `rustc --explain E0080`.
diff --git a/src/test/ui/consts/const-prop-read-static-in-const.rs b/src/test/ui/consts/const-prop-read-static-in-const.rs
new file mode 100644
index 0000000000000..7504fd525955a
--- /dev/null
+++ b/src/test/ui/consts/const-prop-read-static-in-const.rs
@@ -0,0 +1,12 @@
+// compile-flags: -Zunleash-the-miri-inside-of-you
+// run-pass
+
+#![allow(dead_code)]
+
+const TEST: u8 = MY_STATIC;
+//~^ skipping const checks
+
+static MY_STATIC: u8 = 4;
+
+fn main() {
+}
diff --git a/src/test/ui/consts/const-prop-read-static-in-const.stderr b/src/test/ui/consts/const-prop-read-static-in-const.stderr
new file mode 100644
index 0000000000000..bbd5b12ed7dfc
--- /dev/null
+++ b/src/test/ui/consts/const-prop-read-static-in-const.stderr
@@ -0,0 +1,6 @@
+warning: skipping const checks
+  --> $DIR/const-prop-read-static-in-const.rs:6:18
+   |
+LL | const TEST: u8 = MY_STATIC;
+   |                  ^^^^^^^^^
+
diff --git a/src/test/ui/enums-pats-not-idents.stderr b/src/test/ui/enums-pats-not-idents.stderr
index 3891d1eac487b..6b1e6046260a9 100644
--- a/src/test/ui/enums-pats-not-idents.stderr
+++ b/src/test/ui/enums-pats-not-idents.stderr
@@ -6,3 +6,4 @@ LL |     let a(1) = 13;
 
 error: aborting due to previous error
 
+For more information about this error, try `rustc --explain E0531`.
diff --git a/src/test/ui/feature-gate/issue-43106-gating-of-rustc_deprecated.stderr b/src/test/ui/feature-gate/issue-43106-gating-of-rustc_deprecated.stderr
index 4eead36910356..8c6c26f7b2d81 100644
--- a/src/test/ui/feature-gate/issue-43106-gating-of-rustc_deprecated.stderr
+++ b/src/test/ui/feature-gate/issue-43106-gating-of-rustc_deprecated.stderr
@@ -1,40 +1,40 @@
-error: stability attributes may not be used outside of the standard library
+error[E0734]: stability attributes may not be used outside of the standard library
   --> $DIR/issue-43106-gating-of-rustc_deprecated.rs:7:1
    |
 LL | #![rustc_deprecated()]
    | ^^^^^^^^^^^^^^^^^^^^^^
 
-error: stability attributes may not be used outside of the standard library
+error[E0734]: stability attributes may not be used outside of the standard library
   --> $DIR/issue-43106-gating-of-rustc_deprecated.rs:10:1
    |
 LL | #[rustc_deprecated()]
    | ^^^^^^^^^^^^^^^^^^^^^
 
-error: stability attributes may not be used outside of the standard library
+error[E0734]: stability attributes may not be used outside of the standard library
   --> $DIR/issue-43106-gating-of-rustc_deprecated.rs:13:17
    |
 LL |     mod inner { #![rustc_deprecated()] }
    |                 ^^^^^^^^^^^^^^^^^^^^^^
 
-error: stability attributes may not be used outside of the standard library
+error[E0734]: stability attributes may not be used outside of the standard library
   --> $DIR/issue-43106-gating-of-rustc_deprecated.rs:16:5
    |
 LL |     #[rustc_deprecated()] fn f() { }
    |     ^^^^^^^^^^^^^^^^^^^^^
 
-error: stability attributes may not be used outside of the standard library
+error[E0734]: stability attributes may not be used outside of the standard library
   --> $DIR/issue-43106-gating-of-rustc_deprecated.rs:19:5
    |
 LL |     #[rustc_deprecated()] struct S;
    |     ^^^^^^^^^^^^^^^^^^^^^
 
-error: stability attributes may not be used outside of the standard library
+error[E0734]: stability attributes may not be used outside of the standard library
   --> $DIR/issue-43106-gating-of-rustc_deprecated.rs:22:5
    |
 LL |     #[rustc_deprecated()] type T = S;
    |     ^^^^^^^^^^^^^^^^^^^^^
 
-error: stability attributes may not be used outside of the standard library
+error[E0734]: stability attributes may not be used outside of the standard library
   --> $DIR/issue-43106-gating-of-rustc_deprecated.rs:25:5
    |
 LL |     #[rustc_deprecated()] impl S { }
@@ -42,3 +42,4 @@ LL |     #[rustc_deprecated()] impl S { }
 
 error: aborting due to 7 previous errors
 
+For more information about this error, try `rustc --explain E0734`.
diff --git a/src/test/ui/feature-gate/issue-43106-gating-of-stable.stderr b/src/test/ui/feature-gate/issue-43106-gating-of-stable.stderr
index 03410eabe3652..09dabd293ff97 100644
--- a/src/test/ui/feature-gate/issue-43106-gating-of-stable.stderr
+++ b/src/test/ui/feature-gate/issue-43106-gating-of-stable.stderr
@@ -1,40 +1,40 @@
-error: stability attributes may not be used outside of the standard library
+error[E0734]: stability attributes may not be used outside of the standard library
   --> $DIR/issue-43106-gating-of-stable.rs:7:1
    |
 LL | #![stable()]
    | ^^^^^^^^^^^^
 
-error: stability attributes may not be used outside of the standard library
+error[E0734]: stability attributes may not be used outside of the standard library
   --> $DIR/issue-43106-gating-of-stable.rs:10:1
    |
 LL | #[stable()]
    | ^^^^^^^^^^^
 
-error: stability attributes may not be used outside of the standard library
+error[E0734]: stability attributes may not be used outside of the standard library
   --> $DIR/issue-43106-gating-of-stable.rs:13:17
    |
 LL |     mod inner { #![stable()] }
    |                 ^^^^^^^^^^^^
 
-error: stability attributes may not be used outside of the standard library
+error[E0734]: stability attributes may not be used outside of the standard library
   --> $DIR/issue-43106-gating-of-stable.rs:16:5
    |
 LL |     #[stable()] fn f() { }
    |     ^^^^^^^^^^^
 
-error: stability attributes may not be used outside of the standard library
+error[E0734]: stability attributes may not be used outside of the standard library
   --> $DIR/issue-43106-gating-of-stable.rs:19:5
    |
 LL |     #[stable()] struct S;
    |     ^^^^^^^^^^^
 
-error: stability attributes may not be used outside of the standard library
+error[E0734]: stability attributes may not be used outside of the standard library
   --> $DIR/issue-43106-gating-of-stable.rs:22:5
    |
 LL |     #[stable()] type T = S;
    |     ^^^^^^^^^^^
 
-error: stability attributes may not be used outside of the standard library
+error[E0734]: stability attributes may not be used outside of the standard library
   --> $DIR/issue-43106-gating-of-stable.rs:25:5
    |
 LL |     #[stable()] impl S { }
@@ -42,3 +42,4 @@ LL |     #[stable()] impl S { }
 
 error: aborting due to 7 previous errors
 
+For more information about this error, try `rustc --explain E0734`.
diff --git a/src/test/ui/feature-gate/issue-43106-gating-of-unstable.stderr b/src/test/ui/feature-gate/issue-43106-gating-of-unstable.stderr
index 5952b3836aac8..49da2c59580e7 100644
--- a/src/test/ui/feature-gate/issue-43106-gating-of-unstable.stderr
+++ b/src/test/ui/feature-gate/issue-43106-gating-of-unstable.stderr
@@ -1,40 +1,40 @@
-error: stability attributes may not be used outside of the standard library
+error[E0734]: stability attributes may not be used outside of the standard library
   --> $DIR/issue-43106-gating-of-unstable.rs:7:1
    |
 LL | #![unstable()]
    | ^^^^^^^^^^^^^^
 
-error: stability attributes may not be used outside of the standard library
+error[E0734]: stability attributes may not be used outside of the standard library
   --> $DIR/issue-43106-gating-of-unstable.rs:10:1
    |
 LL | #[unstable()]
    | ^^^^^^^^^^^^^
 
-error: stability attributes may not be used outside of the standard library
+error[E0734]: stability attributes may not be used outside of the standard library
   --> $DIR/issue-43106-gating-of-unstable.rs:13:17
    |
 LL |     mod inner { #![unstable()] }
    |                 ^^^^^^^^^^^^^^
 
-error: stability attributes may not be used outside of the standard library
+error[E0734]: stability attributes may not be used outside of the standard library
   --> $DIR/issue-43106-gating-of-unstable.rs:16:5
    |
 LL |     #[unstable()] fn f() { }
    |     ^^^^^^^^^^^^^
 
-error: stability attributes may not be used outside of the standard library
+error[E0734]: stability attributes may not be used outside of the standard library
   --> $DIR/issue-43106-gating-of-unstable.rs:19:5
    |
 LL |     #[unstable()] struct S;
    |     ^^^^^^^^^^^^^
 
-error: stability attributes may not be used outside of the standard library
+error[E0734]: stability attributes may not be used outside of the standard library
   --> $DIR/issue-43106-gating-of-unstable.rs:22:5
    |
 LL |     #[unstable()] type T = S;
    |     ^^^^^^^^^^^^^
 
-error: stability attributes may not be used outside of the standard library
+error[E0734]: stability attributes may not be used outside of the standard library
   --> $DIR/issue-43106-gating-of-unstable.rs:25:5
    |
 LL |     #[unstable()] impl S { }
@@ -42,3 +42,4 @@ LL |     #[unstable()] impl S { }
 
 error: aborting due to 7 previous errors
 
+For more information about this error, try `rustc --explain E0734`.
diff --git a/src/test/ui/feature-gates/feature-gate-staged_api.stderr b/src/test/ui/feature-gates/feature-gate-staged_api.stderr
index f0db47fe8a875..a71d26ce16f5b 100644
--- a/src/test/ui/feature-gates/feature-gate-staged_api.stderr
+++ b/src/test/ui/feature-gates/feature-gate-staged_api.stderr
@@ -1,10 +1,10 @@
-error: stability attributes may not be used outside of the standard library
+error[E0734]: stability attributes may not be used outside of the standard library
   --> $DIR/feature-gate-staged_api.rs:1:1
    |
 LL | #![stable(feature = "a", since = "b")]
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
-error: stability attributes may not be used outside of the standard library
+error[E0734]: stability attributes may not be used outside of the standard library
   --> $DIR/feature-gate-staged_api.rs:8:1
    |
 LL | #[stable(feature = "a", since = "b")]
@@ -12,3 +12,4 @@ LL | #[stable(feature = "a", since = "b")]
 
 error: aborting due to 2 previous errors
 
+For more information about this error, try `rustc --explain E0734`.
diff --git a/src/test/ui/issues/issue-5927.stderr b/src/test/ui/issues/issue-5927.stderr
index 89f5e399ae689..3d4550ec8b238 100644
--- a/src/test/ui/issues/issue-5927.stderr
+++ b/src/test/ui/issues/issue-5927.stderr
@@ -12,4 +12,5 @@ LL |         x(1) => x(1)
 
 error: aborting due to 2 previous errors
 
-For more information about this error, try `rustc --explain E0425`.
+Some errors have detailed explanations: E0425, E0531.
+For more information about an error, try `rustc --explain E0425`.
diff --git a/src/test/ui/keyword/keyword-self-as-identifier.stderr b/src/test/ui/keyword/keyword-self-as-identifier.stderr
index 5f567910ed81b..be57c6ad26fd8 100644
--- a/src/test/ui/keyword/keyword-self-as-identifier.stderr
+++ b/src/test/ui/keyword/keyword-self-as-identifier.stderr
@@ -6,3 +6,4 @@ LL |     let Self = 22;
 
 error: aborting due to previous error
 
+For more information about this error, try `rustc --explain E0531`.
diff --git a/src/test/ui/lint/lint-exceeding-bitshifts.rs b/src/test/ui/lint/lint-exceeding-bitshifts.rs
index 0f397a7efe81f..dd3b839342911 100644
--- a/src/test/ui/lint/lint-exceeding-bitshifts.rs
+++ b/src/test/ui/lint/lint-exceeding-bitshifts.rs
@@ -1,3 +1,5 @@
+// compile-flags: -O
+
 #![deny(exceeding_bitshifts, const_err)]
 #![allow(unused_variables)]
 #![allow(dead_code)]
diff --git a/src/test/ui/lint/lint-exceeding-bitshifts.stderr b/src/test/ui/lint/lint-exceeding-bitshifts.stderr
index f9f168c14dee3..25e079b6d814f 100644
--- a/src/test/ui/lint/lint-exceeding-bitshifts.stderr
+++ b/src/test/ui/lint/lint-exceeding-bitshifts.stderr
@@ -1,113 +1,113 @@
 error: attempt to shift left with overflow
-  --> $DIR/lint-exceeding-bitshifts.rs:7:15
+  --> $DIR/lint-exceeding-bitshifts.rs:9:15
    |
 LL |       let n = 1u8 << 8;
    |               ^^^^^^^^
    |
 note: lint level defined here
-  --> $DIR/lint-exceeding-bitshifts.rs:1:9
+  --> $DIR/lint-exceeding-bitshifts.rs:3:9
    |
 LL | #![deny(exceeding_bitshifts, const_err)]
    |         ^^^^^^^^^^^^^^^^^^^
 
 error: attempt to shift left with overflow
-  --> $DIR/lint-exceeding-bitshifts.rs:9:15
+  --> $DIR/lint-exceeding-bitshifts.rs:11:15
    |
 LL |       let n = 1u16 << 16;
    |               ^^^^^^^^^^
 
 error: attempt to shift left with overflow
-  --> $DIR/lint-exceeding-bitshifts.rs:11:15
+  --> $DIR/lint-exceeding-bitshifts.rs:13:15
    |
 LL |       let n = 1u32 << 32;
    |               ^^^^^^^^^^
 
 error: attempt to shift left with overflow
-  --> $DIR/lint-exceeding-bitshifts.rs:13:15
+  --> $DIR/lint-exceeding-bitshifts.rs:15:15
    |
 LL |       let n = 1u64 << 64;
    |               ^^^^^^^^^^
 
 error: attempt to shift left with overflow
-  --> $DIR/lint-exceeding-bitshifts.rs:15:15
+  --> $DIR/lint-exceeding-bitshifts.rs:17:15
    |
 LL |       let n = 1i8 << 8;
    |               ^^^^^^^^
 
 error: attempt to shift left with overflow
-  --> $DIR/lint-exceeding-bitshifts.rs:17:15
+  --> $DIR/lint-exceeding-bitshifts.rs:19:15
    |
 LL |       let n = 1i16 << 16;
    |               ^^^^^^^^^^
 
 error: attempt to shift left with overflow
-  --> $DIR/lint-exceeding-bitshifts.rs:19:15
+  --> $DIR/lint-exceeding-bitshifts.rs:21:15
    |
 LL |       let n = 1i32 << 32;
    |               ^^^^^^^^^^
 
 error: attempt to shift left with overflow
-  --> $DIR/lint-exceeding-bitshifts.rs:21:15
+  --> $DIR/lint-exceeding-bitshifts.rs:23:15
    |
 LL |       let n = 1i64 << 64;
    |               ^^^^^^^^^^
 
 error: attempt to shift right with overflow
-  --> $DIR/lint-exceeding-bitshifts.rs:24:15
+  --> $DIR/lint-exceeding-bitshifts.rs:26:15
    |
 LL |       let n = 1u8 >> 8;
    |               ^^^^^^^^
 
 error: attempt to shift right with overflow
-  --> $DIR/lint-exceeding-bitshifts.rs:26:15
+  --> $DIR/lint-exceeding-bitshifts.rs:28:15
    |
 LL |       let n = 1u16 >> 16;
    |               ^^^^^^^^^^
 
 error: attempt to shift right with overflow
-  --> $DIR/lint-exceeding-bitshifts.rs:28:15
+  --> $DIR/lint-exceeding-bitshifts.rs:30:15
    |
 LL |       let n = 1u32 >> 32;
    |               ^^^^^^^^^^
 
 error: attempt to shift right with overflow
-  --> $DIR/lint-exceeding-bitshifts.rs:30:15
+  --> $DIR/lint-exceeding-bitshifts.rs:32:15
    |
 LL |       let n = 1u64 >> 64;
    |               ^^^^^^^^^^
 
 error: attempt to shift right with overflow
-  --> $DIR/lint-exceeding-bitshifts.rs:32:15
+  --> $DIR/lint-exceeding-bitshifts.rs:34:15
    |
 LL |       let n = 1i8 >> 8;
    |               ^^^^^^^^
 
 error: attempt to shift right with overflow
-  --> $DIR/lint-exceeding-bitshifts.rs:34:15
+  --> $DIR/lint-exceeding-bitshifts.rs:36:15
    |
 LL |       let n = 1i16 >> 16;
    |               ^^^^^^^^^^
 
 error: attempt to shift right with overflow
-  --> $DIR/lint-exceeding-bitshifts.rs:36:15
+  --> $DIR/lint-exceeding-bitshifts.rs:38:15
    |
 LL |       let n = 1i32 >> 32;
    |               ^^^^^^^^^^
 
 error: attempt to shift right with overflow
-  --> $DIR/lint-exceeding-bitshifts.rs:38:15
+  --> $DIR/lint-exceeding-bitshifts.rs:40:15
    |
 LL |       let n = 1i64 >> 64;
    |               ^^^^^^^^^^
 
 error: attempt to shift left with overflow
-  --> $DIR/lint-exceeding-bitshifts.rs:42:15
+  --> $DIR/lint-exceeding-bitshifts.rs:44:15
    |
 LL |       let n = n << 8;
    |               ^^^^^^
 
 error: attempt to shift left with overflow
-  --> $DIR/lint-exceeding-bitshifts.rs:44:15
+  --> $DIR/lint-exceeding-bitshifts.rs:46:15
    |
 LL |       let n = 1u8 << -8;
    |               ^^^^^^^^^
diff --git a/src/test/ui/lint/lint-exceeding-bitshifts2.rs b/src/test/ui/lint/lint-exceeding-bitshifts2.rs
index bde4865aa3f9e..69b627355b801 100644
--- a/src/test/ui/lint/lint-exceeding-bitshifts2.rs
+++ b/src/test/ui/lint/lint-exceeding-bitshifts2.rs
@@ -1,3 +1,5 @@
+// compile-flags: -O
+
 #![deny(exceeding_bitshifts, const_err)]
 #![allow(unused_variables)]
 #![allow(dead_code)]
diff --git a/src/test/ui/lint/lint-exceeding-bitshifts2.stderr b/src/test/ui/lint/lint-exceeding-bitshifts2.stderr
index 8a6d2a89c7063..cb96982a78930 100644
--- a/src/test/ui/lint/lint-exceeding-bitshifts2.stderr
+++ b/src/test/ui/lint/lint-exceeding-bitshifts2.stderr
@@ -1,23 +1,23 @@
 error: attempt to shift left with overflow
-  --> $DIR/lint-exceeding-bitshifts2.rs:7:15
+  --> $DIR/lint-exceeding-bitshifts2.rs:9:15
    |
 LL |       let n = 1u8 << (4+4);
    |               ^^^^^^^^^^^^
    |
 note: lint level defined here
-  --> $DIR/lint-exceeding-bitshifts2.rs:1:9
+  --> $DIR/lint-exceeding-bitshifts2.rs:3:9
    |
 LL | #![deny(exceeding_bitshifts, const_err)]
    |         ^^^^^^^^^^^^^^^^^^^
 
 error: attempt to shift left with overflow
-  --> $DIR/lint-exceeding-bitshifts2.rs:15:15
+  --> $DIR/lint-exceeding-bitshifts2.rs:17:15
    |
 LL |       let n = 1_isize << BITS;
    |               ^^^^^^^^^^^^^^^
 
 error: attempt to shift left with overflow
-  --> $DIR/lint-exceeding-bitshifts2.rs:16:15
+  --> $DIR/lint-exceeding-bitshifts2.rs:18:15
    |
 LL |       let n = 1_usize << BITS;
    |               ^^^^^^^^^^^^^^^
diff --git a/src/test/ui/resolve/resolve-assoc-suggestions.stderr b/src/test/ui/resolve/resolve-assoc-suggestions.stderr
index 87040015b8d80..f3b8909ab2236 100644
--- a/src/test/ui/resolve/resolve-assoc-suggestions.stderr
+++ b/src/test/ui/resolve/resolve-assoc-suggestions.stderr
@@ -54,5 +54,5 @@ LL |         method;
 
 error: aborting due to 9 previous errors
 
-Some errors have detailed explanations: E0412, E0425.
+Some errors have detailed explanations: E0412, E0425, E0531.
 For more information about an error, try `rustc --explain E0412`.
diff --git a/src/test/ui/self/self_type_keyword-2.stderr b/src/test/ui/self/self_type_keyword-2.stderr
index 359410bc1cd6a..560c6d2199ca0 100644
--- a/src/test/ui/self/self_type_keyword-2.stderr
+++ b/src/test/ui/self/self_type_keyword-2.stderr
@@ -24,4 +24,5 @@ LL |         Foo { x: Self } => (),
 
 error: aborting due to 4 previous errors
 
-For more information about this error, try `rustc --explain E0432`.
+Some errors have detailed explanations: E0432, E0531.
+For more information about an error, try `rustc --explain E0432`.
diff --git a/src/test/ui/self/self_type_keyword.stderr b/src/test/ui/self/self_type_keyword.stderr
index 11b3b012c5f5e..6534d8c36e343 100644
--- a/src/test/ui/self/self_type_keyword.stderr
+++ b/src/test/ui/self/self_type_keyword.stderr
@@ -80,4 +80,5 @@ LL | struct Bar<'Self>;
 
 error: aborting due to 12 previous errors
 
-For more information about this error, try `rustc --explain E0392`.
+Some errors have detailed explanations: E0392, E0531.
+For more information about an error, try `rustc --explain E0392`.
diff --git a/src/test/ui/stability-attribute/stability-attribute-non-staged-force-unstable.stderr b/src/test/ui/stability-attribute/stability-attribute-non-staged-force-unstable.stderr
index 77f896a86d58a..32b0f405d6fb0 100644
--- a/src/test/ui/stability-attribute/stability-attribute-non-staged-force-unstable.stderr
+++ b/src/test/ui/stability-attribute/stability-attribute-non-staged-force-unstable.stderr
@@ -1,16 +1,16 @@
-error: stability attributes may not be used outside of the standard library
+error[E0734]: stability attributes may not be used outside of the standard library
   --> $DIR/stability-attribute-non-staged-force-unstable.rs:3:1
    |
 LL | #[unstable()]
    | ^^^^^^^^^^^^^
 
-error: stability attributes may not be used outside of the standard library
+error[E0734]: stability attributes may not be used outside of the standard library
   --> $DIR/stability-attribute-non-staged-force-unstable.rs:4:1
    |
 LL | #[stable()]
    | ^^^^^^^^^^^
 
-error: stability attributes may not be used outside of the standard library
+error[E0734]: stability attributes may not be used outside of the standard library
   --> $DIR/stability-attribute-non-staged-force-unstable.rs:5:1
    |
 LL | #[rustc_deprecated()]
@@ -18,3 +18,4 @@ LL | #[rustc_deprecated()]
 
 error: aborting due to 3 previous errors
 
+For more information about this error, try `rustc --explain E0734`.
diff --git a/src/test/ui/stability-attribute/stability-attribute-non-staged.stderr b/src/test/ui/stability-attribute/stability-attribute-non-staged.stderr
index e98f789f54c7d..7648effc480b5 100644
--- a/src/test/ui/stability-attribute/stability-attribute-non-staged.stderr
+++ b/src/test/ui/stability-attribute/stability-attribute-non-staged.stderr
@@ -1,16 +1,16 @@
-error: stability attributes may not be used outside of the standard library
+error[E0734]: stability attributes may not be used outside of the standard library
   --> $DIR/stability-attribute-non-staged.rs:1:1
    |
 LL | #[unstable()]
    | ^^^^^^^^^^^^^
 
-error: stability attributes may not be used outside of the standard library
+error[E0734]: stability attributes may not be used outside of the standard library
   --> $DIR/stability-attribute-non-staged.rs:2:1
    |
 LL | #[stable()]
    | ^^^^^^^^^^^
 
-error: stability attributes may not be used outside of the standard library
+error[E0734]: stability attributes may not be used outside of the standard library
   --> $DIR/stability-attribute-non-staged.rs:3:1
    |
 LL | #[rustc_deprecated()]
@@ -18,3 +18,4 @@ LL | #[rustc_deprecated()]
 
 error: aborting due to 3 previous errors
 
+For more information about this error, try `rustc --explain E0734`.
diff --git a/src/tools/tidy/src/features.rs b/src/tools/tidy/src/features.rs
index 6d38cfc8630d1..a824546d436f7 100644
--- a/src/tools/tidy/src/features.rs
+++ b/src/tools/tidy/src/features.rs
@@ -384,7 +384,7 @@ fn map_lib_features(base_src_path: &Path,
         let file = entry.path();
         let filename = file.file_name().unwrap().to_string_lossy();
         if !filename.ends_with(".rs") || filename == "features.rs" ||
-           filename == "diagnostic_list.rs" {
+           filename == "diagnostic_list.rs" || filename == "error_codes.rs" {
             return;
         }