Rollup merge of #75652 - jyn514:true-false-2, r=GuillaumeGomez
Resolve true and false as booleans Successor to https://github.com/rust-lang/rust/pull/75101. r? @Manishearth cc @rust-lang/rustdoc
This commit is contained in:
commit
e6e917e12d
@ -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::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> {
|
||||
|
10
src/test/rustdoc/intra-doc-link-true-false.rs
Normal file
10
src/test/rustdoc/intra-doc-link-true-false.rs
Normal file
@ -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`].
|
Loading…
Reference in New Issue
Block a user