diff options
| author | bors <bors@rust-lang.org> | 2022-03-29 12:49:03 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-03-29 12:49:03 +0000 |
| commit | 11909e3588319235e28e99294e17cca11db1d7e2 (patch) | |
| tree | 87b405abf60210044785f568e7f1f95e7d671b3c /src/librustdoc/html/render | |
| parent | e2301ca54320659835467072f37201591db959b5 (diff) | |
| parent | 8071332d833073fca42ee128d25f49ee140229eb (diff) | |
| download | rust-11909e3588319235e28e99294e17cca11db1d7e2.tar.gz rust-11909e3588319235e28e99294e17cca11db1d7e2.zip | |
Auto merge of #95096 - GuillaumeGomez:rm-header-fn-field, r=camelid
Remove header field from clean::Function Fixes https://github.com/rust-lang/rust/issues/89673. This is another take on https://github.com/rust-lang/rust/issues/89673 (compared to https://github.com/rust-lang/rust/pull/91217) but very different on the approach: I moved the header call in one place but still require to have the `clean::Item` so I can use the `DefId` to get what is missing. cc `@jyn514` (you reviewed the original so maybe you want to take a look?) r? `@camelid`
Diffstat (limited to 'src/librustdoc/html/render')
| -rw-r--r-- | src/librustdoc/html/render/mod.rs | 7 | ||||
| -rw-r--r-- | src/librustdoc/html/render/print_item.rs | 22 |
2 files changed, 15 insertions, 14 deletions
diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index 3666767a9d9..93b33b0d609 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -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) diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs index efeb2e0d463..6c9a5a955d7 100644 --- a/src/librustdoc/html/render/print_item.rs +++ b/src/librustdoc/html/render/print_item.rs @@ -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>" } @@ -462,16 +463,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() @@ -487,7 +489,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, @@ -495,7 +497,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), ); }); |
