Skip to content

Commit

Permalink
Auto merge of #66680 - Centril:rollup-1ke3svj, r=Centril
Browse files Browse the repository at this point in the history
Rollup of 5 pull requests

Successful merges:

 - #61351 (Stabilize cfg(doc))
 - #66539 (Point at type in `let` assignment on type errors)
 - #66655 (rustdoc: Mark `--extern-private` as unstable)
 - #66657 (rustdoc: Don't panic when failing to write .lock file)
 - #66673 (Move def collector from `rustc` to `rustc_resolve`)

Failed merges:

r? @ghost
  • Loading branch information
bors committed Nov 23, 2019
2 parents 0c987c5 + c215de0 commit ad808d9
Show file tree
Hide file tree
Showing 119 changed files with 768 additions and 404 deletions.
1 change: 1 addition & 0 deletions src/doc/rustdoc/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
- [Documentation tests](documentation-tests.md)
- [Lints](lints.md)
- [Passes](passes.md)
- [Advanced Features](advanced-features.md)
- [Unstable features](unstable-features.md)
34 changes: 34 additions & 0 deletions src/doc/rustdoc/src/advanced-features.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Advanced Features

The features listed on this page fall outside the rest of the main categories.

## `#[cfg(doc)]`: Documenting platform-/feature-specific information

For conditional compilation, Rustdoc treats your crate the same way the compiler does: Only things
from the host target are available (or from the given `--target` if present), and everything else is
"filtered out" from the crate. This can cause problems if your crate is providing different things
on different targets and you want your documentation to reflect all the available items you
provide.

If you want to make sure an item is seen by Rustdoc regardless of what platform it's targeting,
you can apply `#[cfg(doc)]` to it. Rustdoc sets this whenever it's building documentation, so
anything that uses that flag will make it into documentation it generates. To apply this to an item
with other `#[cfg]` filters on it, you can write something like `#[cfg(any(windows, doc))]`.
This will preserve the item either when built normally on Windows, or when being documented
anywhere.

Please note that this feature is not passed to doctests.

Example:

```rust
/// Token struct that can only be used on Windows.
#[cfg(any(windows, doc))]
pub struct WindowsToken;
/// Token struct that can only be used on Unix.
#[cfg(any(unix, doc))]
pub struct UnixToken;
```

Here, the respective tokens can only be used by dependent crates on their respective platforms, but
they will both appear in documentation.
11 changes: 10 additions & 1 deletion src/librustc/hir/map/definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ pub struct Definitions {
/// we know what parent node that fragment should be attached to thanks to this table.
invocation_parents: FxHashMap<ExpnId, DefIndex>,
/// Indices of unnamed struct or variant fields with unresolved attributes.
pub(super) placeholder_field_indices: NodeMap<usize>,
placeholder_field_indices: NodeMap<usize>,
}

/// A unique identifier that we can use to lookup a definition
Expand Down Expand Up @@ -535,6 +535,15 @@ impl Definitions {
let old_parent = self.invocation_parents.insert(invoc_id, parent);
assert!(old_parent.is_none(), "parent `DefIndex` is reset for an invocation");
}

pub fn placeholder_field_index(&self, node_id: ast::NodeId) -> usize {
self.placeholder_field_indices[&node_id]
}

pub fn set_placeholder_field_index(&mut self, node_id: ast::NodeId, index: usize) {
let old_index = self.placeholder_field_indices.insert(node_id, index);
assert!(old_index.is_none(), "placeholder field index is reset for a node ID");
}
}

impl DefPathData {
Expand Down
2 changes: 0 additions & 2 deletions src/librustc/hir/map/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use self::collector::NodeCollector;
pub use self::def_collector::DefCollector;
pub use self::definitions::{
Definitions, DefKey, DefPath, DefPathData, DisambiguatedDefPathData, DefPathHash
};
Expand All @@ -25,7 +24,6 @@ use syntax_pos::{Span, DUMMY_SP};

pub mod blocks;
mod collector;
mod def_collector;
pub mod definitions;
mod hir_id_validator;

Expand Down
12 changes: 0 additions & 12 deletions src/librustc_data_structures/flock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,15 +298,3 @@ cfg_if! {
}
}
}

impl Lock {
pub fn panicking_new(p: &Path,
wait: bool,
create: bool,
exclusive: bool)
-> Lock {
Lock::new(p, wait, create, exclusive).unwrap_or_else(|err| {
panic!("could not lock `{}`: {}", p.display(), err);
})
}
}
5 changes: 2 additions & 3 deletions src/librustc_resolve/build_reduced_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
//! unexpanded macros in the fragment are visited and registered.
//! Imports are also considered items and placed into modules here, but not resolved yet.
use crate::def_collector::collect_definitions;
use crate::macros::{LegacyBinding, LegacyScope};
use crate::resolve_imports::ImportDirective;
use crate::resolve_imports::ImportDirectiveSubclass::{self, GlobImport, SingleImport};
Expand All @@ -16,7 +17,6 @@ use crate::{ResolutionError, Determinacy, PathResult, CrateLint};
use rustc::bug;
use rustc::hir::def::{self, *};
use rustc::hir::def_id::{CRATE_DEF_INDEX, LOCAL_CRATE, DefId};
use rustc::hir::map::DefCollector;
use rustc::ty;
use rustc::middle::cstore::CrateStore;
use rustc_metadata::cstore::LoadedMacro;
Expand Down Expand Up @@ -167,8 +167,7 @@ impl<'a> Resolver<'a> {
fragment: &AstFragment,
parent_scope: ParentScope<'a>,
) -> LegacyScope<'a> {
let mut def_collector = DefCollector::new(&mut self.definitions, parent_scope.expansion);
fragment.visit_with(&mut def_collector);
collect_definitions(&mut self.definitions, fragment, parent_scope.expansion);
let mut visitor = BuildReducedGraphVisitor { r: self, parent_scope };
fragment.visit_with(&mut visitor);
visitor.parent_scope.legacy
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,31 @@
use crate::hir::map::definitions::*;
use crate::hir::def_id::DefIndex;

use log::debug;
use rustc::hir::map::definitions::*;
use rustc::hir::def_id::DefIndex;
use syntax::ast::*;
use syntax::visit;
use syntax::symbol::{kw, sym};
use syntax::token::{self, Token};
use syntax_expand::expand::AstFragment;
use syntax_pos::hygiene::ExpnId;
use syntax_pos::Span;

crate fn collect_definitions(
definitions: &mut Definitions,
fragment: &AstFragment,
expansion: ExpnId,
) {
let parent_def = definitions.invocation_parent(expansion);
fragment.visit_with(&mut DefCollector { definitions, parent_def, expansion });
}

/// Creates `DefId`s for nodes in the AST.
pub struct DefCollector<'a> {
struct DefCollector<'a> {
definitions: &'a mut Definitions,
parent_def: DefIndex,
expansion: ExpnId,
}

impl<'a> DefCollector<'a> {
pub fn new(definitions: &'a mut Definitions, expansion: ExpnId) -> Self {
let parent_def = definitions.invocation_parent(expansion);
DefCollector { definitions, parent_def, expansion }
}

fn create_def(&mut self,
node_id: NodeId,
data: DefPathData,
Expand Down Expand Up @@ -82,7 +87,7 @@ impl<'a> DefCollector<'a> {
.or_else(|| index.map(sym::integer))
.unwrap_or_else(|| {
let node_id = NodeId::placeholder_from_expn_id(self.expansion);
sym::integer(self.definitions.placeholder_field_indices[&node_id])
sym::integer(self.definitions.placeholder_field_index(node_id))
});
let def = self.create_def(field.id, DefPathData::ValueNs(name), field.span);
self.with_parent(def, |this| visit::walk_struct_field(this, field));
Expand Down Expand Up @@ -186,7 +191,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
for (index, field) in data.fields().iter().enumerate() {
self.collect_field(field, Some(index));
if field.is_placeholder && field.ident.is_none() {
self.definitions.placeholder_field_indices.insert(field.id, index);
self.definitions.set_placeholder_field_index(field.id, index);
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ use rustc_error_codes::*;

type Res = def::Res<NodeId>;

mod def_collector;
mod diagnostics;
mod late;
mod macros;
Expand Down
28 changes: 22 additions & 6 deletions src/librustc_typeck/check/demand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// N.B., this code relies on `self.diverges` to be accurate. In
// particular, assignments to `!` will be permitted if the
// diverges flag is currently "always".
pub fn demand_coerce_diag(&self,
expr: &hir::Expr,
checked_ty: Ty<'tcx>,
expected: Ty<'tcx>,
allow_two_phase: AllowTwoPhase)
-> (Ty<'tcx>, Option<DiagnosticBuilder<'tcx>>) {
pub fn demand_coerce_diag(
&self,
expr: &hir::Expr,
checked_ty: Ty<'tcx>,
expected: Ty<'tcx>,
allow_two_phase: AllowTwoPhase,
) -> (Ty<'tcx>, Option<DiagnosticBuilder<'tcx>>) {
let expected = self.resolve_vars_with_obligations(expected);

let e = match self.try_coerce(expr, checked_ty, expected, allow_two_phase) {
Expand All @@ -126,6 +127,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
return (expected, None)
}

self.annotate_expected_due_to_let_ty(&mut err, expr);
self.suggest_compatible_variants(&mut err, expr, expected, expr_ty);
self.suggest_ref_or_into(&mut err, expr, expected, expr_ty);
self.suggest_boxing_when_appropriate(&mut err, expr, expected, expr_ty);
Expand All @@ -134,6 +136,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
(expected, Some(err))
}

fn annotate_expected_due_to_let_ty(&self, err: &mut DiagnosticBuilder<'_>, expr: &hir::Expr) {
let parent = self.tcx.hir().get_parent_node(expr.hir_id);
if let Some(hir::Node::Local(hir::Local {
ty: Some(ty),
init: Some(init),
..
})) = self.tcx.hir().find(parent) {
if init.hir_id == expr.hir_id {
// Point at `let` assignment type.
err.span_label(ty.span, "expected due to this");
}
}
}

/// Returns whether the expected type is `bool` and the expression is `x = y`.
pub fn is_assign_to_bool(&self, expr: &hir::Expr, expected: Ty<'tcx>) -> bool {
if let hir::ExprKind::Assign(..) = expr.kind {
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt

let extern_names: Vec<String> = externs.iter().map(|(s,_)| s).cloned().collect();

// Add the rustdoc cfg into the doc build.
// Add the doc cfg into the doc build.
cfgs.push("doc".to_string());

let cpath = Some(input.clone());
Expand Down
3 changes: 2 additions & 1 deletion src/librustdoc/html/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,8 @@ fn write_shared(
// Write out the shared files. Note that these are shared among all rustdoc
// docs placed in the output directory, so this needs to be a synchronized
// operation with respect to all other rustdocs running around.
let _lock = flock::Lock::panicking_new(&cx.dst.join(".lock"), true, true, true);
let lock_file = cx.dst.join(".lock");
let _lock = try_err!(flock::Lock::new(&lock_file, true, true, true), &lock_file);

// Add all the static files. These may already exist, but we just
// overwrite them anyway to make sure that they're fresh and up-to-date.
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ fn opts() -> Vec<RustcOptGroup> {
stable("extern", |o| {
o.optmulti("", "extern", "pass an --extern to rustc", "NAME[=PATH]")
}),
stable("extern-private", |o| {
unstable("extern-private", |o| {
o.optmulti("", "extern-private",
"pass an --extern to rustc (compatibility only)", "NAME=PATH")
}),
Expand Down
1 change: 0 additions & 1 deletion src/libsyntax/feature_gate/builtin_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ const GATED_CFGS: &[(Symbol, Symbol, GateFn)] = &[
(sym::target_thread_local, sym::cfg_target_thread_local, cfg_fn!(cfg_target_thread_local)),
(sym::target_has_atomic, sym::cfg_target_has_atomic, cfg_fn!(cfg_target_has_atomic)),
(sym::target_has_atomic_load_store, sym::cfg_target_has_atomic, cfg_fn!(cfg_target_has_atomic)),
(sym::doc, sym::doc_cfg, cfg_fn!(doc_cfg)),
];

#[derive(Debug)]
Expand Down
1 change: 0 additions & 1 deletion src/libsyntax_pos/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,6 @@ symbols! {
rustc_test_marker,
rustc_then_this_would_need,
rustc_variance,
rustdoc,
rustfmt,
rust_eh_personality,
rust_eh_unwind_resume,
Expand Down
4 changes: 3 additions & 1 deletion src/test/rustdoc-ui/failed-doctest-missing-codes.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ error[E0308]: mismatched types
--> $DIR/failed-doctest-missing-codes.rs:9:13
|
LL | let x: () = 5i32;
| ^^^^ expected `()`, found `i32`
| -- ^^^^ expected `()`, found `i32`
| |
| expected due to this

error: aborting due to previous error

Expand Down
1 change: 1 addition & 0 deletions src/test/rustdoc/issue-66159.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// aux-build:issue-66159-1.rs
// compile-flags:-Z unstable-options
// extern-private:issue_66159_1

// The issue was an ICE which meant that we never actually generated the docs
Expand Down
8 changes: 6 additions & 2 deletions src/test/ui/array-not-vector.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@ error[E0308]: mismatched types
--> $DIR/array-not-vector.rs:2:19
|
LL | let _x: i32 = [1, 2, 3];
| ^^^^^^^^^ expected `i32`, found array `[{integer}; 3]`
| --- ^^^^^^^^^ expected `i32`, found array `[{integer}; 3]`
| |
| expected due to this

error[E0308]: mismatched types
--> $DIR/array-not-vector.rs:7:20
|
LL | let _y: &i32 = x;
| ^ expected `i32`, found slice `[i32]`
| ---- ^ expected `i32`, found slice `[i32]`
| |
| expected due to this
|
= note: expected reference `&i32`
found reference `&[i32]`
Expand Down
4 changes: 3 additions & 1 deletion src/test/ui/associated-types/associated-types-eq-3.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ error[E0308]: mismatched types
--> $DIR/associated-types-eq-3.rs:23:18
|
LL | let _: Bar = x.boo();
| ^^^^^^^ expected struct `Bar`, found associated type
| --- ^^^^^^^ expected struct `Bar`, found associated type
| |
| expected due to this
|
= note: expected struct `Bar`
found associated type `<I as Foo>::A`
Expand Down
4 changes: 3 additions & 1 deletion src/test/ui/associated-types/associated-types-path-2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ error[E0308]: mismatched types
--> $DIR/associated-types-path-2.rs:41:18
|
LL | let _: i32 = f2(2i32);
| ^^^^^^^^ expected `i32`, found `u32`
| --- ^^^^^^^^ expected `i32`, found `u32`
| |
| expected due to this
|
help: you can convert an `u32` to `i32` and panic if the converted value wouldn't fit
|
Expand Down
8 changes: 6 additions & 2 deletions src/test/ui/c-variadic/variadic-ffi-1.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ error[E0308]: mismatched types
--> $DIR/variadic-ffi-1.rs:19:56
|
LL | let x: unsafe extern "C" fn(f: isize, x: u8) = foo;
| ^^^ expected non-variadic fn, found variadic function
| ------------------------------------- ^^^ expected non-variadic fn, found variadic function
| |
| expected due to this
|
= note: expected fn pointer `unsafe extern "C" fn(isize, u8)`
found fn item `unsafe extern "C" fn(isize, u8, ...) {foo}`
Expand All @@ -35,7 +37,9 @@ error[E0308]: mismatched types
--> $DIR/variadic-ffi-1.rs:20:54
|
LL | let y: extern "C" fn(f: isize, x: u8, ...) = bar;
| ^^^ expected variadic fn, found non-variadic function
| ----------------------------------- ^^^ expected variadic fn, found non-variadic function
| |
| expected due to this
|
= note: expected fn pointer `extern "C" fn(isize, u8, ...)`
found fn item `extern "C" fn(isize, u8) {bar}`
Expand Down
6 changes: 6 additions & 0 deletions src/test/ui/cfg-rustdoc.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#[cfg(doc)]
pub struct Foo;

fn main() {
let f = Foo; //~ ERROR
}
9 changes: 9 additions & 0 deletions src/test/ui/cfg-rustdoc.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
error[E0425]: cannot find value `Foo` in this scope
--> $DIR/cfg-rustdoc.rs:5:13
|
LL | let f = Foo;
| ^^^ not found in this scope

error: aborting due to previous error

For more information about this error, try `rustc --explain E0425`.
4 changes: 3 additions & 1 deletion src/test/ui/closures/closure-no-fn-1.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ error[E0308]: mismatched types
--> $DIR/closure-no-fn-1.rs:6:29
|
LL | let foo: fn(u8) -> u8 = |v: u8| { a += v; a };
| ^^^^^^^^^^^^^^^^^^^^^ expected fn pointer, found closure
| ------------ ^^^^^^^^^^^^^^^^^^^^^ expected fn pointer, found closure
| |
| expected due to this
|
= note: expected fn pointer `fn(u8) -> u8`
found closure `[closure@$DIR/closure-no-fn-1.rs:6:29: 6:50 a:_]`
Expand Down
Loading

0 comments on commit ad808d9

Please sign in to comment.