Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 16 pull requests #58361

Merged
merged 36 commits into from
Feb 11, 2019
Merged
Changes from 2 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
7cdcdb5
Update reference of rlibc crate to compiler-builtins crate
king6cong Jan 2, 2019
5581207
Remove outdated comment
king6cong Jan 9, 2019
87f5a98
Use `to_ne_bytes` for converting IPv4Address to octets
JakubOnderka Jan 18, 2019
b4d3c87
Tiny improvement to docs for `core::convert`.
icefoxen Jan 26, 2019
bd4df0c
Add Cargo.lock automatically adding message
h-michael Feb 4, 2019
4deb595
display sugared return types for async functions
euclio Feb 5, 2019
1d05f81
Add #[must_use] message to Fn* traits
taiki-e Feb 7, 2019
541503a
std::sys::unix::stdio: explain why we do into_raw
RalfJung Feb 8, 2019
b962ecc
Cleanup JS a bit
GuillaumeGomez Feb 8, 2019
caf7126
Some writing improvement, conciseness of intro
hayekr Feb 9, 2019
66adf52
miri: give non-generic functions a stable address
RalfJung Feb 9, 2019
a01efbc
operand-to-place copies should never be overlapping
RalfJung Feb 9, 2019
3a3691f
when there are multiple filenames, print what got interpreted as 2nd …
RalfJung Feb 10, 2019
adb3300
rpath computation: explain why we pop()
RalfJung Feb 10, 2019
55f90c7
Fix failing tidy (line endings on Windows)
petrochenkov Feb 10, 2019
74e97f3
Add trait alias support in rustdoc
GuillaumeGomez Feb 5, 2019
29354dd
Add style for trait aliases
GuillaumeGomez Feb 7, 2019
c20357a
Add trait aliases to js types
GuillaumeGomez Feb 7, 2019
eaf81c2
miri value visitor: use in macro
RalfJung Feb 10, 2019
b1d82ac
Remove spotlight for trait aliases and fix nits
GuillaumeGomez Feb 10, 2019
e917f8b
Rollup merge of #57259 - king6cong:master, r=alexcrichton
GuillaumeGomez Feb 10, 2019
d9f9780
Rollup merge of #57740 - JakubOnderka:ipv4addr-to_ne_bytes, r=scottmcm
GuillaumeGomez Feb 10, 2019
82e051b
Rollup merge of #57926 - icefoxen:test-doc-pr, r=frewsxcv
GuillaumeGomez Feb 10, 2019
a74e4f7
Rollup merge of #58157 - h-michael:cargo-lock, r=alexcrichton
GuillaumeGomez Feb 10, 2019
cdbd07c
Rollup merge of #58203 - euclio:rustdoc-async, r=GuillaumeGomez
GuillaumeGomez Feb 10, 2019
adf516b
Rollup merge of #58243 - GuillaumeGomez:trait-alias-docs, r=Manishearth
GuillaumeGomez Feb 10, 2019
112629b
Rollup merge of #58262 - taiki-e:must_use, r=estebank
GuillaumeGomez Feb 10, 2019
d59ca59
Rollup merge of #58295 - RalfJung:stdio, r=alexcrichton
GuillaumeGomez Feb 10, 2019
d5a8b24
Rollup merge of #58297 - GuillaumeGomez:cleanup-js, r=QuietMisdreavus
GuillaumeGomez Feb 10, 2019
f4e7bc5
Rollup merge of #58317 - hayekr:patch-1, r=frewsxcv
GuillaumeGomez Feb 10, 2019
a09aa0f
Rollup merge of #58324 - RalfJung:fn-ptr-eq, r=oli-obk
GuillaumeGomez Feb 10, 2019
c3aa847
Rollup merge of #58332 - RalfJung:miri-copy-nonoverlapping, r=oli-obk
GuillaumeGomez Feb 10, 2019
53e9a65
Rollup merge of #58345 - RalfJung:2nd-filename, r=matthewjasper
GuillaumeGomez Feb 10, 2019
9ccfb74
Rollup merge of #58346 - RalfJung:rpath-pop, r=Mark-Simulacrum
GuillaumeGomez Feb 10, 2019
585f9a7
Rollup merge of #58350 - petrochenkov:embed, r=frewsxcv
GuillaumeGomez Feb 10, 2019
d792cef
Rollup merge of #58352 - RalfJung:macro, r=oli-obk
GuillaumeGomez Feb 10, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
@@ -1724,6 +1724,30 @@ impl FnDecl {
pub fn self_type(&self) -> Option<SelfTy> {
self.inputs.values.get(0).and_then(|v| v.to_self())
}

/// Returns the sugared return type for an async function.
///
/// For example, if the return type is `impl std::future::Future<Output = i32>`, this function
/// will return `i32`.
///
/// # Panics
///
/// This function will panic if the return type does not match the expected sugaring for async
/// functions.
pub fn sugared_async_return_type(&self) -> FunctionRetTy {
match &self.output {
FunctionRetTy::Return(Type::ImplTrait(bounds)) => {
match &bounds[0] {
GenericBound::TraitBound(PolyTrait { trait_, .. }, ..) => {
let bindings = trait_.bindings().unwrap();
FunctionRetTy::Return(bindings[0].ty.clone())
}
_ => panic!("unexpected desugaring of async function"),
}
}
_ => panic!("unexpected desugaring of async function"),
}
}
}

#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Eq, Debug, Hash)]
@@ -2282,6 +2306,21 @@ impl Type {
_ => None,
}
}

pub fn bindings(&self) -> Option<&[TypeBinding]> {
match *self {
ResolvedPath { ref path, .. } => {
path.segments.last().and_then(|seg| {
if let GenericArgs::AngleBracketed { ref bindings, .. } = seg.args {
Some(&**bindings)
} else {
None
}
})
}
_ => None
}
}
}

impl GetDefId for Type {
23 changes: 16 additions & 7 deletions src/librustdoc/html/format.rs
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@
//! assume that HTML output is desired, although it may be possible to redesign
//! them in the future to instead emit any format desired.

use std::borrow::Cow;
use std::fmt;

use rustc::hir::def_id::DefId;
@@ -44,14 +45,16 @@ pub struct GenericBounds<'a>(pub &'a [clean::GenericBound]);
pub struct CommaSep<'a, T: 'a>(pub &'a [T]);
pub struct AbiSpace(pub Abi);

/// Wrapper struct for properly emitting a method declaration.
pub struct Method<'a> {
/// Wrapper struct for properly emitting a function or method declaration.
pub struct Function<'a> {
/// The declaration to emit.
pub decl: &'a clean::FnDecl,
/// The length of the function's "name", used to determine line-wrapping.
pub name_len: usize,
/// The number of spaces to indent each successive line with, if line-wrapping is necessary.
pub indent: usize,
/// Whether the function is async or not.
pub asyncness: hir::IsAsync,
}

/// Wrapper struct for emitting a where clause from Generics.
@@ -829,9 +832,9 @@ impl fmt::Display for clean::FnDecl {
}
}

impl<'a> fmt::Display for Method<'a> {
impl<'a> fmt::Display for Function<'a> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let &Method { decl, name_len, indent } = self;
let &Function { decl, name_len, indent, asyncness } = self;
let amp = if f.alternate() { "&" } else { "&amp;" };
let mut args = String::new();
let mut args_plain = String::new();
@@ -891,11 +894,17 @@ impl<'a> fmt::Display for Method<'a> {
args_plain.push_str(", ...");
}

let arrow_plain = format!("{:#}", decl.output);
let output = if let hir::IsAsync::Async = asyncness {
Cow::Owned(decl.sugared_async_return_type())
} else {
Cow::Borrowed(&decl.output)
};

let arrow_plain = format!("{:#}", &output);
let arrow = if f.alternate() {
format!("{:#}", decl.output)
format!("{:#}", &output)
} else {
decl.output.to_string()
output.to_string()
};

let pad = " ".repeat(name_len);
8 changes: 5 additions & 3 deletions src/librustdoc/html/render.rs
Original file line number Diff line number Diff line change
@@ -62,7 +62,7 @@ use fold::DocFolder;
use html::escape::Escape;
use html::format::{AsyncSpace, ConstnessSpace};
use html::format::{GenericBounds, WhereClause, href, AbiSpace};
use html::format::{VisSpace, Method, UnsafetySpace, MutableSpace};
use html::format::{VisSpace, Function, UnsafetySpace, MutableSpace};
use html::format::fmt_impl_for_trait_page;
use html::item_type::ItemType;
use html::markdown::{self, Markdown, MarkdownHtml, MarkdownSummaryLine, ErrorCodes, IdMap};
@@ -2977,10 +2977,11 @@ fn item_function(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
name = it.name.as_ref().unwrap(),
generics = f.generics,
where_clause = WhereClause { gens: &f.generics, indent: 0, end_newline: true },
decl = Method {
decl = Function {
decl: &f.decl,
name_len,
indent: 0,
asyncness: f.header.asyncness,
})?;
document(w, cx, it)
}
@@ -3424,10 +3425,11 @@ fn render_assoc_item(w: &mut fmt::Formatter,
href = href,
name = name,
generics = *g,
decl = Method {
decl = Function {
decl: d,
name_len: head_len,
indent,
asyncness: header.asyncness,
},
where_clause = WhereClause {
gens: g,
35 changes: 28 additions & 7 deletions src/test/rustdoc/async-fn.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,35 @@
// edition:2018
// compile-flags:-Z unstable-options

// FIXME: once `--edition` is stable in rustdoc, remove that `compile-flags` directive

#![feature(async_await, futures_api)]

// @has async_fn/struct.S.html
// @has - '//code' 'pub async fn f()'
pub struct S;
// @has async_fn/fn.foo.html '//pre[@class="rust fn"]' 'pub async fn foo() -> Option<Foo>'
pub async fn foo() -> Option<Foo> {
None
}

// @has async_fn/fn.bar.html '//pre[@class="rust fn"]' 'pub async fn bar(a: i32, b: i32) -> i32'
pub async fn bar(a: i32, b: i32) -> i32 {
0
}

// @has async_fn/fn.baz.html '//pre[@class="rust fn"]' 'pub async fn baz<T>(a: T) -> T'
pub async fn baz<T>(a: T) -> T {
a
}

trait Bar {}

impl Bar for () {}

// @has async_fn/fn.quux.html '//pre[@class="rust fn"]' 'pub async fn quux() -> impl Bar'
pub async fn quux() -> impl Bar {
()
}

// @has async_fn/struct.Foo.html
// @matches - '//code' 'pub async fn f\(\)$'
pub struct Foo;

impl S {
impl Foo {
pub async fn f() {}
}