Rollup merge of #112113 - notriddle:notriddle/rm-fnretty, r=GuillaumeGomez
rustdoc: simplify `clean` by removing `FnRetTy` The default fn ret ty is always unit. Just use that. Looking back at the time when `FnRetTy` (then called `FunctionRetTy`) was first added to rustdoc, it seems to originally be there because `-> !` was a special form: the never type didn't exist back then.eb01b17b06 (diff-384affc1b4190940f114f3fcebbf969e7e18657a71ef9001da6b223a036687d9L921-L924)`DefaultReturn` was later added to rustdoc to mirror a change in HIR, which added a variant for DefaultReturn because it makes `Span` management easier. This isn't needed in rustdoc, since it doesn't carry spans.3f0cc8011a (diff-384affc1b4190940f114f3fcebbf969e7e18657a71ef9001da6b223a036687d9R1144)
This commit is contained in:
commit
77bbfbcdec
7 changed files with 49 additions and 81 deletions
|
|
@ -1257,9 +1257,9 @@ impl clean::Impl {
|
|||
};
|
||||
primitive_link_fragment(f, PrimitiveType::Tuple, &format!("fn ({name}₁, {name}₂, …, {name}ₙ{ellipsis})"), "#trait-implementations-1", cx)?;
|
||||
// Write output.
|
||||
if let clean::FnRetTy::Return(ty) = &bare_fn.decl.output {
|
||||
if !bare_fn.decl.output.is_unit() {
|
||||
write!(f, " -> ")?;
|
||||
fmt_type(ty, f, use_absolute, cx)?;
|
||||
fmt_type(&bare_fn.decl.output, f, use_absolute, cx)?;
|
||||
}
|
||||
} else if let Some(ty) = self.kind.as_blanket_ty() {
|
||||
fmt_type(ty, f, use_absolute, cx)?;
|
||||
|
|
@ -1296,22 +1296,6 @@ impl clean::Arguments {
|
|||
}
|
||||
}
|
||||
|
||||
impl clean::FnRetTy {
|
||||
pub(crate) fn print<'a, 'tcx: 'a>(
|
||||
&'a self,
|
||||
cx: &'a Context<'tcx>,
|
||||
) -> impl fmt::Display + 'a + Captures<'tcx> {
|
||||
display_fn(move |f| match self {
|
||||
clean::Return(clean::Tuple(tys)) if tys.is_empty() => Ok(()),
|
||||
clean::Return(ty) if f.alternate() => {
|
||||
write!(f, " -> {:#}", ty.print(cx))
|
||||
}
|
||||
clean::Return(ty) => write!(f, " -> {}", ty.print(cx)),
|
||||
clean::DefaultReturn => Ok(()),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl clean::BareFunctionDecl {
|
||||
fn print_hrtb_with_space<'a, 'tcx: 'a>(
|
||||
&'a self,
|
||||
|
|
@ -1366,7 +1350,7 @@ impl clean::FnDecl {
|
|||
"({args:#}{ellipsis}){arrow:#}",
|
||||
args = self.inputs.print(cx),
|
||||
ellipsis = ellipsis,
|
||||
arrow = self.output.print(cx)
|
||||
arrow = self.print_output(cx)
|
||||
)
|
||||
} else {
|
||||
write!(
|
||||
|
|
@ -1374,7 +1358,7 @@ impl clean::FnDecl {
|
|||
"({args}{ellipsis}){arrow}",
|
||||
args = self.inputs.print(cx),
|
||||
ellipsis = ellipsis,
|
||||
arrow = self.output.print(cx)
|
||||
arrow = self.print_output(cx)
|
||||
)
|
||||
}
|
||||
})
|
||||
|
|
@ -1464,9 +1448,22 @@ impl clean::FnDecl {
|
|||
Some(n) => write!(f, "\n{})", Indent(n))?,
|
||||
};
|
||||
|
||||
fmt::Display::fmt(&self.output.print(cx), f)?;
|
||||
fmt::Display::fmt(&self.print_output(cx), f)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn print_output<'a, 'tcx: 'a>(
|
||||
&'a self,
|
||||
cx: &'a Context<'tcx>,
|
||||
) -> impl fmt::Display + 'a + Captures<'tcx> {
|
||||
display_fn(move |f| match &self.output {
|
||||
clean::Tuple(tys) if tys.is_empty() => Ok(()),
|
||||
ty if f.alternate() => {
|
||||
write!(f, " -> {:#}", ty.print(cx))
|
||||
}
|
||||
ty => write!(f, " -> {}", ty.print(cx)),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn visibility_print_with_space<'a, 'tcx: 'a>(
|
||||
|
|
|
|||
|
|
@ -844,7 +844,7 @@ fn assoc_method(
|
|||
+ name.as_str().len()
|
||||
+ generics_len;
|
||||
|
||||
let notable_traits = d.output.as_return().and_then(|output| notable_traits_button(output, cx));
|
||||
let notable_traits = notable_traits_button(&d.output, cx);
|
||||
|
||||
let (indent, indent_str, end_newline) = if parent == ItemType::Trait {
|
||||
header_len += 4;
|
||||
|
|
@ -1282,6 +1282,11 @@ fn should_render_item(item: &clean::Item, deref_mut_: bool, tcx: TyCtxt<'_>) ->
|
|||
pub(crate) fn notable_traits_button(ty: &clean::Type, cx: &mut Context<'_>) -> Option<String> {
|
||||
let mut has_notable_trait = false;
|
||||
|
||||
if ty.is_unit() {
|
||||
// Very common fast path.
|
||||
return None;
|
||||
}
|
||||
|
||||
let did = ty.def_id(cx.cache())?;
|
||||
|
||||
// Box has pass-through impls for Read, Write, Iterator, and Future when the
|
||||
|
|
|
|||
|
|
@ -587,8 +587,7 @@ fn item_function(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, f: &cle
|
|||
+ name.as_str().len()
|
||||
+ generics_len;
|
||||
|
||||
let notable_traits =
|
||||
f.decl.output.as_return().and_then(|output| notable_traits_button(output, cx));
|
||||
let notable_traits = notable_traits_button(&f.decl.output, cx);
|
||||
|
||||
wrap_item(w, |w| {
|
||||
w.reserve(header_len);
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ use rustc_span::symbol::Symbol;
|
|||
use serde::ser::{Serialize, SerializeStruct, Serializer};
|
||||
|
||||
use crate::clean;
|
||||
use crate::clean::types::{FnRetTy, Function, Generics, ItemId, Type, WherePredicate};
|
||||
use crate::clean::types::{Function, Generics, ItemId, Type, WherePredicate};
|
||||
use crate::formats::cache::{Cache, OrphanImplItem};
|
||||
use crate::formats::item_type::ItemType;
|
||||
use crate::html::format::join_with_double_colon;
|
||||
|
|
@ -656,22 +656,9 @@ fn get_fn_inputs_and_outputs<'tcx>(
|
|||
}
|
||||
|
||||
let mut ret_types = Vec::new();
|
||||
match decl.output {
|
||||
FnRetTy::Return(ref return_type) => {
|
||||
add_generics_and_bounds_as_types(
|
||||
self_,
|
||||
generics,
|
||||
return_type,
|
||||
tcx,
|
||||
0,
|
||||
&mut ret_types,
|
||||
cache,
|
||||
);
|
||||
if ret_types.is_empty() {
|
||||
ret_types.push(get_index_type(return_type, vec![]));
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
};
|
||||
add_generics_and_bounds_as_types(self_, generics, &decl.output, tcx, 0, &mut ret_types, cache);
|
||||
if ret_types.is_empty() {
|
||||
ret_types.push(get_index_type(&decl.output, vec![]));
|
||||
}
|
||||
(all_types, ret_types)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue