]> git.lizzy.rs Git - rust.git/commitdiff
Remove fn special casing in const printing
authorOliver Scherer <github35764891676564198441@oli-obk.de>
Thu, 12 Mar 2020 12:35:44 +0000 (13:35 +0100)
committerOliver Scherer <github35764891676564198441@oli-obk.de>
Thu, 12 Mar 2020 12:35:44 +0000 (13:35 +0100)
src/librustc/ty/print/pretty.rs
src/test/ui/const-generics/cannot-infer-const-args.stderr

index 0eb9c102b588569a2db8e97f96f2bc434895c834..fdd1533e1302f05b29abf157963f4a689468da26 100644 (file)
@@ -858,16 +858,23 @@ fn pretty_print_const(
 
         macro_rules! print_underscore {
             () => {{
-                p!(write("_"));
                 if print_ty {
-                    p!(write(": "), print(ct.ty));
+                    self = self.typed_value(
+                        |mut this| {
+                            write!(this, "_")?;
+                            Ok(this)
+                        },
+                        |this| this.print_type(ct.ty),
+                        ": ",
+                    )?;
+                } else {
+                    write!(self, "_")?;
                 }
             }};
         }
 
-        match (ct.val, &ct.ty.kind) {
-            (_, ty::FnDef(did, substs)) => p!(print_value_path(*did, substs)),
-            (ty::ConstKind::Unevaluated(did, substs, promoted), _) => {
+        match ct.val {
+            ty::ConstKind::Unevaluated(did, substs, promoted) => {
                 if let Some(promoted) = promoted {
                     p!(print_value_path(did, substs));
                     p!(write("::{:?}", promoted));
@@ -892,17 +899,25 @@ macro_rules! print_underscore {
                     }
                 }
             }
-            (ty::ConstKind::Infer(..), _) => print_underscore!(),
-            (ty::ConstKind::Param(ParamConst { name, .. }), _) => p!(write("{}", name)),
-            (ty::ConstKind::Value(value), _) => {
+            ty::ConstKind::Infer(..) => print_underscore!(),
+            ty::ConstKind::Param(ParamConst { name, .. }) => p!(write("{}", name)),
+            ty::ConstKind::Value(value) => {
                 return self.pretty_print_const_value(value, ct.ty, print_ty);
             }
 
-            _ => {
+            ty::ConstKind::Bound(..) | ty::ConstKind::Placeholder(_) => {
                 // fallback
-                p!(write("{:?}", ct.val));
                 if print_ty {
-                    p!(write(": "), print(ct.ty));
+                    self = self.typed_value(
+                        |mut this| {
+                            write!(this, "{:?}", ct.val)?;
+                            Ok(this)
+                        },
+                        |this| this.print_type(ct.ty),
+                        ": ",
+                    )?;
+                } else {
+                    p!(write("{:?}", ct.val));
                 }
             }
         };
index 8379cbd4908e95fa51f7bf81f674ad999695813f..c1d7022d56b5f848d92e718162cb9fd4808ac301 100644 (file)
@@ -10,7 +10,7 @@ error[E0282]: type annotations needed
   --> $DIR/cannot-infer-const-args.rs:9:5
    |
 LL |     foo();
-   |     ^^^ cannot infer type for fn item `fn() -> usize {foo::<_: usize>}`
+   |     ^^^ cannot infer type for fn item `fn() -> usize {foo::<{_: usize}>}`
 
 error: aborting due to previous error