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 14 pull requests #74195

Merged
merged 42 commits into from
Jul 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
049f6ea
Fixing broken link for the Eq trait
poliorcetics Jun 12, 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
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
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
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
0965443
Remove unneeded ToString import in liballoc slice
pickfire Jul 8, 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
81c5bb6
Eliminate confusing "globals" terminology.
nnethercote Jul 6, 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
5fc46fa
Rollup merge of #73292 - poliorcetics:fix-link-in-partialeq, r=Dylan-DPC
Manishearth Jul 9, 2020
d163524
Rollup merge of #73791 - Manishearth:parens-intra-doc, r=GuillaumeGom…
Manishearth Jul 9, 2020
65ac394
Rollup merge of #74070 - eddyb:forall-tcx-providers, r=nikomatsakis
Manishearth Jul 9, 2020
07301e3
Rollup merge of #74077 - sethp:docs/fix-intra-doc-primitive-link, r=j…
Manishearth Jul 9, 2020
89c9e97
Rollup merge of #74079 - nnethercote:session-globals, r=nikomatsakis
Manishearth Jul 9, 2020
38541b7
Rollup merge of #74107 - nbdd0121:rustdoc, r=GuillaumeGomez
Manishearth Jul 9, 2020
640569c
Rollup merge of #74136 - JohnTitor:index-page-link, r=GuillaumeGomez
Manishearth Jul 9, 2020
178cdc5
Rollup merge of #74137 - ehuss:update-cargo, r=ehuss
Manishearth Jul 9, 2020
887f9e7
Rollup merge of #74142 - pickfire:patch-1, r=dtolnay
Manishearth Jul 9, 2020
2d432ae
Rollup merge of #74143 - pickfire:patch-2, r=jonas-schievink
Manishearth Jul 9, 2020
089a6e1
Rollup merge of #74146 - RalfJung:miri, r=RalfJung
Manishearth Jul 9, 2020
d4d1111
Rollup merge of #74150 - tamird:blocklist, r=nikomatsakis
Manishearth Jul 9, 2020
31d53de
Rollup merge of #74184 - Manishearth:doc-intra-doc, r=GuillaumeGomez
Manishearth Jul 9, 2020
9353e21
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
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
8 changes: 3 additions & 5 deletions src/liballoc/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,6 @@ pub use hack::to_vec;
// `test_permutations` test
mod hack {
use crate::boxed::Box;
#[cfg(test)]
use crate::string::ToString;
use crate::vec::Vec;

// We shouldn't add inline attribute to this since this is used in
Expand All @@ -156,9 +154,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
42 changes: 24 additions & 18 deletions src/librustc_ast/attr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,55 +21,61 @@ use log::debug;
use std::iter;
use std::ops::DerefMut;

pub struct Globals {
// Per-session global variables: this struct is stored in thread-local storage
// in such a way that it is accessible without any kind of handle to all
// threads within the compilation session, but is not accessible outside the
// session.
pub struct SessionGlobals {
used_attrs: Lock<GrowableBitSet<AttrId>>,
known_attrs: Lock<GrowableBitSet<AttrId>>,
rustc_span_globals: rustc_span::Globals,
span_session_globals: rustc_span::SessionGlobals,
}

impl Globals {
fn new(edition: Edition) -> Globals {
Globals {
impl SessionGlobals {
fn new(edition: Edition) -> SessionGlobals {
SessionGlobals {
// We have no idea how many attributes there will be, so just
// initiate the vectors with 0 bits. We'll grow them as necessary.
used_attrs: Lock::new(GrowableBitSet::new_empty()),
known_attrs: Lock::new(GrowableBitSet::new_empty()),
rustc_span_globals: rustc_span::Globals::new(edition),
span_session_globals: rustc_span::SessionGlobals::new(edition),
}
}
}

pub fn with_globals<R>(edition: Edition, f: impl FnOnce() -> R) -> R {
let globals = Globals::new(edition);
GLOBALS.set(&globals, || rustc_span::GLOBALS.set(&globals.rustc_span_globals, f))
pub fn with_session_globals<R>(edition: Edition, f: impl FnOnce() -> R) -> R {
let ast_session_globals = SessionGlobals::new(edition);
SESSION_GLOBALS.set(&ast_session_globals, || {
rustc_span::SESSION_GLOBALS.set(&ast_session_globals.span_session_globals, f)
})
}

pub fn with_default_globals<R>(f: impl FnOnce() -> R) -> R {
with_globals(DEFAULT_EDITION, f)
pub fn with_default_session_globals<R>(f: impl FnOnce() -> R) -> R {
with_session_globals(DEFAULT_EDITION, f)
}

scoped_tls::scoped_thread_local!(pub static GLOBALS: Globals);
scoped_tls::scoped_thread_local!(pub static SESSION_GLOBALS: SessionGlobals);

pub fn mark_used(attr: &Attribute) {
debug!("marking {:?} as used", attr);
GLOBALS.with(|globals| {
globals.used_attrs.lock().insert(attr.id);
SESSION_GLOBALS.with(|session_globals| {
session_globals.used_attrs.lock().insert(attr.id);
});
}

pub fn is_used(attr: &Attribute) -> bool {
GLOBALS.with(|globals| globals.used_attrs.lock().contains(attr.id))
SESSION_GLOBALS.with(|session_globals| session_globals.used_attrs.lock().contains(attr.id))
}

pub fn mark_known(attr: &Attribute) {
debug!("marking {:?} as known", attr);
GLOBALS.with(|globals| {
globals.known_attrs.lock().insert(attr.id);
SESSION_GLOBALS.with(|session_globals| {
session_globals.known_attrs.lock().insert(attr.id);
});
}

pub fn is_known(attr: &Attribute) -> bool {
GLOBALS.with(|globals| globals.known_attrs.lock().contains(attr.id))
SESSION_GLOBALS.with(|session_globals| session_globals.known_attrs.lock().contains(attr.id))
}

pub fn is_known_lint_tool(m_item: Ident) -> bool {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_ast/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub mod util {

pub mod ast;
pub mod attr;
pub use attr::{with_default_globals, with_globals, GLOBALS};
pub use attr::{with_default_session_globals, with_session_globals, SESSION_GLOBALS};
pub mod crate_disambiguator;
pub mod entry;
pub mod expand;
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_ast/util/lev_distance/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ fn test_lev_distance() {

#[test]
fn test_find_best_match_for_name() {
use crate::with_default_globals;
with_default_globals(|| {
use crate::with_default_session_globals;
with_default_session_globals(|| {
let input = vec![Symbol::intern("aaab"), Symbol::intern("aaabc")];
assert_eq!(
find_best_match_for_name(input.iter(), "aaaa", None),
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_ast_pretty/pprust/tests.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::*;

use rustc_ast::ast;
use rustc_ast::with_default_globals;
use rustc_ast::with_default_session_globals;
use rustc_span::source_map::respan;
use rustc_span::symbol::Ident;

Expand All @@ -25,7 +25,7 @@ fn variant_to_string(var: &ast::Variant) -> String {

#[test]
fn test_fun_to_string() {
with_default_globals(|| {
with_default_session_globals(|| {
let abba_ident = Ident::from_str("abba");

let decl =
Expand All @@ -40,7 +40,7 @@ fn test_fun_to_string() {

#[test]
fn test_variant_to_string() {
with_default_globals(|| {
with_default_session_globals(|| {
let ident = Ident::from_str("principal_skinner");

let var = ast::Variant {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_codegen_llvm/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ pub fn from_fn_attrs(cx: &CodegenCx<'ll, 'tcx>, llfn: &'ll Value, instance: ty::
}
}

pub fn provide(providers: &mut Providers<'_>) {
pub fn provide(providers: &mut Providers) {
providers.target_features_whitelist = |tcx, cnum| {
assert_eq!(cnum, LOCAL_CRATE);
if tcx.sess.opts.actually_rustdoc {
Expand All @@ -360,7 +360,7 @@ pub fn provide(providers: &mut Providers<'_>) {
provide_extern(providers);
}

pub fn provide_extern(providers: &mut Providers<'_>) {
pub fn provide_extern(providers: &mut Providers) {
providers.wasm_import_module_map = |tcx, cnum| {
// Build up a map from DefId to a `NativeLib` structure, where
// `NativeLib` internally contains information about
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_codegen_llvm/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,11 +241,11 @@ impl CodegenBackend for LlvmCodegenBackend {
Box::new(metadata::LlvmMetadataLoader)
}

fn provide(&self, providers: &mut ty::query::Providers<'_>) {
fn provide(&self, providers: &mut ty::query::Providers) {
attributes::provide(providers);
}

fn provide_extern(&self, providers: &mut ty::query::Providers<'_>) {
fn provide_extern(&self, providers: &mut ty::query::Providers) {
attributes::provide_extern(providers);
}

Expand Down
8 changes: 4 additions & 4 deletions src/librustc_codegen_ssa/back/symbol_export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,9 @@ fn is_reachable_non_generic_provider_extern(tcx: TyCtxt<'_>, def_id: DefId) -> b
}

fn exported_symbols_provider_local(
tcx: TyCtxt<'_>,
tcx: TyCtxt<'tcx>,
cnum: CrateNum,
) -> &'tcx [(ExportedSymbol<'_>, SymbolExportLevel)] {
) -> &'tcx [(ExportedSymbol<'tcx>, SymbolExportLevel)] {
assert_eq!(cnum, LOCAL_CRATE);

if !tcx.sess.opts.output_types.should_codegen() {
Expand Down Expand Up @@ -366,7 +366,7 @@ fn is_unreachable_local_definition_provider(tcx: TyCtxt<'_>, def_id: DefId) -> b
}
}

pub fn provide(providers: &mut Providers<'_>) {
pub fn provide(providers: &mut Providers) {
providers.reachable_non_generics = reachable_non_generics_provider;
providers.is_reachable_non_generic = is_reachable_non_generic_provider_local;
providers.exported_symbols = exported_symbols_provider_local;
Expand All @@ -375,7 +375,7 @@ pub fn provide(providers: &mut Providers<'_>) {
providers.upstream_drop_glue_for = upstream_drop_glue_for_provider;
}

pub fn provide_extern(providers: &mut Providers<'_>) {
pub fn provide_extern(providers: &mut Providers) {
providers.is_reachable_non_generic = is_reachable_non_generic_provider_extern;
providers.upstream_monomorphizations_for = upstream_monomorphizations_for_provider;
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_ssa/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,7 @@ impl CrateInfo {
}
}

pub fn provide_both(providers: &mut Providers<'_>) {
pub fn provide_both(providers: &mut Providers) {
providers.backend_optimization_level = |tcx, cratenum| {
let for_speed = match tcx.sess.opts.optimize {
// If globally no optimisation is done, #[optimize] has no effect.
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_codegen_ssa/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,12 @@ pub struct CodegenResults {
pub crate_info: CrateInfo,
}

pub fn provide(providers: &mut Providers<'_>) {
pub fn provide(providers: &mut Providers) {
crate::back::symbol_export::provide(providers);
crate::base::provide_both(providers);
}

pub fn provide_extern(providers: &mut Providers<'_>) {
pub fn provide_extern(providers: &mut Providers) {
crate::back::symbol_export::provide_extern(providers);
crate::base::provide_both(providers);
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_codegen_ssa/traits/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ pub trait CodegenBackend {
fn print_version(&self) {}

fn metadata_loader(&self) -> Box<MetadataLoaderDyn>;
fn provide(&self, _providers: &mut Providers<'_>);
fn provide_extern(&self, _providers: &mut Providers<'_>);
fn provide(&self, _providers: &mut Providers);
fn provide_extern(&self, _providers: &mut Providers);
fn codegen_crate<'tcx>(
&self,
tcx: TyCtxt<'tcx>,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_error_codes/error_codes/E0570.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The requested ABI is unsupported by the current target.

The rust compiler maintains for each target a blacklist of ABIs unsupported on
The rust compiler maintains for each target a list of unsupported ABIs on
that target. If an ABI is present in such a list this usually means that the
target / ABI combination is currently unsupported by llvm.

Expand Down
8 changes: 4 additions & 4 deletions src/librustc_errors/json/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,16 @@ impl<T: Write> Write for Shared<T> {
}
}

fn with_default_globals(f: impl FnOnce()) {
let globals = rustc_span::Globals::new(rustc_span::edition::DEFAULT_EDITION);
rustc_span::GLOBALS.set(&globals, || rustc_span::GLOBALS.set(&globals, f))
fn with_default_session_globals(f: impl FnOnce()) {
let session_globals = rustc_span::SessionGlobals::new(rustc_span::edition::DEFAULT_EDITION);
rustc_span::SESSION_GLOBALS.set(&session_globals, f);
}

/// Test the span yields correct positions in JSON.
fn test_positions(code: &str, span: (u32, u32), expected_output: SpanTestData) {
let expected_output = TestData { spans: vec![expected_output] };

with_default_globals(|| {
with_default_session_globals(|| {
let sm = Lrc::new(SourceMap::new(FilePathMapping::empty()));
sm.new_source_file(Path::new("test.rs").to_owned().into(), code.to_owned());

Expand Down
Loading