Commit Graph

125776 Commits

Author SHA1 Message Date
Matthias Krüger
51fd48f157
Rollup merge of #93099 - tomkris:rustdoc-fix, r=jsha
rustdoc: auto create output directory when "--output-format json"

This PR allows rustdoc to automatically create output directory in case it does not exist (when run with `--output-format json`).

This fixes rustdoc crash:

````
$ rustdoc --output-format json -Z unstable-options src/main.rs
error: couldn't generate documentation: No such file or directory (os error 2)
  |
  = note: failed to create or modify "doc/main.json"

error: aborting due to previous error
````

With this fix behavior of `rustdoc --output-format json` becomes consistent with `rustdoc --output-format html` (which already auto-creates output directory if it's missing)
2022-01-20 23:37:39 +01:00
Matthias Krüger
6cdd2e510c
Rollup merge of #93094 - Enselic:check-for-enum-tuple-struct-fields, r=CraftSpider
src/test/rustdoc-json: Check for `struct_field`s in `variant_tuple_struct.rs`

The presence of `struct_field`s is being checked for already in
`variant_struct.rs`. We should also check for them in `variant_tuple_struct.rs`.

This PR is one small step towards resolving #92945.
2022-01-20 23:37:37 +01:00
Matthias Krüger
894a867fd2
Rollup merge of #93087 - ricobbe:alt-calling-convention-test-fix, r=Mark-Simulacrum
Fix src/test/run-make/raw-dylib-alt-calling-convention

Fix the test headers so that the test now runs on all intended platforms; it is currently ignored on all platforms because the headers are incorrect.  Also comment out a couple of function calls that fail because of an unrelated problem, described in issue #91167.
2022-01-20 23:37:36 +01:00
Matthias Krüger
0a9aaec8eb
Rollup merge of #93086 - c410-f3r:let-guard, r=Mark-Simulacrum
Add tests to ensure that `let_chains` works with `if_let_guard`

The current machinery already makes such combination possible but lacks tests.

cc `@matthewjasper`
2022-01-20 23:37:35 +01:00
Matthias Krüger
35a53b229f
Rollup merge of #93067 - jsha:fix-scroll-padding-top, r=GuillaumeGomez
rustdoc mobile: fix scroll offset when jumping to internal id

Followup to #92692. The semantics of `scroll-margin-top` are a little surprising - the attribute needs to be applied to the element that gets scrolled into the viewport, not the scrolling element.

This fixes an issue where clicking on a method (or other item) from the sidebar takes you to a scroll position where the topbar covers up the method name.

I'm interested in ideas for how to test this with browser-ui-test, but I think it doesn't yet have what I need. What I need is an assert that `<element>.getBoundingClientRect().y` is > 45.

Demo: https://rustdoc.crud.net/jsha/fix-scroll-padding-top/std/string/struct.String.html#method.extend_from_within

r? `@GuillaumeGomez`
2022-01-20 23:37:34 +01:00
Matthias Krüger
dc393b2ecc
Rollup merge of #93061 - estebank:macr-suggestion, r=cjgillot
Only suggest adding `!` to expressions that can be macro invocation
2022-01-20 23:37:33 +01:00
Matthias Krüger
aa7f4520a1
Rollup merge of #93038 - GuillaumeGomez:block-doc-comments, r=notriddle
Fix star handling in block doc comments

Fixes #92872.

Some extra explanation about this PR and why https://github.com/rust-lang/rust/pull/92357 created this regression: when we merge doc comment kinds for example in:

```rust
/// he
/**
* hello
*/
#[doc = "boom"]
```

We don't want to remove the empty lines between them. However, to correctly compute the "horizontal trim", we still need it, so instead, I put back a part of the "vertical trim" directly in the "horizontal trim" computation so it doesn't impact the output buffer but allows us to correctly handle the stars.

r? ``@camelid``
2022-01-20 23:37:32 +01:00
Matthias Krüger
530c884372
Rollup merge of #92860 - CraftSpider:rustdoc-json-impl-ice, r=jsha
Fix errors on blanket impls by ignoring the children of generated impls

Related to #83718

We can safely skip the children, as they don't contain any new info, and may be subtly different for reasons hard to track down, in ways that are consistently worse than the actual generic impl.
2022-01-20 23:37:31 +01:00
Matthias Krüger
10a7204af9
Rollup merge of #92856 - GuillaumeGomez:exclude-test-doc_auto_cfg, r=Nemo157
Exclude "test" from doc_auto_cfg

Fixes #91740.

cc `@Nemo157` (you were the one suggesting this iirc)
r? `@camelid`
2022-01-20 23:37:30 +01:00
Matthias Krüger
3d10c64b26
Rollup merge of #91032 - eholk:generator-drop-tracking, r=nikomatsakis
Introduce drop range tracking to generator interior analysis

This PR addresses cases such as this one from #57478:
```rust
struct Foo;
impl !Send for Foo {}

let _: impl Send = || {
    let guard = Foo;
    drop(guard);
    yield;
};
```

Previously, the `generator_interior` pass would unnecessarily include the type `Foo` in the generator because it was not aware of the behavior of `drop`. We fix this issue by introducing a drop range analysis that finds portions of the code where a value is guaranteed to be dropped. If a value is dropped at all suspend points, then it is no longer included in the generator type. Note that we are using "dropped" in a generic sense to include any case in which a value has been moved. That is, we do not only look at calls to the `drop` function.

There are several phases to the drop tracking algorithm, and we'll go into more detail below.
1. Use `ExprUseVisitor` to find values that are consumed and borrowed.
2. `DropRangeVisitor` uses consume and borrow information to gather drop and reinitialization events, as well as build a control flow graph.
3. We then propagate drop and reinitialization information through the CFG until we reach a fix point (see `DropRanges::propagate_to_fixpoint`).
4. When recording a type (see `InteriorVisitor::record`), we check the computed drop ranges to see if that value is definitely dropped at the suspend point. If so, we skip including it in the type.

## 1. Use `ExprUseVisitor` to find values that are consumed and borrowed.

We use `ExprUseVisitor` to identify the places where values are consumed. We track both the `hir_id` of the value, and the `hir_id` of the expression that consumes it. For example, in the expression `[Foo]`, the `Foo` is consumed by the array expression, so after the array expression we can consider the `Foo` temporary to be dropped.

In this process, we also collect values that are borrowed. The reason is that the MIR transform for generators conservatively assumes anything borrowed is live across a suspend point (see `rustc_mir_transform::generator::locals_live_across_suspend_points`). We match this behavior here as well.

## 2. Gather drop events, reinitialization events, and control flow graph

After finding the values of interest, we perform a post-order traversal over the HIR tree to find the points where these values are dropped or reinitialized. We use the post-order index of each event because this is how the existing generator interior analysis refers to the position of suspend points and the scopes of variables.

During this traversal, we also record branching and merging information to handle control flow constructs such as `if`, `match`, and `loop`. This is necessary because values may be dropped along some control flow paths but not others.

## 3. Iterate to fixed point

The previous pass found the interesting events and locations, but now we need to find the actual ranges where things are dropped. Upon entry, we have a list of nodes ordered by their position in the post-order traversal. Each node has a set of successors. For each node we additionally keep a bitfield with one bit per potentially consumed value. The bit is set if we the value is dropped along all paths entering this node.

To compute the drop information, we first reverse the successor edges to find each node's predecessors. Then we iterate through each node, and for each node we set its dropped value bitfield to the intersection of all incoming dropped value bitfields.

If any bitfield for any node changes, we re-run the propagation loop again.

## 4. Ignore dropped values across suspend points

At this point we have a data structure where we can ask whether a value is guaranteed to be dropped at any post order index for the HIR tree. We use this information in `InteriorVisitor` to check whether a value in question is dropped at a particular suspend point. If it is, we do not include that value's type in the generator type.

Note that we had to augment the region scope tree to include all yields in scope, rather than just the last one as we did before.

r? `@nikomatsakis`
2022-01-20 23:37:29 +01:00
Guillaume Gomez
b0df7653d0 More clean up 2022-01-20 22:13:32 +01:00
Guillaume Gomez
caec4a23f2 Extra cfg_hide a bit to handle inner cfgs 2022-01-20 22:05:26 +01:00
Guillaume Gomez
fd005f53c2 Update doc_auto_cfg test 2022-01-20 22:05:26 +01:00
Guillaume Gomez
682ef4db80 Exclude "test" from doc_auto_cfg rendering 2022-01-20 22:05:25 +01:00
Artem Kryvokrysenko
4e17170c54 rustdoc: auto create output directory when "--output-format json"
This PR allows rustdoc to automatically create output directory in case
it does not exist (when run with `--output-format json`).

This fixes rustdoc crash:

````
$ rustdoc --output-format json -Z unstable-options src/main.rs
error: couldn't generate documentation: No such file or directory (os error 2)
  |
  = note: failed to create or modify "doc/main.json"

error: aborting due to previous error
````

With this fix behavior of `rustdoc --output-format json` becomes consistent
with `rustdoc --output-format html` (which already auto-creates output
directory if it's missing)
2022-01-19 22:28:07 -08:00
Martin Nordholts
ab239cc749 src/test/rustdoc-json: Check for struct_fields in variant_tuple_struct.rs
The presence of `struct_field`s is being checked for already in
`variant_struct.rs`. We should also check for them in `variant_tuple_struct.rs`.
2022-01-19 22:10:26 +01:00
Jacob Hoffman-Andrews
801ac0e24f Fix scroll offset when jumping to internal id 2022-01-19 12:45:16 -08:00
Caio
f491a9f601 Add tests to ensure that let_chains works with if_let_guard 2022-01-19 16:23:44 -03:00
Richard Cobbe
10858d28af Fix test directives; comment out calls broken on windows-gnu 2022-01-19 10:54:08 -08:00
Matthias Krüger
623791df24
Rollup merge of #93005 - GuillaumeGomez:templates-in-html, r=notriddle
Move back templates into html folder

Follow-up of https://github.com/rust-lang/rust/pull/92526.

r? `@notriddle`
2022-01-19 19:19:49 +01:00
Matthias Krüger
bcb093efcd
Rollup merge of #92800 - ehuss:docs-fallback, r=Mark-Simulacrum
Add manifest docs fallback.

This adds a fallback so that the rustup manifest will contain the rust-docs component for all hosts. There is a mapping so that the docs that get downloaded are roughly close to the actual host. There inevitably will be things that don't match. Ideally the standard library docs would be the same for every platform (`cfg(doc)` goes a long way towards this), but there are still lots of minor differences.

Closes #69525
2022-01-19 19:19:48 +01:00
Matthias Krüger
715cda2e81
Rollup merge of #92316 - petrochenkov:extmangle, r=wesleywiser
mangling_v0: Skip extern blocks during mangling

There's no need to include the dummy `Nt` into the symbol name, items in extern blocks belong to their parent modules for all purposes except for inheriting the ABI and attributes.

Follow up to https://github.com/rust-lang/rust/pull/92032

(There's also a drive-by fix to the `rust-demangler` tool's tests, which don't run on CI, I initially attempted using them for testing this PR.)
2022-01-19 19:19:45 +01:00
Esteban Kuber
017747fa5a Only suggest adding ! to expressions that can be macro invocation 2022-01-19 18:00:10 +00:00
Eric Huss
c8e6889e08 Add assert that fallback targets must be available. 2022-01-19 09:41:04 -08:00
Guillaume Gomez
06b00ad199 Add test for block doc comments 2022-01-19 11:18:17 +01:00
Guillaume Gomez
2938be612d Correctly handle starts in block doc comments 2022-01-19 11:18:17 +01:00
Guillaume Gomez
48f5dcad10 Move back templates into html folder 2022-01-19 11:13:24 +01:00
Matthias Krüger
ea1275a62c
Rollup merge of #93062 - ehuss:update-books, r=ehuss
Update books

## nomicon

1 commits in c05c452b36358821bf4122f9c418674edd1d713d..66d097d3d80e8f88c288c6879c7c2b909ecf8ad4
2021-12-13 15:23:48 +0900 to 2022-01-05 05:45:21 +0900
- Fix typo / type error in FFI code example (rust-lang/nomicon#327)

## reference

8 commits in f8ba2f12df60ee19b96de24ae5b73af3de8a446b..4dee6eb63d728ffb9e7a2ed443e9ada9275c69d2
2022-01-03 11:02:08 -0800 to 2022-01-18 09:26:33 -0800
- (minor) Remove Expression Path sub-types splits in Pattern specs (rust-lang/reference#1138)
- Document destructuring assignment (rust-lang/reference#1116)
- Document the 2021 edition changes to macros-by-example `pat` metavariables (rust-lang/reference#1135)
- Improve the documentation of macros-by-example metavariable names (rust-lang/reference#1130)
- trait-bounds.md: add pronoun 'that' (rust-lang/reference#1131)
- Say that macros-by-example `ident` metavariables can match raw identifiers (rust-lang/reference#1133)
- State in the UAX31 profile description that a lone `_` is not an identifier (rust-lang/reference#1129)
- Document syntax reserved in Rust 2021 (rust-lang/reference#1128)

## book

17 commits in d3740fb7aad0ea4a80ae20f64dee3a8cfc0c5c3c..f17df27fc14696912c48b8b7a7a8fa49e648088d
2022-01-03 21:46:04 -0500 to 2022-01-18 17:46:28 -0500
- Add a notice to the top of all nostarch snapshots
- Fix quotes
- Grammar (minor): 'or' → 'and' for enum variants
- Propagate edits of chapter 8 to src
- Replies to nostarch edits
- more edits
- ch8 from nostarch
- Fix grammar and line wrapping
- Merge remote-tracking branch 'origin/pr/2880'
- Remove wikipedia link
- Merge remote-tracking branch 'origin/pr/2927'
- Snapshot of ch14 for nostarch
- Backport fixes to chapter 14 noticed while doing nostarch snapshot
- Fix usage of find piped into xargs
- Adjust some more line numbers of Cargo.toml includes
- Merge branch '2909'
- Merge remote-tracking branch 'parkerziegler/fix/ch14-add-one-naming'

## rustc-dev-guide

7 commits in 875464457c4104686faf667f47848aa7b0f0a744..78dd6a4684cf8d6b72275fab6d0429ea40b66338
2021-12-28 22:17:49 -0600 to 2022-01-18 14:44:26 -0300
- Reorganize and expand the testing chapters. (rust-lang/rustc-dev-guide#1281)
- Add inline assembly internals (rust-lang/rustc-dev-guide#1266)
- Spelling: Rename `rust` to `Rust` (rust-lang/rustc-dev-guide#1288)
- Clean up section about FCPs (rust-lang/rustc-dev-guide#1287)
- Address more review comments in rust-lang/rustc-dev-guide#1286.
- Address review comments in rust-lang/rustc-dev-guide#1286.
- Streamline "Getting Started" some more.
2022-01-19 10:42:21 +01:00
Matthias Krüger
7f2dbcba38
Rollup merge of #92797 - jsha:fewer-lines, r=GuillaumeGomez
Remove horizontal lines at top of page

They are not needed to separate the search bar and the title, which are visually distinct on their own.

Part of #59840

Demo: https://rustdoc.crud.net/jsha/fewer-lines/std/string/struct.String.html

r? `@GuillaumeGomez`
2022-01-19 10:42:17 +01:00
Matthias Krüger
9a82f74cdf
Rollup merge of #92783 - FabianWolff:issue-92726, r=nikomatsakis
Annotate dead code lint with notes about ignored derived impls

Fixes #92726. CC `@pmetzger,` is this what you had in mind?

r? `@nikomatsakis`
2022-01-19 10:42:16 +01:00
Matthias Krüger
5d2928f7b9
Rollup merge of #88642 - c410-f3r:let_chains_2, r=matthewjasper
Formally implement let chains

## Let chains

My longest and hardest contribution since #64010.

Thanks to `@Centril` for creating the RFC and special thanks to `@matthewjasper` for helping me since the beginning of this journey. In fact, `@matthewjasper` did much of the complicated MIR stuff so it's true to say that this feature wouldn't be possible without him. Thanks again `@matthewjasper!`

With the changes proposed in this PR, it will be possible to chain let expressions along side local variable declarations or ordinary conditional expressions. In other words, do much of what the `if_chain` crate already does.

## Other considerations

* `if let guard` and `let ... else` features need special care and should be handled in a following PR.

* Irrefutable patterns are allowed within a let chain context

* ~~Three Clippy lints were already converted to start dogfooding and help detect possible corner cases~~

cc #53667
2022-01-19 10:42:12 +01:00
Eric Huss
84e0d9db6c Update books 2022-01-18 19:23:45 -08:00
Eric Huss
bfacc5cc73 Update cargo 2022-01-18 19:14:33 -08:00
Jacob Hoffman-Andrews
fa9a8430ea Remove horizontal lines at top of page
They are not needed to separate the search bar and the title, which are
visually distinct on their own.
2022-01-18 18:45:43 -08:00
Caio
5f74ef4fb1 Formally implement let chains 2022-01-18 19:38:17 -03:00
Eric Holk
e0a5370ef0 Respond to code review comments 2022-01-18 14:25:31 -08:00
Eric Holk
32930d9ea7 Safely handle partial drops
We previously weren't tracking partial re-inits while being too
aggressive around partial drops. With this change, we simply ignore
partial drops, which is the safer, more conservative choice.
2022-01-18 14:25:30 -08:00
Eric Holk
887e843eeb Update async-fn-nonsend.rs
The previous commit made the non_sync_with_method_call case pass due to
the await being unreachable. Unfortunately, this isn't actually the
behavior the test was verifying. This change lifts the panic into a
helper function so that the generator analysis still thinks the await
is reachable, and therefore we preserve the same testing behavior.
2022-01-18 14:25:30 -08:00
Eric Holk
787f4cbd15 Handle uninhabited return types
This changes drop range analysis to handle uninhabited return types such
as `!`. Since these calls to these functions do not return, we model
them as ending in an infinite loop.
2022-01-18 14:25:30 -08:00
Eric Holk
a7df4e8d2f Handle empty loops better 2022-01-18 14:25:29 -08:00
Eric Holk
4a70de7932 Handle reinits in match guards 2022-01-18 14:25:29 -08:00
Eric Holk
7d82e4f764 Update stderr files 2022-01-18 14:25:28 -08:00
Eric Holk
30e1b1e92e Address code review comments
1. Add test case for partial drops
2. Simplify code in `propagate_to_fixpoint` and remove most clones
3. Clean up PostOrderIndex creation
2022-01-18 14:25:27 -08:00
Eric Holk
46760b4e67 Update async-fn-nonsend.stderr 2022-01-18 14:25:27 -08:00
Eric Holk
457415294c Handle more cases with conditionally initialized/dropped values 2022-01-18 14:25:25 -08:00
Eric Holk
298ca2f679 Basic loop support 2022-01-18 14:25:25 -08:00
Eric Holk
96117701f9 Support reinitialization of variables 2022-01-18 14:25:25 -08:00
Eric Holk
aa029d4bbe Support conditional drops
This adds support for branching and merging control flow and uses this
to correctly handle the case where a value is dropped in one branch of
an if expression but not another.

There are other cases we need to handle, which will come in follow up
patches.

Issue #57478
2022-01-18 14:25:24 -08:00
Eric Holk
f246c0b116 Attribute drop to parent expression of the consume point
This is needed to handle cases like `[a, b.await, c]`. `ExprUseVisitor`
considers `a` to be consumed when it is passed to the array, but the
array is not quite live yet at that point. This means we were missing
the `a` value across the await point. Attributing drops to the parent
expression means we do not consider the value consumed until the
consuming expression has finished.

Issue #57478
2022-01-18 14:25:24 -08:00
Eric Holk
f664cfc47c Make generator and async-await tests pass
The main change needed to make this work is to do a pessimistic over-
approximation for AssignOps. The existing ScopeTree analysis in
region.rs works by doing both left to right and right to left order and
then choosing the most conservative ordering. This behavior is needed
because AssignOp's evaluation order depends on whether it is a primitive
type or an overloaded operator, which runs as a method call.

This change mimics the same behavior as region.rs in
generator_interior.rs.

Issue #57478
2022-01-18 14:25:24 -08:00