Fix clippy lints in librustdoc

This commit is contained in:
Guillaume Gomez 2025-07-19 16:20:37 +02:00
parent 83825dd277
commit c75edc982c
20 changed files with 153 additions and 173 deletions

View file

@ -1677,7 +1677,7 @@ impl Type {
}
}
pub(crate) fn generics<'a>(&'a self) -> Option<impl Iterator<Item = &'a Type>> {
pub(crate) fn generics(&self) -> Option<impl Iterator<Item = &Type>> {
match self {
Type::Path { path, .. } => path.generics(),
_ => None,
@ -2227,7 +2227,7 @@ impl Path {
self.segments.last().map(|seg| &seg.args)
}
pub(crate) fn generics<'a>(&'a self) -> Option<impl Iterator<Item = &'a Type>> {
pub(crate) fn generics(&self) -> Option<impl Iterator<Item = &Type>> {
self.segments.last().and_then(|seg| {
if let GenericArgs::AngleBracketed { ref args, .. } = seg.args {
Some(args.iter().filter_map(|arg| match arg {

View file

@ -343,13 +343,11 @@ pub(crate) fn name_from_pat(p: &hir::Pat<'_>) -> Symbol {
pub(crate) fn print_const(cx: &DocContext<'_>, n: ty::Const<'_>) -> String {
match n.kind() {
ty::ConstKind::Unevaluated(ty::UnevaluatedConst { def, args: _ }) => {
let s = if let Some(def) = def.as_local() {
if let Some(def) = def.as_local() {
rendered_const(cx.tcx, cx.tcx.hir_body_owned_by(def), def)
} else {
inline::print_inlined_const(cx.tcx, def)
};
s
}
}
// array lengths are obviously usize
ty::ConstKind::Value(cv) if *cv.ty.kind() == ty::Uint(ty::UintTy::Usize) => {

View file

@ -632,7 +632,7 @@ fn run_test(
// the user to exploit nightly-only features on stable
runner_compiler.env("RUSTC_BOOTSTRAP", "1");
runner_compiler.args(compiler_args);
runner_compiler.args(&["--crate-type=bin", "-o"]).arg(&output_file);
runner_compiler.args(["--crate-type=bin", "-o"]).arg(&output_file);
let mut extern_path = std::ffi::OsString::from(format!(
"--extern=doctest_bundle_{edition}=",
edition = doctest.edition
@ -657,7 +657,7 @@ fn run_test(
extern_path.push(&output_bundle_file);
runner_compiler.arg(extern_path);
runner_compiler.arg(&runner_input_file);
if std::fs::write(&runner_input_file, &merged_test_code).is_err() {
if std::fs::write(&runner_input_file, merged_test_code).is_err() {
// If we cannot write this file for any reason, we leave. All combined tests will be
// tested as standalone tests.
return Err(TestFailure::CompileError);

View file

@ -140,7 +140,7 @@ impl HirCollector<'_> {
.iter()
.filter(|a| a.has_name(sym::attr))
.flat_map(|a| a.meta_item_list().unwrap_or_default())
.map(|i| pprust::meta_list_item_to_string(i))
.map(pprust::meta_list_item_to_string)
{
// Add the additional attributes to the global_crate_attrs vector
self.collector.global_crate_attrs.push(attr);

View file

@ -81,7 +81,7 @@ fn run_format_inner<'tcx, T: FormatRenderer<'tcx>>(
let _timer =
prof.generic_activity_with_arg("render_mod_item", item.name.unwrap().to_string());
cx.mod_item_in(&item)?;
cx.mod_item_in(item)?;
let (clean::StrippedItem(box clean::ModuleItem(ref module))
| clean::ModuleItem(ref module)) = item.inner.kind
else {
@ -99,7 +99,7 @@ fn run_format_inner<'tcx, T: FormatRenderer<'tcx>>(
} else if let Some(item_name) = item.name
&& !item.is_extern_crate()
{
prof.generic_activity_with_arg("render_item", item_name.as_str()).run(|| cx.item(&item))?;
prof.generic_activity_with_arg("render_item", item_name.as_str()).run(|| cx.item(item))?;
}
Ok(())
}

View file

@ -114,9 +114,9 @@ impl clean::Generics {
let real_params =
fmt::from_fn(|f| real_params.clone().map(|g| g.print(cx)).joined(", ", f));
if f.alternate() {
write!(f, "<{:#}>", real_params)
write!(f, "<{real_params:#}>")
} else {
write!(f, "&lt;{}&gt;", real_params)
write!(f, "&lt;{real_params}&gt;")
}
})
}
@ -594,7 +594,7 @@ pub(crate) fn href_with_root_path(
}
}
};
let url_parts = make_href(root_path, shortty, url_parts, &fqp, is_remote);
let url_parts = make_href(root_path, shortty, url_parts, fqp, is_remote);
Ok((url_parts, shortty, fqp.clone()))
}
@ -1115,7 +1115,7 @@ impl clean::Impl {
{
let last = ty.last();
if f.alternate() {
write!(f, "{}<", last)?;
write!(f, "{last}<")?;
self.print_type(inner_type, f, use_absolute, cx)?;
write!(f, ">")?;
} else {
@ -1219,7 +1219,7 @@ pub(crate) fn print_params(params: &[clean::Parameter], cx: &Context<'_>) -> imp
.map(|param| {
fmt::from_fn(|f| {
if let Some(name) = param.name {
write!(f, "{}: ", name)?;
write!(f, "{name}: ")?;
}
param.type_.print(cx).fmt(f)
})
@ -1341,7 +1341,7 @@ impl clean::FnDecl {
write!(f, "const ")?;
}
if let Some(name) = param.name {
write!(f, "{}: ", name)?;
write!(f, "{name}: ")?;
}
param.type_.print(cx).fmt(f)?;
}

View file

@ -547,7 +547,7 @@ impl<'a> Iterator for TokenIter<'a> {
fn get_real_ident_class(text: &str, allow_path_keywords: bool) -> Option<Class> {
let ignore: &[&str] =
if allow_path_keywords { &["self", "Self", "super", "crate"] } else { &["self", "Self"] };
if ignore.iter().any(|k| *k == text) {
if ignore.contains(&text) {
return None;
}
Some(match text {
@ -1159,7 +1159,7 @@ fn string_without_closing_tag<T: Display>(
return Some("</a>");
}
if !open_tag {
write!(out, "{}", text_s).unwrap();
out.write_str(&text_s).unwrap();
return None;
}
let klass_s = klass.as_html();

View file

@ -132,6 +132,5 @@ pub(crate) fn redirect(url: &str) -> String {
<script>location.replace("{url}" + location.search + location.hash);</script>
</body>
</html>"##,
url = url,
)
}

View file

@ -251,7 +251,7 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for CodeBlocks<'_, 'a, I> {
if !parse_result.rust {
let added_classes = parse_result.added_classes;
let lang_string = if let Some(lang) = parse_result.unknown.first() {
format!("language-{}", lang)
format!("language-{lang}")
} else {
String::new()
};
@ -999,7 +999,7 @@ impl<'a, 'tcx> TagIterator<'a, 'tcx> {
if let Some((_, c)) = self.inner.next() {
if c != '=' {
self.emit_error(format!("expected `=`, found `{}`", c));
self.emit_error(format!("expected `=`, found `{c}`"));
return None;
}
} else {

View file

@ -193,14 +193,12 @@ impl<'tcx> Context<'tcx> {
if it.is_stripped()
&& let Some(def_id) = it.def_id()
&& def_id.is_local()
&& (self.info.is_inside_inlined_module
|| self.shared.cache.inlined_items.contains(&def_id))
{
if self.info.is_inside_inlined_module
|| self.shared.cache.inlined_items.contains(&def_id)
{
// For now we're forced to generate a redirect page for stripped items until
// `record_extern_fqn` correctly points to external items.
render_redirect_pages = true;
}
// For now we're forced to generate a redirect page for stripped items until
// `record_extern_fqn` correctly points to external items.
render_redirect_pages = true;
}
let mut title = String::new();
if !is_module {
@ -254,40 +252,36 @@ impl<'tcx> Context<'tcx> {
&self.shared.style_files,
)
} else {
if let Some(&(ref names, ty)) = self.cache().paths.get(&it.item_id.expect_def_id()) {
if self.current.len() + 1 != names.len()
|| self.current.iter().zip(names.iter()).any(|(a, b)| a != b)
{
// We checked that the redirection isn't pointing to the current file,
// preventing an infinite redirection loop in the generated
// documentation.
if let Some(&(ref names, ty)) = self.cache().paths.get(&it.item_id.expect_def_id())
&& (self.current.len() + 1 != names.len()
|| self.current.iter().zip(names.iter()).any(|(a, b)| a != b))
{
// We checked that the redirection isn't pointing to the current file,
// preventing an infinite redirection loop in the generated
// documentation.
let path = fmt::from_fn(|f| {
for name in &names[..names.len() - 1] {
write!(f, "{name}/")?;
}
write!(f, "{}", print_item_path(ty, names.last().unwrap().as_str()))
});
match self.shared.redirections {
Some(ref redirections) => {
let mut current_path = String::new();
for name in &self.current {
current_path.push_str(name.as_str());
current_path.push('/');
}
let _ = write!(
current_path,
"{}",
print_item_path(ty, names.last().unwrap().as_str())
);
redirections.borrow_mut().insert(current_path, path.to_string());
}
None => {
return layout::redirect(&format!(
"{root}{path}",
root = self.root_path()
));
let path = fmt::from_fn(|f| {
for name in &names[..names.len() - 1] {
write!(f, "{name}/")?;
}
write!(f, "{}", print_item_path(ty, names.last().unwrap().as_str()))
});
match self.shared.redirections {
Some(ref redirections) => {
let mut current_path = String::new();
for name in &self.current {
current_path.push_str(name.as_str());
current_path.push('/');
}
let _ = write!(
current_path,
"{}",
print_item_path(ty, names.last().unwrap().as_str())
);
redirections.borrow_mut().insert(current_path, path.to_string());
}
None => {
return layout::redirect(&format!("{root}{path}", root = self.root_path()));
}
}
}
@ -762,11 +756,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
// Flush pending errors.
self.shared.fs.close();
let nb_errors = self.shared.errors.iter().map(|err| self.tcx().dcx().err(err)).count();
if nb_errors > 0 {
Err(Error::new(io::Error::new(io::ErrorKind::Other, "I/O error"), ""))
} else {
Ok(())
}
if nb_errors > 0 { Err(Error::new(io::Error::other("I/O error"), "")) } else { Ok(()) }
}
fn mod_item_in(&mut self, item: &clean::Item) -> Result<(), Error> {
@ -842,7 +832,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
self.info.render_redirect_pages = item.is_stripped();
}
let buf = self.render_item(&item, false);
let buf = self.render_item(item, false);
// buf will be empty if the item is stripped and there is no redirect for it
if !buf.is_empty() {
let name = item.name.as_ref().unwrap();
@ -853,7 +843,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
self.shared.fs.write(joint_dst, buf)?;
if !self.info.render_redirect_pages {
self.shared.all.borrow_mut().append(full_path(self, &item), &item_type);
self.shared.all.borrow_mut().append(full_path(self, item), &item_type);
}
// If the item is a macro, redirect from the old macro URL (with !)
// to the new one (without).

View file

@ -1483,10 +1483,10 @@ fn render_deref_methods(
}
}
render_assoc_items_inner(&mut w, cx, container_item, did, what, derefs);
} else if let Some(prim) = target.primitive_type() {
if let Some(&did) = cache.primitive_locations.get(&prim) {
render_assoc_items_inner(&mut w, cx, container_item, did, what, derefs);
}
} else if let Some(prim) = target.primitive_type()
&& let Some(&did) = cache.primitive_locations.get(&prim)
{
render_assoc_items_inner(&mut w, cx, container_item, did, what, derefs);
}
}
@ -2058,21 +2058,20 @@ fn render_impl(
// default items which weren't overridden in the implementation block.
// We don't emit documentation for default items if they appear in the
// Implementations on Foreign Types or Implementors sections.
if rendering_params.show_default_items {
if let Some(t) = trait_
&& !impl_.is_negative_trait_impl()
{
render_default_items(
&mut default_impl_items,
&mut impl_items,
cx,
t,
impl_,
&i.impl_item,
render_mode,
rendering_params,
)?;
}
if rendering_params.show_default_items
&& let Some(t) = trait_
&& !impl_.is_negative_trait_impl()
{
render_default_items(
&mut default_impl_items,
&mut impl_items,
cx,
t,
impl_,
&i.impl_item,
render_mode,
rendering_params,
)?;
}
if render_mode == RenderMode::Normal {
let toggled = !(impl_items.is_empty() && default_impl_items.is_empty());
@ -2570,7 +2569,7 @@ fn collect_paths_for_type(first_ty: &clean::Type, cache: &Cache) -> Vec<String>
match ty {
clean::Type::Path { path } => process_path(path.def_id()),
clean::Type::Tuple(tys) => {
work.extend(tys.into_iter());
work.extend(tys.iter());
}
clean::Type::Slice(ty) => {
work.push_back(ty);

View file

@ -25,7 +25,7 @@ impl OrderedJson {
.into_iter()
.sorted_unstable_by(|a, b| a.borrow().cmp(b.borrow()))
.format_with(",", |item, f| f(item.borrow()));
Self(format!("[{}]", items))
Self(format!("[{items}]"))
}
pub(crate) fn array_unsorted<T: Borrow<Self>, I: IntoIterator<Item = T>>(items: I) -> Self {

View file

@ -1451,7 +1451,7 @@ item_template!(
impl<'a, 'cx: 'a> ItemUnion<'a, 'cx> {
fn render_union(&self) -> impl Display {
render_union(self.it, Some(&self.generics), &self.fields, self.cx)
render_union(self.it, Some(self.generics), self.fields, self.cx)
}
fn document_field(&self, field: &'a clean::Item) -> impl Display {
@ -1982,16 +1982,14 @@ fn item_constant(
w.write_str(";")?;
}
if !is_literal {
if let Some(value) = &value {
let value_lowercase = value.to_lowercase();
let expr_lowercase = expr.to_lowercase();
if !is_literal && let Some(value) = &value {
let value_lowercase = value.to_lowercase();
let expr_lowercase = expr.to_lowercase();
if value_lowercase != expr_lowercase
&& value_lowercase.trim_end_matches("i32") != expr_lowercase
{
write!(w, " // {value}", value = Escape(value))?;
}
if value_lowercase != expr_lowercase
&& value_lowercase.trim_end_matches("i32") != expr_lowercase
{
write!(w, " // {value}", value = Escape(value))?;
}
}
Ok::<(), fmt::Error>(())
@ -2071,41 +2069,39 @@ fn item_fields(
_ => None,
})
.peekable();
if let None | Some(CtorKind::Fn) = ctor_kind {
if fields.peek().is_some() {
let title = format!(
"{}{}",
if ctor_kind.is_none() { "Fields" } else { "Tuple Fields" },
document_non_exhaustive_header(it),
);
if let None | Some(CtorKind::Fn) = ctor_kind
&& fields.peek().is_some()
{
let title = format!(
"{}{}",
if ctor_kind.is_none() { "Fields" } else { "Tuple Fields" },
document_non_exhaustive_header(it),
);
write!(
w,
"{}",
write_section_heading(
&title,
"fields",
Some("fields"),
document_non_exhaustive(it)
)
)?;
for (index, (field, ty)) in fields.enumerate() {
let field_name =
field.name.map_or_else(|| index.to_string(), |sym| sym.as_str().to_string());
let id = cx.derive_id(format!("{typ}.{field_name}", typ = ItemType::StructField));
write!(
w,
"{}",
write_section_heading(
&title,
"fields",
Some("fields"),
document_non_exhaustive(it)
)
"<span id=\"{id}\" class=\"{item_type} section-header\">\
<a href=\"#{id}\" class=\"anchor field\">§</a>\
<code>{field_name}: {ty}</code>\
</span>\
{doc}",
item_type = ItemType::StructField,
ty = ty.print(cx),
doc = document(cx, field, Some(it), HeadingOffset::H3),
)?;
for (index, (field, ty)) in fields.enumerate() {
let field_name = field
.name
.map_or_else(|| index.to_string(), |sym| sym.as_str().to_string());
let id =
cx.derive_id(format!("{typ}.{field_name}", typ = ItemType::StructField));
write!(
w,
"<span id=\"{id}\" class=\"{item_type} section-header\">\
<a href=\"#{id}\" class=\"anchor field\">§</a>\
<code>{field_name}: {ty}</code>\
</span>\
{doc}",
item_type = ItemType::StructField,
ty = ty.print(cx),
doc = document(cx, field, Some(it), HeadingOffset::H3),
)?;
}
}
}
Ok(())

View file

@ -541,7 +541,7 @@ fn sidebar_deref_methods<'a>(
.iter()
.filter(|i| {
i.inner_impl().trait_.is_none()
&& real_target.is_doc_subtype_of(&i.inner_impl().for_, &c)
&& real_target.is_doc_subtype_of(&i.inner_impl().for_, c)
})
.flat_map(|i| get_methods(i.inner_impl(), true, used_links, deref_mut, cx.tcx()))
.collect::<Vec<_>>();

View file

@ -63,7 +63,8 @@ impl<F: FileFormat> fmt::Display for SortedTemplate<F> {
for (p, fragment) in self.fragments.iter().with_position() {
let mut f = DeltaWriter { inner: &mut f, delta: 0 };
let sep = if matches!(p, Position::First | Position::Only) { "" } else { F::SEPARATOR };
write!(f, "{}{}", sep, fragment)?;
f.write_str(sep)?;
f.write_str(fragment)?;
fragment_lengths.push(f.delta);
}
let offset = Offset { start: self.before.len(), fragment_lengths };

View file

@ -50,7 +50,7 @@ impl JsonRenderer<'_> {
let span = item.span(self.tcx);
let visibility = item.visibility(self.tcx);
let clean::ItemInner { name, item_id, .. } = *item.inner;
let id = self.id_from_item(&item);
let id = self.id_from_item(item);
let inner = match item.kind {
clean::KeywordItem => return None,
clean::StrippedItem(ref inner) => {
@ -86,14 +86,14 @@ impl JsonRenderer<'_> {
items
.iter()
.filter(|i| !i.is_stripped() && !i.is_keyword())
.map(|i| self.id_from_item(&i))
.map(|i| self.id_from_item(i))
.collect()
}
fn ids_keeping_stripped(&self, items: &[clean::Item]) -> Vec<Option<Id>> {
items
.iter()
.map(|i| (!i.is_stripped() && !i.is_keyword()).then(|| self.id_from_item(&i)))
.map(|i| (!i.is_stripped() && !i.is_keyword()).then(|| self.id_from_item(i)))
.collect()
}
}
@ -358,12 +358,12 @@ impl FromClean<clean::Struct> for Struct {
let clean::Struct { ctor_kind, generics, fields } = struct_;
let kind = match ctor_kind {
Some(CtorKind::Fn) => StructKind::Tuple(renderer.ids_keeping_stripped(&fields)),
Some(CtorKind::Fn) => StructKind::Tuple(renderer.ids_keeping_stripped(fields)),
Some(CtorKind::Const) => {
assert!(fields.is_empty());
StructKind::Unit
}
None => StructKind::Plain { fields: renderer.ids(&fields), has_stripped_fields },
None => StructKind::Plain { fields: renderer.ids(fields), has_stripped_fields },
};
Struct {
@ -381,7 +381,7 @@ impl FromClean<clean::Union> for Union {
Union {
generics: generics.into_json(renderer),
has_stripped_fields,
fields: renderer.ids(&fields),
fields: renderer.ids(fields),
impls: Vec::new(), // Added in JsonRenderer::item
}
}
@ -659,7 +659,7 @@ impl FromClean<clean::FnDecl> for FunctionSignature {
let clean::FnDecl { inputs, output, c_variadic } = decl;
FunctionSignature {
inputs: inputs
.into_iter()
.iter()
.map(|param| {
// `_` is the most sensible name for missing param names.
let name = param.name.unwrap_or(kw::Underscore).to_string();
@ -684,7 +684,7 @@ impl FromClean<clean::Trait> for Trait {
is_auto,
is_unsafe,
is_dyn_compatible,
items: renderer.ids(&items),
items: renderer.ids(items),
generics: generics.into_json(renderer),
bounds: bounds.into_json(renderer),
implementations: Vec::new(), // Added in JsonRenderer::item
@ -727,7 +727,7 @@ impl FromClean<clean::Impl> for Impl {
.collect(),
trait_: trait_.into_json(renderer),
for_: for_.into_json(renderer),
items: renderer.ids(&items),
items: renderer.ids(items),
is_negative,
is_synthetic,
blanket_impl: blanket_impl.map(|x| x.into_json(renderer)),
@ -770,7 +770,7 @@ impl FromClean<clean::Variant> for Variant {
let kind = match &variant.kind {
CLike => VariantKind::Plain,
Tuple(fields) => VariantKind::Tuple(renderer.ids_keeping_stripped(&fields)),
Tuple(fields) => VariantKind::Tuple(renderer.ids_keeping_stripped(fields)),
Struct(s) => VariantKind::Struct {
has_stripped_fields: s.has_stripped_entries(),
fields: renderer.ids(&s.fields),

View file

@ -133,7 +133,7 @@ fn target(sess: &rustc_session::Session) -> types::Target {
let feature_stability: FxHashMap<&str, Stability> = sess
.target
.rust_target_features()
.into_iter()
.iter()
.copied()
.map(|(name, stability, _)| (name, stability))
.collect();
@ -143,7 +143,7 @@ fn target(sess: &rustc_session::Session) -> types::Target {
target_features: sess
.target
.rust_target_features()
.into_iter()
.iter()
.copied()
.filter(|(_, stability, _)| {
// Describe only target features which the user can toggle
@ -157,7 +157,7 @@ fn target(sess: &rustc_session::Session) -> types::Target {
_ => None,
},
implies_features: implied_features
.into_iter()
.iter()
.copied()
.filter(|name| {
// Imply only target features which the user can toggle

View file

@ -274,7 +274,7 @@ impl From<DiagnosticInfo<'_>> for OwnedDiagnosticInfo {
}
impl OwnedDiagnosticInfo {
pub(crate) fn into_info(&self) -> DiagnosticInfo<'_> {
pub(crate) fn as_info(&self) -> DiagnosticInfo<'_> {
DiagnosticInfo {
item: &self.item,
ori_link: &self.ori_link,
@ -1177,7 +1177,7 @@ impl LinkCollector<'_, '_> {
// Primitive types are always valid.
Res::Primitive(_) => true,
});
let diag_info = info.diag_info.into_info();
let diag_info = info.diag_info.as_info();
match info.resolved.len() {
1 => {
let (res, fragment) = info.resolved.pop().unwrap();
@ -1243,17 +1243,16 @@ impl LinkCollector<'_, '_> {
disambiguator,
None | Some(Disambiguator::Namespace(Namespace::TypeNS) | Disambiguator::Primitive)
) && !matches!(res, Res::Primitive(_))
&& let Some(prim) = resolve_primitive(path_str, TypeNS)
{
if let Some(prim) = resolve_primitive(path_str, TypeNS) {
// `prim@char`
if matches!(disambiguator, Some(Disambiguator::Primitive)) {
res = prim;
} else {
// `[char]` when a `char` module is in scope
let candidates = &[(res, res.def_id(self.cx.tcx)), (prim, None)];
ambiguity_error(self.cx, &diag_info, path_str, candidates, true);
return None;
}
// `prim@char`
if matches!(disambiguator, Some(Disambiguator::Primitive)) {
res = prim;
} else {
// `[char]` when a `char` module is in scope
let candidates = &[(res, res.def_id(self.cx.tcx)), (prim, None)];
ambiguity_error(self.cx, &diag_info, path_str, candidates, true);
return None;
}
}
@ -2233,7 +2232,7 @@ fn ambiguity_error(
// proc macro can exist in multiple namespaces at once, so we need to compare `DefIds`
// to remove the candidate in the fn namespace.
let mut possible_proc_macro_id = None;
let is_proc_macro_crate = cx.tcx.crate_types() == &[CrateType::ProcMacro];
let is_proc_macro_crate = cx.tcx.crate_types() == [CrateType::ProcMacro];
let mut kinds = candidates
.iter()
.map(|(res, def_id)| {

View file

@ -93,14 +93,14 @@ fn check_redundant_explicit_link<'md>(
if let Event::Start(Tag::Link { link_type, dest_url, .. }) = event {
let link_data = collect_link_data(&mut offset_iter);
if let Some(resolvable_link) = link_data.resolvable_link.as_ref() {
if &link_data.display_link.replace('`', "") != resolvable_link {
// Skips if display link does not match to actual
// resolvable link, usually happens if display link
// has several segments, e.g.
// [this is just an `Option`](Option)
continue;
}
if let Some(resolvable_link) = link_data.resolvable_link.as_ref()
&& &link_data.display_link.replace('`', "") != resolvable_link
{
// Skips if display link does not match to actual
// resolvable link, usually happens if display link
// has several segments, e.g.
// [this is just an `Option`](Option)
continue;
}
let explicit_link = dest_url.to_string();

View file

@ -47,13 +47,11 @@ impl DocFolder for NonLocalStripper<'_> {
// FIXME(#125009): Not-local should probably consider same Cargo workspace
if let Some(def_id) = i.def_id()
&& !def_id.is_local()
{
if i.is_doc_hidden()
&& (i.is_doc_hidden()
// Default to *not* stripping items with inherited visibility.
|| i.visibility(self.tcx).is_some_and(|viz| viz != Visibility::Public)
{
return Some(strip_item(i));
}
|| i.visibility(self.tcx).is_some_and(|viz| viz != Visibility::Public))
{
return Some(strip_item(i));
}
Some(self.fold_item_recur(i))