Parse async fn header.
This is gated on edition 2018 & the `async_await` feature gate. The parser will accept `async fn` and `async unsafe fn` as fn items. Along the same lines as `const fn`, only `async unsafe fn` is permitted, not `unsafe async fn`.The parser will not accept `async` functions as trait methods. To do a little code clean up, four fields of the function type struct have been merged into the new `FnHeader` struct: constness, asyncness, unsafety, and ABI. Also, a small bug in HIR printing is fixed: it previously printed `const unsafe fn` as `unsafe const fn`, which is grammatically incorrect.
This commit is contained in:
parent
4b17d31f11
commit
18ff7d091a
33 changed files with 367 additions and 288 deletions
|
@ -62,7 +62,6 @@ use rustc::middle::stability;
|
|||
use rustc::hir;
|
||||
use rustc::util::nodemap::{FxHashMap, FxHashSet};
|
||||
use rustc_data_structures::flock;
|
||||
use rustc_target::spec::abi;
|
||||
|
||||
use clean::{self, AttributesExt, GetDefId, SelfTy, Mutability};
|
||||
use doctree;
|
||||
|
@ -2405,7 +2404,7 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context,
|
|||
|
||||
let unsafety_flag = match myitem.inner {
|
||||
clean::FunctionItem(ref func) | clean::ForeignFunctionItem(ref func)
|
||||
if func.unsafety == hir::Unsafety::Unsafe => {
|
||||
if func.header.unsafety == hir::Unsafety::Unsafe => {
|
||||
"<a title='unsafe function' href='#'><sup>⚠</sup></a>"
|
||||
}
|
||||
_ => "",
|
||||
|
@ -2577,9 +2576,9 @@ fn item_function(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
|
|||
f: &clean::Function) -> fmt::Result {
|
||||
let name_len = format!("{}{}{}{:#}fn {}{:#}",
|
||||
VisSpace(&it.visibility),
|
||||
ConstnessSpace(f.constness),
|
||||
UnsafetySpace(f.unsafety),
|
||||
AbiSpace(f.abi),
|
||||
ConstnessSpace(f.header.constness),
|
||||
UnsafetySpace(f.header.unsafety),
|
||||
AbiSpace(f.header.abi),
|
||||
it.name.as_ref().unwrap(),
|
||||
f.generics).len();
|
||||
write!(w, "{}<pre class='rust fn'>", render_spotlight_traits(it)?)?;
|
||||
|
@ -2587,9 +2586,9 @@ fn item_function(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
|
|||
write!(w,
|
||||
"{vis}{constness}{unsafety}{abi}fn {name}{generics}{decl}{where_clause}</pre>",
|
||||
vis = VisSpace(&it.visibility),
|
||||
constness = ConstnessSpace(f.constness),
|
||||
unsafety = UnsafetySpace(f.unsafety),
|
||||
abi = AbiSpace(f.abi),
|
||||
constness = ConstnessSpace(f.header.constness),
|
||||
unsafety = UnsafetySpace(f.header.unsafety),
|
||||
abi = AbiSpace(f.header.abi),
|
||||
name = it.name.as_ref().unwrap(),
|
||||
generics = f.generics,
|
||||
where_clause = WhereClause { gens: &f.generics, indent: 0, end_newline: true },
|
||||
|
@ -2999,9 +2998,7 @@ fn render_assoc_item(w: &mut fmt::Formatter,
|
|||
parent: ItemType) -> fmt::Result {
|
||||
fn method(w: &mut fmt::Formatter,
|
||||
meth: &clean::Item,
|
||||
unsafety: hir::Unsafety,
|
||||
constness: hir::Constness,
|
||||
abi: abi::Abi,
|
||||
header: hir::FnHeader,
|
||||
g: &clean::Generics,
|
||||
d: &clean::FnDecl,
|
||||
link: AssocItemLink,
|
||||
|
@ -3026,9 +3023,9 @@ fn render_assoc_item(w: &mut fmt::Formatter,
|
|||
};
|
||||
let mut head_len = format!("{}{}{}{:#}fn {}{:#}",
|
||||
VisSpace(&meth.visibility),
|
||||
ConstnessSpace(constness),
|
||||
UnsafetySpace(unsafety),
|
||||
AbiSpace(abi),
|
||||
ConstnessSpace(header.constness),
|
||||
UnsafetySpace(header.unsafety),
|
||||
AbiSpace(header.abi),
|
||||
name,
|
||||
*g).len();
|
||||
let (indent, end_newline) = if parent == ItemType::Trait {
|
||||
|
@ -3041,9 +3038,9 @@ fn render_assoc_item(w: &mut fmt::Formatter,
|
|||
write!(w, "{}{}{}{}fn <a href='{href}' class='fnname'>{name}</a>\
|
||||
{generics}{decl}{where_clause}",
|
||||
VisSpace(&meth.visibility),
|
||||
ConstnessSpace(constness),
|
||||
UnsafetySpace(unsafety),
|
||||
AbiSpace(abi),
|
||||
ConstnessSpace(header.constness),
|
||||
UnsafetySpace(header.unsafety),
|
||||
AbiSpace(header.abi),
|
||||
href = href,
|
||||
name = name,
|
||||
generics = *g,
|
||||
|
@ -3061,12 +3058,10 @@ fn render_assoc_item(w: &mut fmt::Formatter,
|
|||
match item.inner {
|
||||
clean::StrippedItem(..) => Ok(()),
|
||||
clean::TyMethodItem(ref m) => {
|
||||
method(w, item, m.unsafety, hir::Constness::NotConst,
|
||||
m.abi, &m.generics, &m.decl, link, parent)
|
||||
method(w, item, m.header, &m.generics, &m.decl, link, parent)
|
||||
}
|
||||
clean::MethodItem(ref m) => {
|
||||
method(w, item, m.unsafety, m.constness,
|
||||
m.abi, &m.generics, &m.decl, link, parent)
|
||||
method(w, item, m.header, &m.generics, &m.decl, link, parent)
|
||||
}
|
||||
clean::AssociatedConstItem(ref ty, ref default) => {
|
||||
assoc_const(w, item, ty, default.as_ref(), link)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue