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 7 pull requests #33768

Merged
merged 20 commits into from
May 21, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
38e1797
rustdoc: Add doc snippets for trait impls, with a read more link
Manishearth May 17, 2016
8e94b04
rustdoc: Support short doc fallback for non-default items
Manishearth May 17, 2016
74633b0
Move read more link to same line
Manishearth May 18, 2016
519cc82
Book: small improvement to a table to make it clearer
royalstream May 19, 2016
2fd4e60
Clarify the English translation of `?Sized`
postmodern May 20, 2016
d021d7d
Keep line-width within 80 columns
postmodern May 20, 2016
d8c086b
Grammar change
postmodern May 20, 2016
e614bb7
book: ownership: fix typo
alx741 May 20, 2016
9ce018b
Update tests
Manishearth May 18, 2016
bbed89b
Update simd syntax
GuillaumeGomez May 20, 2016
bf8c070
Clarify docs for sort(&mut self)
dns2utf8 May 19, 2016
b9d1e76
update tracking issue for once_poison
durka May 12, 2016
71af58a
Wording changes
postmodern May 21, 2016
87a2288
Rollup merge of #33578 - durka:patch-21, r=alexcrichton
Manishearth May 21, 2016
3f4d915
Rollup merge of #33679 - Manishearth:rustdoc-readmore-impls, r=alexcr…
Manishearth May 21, 2016
0c949d8
Rollup merge of #33743 - royalstream:royalstream-stack-doc, r=stevekl…
Manishearth May 21, 2016
c57bb10
Rollup merge of #33746 - dns2utf8:doc_sort_memory, r=steveklabnik
Manishearth May 21, 2016
f262bb8
Rollup merge of #33747 - postmodern:patch-2, r=Manishearth
Manishearth May 21, 2016
197aa52
Rollup merge of #33750 - alx741:fix_typo, r=Manishearth
Manishearth May 21, 2016
61b9be7
Rollup merge of #33757 - GuillaumeGomez:simd, r=steveklabnik
Manishearth May 21, 2016
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
2 changes: 1 addition & 1 deletion src/doc/book/ownership.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ vector object and its data live in separate memory regions instead of being a
single contiguous memory allocation (due to reasons we will not go into at
this point of time). These two parts of the vector (the one on the stack and
one on the heap) must agree with each other at all times with regards to
things like the length, capacity etc.
things like the length, capacity, etc.

When we move `v` to `v2`, Rust actually does a bitwise copy of the vector
object `v` into the stack allocation represented by `v2`. This shallow copy
Expand Down
4 changes: 2 additions & 2 deletions src/doc/book/the-stack-and-the-heap.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ And then `bold()` calls `italic()`:
| **2** | **b**|**100**|
| **1** | **a**| **5** |
| 0 | x | 42 |

Whew! Our stack is growing tall.

After `italic()` is over, its frame is deallocated, leaving only `bold()` and
Expand Down Expand Up @@ -260,8 +261,7 @@ layout of a program which has been running for a while now:
| (2<sup>30</sup>) - 3 | | |
| (2<sup>30</sup>) - 4 | | 42 |
| ... | ... | ... |
| 3 | y | → (2<sup>30</sup>) - 4 |
| 2 | y | 42 |
| 2 | z | → (2<sup>30</sup>) - 4 |
| 1 | y | 42 |
| 0 | x | → (2<sup>30</sup>) - 1 |

Expand Down
9 changes: 5 additions & 4 deletions src/doc/book/unsized-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,15 @@ pointers, can use this `impl`.
# ?Sized

If you want to write a function that accepts a dynamically sized type, you
can use the special bound, `?Sized`:
can use the special bound syntax, `?Sized`:

```rust
struct Foo<T: ?Sized> {
f: T,
}
```

This `?`, read as “T may be `Sized`”, means that this bound is special: it
lets us match more kinds, not less. It’s almost like every `T` implicitly has
`T: Sized`, and the `?` undoes this default.
This `?Sized`, read as “T may or may not be `Sized`”, which allows us to match
both sized and unsized types. All generic type parameters implicitly
have the `Sized` bound, so the `?Sized` can be used to opt-out of the implicit
bound.
11 changes: 4 additions & 7 deletions src/libcollections/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -779,11 +779,10 @@ impl<T> [T] {
core_slice::SliceExt::binary_search_by_key(self, b, f)
}

/// Sorts the slice, in place.
///
/// This is equivalent to `self.sort_by(|a, b| a.cmp(b))`.
///
/// This is a stable sort.
/// This sort is stable and `O(n log n)` worst-case but allocates
/// approximately `2 * n` where `n` is the length of `self`.
///
/// # Examples
///
Expand All @@ -804,11 +803,9 @@ impl<T> [T] {
/// Sorts the slice, in place, using `key` to extract a key by which to
/// order the sort by.
///
/// This sort is `O(n log n)` worst-case and stable, but allocates
/// This sort is stable and `O(n log n)` worst-case but allocates
/// approximately `2 * n`, where `n` is the length of `self`.
///
/// This is a stable sort.
///
/// # Examples
///
/// ```rust
Expand All @@ -828,7 +825,7 @@ impl<T> [T] {
/// Sorts the slice, in place, using `compare` to compare
/// elements.
///
/// This sort is `O(n log n)` worst-case and stable, but allocates
/// This sort is stable and `O(n log n)` worst-case but allocates
/// approximately `2 * n`, where `n` is the length of `self`.
///
/// # Examples
Expand Down
8 changes: 4 additions & 4 deletions src/librustc_typeck/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1002,18 +1002,18 @@ operate on.
This will cause an error:

```compile_fail
#![feature(simd)]
#![feature(repr_simd)]

#[simd]
#[repr(simd)]
struct Bad;
```

This will not:

```
#![feature(simd)]
#![feature(repr_simd)]

#[simd]
#[repr(simd)]
struct Good(u32);
```
"##,
Expand Down
55 changes: 43 additions & 12 deletions src/librustdoc/html/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1658,6 +1658,19 @@ fn document(w: &mut fmt::Formatter, cx: &Context, item: &clean::Item) -> fmt::Re
Ok(())
}

fn document_short(w: &mut fmt::Formatter, item: &clean::Item, link: AssocItemLink) -> fmt::Result {
if let Some(s) = item.doc_value() {
let markdown = if s.contains('\n') {
format!("{} [Read more]({})",
&plain_summary_line(Some(s)), naive_assoc_href(item, link))
} else {
format!("{}", &plain_summary_line(Some(s)))
};
write!(w, "<div class='docblock'>{}</div>", Markdown(&markdown))?;
}
Ok(())
}

fn item_module(w: &mut fmt::Formatter, cx: &Context,
item: &clean::Item, items: &[clean::Item]) -> fmt::Result {
document(w, cx, item)?;
Expand Down Expand Up @@ -2555,8 +2568,9 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi
}

fn doctraititem(w: &mut fmt::Formatter, cx: &Context, item: &clean::Item,
link: AssocItemLink, render_static: bool, is_default_item: bool,
outer_version: Option<&str>) -> fmt::Result {
link: AssocItemLink, render_static: bool,
is_default_item: bool, outer_version: Option<&str>,
trait_: Option<&clean::Trait>) -> fmt::Result {
let shortty = shortty(item);
let name = item.name.as_ref().unwrap();

Expand Down Expand Up @@ -2607,16 +2621,35 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi
_ => panic!("can't make docs for trait item with name {:?}", item.name)
}

if !is_default_item && (!is_static || render_static) {
document(w, cx, item)
} else {
Ok(())
if !is_static || render_static {
if !is_default_item {

if item.doc_value().is_some() {
document(w, cx, item)?;
} else {
// In case the item isn't documented,
// provide short documentation from the trait
if let Some(t) = trait_ {
if let Some(it) = t.items.iter()
.find(|i| i.name == item.name) {
document_short(w, it, link)?;
}
}
}
} else {
document_short(w, item, link)?;
}
}
Ok(())
}

let traits = &cache().traits;
let trait_ = i.trait_did().and_then(|did| traits.get(&did));

write!(w, "<div class='impl-items'>")?;
for trait_item in &i.inner_impl().items {
doctraititem(w, cx, trait_item, link, render_header, false, outer_version)?;
doctraititem(w, cx, trait_item, link, render_header,
false, outer_version, trait_)?;
}

fn render_default_items(w: &mut fmt::Formatter,
Expand All @@ -2634,17 +2667,15 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi
let assoc_link = AssocItemLink::GotoSource(did, &i.provided_trait_methods);

doctraititem(w, cx, trait_item, assoc_link, render_static, true,
outer_version)?;
outer_version, None)?;
}
Ok(())
}

// If we've implemented a trait, then also emit documentation for all
// default items which weren't overridden in the implementation block.
if let Some(did) = i.trait_did() {
if let Some(t) = cache().traits.get(&did) {
render_default_items(w, cx, t, &i.inner_impl(), render_header, outer_version)?;
}
if let Some(t) = trait_ {
render_default_items(w, cx, t, &i.inner_impl(), render_header, outer_version)?;
}
write!(w, "</div>")?;
Ok(())
Expand Down
6 changes: 3 additions & 3 deletions src/libstd/sync/once.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ unsafe impl Send for Once {}

/// State yielded to the `call_once_force` method which can be used to query
/// whether the `Once` was previously poisoned or not.
#[unstable(feature = "once_poison", issue = "31688")]
#[unstable(feature = "once_poison", issue = "33577")]
pub struct OnceState {
poisoned: bool,
}
Expand Down Expand Up @@ -218,7 +218,7 @@ impl Once {
/// The closure `f` is yielded a structure which can be used to query the
/// state of this `Once` (whether initialization has previously panicked or
/// not).
#[unstable(feature = "once_poison", issue = "31688")]
#[unstable(feature = "once_poison", issue = "33577")]
pub fn call_once_force<F>(&'static self, f: F) where F: FnOnce(&OnceState) {
// same as above, just with a different parameter to `call_inner`.
if self.state.load(Ordering::SeqCst) == COMPLETE {
Expand Down Expand Up @@ -360,7 +360,7 @@ impl OnceState {
///
/// Once an initalization routine for a `Once` has panicked it will forever
/// indicate to future forced initialization routines that it is poisoned.
#[unstable(feature = "once_poison", issue = "31688")]
#[unstable(feature = "once_poison", issue = "33577")]
pub fn poisoned(&self) -> bool {
self.poisoned
}
Expand Down
25 changes: 19 additions & 6 deletions src/test/rustdoc/manual_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,24 @@ pub trait T {
fn b_method(&self) -> usize {
self.a_method()
}

/// Docs associated with the trait c_method definition.
///
/// There is another line
fn c_method(&self) -> usize {
self.a_method()
}
}

// @has manual_impl/struct.S1.html '//*[@class="trait"]' 'T'
// @has - '//*[@class="docblock"]' 'Docs associated with the S1 trait implementation.'
// @has - '//*[@class="docblock"]' 'Docs associated with the S1 trait a_method implementation.'
// @!has - '//*[@class="docblock"]' 'Docs associated with the trait a_method definition.'
// @!has - '//*[@class="docblock"]' 'Docs associated with the trait b_method definition.'
// @has - '//*[@class="docblock"]' 'Docs associated with the trait b_method definition.'
// @has - '//*[@class="docblock"]' 'Docs associated with the trait b_method definition.'
// @has - '//*[@class="docblock"]' 'Docs associated with the trait c_method definition.'
// @!has - '//*[@class="docblock"]' 'There is another line'
// @has - '//*[@class="docblock"]' 'Read more'
pub struct S1(usize);

/// Docs associated with the S1 trait implementation.
Expand All @@ -41,9 +52,11 @@ impl T for S1 {
// @has manual_impl/struct.S2.html '//*[@class="trait"]' 'T'
// @has - '//*[@class="docblock"]' 'Docs associated with the S2 trait implementation.'
// @has - '//*[@class="docblock"]' 'Docs associated with the S2 trait a_method implementation.'
// @has - '//*[@class="docblock"]' 'Docs associated with the S2 trait b_method implementation.'
// @has - '//*[@class="docblock"]' 'Docs associated with the S2 trait c_method implementation.'
// @!has - '//*[@class="docblock"]' 'Docs associated with the trait a_method definition.'
// @!has - '//*[@class="docblock"]' 'Docs associated with the trait b_method definition.'
// @!has - '//*[@class="docblock"]' 'Docs associated with the trait c_method definition.'
// @has - '//*[@class="docblock"]' 'Docs associated with the trait b_method definition.'
// @!has - '//*[@class="docblock"]' 'Read more'
pub struct S2(usize);

/// Docs associated with the S2 trait implementation.
Expand All @@ -53,16 +66,16 @@ impl T for S2 {
self.0
}

/// Docs associated with the S2 trait b_method implementation.
fn b_method(&self) -> usize {
/// Docs associated with the S2 trait c_method implementation.
fn c_method(&self) -> usize {
5
}
}

// @has manual_impl/struct.S3.html '//*[@class="trait"]' 'T'
// @has - '//*[@class="docblock"]' 'Docs associated with the S3 trait implementation.'
// @has - '//*[@class="docblock"]' 'Docs associated with the S3 trait b_method implementation.'
// @!has - '//*[@class="docblock"]' 'Docs associated with the trait a_method definition.'
// @has - '//*[@class="docblock"]' 'Docs associated with the trait a_method definition.'
pub struct S3(usize);

/// Docs associated with the S3 trait implementation.
Expand Down