-use crate::hir;
-use crate::hir::def::{DefKind, Namespace};
-use crate::hir::def_id::{CrateNum, DefId, CRATE_DEF_INDEX, LOCAL_CRATE};
use crate::hir::map::{DefPathData, DisambiguatedDefPathData};
use crate::middle::cstore::{ExternCrate, ExternCrateSource};
use crate::middle::region;
use crate::ty::layout::{Integer, IntegerExt, Size};
use crate::ty::subst::{GenericArg, GenericArgKind, Subst};
use crate::ty::{self, DefIdTree, ParamConst, Ty, TyCtxt, TypeFoldable};
+use rustc_hir as hir;
+use rustc_hir::def::{DefKind, Namespace};
+use rustc_hir::def_id::{CrateNum, DefId, CRATE_DEF_INDEX, LOCAL_CRATE};
use rustc_apfloat::ieee::{Double, Single};
use rustc_apfloat::Float;
match (ct.val, &ct.ty.kind) {
(_, ty::FnDef(did, substs)) => p!(print_value_path(*did, substs)),
- (ty::ConstKind::Unevaluated(did, substs), _) => match self.tcx().def_kind(did) {
- Some(DefKind::Static) | Some(DefKind::Const) | Some(DefKind::AssocConst) => {
- p!(print_value_path(did, substs))
- }
- _ => {
- if did.is_local() {
- let span = self.tcx().def_span(did);
- if let Ok(snip) = self.tcx().sess.source_map().span_to_snippet(span) {
- p!(write("{}", snip))
- } else {
- p!(write("_: "), print(ct.ty))
+ (ty::ConstKind::Unevaluated(did, substs, promoted), _) => {
+ if let Some(promoted) = promoted {
+ p!(print_value_path(did, substs));
+ p!(write("::{:?}", promoted));
+ } else {
+ match self.tcx().def_kind(did) {
+ Some(DefKind::Static)
+ | Some(DefKind::Const)
+ | Some(DefKind::AssocConst) => p!(print_value_path(did, substs)),
+ _ => {
+ if did.is_local() {
+ let span = self.tcx().def_span(did);
+ if let Ok(snip) = self.tcx().sess.source_map().span_to_snippet(span)
+ {
+ p!(write("{}", snip))
+ } else {
+ p!(write("_: "), print(ct.ty))
+ }
+ } else {
+ p!(write("_: "), print(ct.ty))
+ }
}
- } else {
- p!(write("_: "), print(ct.ty))
}
}
- },
+ }
(ty::ConstKind::Infer(..), _) => p!(write("_: "), print(ct.ty)),
(ty::ConstKind::Param(ParamConst { name, .. }), _) => p!(write("{}", name)),
(ty::ConstKind::Value(value), _) => return self.pretty_print_const_value(value, ct.ty),
}
}
-impl TyCtxt<'t> {
- // HACK(eddyb) get rid of `def_path_str` and/or pass `Namespace` explicitly always
- // (but also some things just print a `DefId` generally so maybe we need this?)
- fn guess_def_namespace(self, def_id: DefId) -> Namespace {
- match self.def_key(def_id).disambiguated_data.data {
- DefPathData::TypeNs(..) | DefPathData::CrateRoot | DefPathData::ImplTrait => {
- Namespace::TypeNS
- }
+// HACK(eddyb) get rid of `def_path_str` and/or pass `Namespace` explicitly always
+// (but also some things just print a `DefId` generally so maybe we need this?)
+fn guess_def_namespace(tcx: TyCtxt<'_>, def_id: DefId) -> Namespace {
+ match tcx.def_key(def_id).disambiguated_data.data {
+ DefPathData::TypeNs(..) | DefPathData::CrateRoot | DefPathData::ImplTrait => {
+ Namespace::TypeNS
+ }
- DefPathData::ValueNs(..)
- | DefPathData::AnonConst
- | DefPathData::ClosureExpr
- | DefPathData::Ctor => Namespace::ValueNS,
+ DefPathData::ValueNs(..)
+ | DefPathData::AnonConst
+ | DefPathData::ClosureExpr
+ | DefPathData::Ctor => Namespace::ValueNS,
- DefPathData::MacroNs(..) => Namespace::MacroNS,
+ DefPathData::MacroNs(..) => Namespace::MacroNS,
- _ => Namespace::TypeNS,
- }
+ _ => Namespace::TypeNS,
}
+}
+impl TyCtxt<'t> {
/// Returns a string identifying this `DefId`. This string is
/// suitable for user output.
pub fn def_path_str(self, def_id: DefId) -> String {
}
pub fn def_path_str_with_substs(self, def_id: DefId, substs: &'t [GenericArg<'t>]) -> String {
- let ns = self.guess_def_namespace(def_id);
+ let ns = guess_def_namespace(self, def_id);
debug!("def_path_str: def_id={:?}, ns={:?}", def_id, ns);
let mut s = String::new();
let _ = FmtPrinter::new(self, &mut s, ns).print_def_path(def_id, substs);