]> git.lizzy.rs Git - rust.git/blobdiff - crates/hir_ty/src/display.rs
Add lowering of array lengths in types
[rust.git] / crates / hir_ty / src / display.rs
index e7c9dabc222887858465ad21a5ca4ba4751882ca..7bbd1a1f7dad6474651de8f11757bb11e6c3f4cf 100644 (file)
@@ -9,6 +9,7 @@
 
 use chalk_ir::BoundVar;
 use hir_def::{
+    body,
     db::DefDatabase,
     find_path,
     generics::TypeParamProvenance,
@@ -18,7 +19,7 @@
     visibility::Visibility,
     AssocContainerId, Lookup, ModuleId, TraitId,
 };
-use hir_expand::name::Name;
+use hir_expand::{hygiene::Hygiene, name::Name};
 
 use crate::{
     const_from_placeholder_idx, db::HirDatabase, from_assoc_type_id, from_foreign_def_id,
@@ -307,7 +308,7 @@ fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> {
                 let param_data = &generics.params.consts[id.local_id];
                 write!(f, "{}", param_data.name)
             }
-            ConstValue::Concrete(_) => write!(f, "_"),
+            ConstValue::Concrete(c) => write!(f, "{}", c.interned),
         }
     }
 }
@@ -961,11 +962,10 @@ fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> {
                 write!(f, "{}", mutability)?;
                 inner.hir_fmt(f)?;
             }
-            TypeRef::Array(inner) => {
+            TypeRef::Array(inner, len) => {
                 write!(f, "[")?;
                 inner.hir_fmt(f)?;
-                // FIXME: Array length?
-                write!(f, "; _]")?;
+                write!(f, "; {}]", len)?;
             }
             TypeRef::Slice(inner) => {
                 write!(f, "[")?;
@@ -997,6 +997,18 @@ fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> {
                 write!(f, "dyn ")?;
                 f.write_joined(bounds, " + ")?;
             }
+            TypeRef::Macro(macro_call) => {
+                let macro_call = macro_call.to_node(f.db.upcast());
+                let ctx = body::LowerCtx::with_hygiene(f.db.upcast(), &Hygiene::new_unhygienic());
+                match macro_call.path() {
+                    Some(path) => match Path::from_src(path, &ctx) {
+                        Some(path) => path.hir_fmt(f)?,
+                        None => write!(f, "{{macro}}")?,
+                    },
+                    None => write!(f, "{{macro}}")?,
+                }
+                write!(f, "!(..)")?;
+            }
             TypeRef::Error => write!(f, "{{error}}")?,
         }
         Ok(())