Skip to content

Commit

Permalink
Remove fn special casing in const printing
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Mar 12, 2020
1 parent d0b1211 commit 6e73a14
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
37 changes: 26 additions & 11 deletions src/librustc/ty/print/pretty.rs
Expand Up @@ -858,16 +858,23 @@ pub trait PrettyPrinter<'tcx>:

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));
Expand All @@ -892,17 +899,25 @@ pub trait PrettyPrinter<'tcx>:
}
}
}
(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));
}
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/const-generics/cannot-infer-const-args.stderr
Expand Up @@ -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

Expand Down

0 comments on commit 6e73a14

Please sign in to comment.