Remove header field from clean::Function
This commit is contained in:
parent
3fe3b89cd5
commit
2c4ce9d2dc
6 changed files with 88 additions and 113 deletions
|
@ -48,7 +48,6 @@ use std::string::ToString;
|
|||
use rustc_ast_pretty::pprust;
|
||||
use rustc_attr::{ConstStability, Deprecation, StabilityLevel};
|
||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def::CtorKind;
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_hir::Mutability;
|
||||
|
@ -806,7 +805,6 @@ fn assoc_type(
|
|||
fn assoc_method(
|
||||
w: &mut Buffer,
|
||||
meth: &clean::Item,
|
||||
header: hir::FnHeader,
|
||||
g: &clean::Generics,
|
||||
d: &clean::FnDecl,
|
||||
link: AssocItemLink<'_>,
|
||||
|
@ -814,6 +812,7 @@ fn assoc_method(
|
|||
cx: &Context<'_>,
|
||||
render_mode: RenderMode,
|
||||
) {
|
||||
let header = meth.fn_header(cx.tcx()).expect("Trying to get header from a non-function item");
|
||||
let name = meth.name.as_ref().unwrap();
|
||||
let href = match link {
|
||||
AssocItemLink::Anchor(Some(ref id)) => Some(format!("#{}", id)),
|
||||
|
@ -972,10 +971,10 @@ fn render_assoc_item(
|
|||
match *item.kind {
|
||||
clean::StrippedItem(..) => {}
|
||||
clean::TyMethodItem(ref m) => {
|
||||
assoc_method(w, item, m.header, &m.generics, &m.decl, link, parent, cx, render_mode)
|
||||
assoc_method(w, item, &m.generics, &m.decl, link, parent, cx, render_mode)
|
||||
}
|
||||
clean::MethodItem(ref m, _) => {
|
||||
assoc_method(w, item, m.header, &m.generics, &m.decl, link, parent, cx, render_mode)
|
||||
assoc_method(w, item, &m.generics, &m.decl, link, parent, cx, render_mode)
|
||||
}
|
||||
clean::AssocConstItem(ref ty, _) => {
|
||||
assoc_const(w, item, ty, link, if parent == ItemType::Trait { " " } else { "" }, cx)
|
||||
|
|
|
@ -365,8 +365,9 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl
|
|||
}
|
||||
|
||||
let unsafety_flag = match *myitem.kind {
|
||||
clean::FunctionItem(ref func) | clean::ForeignFunctionItem(ref func)
|
||||
if func.header.unsafety == hir::Unsafety::Unsafe =>
|
||||
clean::FunctionItem(_) | clean::ForeignFunctionItem(_)
|
||||
if myitem.fn_header(cx.tcx()).unwrap().unsafety
|
||||
== hir::Unsafety::Unsafe =>
|
||||
{
|
||||
"<a title=\"unsafe function\" href=\"#\"><sup>⚠</sup></a>"
|
||||
}
|
||||
|
@ -453,16 +454,17 @@ fn extra_info_tags(item: &clean::Item, parent: &clean::Item, tcx: TyCtxt<'_>) ->
|
|||
}
|
||||
|
||||
fn item_function(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, f: &clean::Function) {
|
||||
let vis = it.visibility.print_with_space(it.def_id, cx).to_string();
|
||||
let constness = print_constness_with_space(&f.header.constness, it.const_stability(cx.tcx()));
|
||||
let asyncness = f.header.asyncness.print_with_space();
|
||||
let unsafety = f.header.unsafety.print_with_space();
|
||||
let abi = print_abi_with_space(f.header.abi).to_string();
|
||||
let header = it.fn_header(cx.tcx()).expect("printing a function which isn't a function");
|
||||
let constness = print_constness_with_space(&header.constness, it.const_stability(cx.tcx()));
|
||||
let unsafety = header.unsafety.print_with_space().to_string();
|
||||
let abi = print_abi_with_space(header.abi).to_string();
|
||||
let asyncness = header.asyncness.print_with_space();
|
||||
let visibility = it.visibility.print_with_space(it.def_id, cx).to_string();
|
||||
let name = it.name.unwrap();
|
||||
|
||||
let generics_len = format!("{:#}", f.generics.print(cx)).len();
|
||||
let header_len = "fn ".len()
|
||||
+ vis.len()
|
||||
+ visibility.len()
|
||||
+ constness.len()
|
||||
+ asyncness.len()
|
||||
+ unsafety.len()
|
||||
|
@ -478,7 +480,7 @@ fn item_function(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, f: &clean::
|
|||
w,
|
||||
"{vis}{constness}{asyncness}{unsafety}{abi}fn \
|
||||
{name}{generics}{decl}{notable_traits}{where_clause}",
|
||||
vis = vis,
|
||||
vis = visibility,
|
||||
constness = constness,
|
||||
asyncness = asyncness,
|
||||
unsafety = unsafety,
|
||||
|
@ -486,7 +488,7 @@ fn item_function(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, f: &clean::
|
|||
name = name,
|
||||
generics = f.generics.print(cx),
|
||||
where_clause = print_where_clause(&f.generics, cx, 0, true),
|
||||
decl = f.decl.full_print(header_len, 0, f.header.asyncness, cx),
|
||||
decl = f.decl.full_print(header_len, 0, header.asyncness, cx),
|
||||
notable_traits = notable_traits_decl(&f.decl, cx),
|
||||
);
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue