about summary refs log tree commit diff
path: root/compiler
diff options
context:
space:
mode:
authorJoshua Nelson <jyn514@gmail.com>2020-09-20 02:18:09 -0400
committerJoshua Nelson <jyn514@gmail.com>2020-09-23 21:04:22 -0400
commit472e52e5a03790becdbe21be1002a90dd2d7d3d4 (patch)
tree836bf03336a1fe86d4654436a36231253163b6da /compiler
parentdd7b8c85a6a2bffb2cce1c40ba72680a1d7be93b (diff)
downloadrust-472e52e5a03790becdbe21be1002a90dd2d7d3d4.tar.gz
rust-472e52e5a03790becdbe21be1002a90dd2d7d3d4.zip
Fix intra-doc links for primitives
- Add `PrimTy::name` and `PrimTy::name_str`
- Use those new functions to distinguish between the name in scope and
the canonical name
- Fix diagnostics for primitive types
- Add tests for primitives
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_hir/src/hir.rs24
1 files changed, 24 insertions, 0 deletions
diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs
index cd4185226dc..636f67a77c8 100644
--- a/compiler/rustc_hir/src/hir.rs
+++ b/compiler/rustc_hir/src/hir.rs
@@ -2004,6 +2004,30 @@ pub enum PrimTy {
     Char,
 }
 
+impl PrimTy {
+    pub fn name_str(self) -> &'static str {
+        match self {
+            PrimTy::Int(i) => i.name_str(),
+            PrimTy::Uint(u) => u.name_str(),
+            PrimTy::Float(f) => f.name_str(),
+            PrimTy::Str => "str",
+            PrimTy::Bool => "bool",
+            PrimTy::Char => "char",
+        }
+    }
+
+    pub fn name(self) -> Symbol {
+        match self {
+            PrimTy::Int(i) => i.name(),
+            PrimTy::Uint(u) => u.name(),
+            PrimTy::Float(f) => f.name(),
+            PrimTy::Str => sym::str,
+            PrimTy::Bool => sym::bool,
+            PrimTy::Char => sym::char,
+        }
+    }
+}
+
 #[derive(Debug, HashStable_Generic)]
 pub struct BareFnTy<'hir> {
     pub unsafety: Unsafety,