Skip to content

Commit e6e917e

Browse files
authored
Rollup merge of rust-lang#75652 - jyn514:true-false-2, r=GuillaumeGomez
Resolve true and false as booleans Successor to rust-lang#75101. r? @Manishearth cc @rust-lang/rustdoc
2 parents 9cf3903 + 4f9cd74 commit e6e917e

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

src/librustdoc/passes/collect_intra_doc_links.rs

+18-7
Original file line numberDiff line numberDiff line change
@@ -222,11 +222,11 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
222222
disambiguator,
223223
None | Some(Disambiguator::Namespace(Namespace::TypeNS))
224224
) {
225-
if let Some(prim) = is_primitive(path_str, ns) {
225+
if let Some((path, prim)) = is_primitive(path_str, ns) {
226226
if extra_fragment.is_some() {
227227
return Err(ErrorKind::AnchorFailure(AnchorFailure::Primitive));
228228
}
229-
return Ok((prim, Some(path_str.to_owned())));
229+
return Ok((prim, Some(path.to_owned())));
230230
}
231231
}
232232
return Ok((res, extra_fragment.clone()));
@@ -239,11 +239,11 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
239239
if value != (ns == ValueNS) {
240240
return Err(ErrorKind::ResolutionFailure);
241241
}
242-
} else if let Some(prim) = is_primitive(path_str, ns) {
242+
} else if let Some((path, prim)) = is_primitive(path_str, ns) {
243243
if extra_fragment.is_some() {
244244
return Err(ErrorKind::AnchorFailure(AnchorFailure::Primitive));
245245
}
246-
return Ok((prim, Some(path_str.to_owned())));
246+
return Ok((prim, Some(path.to_owned())));
247247
} else {
248248
// If resolution failed, it may still be a method
249249
// because methods are not handled by the resolver
@@ -269,7 +269,7 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
269269
})
270270
.ok_or(ErrorKind::ResolutionFailure)?;
271271

272-
if let Some(prim) = is_primitive(&path, TypeNS) {
272+
if let Some((path, prim)) = is_primitive(&path, TypeNS) {
273273
let did = primitive_impl(cx, &path).ok_or(ErrorKind::ResolutionFailure)?;
274274
return cx
275275
.tcx
@@ -1220,11 +1220,22 @@ const PRIMITIVES: &[(&str, Res)] = &[
12201220
("f64", Res::PrimTy(hir::PrimTy::Float(rustc_ast::FloatTy::F64))),
12211221
("str", Res::PrimTy(hir::PrimTy::Str)),
12221222
("bool", Res::PrimTy(hir::PrimTy::Bool)),
1223+
("true", Res::PrimTy(hir::PrimTy::Bool)),
1224+
("false", Res::PrimTy(hir::PrimTy::Bool)),
12231225
("char", Res::PrimTy(hir::PrimTy::Char)),
12241226
];
12251227

1226-
fn is_primitive(path_str: &str, ns: Namespace) -> Option<Res> {
1227-
if ns == TypeNS { PRIMITIVES.iter().find(|x| x.0 == path_str).map(|x| x.1) } else { None }
1228+
fn is_primitive(path_str: &str, ns: Namespace) -> Option<(&'static str, Res)> {
1229+
if ns == TypeNS {
1230+
PRIMITIVES
1231+
.iter()
1232+
.filter(|x| x.0 == path_str)
1233+
.copied()
1234+
.map(|x| if x.0 == "true" || x.0 == "false" { ("bool", x.1) } else { x })
1235+
.next()
1236+
} else {
1237+
None
1238+
}
12281239
}
12291240

12301241
fn primitive_impl(cx: &DocContext<'_>, path_str: &str) -> Option<DefId> {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#![deny(broken_intra_doc_links)]
2+
#![crate_name = "foo"]
3+
4+
// ignore-tidy-linelength
5+
6+
// @has foo/index.html
7+
// @has - '//*[@id="main"]//a[@href="https://doc.rust-lang.org/nightly/std/primitive.bool.html"]' 'true'
8+
// @has - '//*[@id="main"]//a[@href="https://doc.rust-lang.org/nightly/std/primitive.bool.html"]' 'false'
9+
10+
//! A `bool` is either [`true`] or [`false`].

0 commit comments

Comments
 (0)