]> git.lizzy.rs Git - rust.git/commitdiff
rustc: support impl's in PrintCx::parameterized.
authorEduard-Mihai Burtescu <edy.burt@gmail.com>
Sun, 9 Dec 2018 15:54:18 +0000 (17:54 +0200)
committerEduard-Mihai Burtescu <edy.burt@gmail.com>
Fri, 15 Mar 2019 07:26:13 +0000 (09:26 +0200)
12 files changed:
src/librustc/util/ppaux.rs
src/test/ui/hygiene/impl_items.rs
src/test/ui/hygiene/impl_items.stderr
src/test/ui/issues/issue-22638.rs
src/test/ui/issues/issue-22638.stderr
src/test/ui/issues/issue-24322.stderr
src/test/ui/issues/issue-29124.rs
src/test/ui/issues/issue-29124.stderr
src/test/ui/issues/issue-39559-2.stderr
src/test/ui/privacy/associated-item-privacy-inherent.rs
src/test/ui/privacy/associated-item-privacy-inherent.stderr
src/test/ui/qualified/qualified-path-params.stderr

index 8dfa924c1dfc9865f1b0c53182a4218fed757e01..6667d37873310e23ca87aed04ea9f8a543eab416 100644 (file)
@@ -352,6 +352,22 @@ fn parameterized<F: fmt::Write>(
 
             write!(f, "::{}", key.disambiguated_data.data.as_interned_str())?;
         } else {
+            // Try to print `impl`s more like how you'd refer to their associated items.
+            if let DefPathData::Impl = key.disambiguated_data.data {
+                if let Some(trait_ref) = self.tcx.impl_trait_ref(def_id) {
+                    // HACK(eddyb) this is in lieu of more specific disambiguation.
+                    print!(f, self, write("{}", self.tcx.item_path_str(def_id)))?;
+
+                    let trait_ref = trait_ref.subst(self.tcx, substs);
+                    print!(f, self, print_debug(trait_ref))?;
+                } else {
+                    let self_ty = self.tcx.type_of(def_id).subst(self.tcx, substs);
+                    // FIXME(eddyb) omit the <> where possible.
+                    print!(f, self, write("<"), print(self_ty), write(">"))?;
+                }
+                return Ok(());
+            }
+
             print!(f, self, write("{}", self.tcx.item_path_str(def_id)))?;
         }
 
index 37794c6e0773c0773af66d9c5b211b6ddf2d065b..d628573d51707386f0291e5b36363ff2f3a888fe 100644 (file)
@@ -9,7 +9,7 @@ fn f(&self) {}
     }
 
     pub macro m() {
-        let _: () = S.f(); //~ ERROR type `for<'r> fn(&'r foo::S) {foo::S::f}` is private
+        let _: () = S.f(); //~ ERROR type `for<'r> fn(&'r foo::S) {<foo::S>::f}` is private
     }
 }
 
index 418c2c73ba157e36521d53aea367883cfe2301fe..0a273bc98ff619dba33b33388cac8fa5341948b2 100644 (file)
@@ -1,4 +1,4 @@
-error: type `for<'r> fn(&'r foo::S) {foo::S::f}` is private
+error: type `for<'r> fn(&'r foo::S) {<foo::S>::f}` is private
   --> $DIR/impl_items.rs:12:23
    |
 LL |         let _: () = S.f();
index fab24404eba7d43b79965706921f66eab17a59c6..ff58c7aaced03186b1bf5809147ed72fe30a3098 100644 (file)
@@ -50,7 +50,7 @@ pub fn matches<F: Fn()>(&self, f: &F) {
 
 impl D {
     pub fn matches<F: Fn()>(&self, f: &F) {
-        //~^ ERROR reached the type-length limit while instantiating `D::matches::<[closure
+        //~^ ERROR reached the type-length limit while instantiating `<D>::matches::<[closure
         let &D(ref a) = self;
         a.matches(f)
     }
index aff968f3618c1edb8da02f3fdcbf0214d4d66e4c..65483abe5c7f9a31efcd4bfc20de4ac33b5c0b5d 100644 (file)
@@ -1,4 +1,4 @@
-error: reached the type-length limit while instantiating `D::matches::$CLOSURE`
+error: reached the type-length limit while instantiating `<D>::matches::$CLOSURE`
   --> $DIR/issue-22638.rs:52:5
    |
 LL | /     pub fn matches<F: Fn()>(&self, f: &F) {
index def373cf2c0a896b4d3c6a7daaea9d1f43991576..b284c8cf1172c9c4d6ebe452642cc39641070684 100644 (file)
@@ -5,7 +5,7 @@ LL |     let x: &fn(&B) -> u32 = &B::func;
    |                             ^^^^^^^^ expected fn pointer, found fn item
    |
    = note: expected type `&for<'r> fn(&'r B) -> u32`
-              found type `&for<'r> fn(&'r B) -> u32 {B::func}`
+              found type `&for<'r> fn(&'r B) -> u32 {<B>::func}`
 
 error: aborting due to previous error
 
index 1cd3f84f7a2270ec54df1c7817df02dbfa64707d..8062045a6c058cbb87018a24b82db4f1a133d6cd 100644 (file)
@@ -13,7 +13,7 @@ fn func() -> Ret {
 
 fn main() {
     Obj::func.x();
-    //~^ ERROR no method named `x` found for type `fn() -> Ret {Obj::func}` in the current scope
+    //~^ ERROR no method named `x` found for type `fn() -> Ret {<Obj>::func}` in the current scope
     func.x();
     //~^ ERROR no method named `x` found for type `fn() -> Ret {func}` in the current scope
 }
index 3beb728978884e36f08a84cc81d9fa327502edb5..67f188e0588e2e81b459d765c4bc92cb3ffeeccd 100644 (file)
@@ -1,4 +1,4 @@
-error[E0599]: no method named `x` found for type `fn() -> Ret {Obj::func}` in the current scope
+error[E0599]: no method named `x` found for type `fn() -> Ret {<Obj>::func}` in the current scope
   --> $DIR/issue-29124.rs:15:15
    |
 LL |     Obj::func.x();
index 700dbe36474978e8798d1474a61b15a7f883f0f1..ca2f2a5ba284569a57f89592b83e33c23378ceff 100644 (file)
@@ -8,7 +8,7 @@ error[E0080]: evaluation of constant value failed
   --> $DIR/issue-39559-2.rs:14:24
    |
 LL |     let array: [usize; Dim3::dim()]
-   |                        ^^^^^^^^^^^ calling non-const function `<Dim3 as Dim>::dim`
+   |                        ^^^^^^^^^^^ calling non-const function `<Dim3 as Dim><Dim3 as Dim>::dim`
 
 error[E0015]: calls in constants are limited to constant functions, tuple structs and tuple variants
   --> $DIR/issue-39559-2.rs:17:15
@@ -20,7 +20,7 @@ error[E0080]: evaluation of constant value failed
   --> $DIR/issue-39559-2.rs:17:15
    |
 LL |         = [0; Dim3::dim()];
-   |               ^^^^^^^^^^^ calling non-const function `<Dim3 as Dim>::dim`
+   |               ^^^^^^^^^^^ calling non-const function `<Dim3 as Dim><Dim3 as Dim>::dim`
 
 error: aborting due to 4 previous errors
 
index c3ae920238f18af71e1c946f5b5f1c13eda1f67d..b6fd22fa669e0d6d34f1688074fc7c52a2245580 100644 (file)
@@ -11,11 +11,11 @@ fn method(&self) {}
 
     pub macro mac() {
         let value = Pub::method;
-        //~^ ERROR type `for<'r> fn(&'r priv_nominal::Pub) {priv_nominal::Pub::method}` is private
+        //~^ ERROR type `for<'r> fn(&'r priv_nominal::Pub) {<priv_nominal::Pub>::method}` is private
         value;
-        //~^ ERROR type `for<'r> fn(&'r priv_nominal::Pub) {priv_nominal::Pub::method}` is private
+        //~^ ERROR type `for<'r> fn(&'r priv_nominal::Pub) {<priv_nominal::Pub>::method}` is private
         Pub.method();
-        //~^ ERROR type `for<'r> fn(&'r priv_nominal::Pub) {priv_nominal::Pub::method}` is private
+        //~^ ERROR type `for<'r> fn(&'r priv_nominal::Pub) {<priv_nominal::Pub>::method}` is private
         Pub::CONST;
         //~^ ERROR associated constant `CONST` is private
         // let _: Pub::AssocTy;
index 6471a7914e1039583d65591ce3921eb0fa49b803..69be9d2cea6df1a0909cad64a0a0e29c78ae7aee 100644 (file)
@@ -1,4 +1,4 @@
-error: type `for<'r> fn(&'r priv_nominal::Pub) {priv_nominal::Pub::method}` is private
+error: type `for<'r> fn(&'r priv_nominal::Pub) {<priv_nominal::Pub>::method}` is private
   --> $DIR/associated-item-privacy-inherent.rs:13:21
    |
 LL |         let value = Pub::method;
@@ -7,7 +7,7 @@ LL |         let value = Pub::method;
 LL |     priv_nominal::mac!();
    |     --------------------- in this macro invocation
 
-error: type `for<'r> fn(&'r priv_nominal::Pub) {priv_nominal::Pub::method}` is private
+error: type `for<'r> fn(&'r priv_nominal::Pub) {<priv_nominal::Pub>::method}` is private
   --> $DIR/associated-item-privacy-inherent.rs:15:9
    |
 LL |         value;
@@ -16,7 +16,7 @@ LL |         value;
 LL |     priv_nominal::mac!();
    |     --------------------- in this macro invocation
 
-error: type `for<'r> fn(&'r priv_nominal::Pub) {priv_nominal::Pub::method}` is private
+error: type `for<'r> fn(&'r priv_nominal::Pub) {<priv_nominal::Pub>::method}` is private
   --> $DIR/associated-item-privacy-inherent.rs:17:13
    |
 LL |         Pub.method();
index 926b098040f1498d427e5ec36f8de41368d5dcd7..6315ec2e5126b6df7bb188e459f2725c26311606 100644 (file)
@@ -11,7 +11,7 @@ LL |         0 ..= <S as Tr>::A::f::<u8> => {}
    |               ^^^^^^^^^^^^^^^^^^^^^ ranges require char or numeric types
    |
    = note: start type: {integer}
-   = note: end type: fn() {S::f::<u8>}
+   = note: end type: fn() {<S>::f::<u8>}
 
 error: aborting due to 2 previous errors