about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorJonas Schievink <jonasschievink@gmail.com>2019-06-13 21:36:15 +0200
committerJonas Schievink <jonasschievink@gmail.com>2020-02-21 19:41:21 +0100
commita323ff2c864801fdc8e044e88f11efb49a565ed1 (patch)
treeb9de022262d7a61c7c233f80595a1e978dc3d658 /src
parent187f3d73abf35404b12782993d6e8880e866d6d1 (diff)
downloadrust-a323ff2c864801fdc8e044e88f11efb49a565ed1.tar.gz
rust-a323ff2c864801fdc8e044e88f11efb49a565ed1.zip
Implement RFC 2532 – Associated Type Defaults
Diffstat (limited to 'src')
-rw-r--r--src/librustc_infer/traits/project.rs43
-rw-r--r--src/librustc_typeck/check/mod.rs21
-rw-r--r--src/test/ui/associated-types/associated-types-overridden-default.rs6
-rw-r--r--src/test/ui/associated-types/associated-types-overridden-default.stderr9
-rw-r--r--src/test/ui/associated-types/defaults-cyclic-fail.rs35
-rw-r--r--src/test/ui/associated-types/defaults-cyclic-fail.stderr21
-rw-r--r--src/test/ui/associated-types/defaults-cyclic-pass.rs22
-rw-r--r--src/test/ui/associated-types/defaults-in-other-trait-items.rs50
-rw-r--r--src/test/ui/associated-types/defaults-in-other-trait-items.stderr25
-rw-r--r--src/test/ui/privacy/associated-item-privacy-trait.rs9
-rw-r--r--src/test/ui/privacy/associated-item-privacy-trait.stderr113
-rw-r--r--src/test/ui/privacy/private-in-public-assoc-ty.rs5
-rw-r--r--src/test/ui/privacy/private-in-public-assoc-ty.stderr25
-rw-r--r--src/test/ui/ufcs/ufcs-partially-resolved.rs4
-rw-r--r--src/test/ui/ufcs/ufcs-partially-resolved.stderr10
15 files changed, 247 insertions, 151 deletions
diff --git a/src/librustc_infer/traits/project.rs b/src/librustc_infer/traits/project.rs
index a7c3e9110ab..8d9e5d3fa20 100644
--- a/src/librustc_infer/traits/project.rs
+++ b/src/librustc_infer/traits/project.rs
@@ -1054,25 +1054,40 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
                     // an error when we confirm the candidate
                     // (which will ultimately lead to `normalize_to_error`
                     // being invoked).
-                    node_item.item.defaultness.has_value()
+                    false
                 } else {
+                    // If we're looking at a trait *impl*, the item is
+                    // specializable if the impl or the item are marked
+                    // `default`.
                     node_item.item.defaultness.is_default()
                         || super::util::impl_is_default(selcx.tcx(), node_item.node.def_id())
                 };
 
-                // Only reveal a specializable default if we're past type-checking
-                // and the obligations is monomorphic, otherwise passes such as
-                // transmute checking and polymorphic MIR optimizations could
-                // get a result which isn't correct for all monomorphizations.
-                if !is_default {
-                    true
-                } else if obligation.param_env.reveal == Reveal::All {
-                    // NOTE(eddyb) inference variables can resolve to parameters, so
-                    // assume `poly_trait_ref` isn't monomorphic, if it contains any.
-                    let poly_trait_ref = selcx.infcx().resolve_vars_if_possible(&poly_trait_ref);
-                    !poly_trait_ref.needs_infer() && !poly_trait_ref.needs_subst()
-                } else {
-                    false
+                match is_default {
+                    // Non-specializable items are always projectable
+                    false => true,
+
+                    // Only reveal a specializable default if we're past type-checking
+                    // and the obligation is monomorphic, otherwise passes such as
+                    // transmute checking and polymorphic MIR optimizations could
+                    // get a result which isn't correct for all monomorphizations.
+                    true if obligation.param_env.reveal == Reveal::All => {
+                        // NOTE(eddyb) inference variables can resolve to parameters, so
+                        // assume `poly_trait_ref` isn't monomorphic, if it contains any.
+                        let poly_trait_ref =
+                            selcx.infcx().resolve_vars_if_possible(&poly_trait_ref);
+                        !poly_trait_ref.needs_infer() && !poly_trait_ref.needs_subst()
+                    }
+
+                    true => {
+                        debug!(
+                            "assemble_candidates_from_impls: not eligible due to default: \
+                             assoc_ty={} predicate={}",
+                            selcx.tcx().def_path_str(node_item.item.def_id),
+                            obligation.predicate,
+                        );
+                        false
+                    }
                 }
             }
             super::VtableParam(..) => {
diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs
index 4f6eb20e6eb..4ab5d8f9ad3 100644
--- a/src/librustc_typeck/check/mod.rs
+++ b/src/librustc_typeck/check/mod.rs
@@ -1964,7 +1964,6 @@ fn check_impl_items_against_trait<'tcx>(
 
     // Locate trait definition and items
     let trait_def = tcx.trait_def(impl_trait_ref.def_id);
-    let mut overridden_associated_type = None;
 
     let impl_items = || impl_item_refs.iter().map(|iiref| tcx.hir().impl_item(iiref.id));
 
@@ -2046,9 +2045,6 @@ fn check_impl_items_against_trait<'tcx>(
                 hir::ImplItemKind::OpaqueTy(..) | hir::ImplItemKind::TyAlias(_) => {
                     let opt_trait_span = tcx.hir().span_if_local(ty_trait_item.def_id);
                     if ty_trait_item.kind == ty::AssocKind::Type {
-                        if ty_trait_item.defaultness.has_value() {
-                            overridden_associated_type = Some(impl_item);
-                        }
                         compare_ty_impl(
                             tcx,
                             &ty_impl_item,
@@ -2082,8 +2078,6 @@ fn check_impl_items_against_trait<'tcx>(
 
     // Check for missing items from trait
     let mut missing_items = Vec::new();
-    let mut invalidated_items = Vec::new();
-    let associated_type_overridden = overridden_associated_type.is_some();
     for trait_item in tcx.associated_items(impl_trait_ref.def_id).in_definition_order() {
         let is_implemented = trait_def
             .ancestors(tcx, impl_id)
@@ -2094,8 +2088,6 @@ fn check_impl_items_against_trait<'tcx>(
         if !is_implemented && !traits::impl_is_default(tcx, impl_id) {
             if !trait_item.defaultness.has_value() {
                 missing_items.push(*trait_item);
-            } else if associated_type_overridden {
-                invalidated_items.push(trait_item.ident);
             }
         }
     }
@@ -2103,19 +2095,6 @@ fn check_impl_items_against_trait<'tcx>(
     if !missing_items.is_empty() {
         missing_items_err(tcx, impl_span, &missing_items, full_impl_span);
     }
-
-    if !invalidated_items.is_empty() {
-        let invalidator = overridden_associated_type.unwrap();
-        struct_span_err!(
-            tcx.sess,
-            invalidator.span,
-            E0399,
-            "the following trait items need to be reimplemented as `{}` was overridden: `{}`",
-            invalidator.ident,
-            invalidated_items.iter().map(|name| name.to_string()).collect::<Vec<_>>().join("`, `")
-        )
-        .emit();
-    }
 }
 
 fn missing_items_err(
diff --git a/src/test/ui/associated-types/associated-types-overridden-default.rs b/src/test/ui/associated-types/associated-types-overridden-default.rs
index 629fc7a7668..72c30df0b3d 100644
--- a/src/test/ui/associated-types/associated-types-overridden-default.rs
+++ b/src/test/ui/associated-types/associated-types-overridden-default.rs
@@ -1,3 +1,8 @@
+// check-pass
+
+// Before RFC 2532, overriding one assoc. type default required overriding all
+// provided defaults.
+
 #![feature(associated_type_defaults)]
 
 pub trait Tr {
@@ -9,7 +14,6 @@ pub trait Tr {
 
 impl Tr for () {
     type Assoc = ();
-    //~^ ERROR need to be reimplemented as `Assoc` was overridden: `Assoc2`, `C`, `foo`
 }
 
 fn main() {}
diff --git a/src/test/ui/associated-types/associated-types-overridden-default.stderr b/src/test/ui/associated-types/associated-types-overridden-default.stderr
deleted file mode 100644
index 79fb9a613c2..00000000000
--- a/src/test/ui/associated-types/associated-types-overridden-default.stderr
+++ /dev/null
@@ -1,9 +0,0 @@
-error[E0399]: the following trait items need to be reimplemented as `Assoc` was overridden: `Assoc2`, `C`, `foo`
-  --> $DIR/associated-types-overridden-default.rs:11:5
-   |
-LL |     type Assoc = ();
-   |     ^^^^^^^^^^^^^^^^
-
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0399`.
diff --git a/src/test/ui/associated-types/defaults-cyclic-fail.rs b/src/test/ui/associated-types/defaults-cyclic-fail.rs
new file mode 100644
index 00000000000..ab66fe0b52e
--- /dev/null
+++ b/src/test/ui/associated-types/defaults-cyclic-fail.rs
@@ -0,0 +1,35 @@
+#![feature(associated_type_defaults)]
+
+// Having a cycle in assoc. type defaults is okay...
+trait Tr {
+    type A = Self::B;
+    type B = Self::A;
+}
+
+// ...but is an error in any impl that doesn't override at least one of the defaults
+impl Tr for () {}
+//~^ ERROR overflow evaluating the requirement
+
+// As soon as at least one is redefined, it works:
+impl Tr for u8 {
+    type A = u8;
+}
+
+impl Tr for u32 {
+    type A = ();
+    type B = u8;
+}
+
+// ...but only if this actually breaks the cycle
+impl Tr for bool {
+//~^ ERROR overflow evaluating the requirement
+    type A = Box<Self::B>;
+    //~^ ERROR overflow evaluating the requirement
+}
+// (the error is shown twice for some reason)
+
+fn main() {
+    // Check that the overridden type propagates to the other
+    let _a: <u8 as Tr>::A = 0u8;
+    let _b: <u8 as Tr>::B = 0u8;
+}
diff --git a/src/test/ui/associated-types/defaults-cyclic-fail.stderr b/src/test/ui/associated-types/defaults-cyclic-fail.stderr
new file mode 100644
index 00000000000..dd0e5c2ef42
--- /dev/null
+++ b/src/test/ui/associated-types/defaults-cyclic-fail.stderr
@@ -0,0 +1,21 @@
+error[E0275]: overflow evaluating the requirement `<() as Tr>::B`
+  --> $DIR/defaults-cyclic-fail.rs:10:6
+   |
+LL | impl Tr for () {}
+   |      ^^
+
+error[E0275]: overflow evaluating the requirement `<bool as Tr>::B`
+  --> $DIR/defaults-cyclic-fail.rs:24:6
+   |
+LL | impl Tr for bool {
+   |      ^^
+
+error[E0275]: overflow evaluating the requirement `<bool as Tr>::B`
+  --> $DIR/defaults-cyclic-fail.rs:26:5
+   |
+LL |     type A = Box<Self::B>;
+   |     ^^^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to 3 previous errors
+
+For more information about this error, try `rustc --explain E0275`.
diff --git a/src/test/ui/associated-types/defaults-cyclic-pass.rs b/src/test/ui/associated-types/defaults-cyclic-pass.rs
new file mode 100644
index 00000000000..618a2038507
--- /dev/null
+++ b/src/test/ui/associated-types/defaults-cyclic-pass.rs
@@ -0,0 +1,22 @@
+// check-pass
+
+#![feature(associated_type_defaults)]
+
+trait Tr {
+    type Item = u8;
+    type Container = Vec<Self::Item>;
+}
+
+impl Tr for () {}
+
+impl Tr for u16 {
+    type Item = u16;
+}
+
+fn main() {
+    let _container: <() as Tr>::Container = Vec::<u8>::new();
+    let _item: <() as Tr>::Item = 0u8;
+
+    let _container: <u16 as Tr>::Container = Vec::<u16>::new();
+    let _item: <u16 as Tr>::Item = 0u16;
+}
diff --git a/src/test/ui/associated-types/defaults-in-other-trait-items.rs b/src/test/ui/associated-types/defaults-in-other-trait-items.rs
new file mode 100644
index 00000000000..0455997b168
--- /dev/null
+++ b/src/test/ui/associated-types/defaults-in-other-trait-items.rs
@@ -0,0 +1,50 @@
+#![feature(associated_type_defaults)]
+
+// Associated type defaults may not be assumed inside the trait defining them.
+// ie. they only resolve to `<Self as Tr>::A`, not the actual type `()`
+trait Tr {
+    type A = ();
+
+    fn f(p: Self::A) {
+        let () = p;
+        //~^ ERROR mismatched types
+        //~| NOTE expected associated type, found `()`
+        //~| NOTE expected associated type `<Self as Tr>::A`
+        //~| NOTE consider constraining
+        //~| NOTE for more information, visit
+    }
+}
+
+// An impl that doesn't override the type *can* assume the default.
+impl Tr for () {
+    fn f(p: Self::A) {
+        let () = p;
+    }
+}
+
+impl Tr for u8 {
+    type A = ();
+
+    fn f(p: Self::A) {
+        let () = p;
+    }
+}
+
+trait AssocConst {
+    type Ty = u8;
+
+    // Assoc. consts also cannot assume that default types hold
+    const C: Self::Ty = 0u8;
+    //~^ ERROR mismatched types
+    //~| NOTE expected associated type, found `u8`
+    //~| NOTE expected associated type `<Self as AssocConst>::Ty`
+    //~| NOTE consider constraining
+    //~| NOTE for more information, visit
+}
+
+// An impl can, however
+impl AssocConst for () {
+    const C: Self::Ty = 0u8;
+}
+
+fn main() {}
diff --git a/src/test/ui/associated-types/defaults-in-other-trait-items.stderr b/src/test/ui/associated-types/defaults-in-other-trait-items.stderr
new file mode 100644
index 00000000000..9ecfe49c2b5
--- /dev/null
+++ b/src/test/ui/associated-types/defaults-in-other-trait-items.stderr
@@ -0,0 +1,25 @@
+error[E0308]: mismatched types
+  --> $DIR/defaults-in-other-trait-items.rs:9:13
+   |
+LL |         let () = p;
+   |             ^^ expected associated type, found `()`
+   |
+   = note: expected associated type `<Self as Tr>::A`
+                    found unit type `()`
+   = note: consider constraining the associated type `<Self as Tr>::A` to `()` or calling a method that returns `<Self as Tr>::A`
+   = note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html
+
+error[E0308]: mismatched types
+  --> $DIR/defaults-in-other-trait-items.rs:37:25
+   |
+LL |     const C: Self::Ty = 0u8;
+   |                         ^^^ expected associated type, found `u8`
+   |
+   = note: expected associated type `<Self as AssocConst>::Ty`
+                         found type `u8`
+   = note: consider constraining the associated type `<Self as AssocConst>::Ty` to `u8` or calling a method that returns `<Self as AssocConst>::Ty`
+   = note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0308`.
diff --git a/src/test/ui/privacy/associated-item-privacy-trait.rs b/src/test/ui/privacy/associated-item-privacy-trait.rs
index b3d42f09596..03347d5b99a 100644
--- a/src/test/ui/privacy/associated-item-privacy-trait.rs
+++ b/src/test/ui/privacy/associated-item-privacy-trait.rs
@@ -23,8 +23,7 @@ mod priv_trait {
         <Pub as PrivTr>::CONST;
         //~^ ERROR associated constant `PrivTr::CONST` is private
         let _: <Pub as PrivTr>::AssocTy;
-        //~^ ERROR trait `priv_trait::PrivTr` is private
-        //~| ERROR trait `priv_trait::PrivTr` is private
+        //~^ ERROR associated type `PrivTr::AssocTy` is private
         pub type InSignatureTy = <Pub as PrivTr>::AssocTy;
         //~^ ERROR trait `priv_trait::PrivTr` is private
         pub trait InSignatureTr: PrivTr {}
@@ -116,15 +115,11 @@ mod priv_parent_substs {
         <Priv as PubTr<_>>::CONST;
         //~^ ERROR type `priv_parent_substs::Priv` is private
 
-        let _: <Pub as PubTr>::AssocTy;
-        //~^ ERROR type `priv_parent_substs::Priv` is private
-        //~| ERROR type `priv_parent_substs::Priv` is private
+        let _: <Pub as PubTr>::AssocTy;  // FIXME no longer an error?!
         let _: <Pub as PubTr<_>>::AssocTy;
         //~^ ERROR type `priv_parent_substs::Priv` is private
-        //~| ERROR type `priv_parent_substs::Priv` is private
         let _: <Priv as PubTr<_>>::AssocTy;
         //~^ ERROR type `priv_parent_substs::Priv` is private
-        //~| ERROR type `priv_parent_substs::Priv` is private
 
         pub type InSignatureTy1 = <Pub as PubTr>::AssocTy;
         //~^ ERROR type `priv_parent_substs::Priv` is private
diff --git a/src/test/ui/privacy/associated-item-privacy-trait.stderr b/src/test/ui/privacy/associated-item-privacy-trait.stderr
index ac422e99855..db24e425a01 100644
--- a/src/test/ui/privacy/associated-item-privacy-trait.stderr
+++ b/src/test/ui/privacy/associated-item-privacy-trait.stderr
@@ -42,18 +42,7 @@ LL |     priv_trait::mac!();
    |
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
 
-error: trait `priv_trait::PrivTr` is private
-  --> $DIR/associated-item-privacy-trait.rs:25:13
-   |
-LL |         let _: <Pub as PrivTr>::AssocTy;
-   |             ^
-...
-LL |     priv_trait::mac!();
-   |     ------------------- in this macro invocation
-   |
-   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
-
-error: trait `priv_trait::PrivTr` is private
+error: associated type `PrivTr::AssocTy` is private
   --> $DIR/associated-item-privacy-trait.rs:25:16
    |
 LL |         let _: <Pub as PrivTr>::AssocTy;
@@ -65,7 +54,7 @@ LL |     priv_trait::mac!();
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
 
 error: trait `priv_trait::PrivTr` is private
-  --> $DIR/associated-item-privacy-trait.rs:28:34
+  --> $DIR/associated-item-privacy-trait.rs:27:34
    |
 LL |         pub type InSignatureTy = <Pub as PrivTr>::AssocTy;
    |                                  ^^^^^^^^^^^^^^^^^^^^^^^^
@@ -76,7 +65,7 @@ LL |     priv_trait::mac!();
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
 
 error: trait `priv_trait::PrivTr` is private
-  --> $DIR/associated-item-privacy-trait.rs:30:34
+  --> $DIR/associated-item-privacy-trait.rs:29:34
    |
 LL |         pub trait InSignatureTr: PrivTr {}
    |                                  ^^^^^^
@@ -87,7 +76,7 @@ LL |     priv_trait::mac!();
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
 
 error: trait `priv_trait::PrivTr` is private
-  --> $DIR/associated-item-privacy-trait.rs:32:14
+  --> $DIR/associated-item-privacy-trait.rs:31:14
    |
 LL |         impl PrivTr for u8 {}
    |              ^^^^^^
@@ -98,7 +87,7 @@ LL |     priv_trait::mac!();
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
 
 error: type `priv_signature::Priv` is private
-  --> $DIR/associated-item-privacy-trait.rs:49:21
+  --> $DIR/associated-item-privacy-trait.rs:48:21
    |
 LL |         let value = <Pub as PubTr>::method;
    |                     ^^^^^^^^^^^^^^^^^^^^^^
@@ -109,7 +98,7 @@ LL |     priv_signature::mac!();
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
 
 error: type `priv_signature::Priv` is private
-  --> $DIR/associated-item-privacy-trait.rs:51:9
+  --> $DIR/associated-item-privacy-trait.rs:50:9
    |
 LL |         value;
    |         ^^^^^
@@ -120,7 +109,7 @@ LL |     priv_signature::mac!();
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
 
 error: type `priv_signature::Priv` is private
-  --> $DIR/associated-item-privacy-trait.rs:53:13
+  --> $DIR/associated-item-privacy-trait.rs:52:13
    |
 LL |         Pub.method(loop {});
    |             ^^^^^^
@@ -131,7 +120,7 @@ LL |     priv_signature::mac!();
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
 
 error: type `priv_substs::Priv` is private
-  --> $DIR/associated-item-privacy-trait.rs:70:21
+  --> $DIR/associated-item-privacy-trait.rs:69:21
    |
 LL |         let value = <Pub as PubTr>::method::<Priv>;
    |                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -142,7 +131,7 @@ LL |     priv_substs::mac!();
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
 
 error: type `priv_substs::Priv` is private
-  --> $DIR/associated-item-privacy-trait.rs:72:9
+  --> $DIR/associated-item-privacy-trait.rs:71:9
    |
 LL |         value;
    |         ^^^^^
@@ -153,7 +142,7 @@ LL |     priv_substs::mac!();
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
 
 error: type `priv_substs::Priv` is private
-  --> $DIR/associated-item-privacy-trait.rs:74:9
+  --> $DIR/associated-item-privacy-trait.rs:73:9
    |
 LL |         Pub.method::<Priv>();
    |         ^^^^^^^^^^^^^^^^^^^^
@@ -164,7 +153,7 @@ LL |     priv_substs::mac!();
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
 
 error: type `priv_parent_substs::Priv` is private
-  --> $DIR/associated-item-privacy-trait.rs:94:21
+  --> $DIR/associated-item-privacy-trait.rs:93:21
    |
 LL |         let value = <Pub as PubTr>::method;
    |                     ^^^^^^^^^^^^^^^^^^^^^^
@@ -175,7 +164,7 @@ LL |     priv_parent_substs::mac!();
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
 
 error: type `priv_parent_substs::Priv` is private
-  --> $DIR/associated-item-privacy-trait.rs:96:9
+  --> $DIR/associated-item-privacy-trait.rs:95:9
    |
 LL |         value;
    |         ^^^^^
@@ -186,7 +175,7 @@ LL |     priv_parent_substs::mac!();
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
 
 error: type `priv_parent_substs::Priv` is private
-  --> $DIR/associated-item-privacy-trait.rs:98:21
+  --> $DIR/associated-item-privacy-trait.rs:97:21
    |
 LL |         let value = <Pub as PubTr<_>>::method;
    |                     ^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -197,7 +186,7 @@ LL |     priv_parent_substs::mac!();
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
 
 error: type `priv_parent_substs::Priv` is private
-  --> $DIR/associated-item-privacy-trait.rs:100:9
+  --> $DIR/associated-item-privacy-trait.rs:99:9
    |
 LL |         value;
    |         ^^^^^
@@ -208,7 +197,7 @@ LL |     priv_parent_substs::mac!();
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
 
 error: type `priv_parent_substs::Priv` is private
-  --> $DIR/associated-item-privacy-trait.rs:102:9
+  --> $DIR/associated-item-privacy-trait.rs:101:9
    |
 LL |         Pub.method();
    |         ^^^^^^^^^^^^
@@ -219,7 +208,7 @@ LL |     priv_parent_substs::mac!();
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
 
 error: type `priv_parent_substs::Priv` is private
-  --> $DIR/associated-item-privacy-trait.rs:105:21
+  --> $DIR/associated-item-privacy-trait.rs:104:21
    |
 LL |         let value = <Priv as PubTr<_>>::method;
    |                     ^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -230,7 +219,7 @@ LL |     priv_parent_substs::mac!();
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
 
 error: type `priv_parent_substs::Priv` is private
-  --> $DIR/associated-item-privacy-trait.rs:107:9
+  --> $DIR/associated-item-privacy-trait.rs:106:9
    |
 LL |         value;
    |         ^^^^^
@@ -241,7 +230,7 @@ LL |     priv_parent_substs::mac!();
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
 
 error: type `priv_parent_substs::Priv` is private
-  --> $DIR/associated-item-privacy-trait.rs:109:9
+  --> $DIR/associated-item-privacy-trait.rs:108:9
    |
 LL |         Priv.method();
    |         ^^^^^^^^^^^^^
@@ -252,7 +241,7 @@ LL |     priv_parent_substs::mac!();
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
 
 error: type `priv_parent_substs::Priv` is private
-  --> $DIR/associated-item-privacy-trait.rs:112:9
+  --> $DIR/associated-item-privacy-trait.rs:111:9
    |
 LL |         <Pub as PubTr>::CONST;
    |         ^^^^^^^^^^^^^^^^^^^^^
@@ -263,7 +252,7 @@ LL |     priv_parent_substs::mac!();
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
 
 error: type `priv_parent_substs::Priv` is private
-  --> $DIR/associated-item-privacy-trait.rs:114:9
+  --> $DIR/associated-item-privacy-trait.rs:113:9
    |
 LL |         <Pub as PubTr<_>>::CONST;
    |         ^^^^^^^^^^^^^^^^^^^^^^^^
@@ -274,7 +263,7 @@ LL |     priv_parent_substs::mac!();
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
 
 error: type `priv_parent_substs::Priv` is private
-  --> $DIR/associated-item-privacy-trait.rs:116:9
+  --> $DIR/associated-item-privacy-trait.rs:115:9
    |
 LL |         <Priv as PubTr<_>>::CONST;
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -285,54 +274,10 @@ LL |     priv_parent_substs::mac!();
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
 
 error: type `priv_parent_substs::Priv` is private
-  --> $DIR/associated-item-privacy-trait.rs:119:13
-   |
-LL |         let _: <Pub as PubTr>::AssocTy;
-   |             ^
-...
-LL |     priv_parent_substs::mac!();
-   |     --------------------------- in this macro invocation
-   |
-   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
-
-error: type `priv_parent_substs::Priv` is private
-  --> $DIR/associated-item-privacy-trait.rs:119:16
-   |
-LL |         let _: <Pub as PubTr>::AssocTy;
-   |                ^^^^^^^^^^^^^^^^^^^^^^^
-...
-LL |     priv_parent_substs::mac!();
-   |     --------------------------- in this macro invocation
-   |
-   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
-
-error: type `priv_parent_substs::Priv` is private
-  --> $DIR/associated-item-privacy-trait.rs:122:13
-   |
-LL |         let _: <Pub as PubTr<_>>::AssocTy;
-   |             ^
-...
-LL |     priv_parent_substs::mac!();
-   |     --------------------------- in this macro invocation
-   |
-   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
-
-error: type `priv_parent_substs::Priv` is private
-  --> $DIR/associated-item-privacy-trait.rs:122:16
+  --> $DIR/associated-item-privacy-trait.rs:119:30
    |
 LL |         let _: <Pub as PubTr<_>>::AssocTy;
-   |                ^^^^^^^^^^^^^^^^^^^^^^^^^^
-...
-LL |     priv_parent_substs::mac!();
-   |     --------------------------- in this macro invocation
-   |
-   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
-
-error: type `priv_parent_substs::Priv` is private
-  --> $DIR/associated-item-privacy-trait.rs:125:13
-   |
-LL |         let _: <Priv as PubTr<_>>::AssocTy;
-   |             ^
+   |                              ^
 ...
 LL |     priv_parent_substs::mac!();
    |     --------------------------- in this macro invocation
@@ -340,10 +285,10 @@ LL |     priv_parent_substs::mac!();
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
 
 error: type `priv_parent_substs::Priv` is private
-  --> $DIR/associated-item-privacy-trait.rs:125:16
+  --> $DIR/associated-item-privacy-trait.rs:121:17
    |
 LL |         let _: <Priv as PubTr<_>>::AssocTy;
-   |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |                 ^^^^
 ...
 LL |     priv_parent_substs::mac!();
    |     --------------------------- in this macro invocation
@@ -351,7 +296,7 @@ LL |     priv_parent_substs::mac!();
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
 
 error: type `priv_parent_substs::Priv` is private
-  --> $DIR/associated-item-privacy-trait.rs:129:35
+  --> $DIR/associated-item-privacy-trait.rs:124:35
    |
 LL |         pub type InSignatureTy1 = <Pub as PubTr>::AssocTy;
    |                                   ^^^^^^^^^^^^^^^^^^^^^^^
@@ -362,7 +307,7 @@ LL |     priv_parent_substs::mac!();
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
 
 error: type `priv_parent_substs::Priv` is private
-  --> $DIR/associated-item-privacy-trait.rs:131:35
+  --> $DIR/associated-item-privacy-trait.rs:126:35
    |
 LL |         pub type InSignatureTy2 = <Priv as PubTr<Pub>>::AssocTy;
    |                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -373,7 +318,7 @@ LL |     priv_parent_substs::mac!();
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
 
 error: type `priv_parent_substs::Priv` is private
-  --> $DIR/associated-item-privacy-trait.rs:133:14
+  --> $DIR/associated-item-privacy-trait.rs:128:14
    |
 LL |         impl PubTr for u8 {}
    |              ^^^^^
@@ -383,5 +328,5 @@ LL |     priv_parent_substs::mac!();
    |
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
 
-error: aborting due to 35 previous errors
+error: aborting due to 30 previous errors
 
diff --git a/src/test/ui/privacy/private-in-public-assoc-ty.rs b/src/test/ui/privacy/private-in-public-assoc-ty.rs
index ad1052ada60..62faae1f399 100644
--- a/src/test/ui/privacy/private-in-public-assoc-ty.rs
+++ b/src/test/ui/privacy/private-in-public-assoc-ty.rs
@@ -10,6 +10,11 @@ mod m {
     impl PrivTr for Priv {}
     pub trait PubTrAux1<T> {}
     pub trait PubTrAux2 { type A; }
+    impl<T> PubTrAux1<T> for u8 {}
+    impl PubTrAux2 for u8 {
+        type A = Priv;
+        //~^ ERROR private type `m::Priv` in public interface
+    }
 
     // "Private-in-public in associated types is hard error" in RFC 2145
     // applies only to the aliased types, not bounds.
diff --git a/src/test/ui/privacy/private-in-public-assoc-ty.stderr b/src/test/ui/privacy/private-in-public-assoc-ty.stderr
index 3cc551cdede..c57073a004d 100644
--- a/src/test/ui/privacy/private-in-public-assoc-ty.stderr
+++ b/src/test/ui/privacy/private-in-public-assoc-ty.stderr
@@ -1,5 +1,14 @@
+error[E0446]: private type `m::Priv` in public interface
+  --> $DIR/private-in-public-assoc-ty.rs:15:9
+   |
+LL |     struct Priv;
+   |     - `m::Priv` declared as private
+...
+LL |         type A = Priv;
+   |         ^^^^^^^^^^^^^^ can't leak private type
+
 warning: private trait `m::PrivTr` in public interface (error E0445)
-  --> $DIR/private-in-public-assoc-ty.rs:16:5
+  --> $DIR/private-in-public-assoc-ty.rs:21:5
    |
 LL | /     pub trait PubTr {
 LL | |
@@ -15,7 +24,7 @@ LL | |     }
    = note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537>
 
 warning: private type `m::Priv` in public interface (error E0446)
-  --> $DIR/private-in-public-assoc-ty.rs:16:5
+  --> $DIR/private-in-public-assoc-ty.rs:21:5
    |
 LL | /     pub trait PubTr {
 LL | |
@@ -30,7 +39,7 @@ LL | |     }
    = note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537>
 
 warning: private type `m::Priv` in public interface (error E0446)
-  --> $DIR/private-in-public-assoc-ty.rs:16:5
+  --> $DIR/private-in-public-assoc-ty.rs:21:5
    |
 LL | /     pub trait PubTr {
 LL | |
@@ -45,7 +54,7 @@ LL | |     }
    = note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537>
 
 error[E0446]: private type `m::Priv` in public interface
-  --> $DIR/private-in-public-assoc-ty.rs:27:9
+  --> $DIR/private-in-public-assoc-ty.rs:32:9
    |
 LL |     struct Priv;
    |     - `m::Priv` declared as private
@@ -54,7 +63,7 @@ LL |         type Alias4 = Priv;
    |         ^^^^^^^^^^^^^^^^^^^ can't leak private type
 
 error[E0446]: private type `m::Priv` in public interface
-  --> $DIR/private-in-public-assoc-ty.rs:34:9
+  --> $DIR/private-in-public-assoc-ty.rs:39:9
    |
 LL |     struct Priv;
    |     - `m::Priv` declared as private
@@ -63,7 +72,7 @@ LL |         type Alias1 = Priv;
    |         ^^^^^^^^^^^^^^^^^^^ can't leak private type
 
 error[E0445]: private trait `m::PrivTr` in public interface
-  --> $DIR/private-in-public-assoc-ty.rs:37:9
+  --> $DIR/private-in-public-assoc-ty.rs:42:9
    |
 LL |     trait PrivTr {}
    |     - `m::PrivTr` declared as private
@@ -72,7 +81,7 @@ LL |         type Exist = impl PrivTr;
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private trait
 
 error[E0445]: private trait `m::PrivTr` in public interface
-  --> $DIR/private-in-public-assoc-ty.rs:37:9
+  --> $DIR/private-in-public-assoc-ty.rs:42:9
    |
 LL |     trait PrivTr {}
    |     - `m::PrivTr` declared as private
@@ -80,7 +89,7 @@ LL |     trait PrivTr {}
 LL |         type Exist = impl PrivTr;
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private trait
 
-error: aborting due to 4 previous errors
+error: aborting due to 5 previous errors
 
 Some errors have detailed explanations: E0445, E0446.
 For more information about an error, try `rustc --explain E0445`.
diff --git a/src/test/ui/ufcs/ufcs-partially-resolved.rs b/src/test/ui/ufcs/ufcs-partially-resolved.rs
index 66d4db3ebaf..e8c767b13e9 100644
--- a/src/test/ui/ufcs/ufcs-partially-resolved.rs
+++ b/src/test/ui/ufcs/ufcs-partially-resolved.rs
@@ -35,7 +35,7 @@ fn main() {
     <u8 as A>::N::NN; //~ ERROR cannot find associated type `N` in `A`
     let _: <u8 as Tr>::Y::NN; //~ ERROR ambiguous associated type
     let _: <u8 as E>::Y::NN; //~ ERROR expected associated type, found variant `E::Y`
-    <u8 as Tr>::Y::NN; //~ ERROR no associated item named `NN` found
+    <u8 as Tr>::Y::NN; //~ ERROR no associated item named `NN` found for type `u16`
     <u8 as E>::Y::NN; //~ ERROR expected associated type, found variant `E::Y`
 
     let _: <u8 as Tr::N>::NN; //~ ERROR cannot find associated type `NN` in `Tr::N`
@@ -52,5 +52,5 @@ fn main() {
     let _: <u8 as Dr>::Z; //~ ERROR expected associated type, found method `Dr::Z`
     <u8 as Dr>::X; //~ ERROR expected method or associated constant, found associated type `Dr::X`
     let _: <u8 as Dr>::Z::N; //~ ERROR expected associated type, found method `Dr::Z`
-    <u8 as Dr>::X::N; //~ ERROR no associated item named `N` found
+    <u8 as Dr>::X::N; //~ ERROR no associated item named `N` found for type `u16`
 }
diff --git a/src/test/ui/ufcs/ufcs-partially-resolved.stderr b/src/test/ui/ufcs/ufcs-partially-resolved.stderr
index 60ebe8ee053..e5e6ed9fac9 100644
--- a/src/test/ui/ufcs/ufcs-partially-resolved.stderr
+++ b/src/test/ui/ufcs/ufcs-partially-resolved.stderr
@@ -205,19 +205,19 @@ error[E0223]: ambiguous associated type
   --> $DIR/ufcs-partially-resolved.rs:36:12
    |
 LL |     let _: <u8 as Tr>::Y::NN;
-   |            ^^^^^^^^^^^^^^^^^ help: use fully-qualified syntax: `<<u8 as Tr>::Y as Trait>::NN`
+   |            ^^^^^^^^^^^^^^^^^ help: use fully-qualified syntax: `<u16 as Trait>::NN`
 
-error[E0599]: no associated item named `NN` found for associated type `<u8 as Tr>::Y` in the current scope
+error[E0599]: no associated item named `NN` found for type `u16` in the current scope
   --> $DIR/ufcs-partially-resolved.rs:38:20
    |
 LL |     <u8 as Tr>::Y::NN;
-   |                    ^^ associated item not found in `<u8 as Tr>::Y`
+   |                    ^^ associated item not found in `u16`
 
-error[E0599]: no associated item named `N` found for associated type `<u8 as Dr>::X` in the current scope
+error[E0599]: no associated item named `N` found for type `u16` in the current scope
   --> $DIR/ufcs-partially-resolved.rs:55:20
    |
 LL |     <u8 as Dr>::X::N;
-   |                    ^ associated item not found in `<u8 as Dr>::X`
+   |                    ^ associated item not found in `u16`
 
 error: aborting due to 32 previous errors