about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorJoshua Nelson <jyn514@gmail.com>2020-08-17 19:51:09 -0400
committerJoshua Nelson <jyn514@gmail.com>2020-08-17 20:13:58 -0400
commit4f9cd749261cf95f48a9473a2b44a5cfcd27e10f (patch)
tree7d7205f69b750c18d47574e2c004a6f699cab720 /src
parentf032cba02e53a8538f3c1cd431edc01a9fa1b3f8 (diff)
downloadrust-4f9cd749261cf95f48a9473a2b44a5cfcd27e10f.tar.gz
rust-4f9cd749261cf95f48a9473a2b44a5cfcd27e10f.zip
Resolve true and false as booleans
Diffstat (limited to 'src')
-rw-r--r--src/librustdoc/passes/collect_intra_doc_links.rs25
-rw-r--r--src/test/rustdoc/intra-doc-link-true-false.rs10
2 files changed, 28 insertions, 7 deletions
diff --git a/src/librustdoc/passes/collect_intra_doc_links.rs b/src/librustdoc/passes/collect_intra_doc_links.rs
index f7fc3579d67..8df089b6d81 100644
--- a/src/librustdoc/passes/collect_intra_doc_links.rs
+++ b/src/librustdoc/passes/collect_intra_doc_links.rs
@@ -222,11 +222,11 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
                             disambiguator,
                             None | Some(Disambiguator::Namespace(Namespace::TypeNS))
                         ) {
-                            if let Some(prim) = is_primitive(path_str, ns) {
+                            if let Some((path, prim)) = is_primitive(path_str, ns) {
                                 if extra_fragment.is_some() {
                                     return Err(ErrorKind::AnchorFailure(AnchorFailure::Primitive));
                                 }
-                                return Ok((prim, Some(path_str.to_owned())));
+                                return Ok((prim, Some(path.to_owned())));
                             }
                         }
                         return Ok((res, extra_fragment.clone()));
@@ -239,11 +239,11 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
                 if value != (ns == ValueNS) {
                     return Err(ErrorKind::ResolutionFailure);
                 }
-            } else if let Some(prim) = is_primitive(path_str, ns) {
+            } else if let Some((path, prim)) = is_primitive(path_str, ns) {
                 if extra_fragment.is_some() {
                     return Err(ErrorKind::AnchorFailure(AnchorFailure::Primitive));
                 }
-                return Ok((prim, Some(path_str.to_owned())));
+                return Ok((prim, Some(path.to_owned())));
             } else {
                 // If resolution failed, it may still be a method
                 // because methods are not handled by the resolver
@@ -269,7 +269,7 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
                 })
                 .ok_or(ErrorKind::ResolutionFailure)?;
 
-            if let Some(prim) = is_primitive(&path, TypeNS) {
+            if let Some((path, prim)) = is_primitive(&path, TypeNS) {
                 let did = primitive_impl(cx, &path).ok_or(ErrorKind::ResolutionFailure)?;
                 return cx
                     .tcx
@@ -1220,11 +1220,22 @@ const PRIMITIVES: &[(&str, Res)] = &[
     ("f64", Res::PrimTy(hir::PrimTy::Float(rustc_ast::ast::FloatTy::F64))),
     ("str", Res::PrimTy(hir::PrimTy::Str)),
     ("bool", Res::PrimTy(hir::PrimTy::Bool)),
+    ("true", Res::PrimTy(hir::PrimTy::Bool)),
+    ("false", Res::PrimTy(hir::PrimTy::Bool)),
     ("char", Res::PrimTy(hir::PrimTy::Char)),
 ];
 
-fn is_primitive(path_str: &str, ns: Namespace) -> Option<Res> {
-    if ns == TypeNS { PRIMITIVES.iter().find(|x| x.0 == path_str).map(|x| x.1) } else { None }
+fn is_primitive(path_str: &str, ns: Namespace) -> Option<(&'static str, Res)> {
+    if ns == TypeNS {
+        PRIMITIVES
+            .iter()
+            .filter(|x| x.0 == path_str)
+            .copied()
+            .map(|x| if x.0 == "true" || x.0 == "false" { ("bool", x.1) } else { x })
+            .next()
+    } else {
+        None
+    }
 }
 
 fn primitive_impl(cx: &DocContext<'_>, path_str: &str) -> Option<DefId> {
diff --git a/src/test/rustdoc/intra-doc-link-true-false.rs b/src/test/rustdoc/intra-doc-link-true-false.rs
new file mode 100644
index 00000000000..7b21e934147
--- /dev/null
+++ b/src/test/rustdoc/intra-doc-link-true-false.rs
@@ -0,0 +1,10 @@
+#![deny(broken_intra_doc_links)]
+#![crate_name = "foo"]
+
+// ignore-tidy-linelength
+
+// @has foo/index.html
+// @has - '//*[@id="main"]//a[@href="https://doc.rust-lang.org/nightly/std/primitive.bool.html"]' 'true'
+// @has - '//*[@id="main"]//a[@href="https://doc.rust-lang.org/nightly/std/primitive.bool.html"]' 'false'
+
+//! A `bool` is either [`true`] or [`false`].