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 #74191

Closed
wants to merge 48 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
049f6ea
Fixing broken link for the Eq trait
poliorcetics Jun 12, 2020
8a2e376
Add Integer::{log,log2, log10}
yoshuawuyts Apr 6, 2020
f25811e
Replace early-bound normalization hack with per-query key/value type …
eddyb Jul 5, 2020
f07100a
Use for<'tcx> fn pointers in Providers, instead of having Providers<'…
eddyb Jul 5, 2020
81fbfc4
Use relative path for local links to primitives in libcore
sethp Jul 6, 2020
6cef103
Touch up checked_log PR
dtolnay Jul 6, 2020
ee3a0f8
Add guard to check for local `core` crate
sethp Jul 6, 2020
e0b69f2
Hide `&mut self` methods from Deref in sidebar
nbdd0121 Jul 6, 2020
5702e02
Only allow `repr(i128/u128)` on enum
nbdd0121 Jul 6, 2020
97867bb
Add UI test for issue 74082
nbdd0121 Jul 6, 2020
368aa6f
Add test for issue 74083
nbdd0121 Jul 6, 2020
33a5d00
Two new rustdoc tests for intra links
sethp Jul 7, 2020
165aecb
build extern docs as well
sethp Jul 7, 2020
865b930
Assert current behavior for links
sethp Jul 7, 2020
f258d98
ignore-tidy-linelength for @has assertions
sethp Jul 7, 2020
b50c13c
Update books
ehuss Jul 7, 2020
8d267db
Revert "Add guard to check for local `core` crate"
sethp Jul 7, 2020
dd07774
Fix broken link in rustdocdoc
JohnTitor Jul 7, 2020
7bc85e2
Liballoc use vec instead of vector
pickfire Jul 8, 2020
3c63fba
Correctly mark the ending span of a match arm
ayazhafiz Jul 7, 2020
9366458
Apply #![crate_type = "rlib"] directly to the linker
sethp Jul 8, 2020
1e567c1
Avoid "blacklist"
tamird Jul 8, 2020
56b6b44
Avoid running test on Windows platforms
sethp Jul 8, 2020
ca22091
Update cargo
ehuss Jul 7, 2020
35fae73
update miri
RalfJung Jul 9, 2020
09f51d4
Add docs for intra-doc-links
Manishearth Jun 27, 2020
271e2a9
Update src/doc/rustdoc/src/intra-doc-links.md
Manishearth Jul 9, 2020
08d3a74
Allow for parentheses after macro intra-doc-links
Manishearth Jun 27, 2020
fc6ee8f
Reduce indentation
estebank Jul 9, 2020
e771a4f
Tweak `::` -> `:` typo heuristic and reduce verbosity
estebank Jul 9, 2020
36a229b
Move to unstable section
Manishearth Jul 9, 2020
fe351e9
Add test
Manishearth Jul 9, 2020
9c7a750
Rollup merge of #70835 - yoshuawuyts:int-log2, r=dtolnay
Manishearth Jul 9, 2020
806cfce
Rollup merge of #73292 - poliorcetics:fix-link-in-partialeq, r=Dylan-DPC
Manishearth Jul 9, 2020
c191cd1
Rollup merge of #73791 - Manishearth:parens-intra-doc, r=GuillaumeGom…
Manishearth Jul 9, 2020
da25c24
Rollup merge of #74070 - eddyb:forall-tcx-providers, r=nikomatsakis
Manishearth Jul 9, 2020
d07bb64
Rollup merge of #74077 - sethp:docs/fix-intra-doc-primitive-link, r=j…
Manishearth Jul 9, 2020
69e30b5
Rollup merge of #74107 - nbdd0121:rustdoc, r=GuillaumeGomez
Manishearth Jul 9, 2020
60213e1
Rollup merge of #74109 - nbdd0121:issue-74082, r=petrochenkov
Manishearth Jul 9, 2020
8ec755c
Rollup merge of #74125 - ayazhafiz:i/74050, r=matthewjasper
Manishearth Jul 9, 2020
f4d530d
Rollup merge of #74135 - ehuss:update-books, r=ehuss
Manishearth Jul 9, 2020
6e58716
Rollup merge of #74136 - JohnTitor:index-page-link, r=GuillaumeGomez
Manishearth Jul 9, 2020
9646357
Rollup merge of #74137 - ehuss:update-cargo, r=ehuss
Manishearth Jul 9, 2020
f6dc620
Rollup merge of #74142 - pickfire:patch-1, r=dtolnay
Manishearth Jul 9, 2020
feaf996
Rollup merge of #74146 - RalfJung:miri, r=RalfJung
Manishearth Jul 9, 2020
71da131
Rollup merge of #74150 - tamird:blocklist, r=nikomatsakis
Manishearth Jul 9, 2020
997bf0e
Rollup merge of #74184 - Manishearth:doc-intra-doc, r=GuillaumeGomez
Manishearth Jul 9, 2020
7d81bb4
Rollup merge of #74188 - estebank:tweak-ascription-typo-heuristic, r=…
Manishearth Jul 9, 2020
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
2 changes: 1 addition & 1 deletion src/doc/embedded-book
2 changes: 1 addition & 1 deletion src/doc/reference
2 changes: 1 addition & 1 deletion src/doc/rust-by-example
74 changes: 43 additions & 31 deletions src/doc/rustdoc/src/unstable-features.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,50 +38,62 @@ future.
Attempting to use these error numbers on stable will result in the code sample being interpreted as
plain text.

### Linking to items by type
### Linking to items by name

As designed in [RFC 1946], Rustdoc can parse paths to items when you use them as links. To resolve
these type names, it uses the items currently in-scope, either by declaration or by `use` statement.
For modules, the "active scope" depends on whether the documentation is written outside the module
(as `///` comments on the `mod` statement) or inside the module (at `//!` comments inside the file
or block). For all other items, it uses the enclosing module's scope.
Rustdoc is capable of directly linking to other rustdoc pages in Markdown documentation using the path of item as a link.

[RFC 1946]: https://github.com/rust-lang/rfcs/pull/1946

For example, in the following code:
For example, in the following code all of the links will link to the rustdoc page for `Bar`:

```rust
/// Does the thing.
pub fn do_the_thing(_: SomeType) {
println!("Let's do the thing!");
}
/// This struct is not [Bar]
pub struct Foo1;

/// This struct is also not [bar](Bar)
pub struct Foo2;

/// This struct is also not [bar][b]
///
/// [b]: Bar
pub struct Foo3;

/// This struct is also not [`Bar`]
pub struct Foo4;

/// Token you use to [`do_the_thing`].
pub struct SomeType;
pub struct Bar;
```

The link to ``[`do_the_thing`]`` in `SomeType`'s docs will properly link to the page for `fn
do_the_thing`. Note that here, rustdoc will insert the link target for you, but manually writing the
target out also works:
You can refer to anything in scope, and use paths, including `Self`. You may also use `foo()` and `foo!()` to refer to methods/functions and macros respectively.

```rust
pub mod some_module {
/// Token you use to do the thing.
pub struct SomeStruct;
}
```rust,edition2018
use std::sync::mpsc::Receiver;

/// Does the thing. Requires one [`SomeStruct`] for the thing to work.
/// This is an version of [`Receiver`], with support for [`std::future`].
///
/// [`SomeStruct`]: some_module::SomeStruct
pub fn do_the_thing(_: some_module::SomeStruct) {
println!("Let's do the thing!");
/// You can obtain a [`std::future::Future`] by calling [`Self::recv()`].
pub struct AsyncReceiver<T> {
sender: Receiver<T>
}

impl<T> AsyncReceiver<T> {
pub async fn recv() -> T {
unimplemented!()
}
}
```

For more details, check out [the RFC][RFC 1946], and see [the tracking issue][43466] for more
information about what parts of the feature are available.
Paths in Rust have three namespaces: type, value, and macro. Items from these namespaces are allowed to overlap. In case of ambiguity, rustdoc will warn about the ambiguity and ask you to disambiguate, which can be done by using a prefix like `struct@`, `enum@`, `type@`, `trait@`, `union@`, `const@`, `static@`, `value@`, `function@`, `mod@`, `fn@`, `module@`, `method@` , `macro@`, or `derive@`:

```rust
/// See also: [`Foo`](struct@Foo)
struct Bar;

/// This is different from [`Foo`](fn@Foo)
struct Foo {}

fn Foo() {}
```

[43466]: https://github.com/rust-lang/rust/issues/43466
Note: Because of how `macro_rules` macros are scoped in Rust, the intra-doc links of a `macro_rules` macro will be resolved relative to the crate root, as opposed to the module it is defined in.

## Extensions to the `#[doc]` attribute

Expand Down Expand Up @@ -321,7 +333,7 @@ library, as an equivalent command-line argument is provided to `rustc` when buil
### `--index-page`: provide a top-level landing page for docs

This feature allows you to generate an index-page with a given markdown file. A good example of it
is the [rust documentation index](https://doc.rust-lang.org/index.html).
is the [rust documentation index](https://doc.rust-lang.org/nightly/index.html).

With this, you'll have a page which you can custom as much as you want at the top of your crates.

Expand Down
6 changes: 3 additions & 3 deletions src/liballoc/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@ mod hack {
where
T: Clone,
{
let mut vector = Vec::with_capacity(s.len());
vector.extend_from_slice(s);
vector
let mut vec = Vec::with_capacity(s.len());
vec.extend_from_slice(s);
vec
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/libcore/cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use self::Ordering::*;
///
/// This trait allows for partial equality, for types that do not have a full
/// equivalence relation. For example, in floating point numbers `NaN != NaN`,
/// so floating point types implement `PartialEq` but not [`Eq`].
/// so floating point types implement `PartialEq` but not [`Eq`](Eq).
///
/// Formally, the equality must be (for all `a`, `b` and `c`):
///
Expand Down Expand Up @@ -191,7 +191,6 @@ use self::Ordering::*;
/// assert_eq!(x.eq(&y), false);
/// ```
///
/// [`Eq`]: Eq
/// [`eq`]: PartialEq::eq
/// [`ne`]: PartialEq::ne
#[lang = "eq"]
Expand Down
218 changes: 218 additions & 0 deletions src/libcore/num/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2160,6 +2160,115 @@ assert_eq!((-a).rem_euclid(-b), 1);
}
}

doc_comment! {
concat!("Returns the logarithm of the number with respect to an arbitrary base.

Returns `None` if the number is negative or zero, or if the base is not at least 2.

This method may not be optimized owing to implementation details;
`self.checked_log2()` can produce results more efficiently for base 2, and
`self.checked_log10()` can produce results more efficiently for base 10.

# Examples

```
#![feature(int_log)]

let five = 5", stringify!($SelfT), ";

// log5(5) == 1
let result = five.checked_log(5);

assert_eq!(result, Some(1));
```"),
#[unstable(feature = "int_log", issue = "70887")]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline]
pub fn checked_log(self, base: Self) -> Option<Self> {
// SAFETY: We check the input to this is always positive
let logb2 = |x: Self| unsafe { intrinsics::ctlz_nonzero(1 as Self) - intrinsics::ctlz_nonzero(x) };

if self <= 0 || base <= 1 {
None
} else {
let mut n = 0;
let mut r = self;

// Optimization for 128 bit wide integers.
if mem::size_of::<Self>() * 8 == 128 {
let b = logb2(self) / (logb2(base) + 1);
n += b;
r /= base.pow(b as u32);
}

while r >= base {
r /= base;
n += 1;
}
Some(n)
}
}
}

doc_comment! {
concat!("Returns the base 2 logarithm of the number.

Returns `None` if the number is negative or zero.

# Examples

```
#![feature(int_log)]

let two = 2", stringify!($SelfT), ";

// checked_log2(2) == 1
let result = two.checked_log2();

assert_eq!(result, Some(1));
```"),
#[unstable(feature = "int_log", issue = "70887")]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline]
pub fn checked_log2(self) -> Option<Self> {
if self <= 0 {
None
} else {
// SAFETY: We just checked that this number is positive
let log = unsafe { intrinsics::ctlz_nonzero(1 as Self) - intrinsics::ctlz_nonzero(self) };
Some(log)
}
}
}

doc_comment! {
concat!("Returns the base 10 logarithm of the number.

Returns `None` if the number is negative or zero.

# Examples

```
#![feature(int_log)]

let ten = 10", stringify!($SelfT), ";

// checked_log10(10) == 1
let result = ten.checked_log10();

assert_eq!(result, Some(1));
```"),
#[unstable(feature = "int_log", issue = "70887")]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline]
pub fn checked_log10(self) -> Option<Self> {
self.checked_log(10)
}
}

doc_comment! {
concat!("Computes the absolute value of `self`.

Expand Down Expand Up @@ -4169,6 +4278,115 @@ assert_eq!(7", stringify!($SelfT), ".rem_euclid(4), 3); // or any other integer
}
}

doc_comment! {
concat!("Returns the logarithm of the number with respect to an arbitrary base.

Returns `None` if the number is zero, or if the base is not at least 2.

This method may not be optimized owing to implementation details;
`self.checked_log2()` can produce results more efficiently for base 2, and
`self.checked_log10()` can produce results more efficiently for base 10.

# Examples

```
#![feature(int_log)]

let five = 5", stringify!($SelfT), ";

// log5(5) == 1
let result = five.checked_log(5);

assert_eq!(result, Some(1));
```"),
#[unstable(feature = "int_log", issue = "70887")]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline]
pub fn checked_log(self, base: Self) -> Option<Self> {
// SAFETY: We check the input to this is always positive.
let logb2 = |x: Self| unsafe { intrinsics::ctlz_nonzero(1 as Self) - intrinsics::ctlz_nonzero(x) };

if self <= 0 || base <= 1 {
None
} else {
let mut n = 0;
let mut r = self;

// Optimization for 128 bit wide integers.
if mem::size_of::<Self>() * 8 == 128 {
let b = logb2(self) / (logb2(base) + 1);
n += b;
r /= base.pow(b as u32);
}

while r >= base {
r /= base;
n += 1;
}
Some(n)
}
}
}

doc_comment! {
concat!("Returns the base 2 logarithm of the number.

Returns `None` if the number is zero.

# Examples

```
#![feature(int_log)]

let two = 2", stringify!($SelfT), ";

// checked_log2(2) == 1
let result = two.checked_log2();

assert_eq!(result, Some(1));
```"),
#[unstable(feature = "int_log", issue = "70887")]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline]
pub fn checked_log2(self) -> Option<Self> {
if self <= 0 {
None
} else {
// SAFETY: We just checked that this number is positive
let log = unsafe { intrinsics::ctlz_nonzero(1 as Self) - intrinsics::ctlz_nonzero(self) };
Some(log)
}
}
}

doc_comment! {
concat!("Returns the base 10 logarithm of the number.

Returns `None` if the number is zero.

# Examples

```
#![feature(int_log)]

let ten = 10", stringify!($SelfT), ";

// checked_log10(10) == 1
let result = ten.checked_log10();

assert_eq!(result, Some(1));
```"),
#[unstable(feature = "int_log", issue = "70887")]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline]
pub fn checked_log10(self) -> Option<Self> {
self.checked_log(10)
}
}

doc_comment! {
concat!("Returns `true` if and only if `self == 2^k` for some `k`.

Expand Down
1 change: 1 addition & 0 deletions src/libcore/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#![feature(fmt_internals)]
#![feature(hashmap_internals)]
#![feature(try_find)]
#![feature(int_log)]
#![feature(is_sorted)]
#![feature(pattern)]
#![feature(range_is_empty)]
Expand Down
Loading