about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2022-10-30 19:39:07 +0000
committerMichael Goulet <michael@errs.io>2022-11-01 20:41:47 +0000
commite24df2778fb7a19dfe386ad563ea216a816db94a (patch)
treec4ff15b9e18a76568744c0ab4dd216e917071830
parente70cbef0c5db81079f4b5643380d6047ccd34a10 (diff)
downloadrust-e24df2778fb7a19dfe386ad563ea216a816db94a.tar.gz
rust-e24df2778fb7a19dfe386ad563ea216a816db94a.zip
Format dyn Trait better in type_name intrinsic
-rw-r--r--compiler/rustc_const_eval/src/util/type_name.rs12
-rw-r--r--compiler/rustc_middle/src/ty/print/pretty.rs2
-rw-r--r--library/core/tests/any.rs18
-rw-r--r--src/test/ui/type/issue-94187-verbose-type-name.rs5
4 files changed, 22 insertions, 15 deletions
diff --git a/compiler/rustc_const_eval/src/util/type_name.rs b/compiler/rustc_const_eval/src/util/type_name.rs
index 221efc6f981..08a6d69b8e4 100644
--- a/compiler/rustc_const_eval/src/util/type_name.rs
+++ b/compiler/rustc_const_eval/src/util/type_name.rs
@@ -73,18 +73,10 @@ impl<'tcx> Printer<'tcx> for AbsolutePathPrinter<'tcx> {
     }
 
     fn print_dyn_existential(
-        mut self,
+        self,
         predicates: &'tcx ty::List<ty::Binder<'tcx, ty::ExistentialPredicate<'tcx>>>,
     ) -> Result<Self::DynExistential, Self::Error> {
-        let mut first = true;
-        for p in predicates {
-            if !first {
-                write!(self, "+")?;
-            }
-            first = false;
-            self = p.print(self)?;
-        }
-        Ok(self)
+        self.pretty_print_dyn_existential(predicates)
     }
 
     fn path_crate(mut self, cnum: CrateNum) -> Result<Self::Path, Self::Error> {
diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs
index f07c60af248..fab85c39d25 100644
--- a/compiler/rustc_middle/src/ty/print/pretty.rs
+++ b/compiler/rustc_middle/src/ty/print/pretty.rs
@@ -1137,7 +1137,7 @@ pub trait PrettyPrinter<'tcx>:
         //
         // To avoid causing instabilities in compiletest
         // output, sort the auto-traits alphabetically.
-        auto_traits.sort_by_cached_key(|did| self.tcx().def_path_str(*did));
+        auto_traits.sort_by_cached_key(|did| with_no_trimmed_paths!(self.tcx().def_path_str(*did)));
 
         for def_id in auto_traits {
             if !first {
diff --git a/library/core/tests/any.rs b/library/core/tests/any.rs
index 9538b813949..e98dac8d12e 100644
--- a/library/core/tests/any.rs
+++ b/library/core/tests/any.rs
@@ -131,6 +131,24 @@ fn distinct_type_names() {
     assert_ne!(type_name_of_val(Velocity), type_name_of_val(Velocity(0.0, -9.8)),);
 }
 
+#[cfg(not(bootstrap))]
+#[test]
+fn dyn_type_name() {
+    trait Foo {
+        type Bar;
+    }
+
+    assert_eq!(
+        "dyn core::ops::function::Fn(i32, i32) -> i32",
+        std::any::type_name::<dyn Fn(i32, i32) -> i32>()
+    );
+    assert_eq!(
+        "dyn coretests::any::dyn_type_name::Foo<Bar = i32> \
+        + core::marker::Send + core::marker::Sync",
+        std::any::type_name::<dyn Foo<Bar = i32> + Send + Sync>()
+    );
+}
+
 // Test the `Provider` API.
 
 struct SomeConcreteType {
diff --git a/src/test/ui/type/issue-94187-verbose-type-name.rs b/src/test/ui/type/issue-94187-verbose-type-name.rs
index 64f0c09e89b..3713a32eb11 100644
--- a/src/test/ui/type/issue-94187-verbose-type-name.rs
+++ b/src/test/ui/type/issue-94187-verbose-type-name.rs
@@ -12,8 +12,5 @@ fn main() {
     struct Wrapper<const VALUE: usize>;
     assert_eq!(type_name::<Wrapper<0>>(), "issue_94187_verbose_type_name::main::Wrapper<0>");
 
-    assert_eq!(
-        type_name::<dyn Fn(u32) -> u32>(),
-        "dyn core::ops::function::Fn<(u32,)>+Output = u32"
-    );
+    assert_eq!(type_name::<dyn Fn(u32) -> u32>(), "dyn core::ops::function::Fn(u32) -> u32");
 }