Skip to content

Commit 6e73a14

Browse files
committed
Remove fn special casing in const printing
1 parent d0b1211 commit 6e73a14

File tree

2 files changed

+27
-12
lines changed

2 files changed

+27
-12
lines changed

src/librustc/ty/print/pretty.rs

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -858,16 +858,23 @@ pub trait PrettyPrinter<'tcx>:
858858

859859
macro_rules! print_underscore {
860860
() => {{
861-
p!(write("_"));
862861
if print_ty {
863-
p!(write(": "), print(ct.ty));
862+
self = self.typed_value(
863+
|mut this| {
864+
write!(this, "_")?;
865+
Ok(this)
866+
},
867+
|this| this.print_type(ct.ty),
868+
": ",
869+
)?;
870+
} else {
871+
write!(self, "_")?;
864872
}
865873
}};
866874
}
867875

868-
match (ct.val, &ct.ty.kind) {
869-
(_, ty::FnDef(did, substs)) => p!(print_value_path(*did, substs)),
870-
(ty::ConstKind::Unevaluated(did, substs, promoted), _) => {
876+
match ct.val {
877+
ty::ConstKind::Unevaluated(did, substs, promoted) => {
871878
if let Some(promoted) = promoted {
872879
p!(print_value_path(did, substs));
873880
p!(write("::{:?}", promoted));
@@ -892,17 +899,25 @@ pub trait PrettyPrinter<'tcx>:
892899
}
893900
}
894901
}
895-
(ty::ConstKind::Infer(..), _) => print_underscore!(),
896-
(ty::ConstKind::Param(ParamConst { name, .. }), _) => p!(write("{}", name)),
897-
(ty::ConstKind::Value(value), _) => {
902+
ty::ConstKind::Infer(..) => print_underscore!(),
903+
ty::ConstKind::Param(ParamConst { name, .. }) => p!(write("{}", name)),
904+
ty::ConstKind::Value(value) => {
898905
return self.pretty_print_const_value(value, ct.ty, print_ty);
899906
}
900907

901-
_ => {
908+
ty::ConstKind::Bound(..) | ty::ConstKind::Placeholder(_) => {
902909
// fallback
903-
p!(write("{:?}", ct.val));
904910
if print_ty {
905-
p!(write(": "), print(ct.ty));
911+
self = self.typed_value(
912+
|mut this| {
913+
write!(this, "{:?}", ct.val)?;
914+
Ok(this)
915+
},
916+
|this| this.print_type(ct.ty),
917+
": ",
918+
)?;
919+
} else {
920+
p!(write("{:?}", ct.val));
906921
}
907922
}
908923
};

src/test/ui/const-generics/cannot-infer-const-args.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ error[E0282]: type annotations needed
1010
--> $DIR/cannot-infer-const-args.rs:9:5
1111
|
1212
LL | foo();
13-
| ^^^ cannot infer type for fn item `fn() -> usize {foo::<_: usize>}`
13+
| ^^^ cannot infer type for fn item `fn() -> usize {foo::<{_: usize}>}`
1414

1515
error: aborting due to previous error
1616

0 commit comments

Comments
 (0)