]> git.lizzy.rs Git - rust.git/log
rust.git
2 years agoRollup merge of #92963 - terrarier2111:tuple-diagnostic, r=davidtwco
Matthias Krüger [Fri, 21 Jan 2022 21:03:16 +0000 (22:03 +0100)]
Rollup merge of #92963 - terrarier2111:tuple-diagnostic, r=davidtwco

Implement tuple array diagnostic

Fixes https://github.com/rust-lang/rust/issues/92089

2 years agoRollup merge of #92843 - camelid:str-concat-sugg, r=davidtwco
Matthias Krüger [Fri, 21 Jan 2022 21:03:15 +0000 (22:03 +0100)]
Rollup merge of #92843 - camelid:str-concat-sugg, r=davidtwco

Improve string concatenation suggestion

Before:

    error[E0369]: cannot add `&str` to `&str`
     --> file.rs:2:22
      |
    2 |     let _x = "hello" + " world";
      |              ------- ^ -------- &str
      |              |       |
      |              |       `+` cannot be used to concatenate two `&str` strings
      |              &str
      |
    help: `to_owned()` can be used to create an owned `String` from a string reference. String concatenation appends the string on the right to the string on the left and may require reallocation. This requires ownership of the string on the left
      |
    2 |     let _x = "hello".to_owned() + " world";
      |              ~~~~~~~~~~~~~~~~~~

After:

    error[E0369]: cannot add `&str` to `&str`
     --> file.rs:2:22
      |
    2 |     let _x = "hello" + " world";
      |              ------- ^ -------- &str
      |              |       |
      |              |       `+` cannot be used to concatenate two `&str` strings
      |              &str
      |
      = note: string concatenation requires an owned `String` on the left
    help: create an owned `String` from a string reference
      |
    2 |     let _x = "hello".to_owned() + " world";
      |                     +++++++++++

2 years agoRollup merge of #92835 - iwanders:issue-66450-improve-cfg-error-message, r=nagisa
Matthias Krüger [Fri, 21 Jan 2022 21:03:14 +0000 (22:03 +0100)]
Rollup merge of #92835 - iwanders:issue-66450-improve-cfg-error-message, r=nagisa

Improve error message for key="value" cfg arguments.

Hi, I ran into difficulties using the `--cfg` flag syntax, first hit when googling for the error was issue https://github.com/rust-lang/rust/issues/66450. Reading that issue, it sounded like the best way to improve the experience was to improve the error message, this is low risk and doesn't introduce any additional argument parsing.

The issue mentions that it is entirely dependent on the shell, while this may be true, I think guiding the the user into the realization that the quotes may need to be escaped is helpful. The two suggested escapings both work in Bash and in the Windows command prompt.

fyi `@ehuss`

2 years agoRollup merge of #92586 - esp-rs:bugfix/allocation-alignment-espidf, r=yaahc
Matthias Krüger [Fri, 21 Jan 2022 21:03:13 +0000 (22:03 +0100)]
Rollup merge of #92586 - esp-rs:bugfix/allocation-alignment-espidf, r=yaahc

Set the allocation MIN_ALIGN for espidf to 4.

Closes https://github.com/esp-rs/rust/issues/99.

cc: `@ivmarkov`

2 years agoRollup merge of #92467 - Aaron1011:extern-local-region, r=oli-obk
Matthias Krüger [Fri, 21 Jan 2022 21:03:12 +0000 (22:03 +0100)]
Rollup merge of #92467 - Aaron1011:extern-local-region, r=oli-obk

Ensure that early-bound function lifetimes are always 'local'

During borrowchecking, we treat any free (early-bound) regions on
the 'defining type' as `RegionClassification::External`. According
to the doc comments, we should only have 'external' regions when
checking a closure/generator.

However, a plain function can also have some if its regions
be considered 'early bound' - this occurs when the region is
constrained by an argument, appears in a `where` clause, or
in an opaque type. This was causing us to incorrectly mark these
regions as 'external', which caused some diagnostic code
to act as if we were referring to a 'parent' region from inside
a closure.

This PR marks all instantiated region variables as 'local'
when we're borrow-checking something other than a
closure/generator/inline-const.

2 years agoRollup merge of #91965 - ferrocene:pa-more-granular-exclude, r=Mark-Simulacrum
Matthias Krüger [Fri, 21 Jan 2022 21:03:11 +0000 (22:03 +0100)]
Rollup merge of #91965 - ferrocene:pa-more-granular-exclude, r=Mark-Simulacrum

Add more granular `--exclude` in `x.py`

x.py has support for excluding some steps from the current invocation, but unfortunately that's not granular enough: some steps have the same name in different modules, and that prevents excluding only *some* of them.

As a practical example, let's say you need to run everything in `./x.py test` except for the standard library tests, as those tests require IPv6 and need to be executed on a separate machine. Before this commit, if you were to just run this:

    ./x.py test --exclude library/std

...the invocation would eventually fail, as that would not only exclude running the tests for the standard library (`library/std` in the `test` module), it would also exclude generating its documentation (`library/std` in the `doc` module), breaking linkchecker.

This commit adds support to the `--exclude` flag for prefixing paths with the name of the module their step is defined in, allowing the user to choose which module to exclude from:

    ./x.py test --exclude test::library/std

This maintains backward compatibility with existing invocations, while allowing more ganular exclusion. Examples of the behavior:

| `--exclude`         | Docs    | Tests   |
| ------------------- | ------- | ------- |
| `library/std`       | Skipped | Skipped |
| `doc::library/std`  | Skipped | Run     |
| `test::library/std` | Run     | Skipped |

Note that this PR only changes the `--exclude` flag, and not in other `x.py` arguments or flags yet.

In the implementation I tried to limit the impact this would have with rustbuild as a whole as much as possible. The module name is extracted from the step by parsing the result of `std::any::type_name()`: unfortunately that output can change at any point in time, but IMO it's better than having to annotate all the existing and future `Step` implementations with the module name. I added a test to ensure the parsing works as expected, so hopefully if anyone makes changes to the output of `std::any::type_name()` they'll also notice they have to update rustbuild.

r? `@Mark-Simulacrum`

2 years agoAuto merge of #92983 - pietroalbini:pa-bump-runner-images, r=Mark-Simulacrum
bors [Fri, 21 Jan 2022 17:43:39 +0000 (17:43 +0000)]
Auto merge of #92983 - pietroalbini:pa-bump-runner-images, r=Mark-Simulacrum

Update Linux runners to Ubuntu 20.04

r? `@Mark-Simulacrum`

2 years agoAuto merge of #92787 - camsteffen:methodcall-span, r=Mark-Simulacrum
bors [Fri, 21 Jan 2022 14:33:17 +0000 (14:33 +0000)]
Auto merge of #92787 - camsteffen:methodcall-span, r=Mark-Simulacrum

Remove a `Span` from `hir::ExprKind::MethodCall`

It's just a copy of `MethodCall.0.ident.span`.

2 years agoRemove a span from hir::ExprKind::MethodCall
Cameron Steffen [Wed, 1 Dec 2021 17:17:50 +0000 (11:17 -0600)]
Remove a span from hir::ExprKind::MethodCall

2 years agoAuto merge of #92896 - lqd:update-deps, r=Mark-Simulacrum
bors [Fri, 21 Jan 2022 10:38:30 +0000 (10:38 +0000)]
Auto merge of #92896 - lqd:update-deps, r=Mark-Simulacrum

Update some rustc dependencies to deduplicate them

This PR updates `rand` and `itertools` in rustc (not the whole workspace) in order to deduplicate them (and hopefully slightly improve compile times).

~~Currently, `object` is still duplicated, but https://github.com/rust-lang/thorin/pull/15 and updating `thorin` in the future will remove the use of version 0.27.~~  Update: Thorin 0.2 has now been released, and this PR updates `rustc_codegen_ssa` to use it and deduplicate the `object` crate.

There's a final tiny rustc dependency, `cfg-if`, which will be left: as both versions 0.1.x and 1.0 looked to be heavily depended on, they will require a few cascading updates to be removed.

2 years agoallow excluding paths only from a single module
Pietro Albini [Wed, 15 Dec 2021 11:51:26 +0000 (12:51 +0100)]
allow excluding paths only from a single module

x.py has support for excluding some steps from the invocation, but
unfortunately that's not granular enough: some steps have the same name
in different modules, and that prevents excluding only *some* of them.

As a practical example, let's say you need to run everything in `./x.py
test` except for the standard library tests, as those tests require IPv6
and need to be executed on a separate machine. Before this commit, if
you were to just run this:

    ./x.py test --exclude library/std

...the execution would fail, as that would not only exclude running the
tests for the standard library, it would also exclude generating its
documentation (breaking linkchecker).

This commit adds support for an optional module annotation in --exclude
paths, allowing the user to choose which module to exclude from:

    ./x.py test --exclude test::library/std

This maintains backward compatibility, but also allows for more ganular
exclusion. More examples on how this works:

| `--exclude`         | Docs    | Tests   |
| ------------------- | ------- | ------- |
| `library/std`       | Skipped | Skipped |
| `doc::library/std`  | Skipped | Run     |
| `test::library/std` | Run     | Skipped |

Note that the new behavior only works in the `--exclude` flag, and not
in other x.py arguments or flags yet.

2 years agoreplace paths in PathSet with a dedicated TaskPath struct
Pietro Albini [Wed, 15 Dec 2021 11:50:06 +0000 (12:50 +0100)]
replace paths in PathSet with a dedicated TaskPath struct

2 years agoAuto merge of #91359 - dtolnay:args, r=Mark-Simulacrum
bors [Fri, 21 Jan 2022 06:20:18 +0000 (06:20 +0000)]
Auto merge of #91359 - dtolnay:args, r=Mark-Simulacrum

Emit simpler code from format_args

I made this PR so that `cargo expand` dumps a less overwhelming amount of formatting-related code.

<br>

`println!("rust")` **Before:**

```rust
{
    ::std::io::_print(::core::fmt::Arguments::new_v1(&["rust\n"],
                                                     &match () {
                                                          _args => [],
                                                      }));
};
```

**After:**

```rust
{ ::std::io::_print(::core::fmt::Arguments::new_v1(&["rust\n"], &[])); };
```

`println!("{}", x)` **Before:**

```rust
{
    ::std::io::_print(::core::fmt::Arguments::new_v1(
        &["", "\n"],
        &match (&x,) {
            _args => [::core::fmt::ArgumentV1::new(
                _args.0,
                ::core::fmt::Display::fmt,
            )],
        },
    ));
};
```

**After:**

```rust
{
    ::std::io::_print(::core::fmt::Arguments::new_v1(
        &["", "\n"],
        &[::core::fmt::ArgumentV1::new(&x, ::core::fmt::Display::fmt)],
    ));
};
```

2 years agoAuto merge of #93138 - matthiaskrgr:rollup-m8akifd, r=matthiaskrgr
bors [Fri, 21 Jan 2022 03:04:43 +0000 (03:04 +0000)]
Auto merge of #93138 - matthiaskrgr:rollup-m8akifd, r=matthiaskrgr

Rollup of 17 pull requests

Successful merges:

 - #91032 (Introduce drop range tracking to generator interior analysis)
 - #92856 (Exclude "test" from doc_auto_cfg)
 - #92860 (Fix errors on blanket impls by ignoring the children of generated impls)
 - #93038 (Fix star handling in block doc comments)
 - #93061 (Only suggest adding `!` to expressions that can be macro invocation)
 - #93067 (rustdoc mobile: fix scroll offset when jumping to internal id)
 - #93086 (Add tests to ensure that `let_chains` works with `if_let_guard`)
 - #93087 (Fix src/test/run-make/raw-dylib-alt-calling-convention)
 - #93091 (⬆ chalk to 0.76.0)
 - #93094 (src/test/rustdoc-json: Check for `struct_field`s in `variant_tuple_struct.rs`)
 - #93098 (Show a more informative panic message when `DefPathHash` does not exist)
 - #93099 (rustdoc: auto create output directory when "--output-format json")
 - #93102 (Pretty printer algorithm revamp step 3)
 - #93104 (Support --bless for pp-exact pretty printer tests)
 - #93114 (update comment for `ensure_monomorphic_enough`)
 - #93128 (Add script to prevent point releases with same number as existing ones)
 - #93136 (Backport the 1.58.1 release notes to master)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup

2 years agoRollup merge of #93136 - pietroalbini:pa-1.58.1-relnotes-master, r=pietroalbini
Matthias Krüger [Thu, 20 Jan 2022 22:37:44 +0000 (23:37 +0100)]
Rollup merge of #93136 - pietroalbini:pa-1.58.1-relnotes-master, r=pietroalbini

Backport the 1.58.1 release notes to master

r? `@ghost`

2 years agoRollup merge of #93128 - pietroalbini:pa-verify-stable-version-number, r=Mark-Simulacrum
Matthias Krüger [Thu, 20 Jan 2022 22:37:43 +0000 (23:37 +0100)]
Rollup merge of #93128 - pietroalbini:pa-verify-stable-version-number, r=Mark-Simulacrum

Add script to prevent point releases with same number as existing ones

This will hopefully prevent what happened today with #93110 and #93121, where we built point release artifacts without changing version numbers, thus requiring another PR to change the version number.

r? `@Mark-Simulacrum`

2 years agoRollup merge of #93114 - lcnr:mk_array, r=RalfJung
Matthias Krüger [Thu, 20 Jan 2022 22:37:42 +0000 (23:37 +0100)]
Rollup merge of #93114 - lcnr:mk_array, r=RalfJung

update comment for `ensure_monomorphic_enough`

r? `@RalfJung`

2 years agoRollup merge of #93104 - dtolnay:ppbless, r=Mark-Simulacrum
Matthias Krüger [Thu, 20 Jan 2022 22:37:41 +0000 (23:37 +0100)]
Rollup merge of #93104 - dtolnay:ppbless, r=Mark-Simulacrum

Support --bless for pp-exact pretty printer tests

I ran into this while working on the stack of PRs containing #93102. `x.py test src/test/pretty --bless` previously would `fatal` instead of blessing the input files.

Tested by making a silly pretty-printer tweak and running the above command: 98823c3929ebfe796786345c5ee713f63317d9c6

2 years agoRollup merge of #93102 - dtolnay:ringbuffer, r=lcnr
Matthias Krüger [Thu, 20 Jan 2022 22:37:40 +0000 (23:37 +0100)]
Rollup merge of #93102 - dtolnay:ringbuffer, r=lcnr

Pretty printer algorithm revamp step 3

This PR follows #93065 as a third chunk of minor modernizations backported from https://github.com/dtolnay/prettyplease into rustc_ast_pretty.

I've broken this up into atomic commits that hopefully are sensible in isolation. At every commit, the pretty printer is compilable and has runtime behavior that is identical to before and after the PR. None of the refactoring so far changes behavior.

This PR is the last chunk of non-behavior-changing cleanup. After this the **next PR** will begin backporting behavior changes from `prettyplease`, starting with block indentation:

```rust
macro_rules! print_expr {
    ($expr:expr) => {
        println!("{}", stringify!($expr));
    };
}

fn main() {
    print_expr!(Struct { x: 0, y: 0 });
    print_expr!(Structtttttttttttttttttttttttttttttttttttttttttttttttttt { xxxxxxxxx: 0, yyyyyyyyy: 0 });
}
```

Output currently on master (nowhere near modern Rust style):

```console
Struct{x: 0, y: 0,}
Structtttttttttttttttttttttttttttttttttttttttttttttttttt{xxxxxxxxx: 0,
                                                         yyyyyyyyy: 0,}
```

After the upcoming PR for block indentation (based on https://github.com/dtolnay/prettyplease/commit/401d60c04213e6c66565e0e69a95b4588db5fdba):

```console
Struct { x: 0, y: 0, }
Structtttttttttttttttttttttttttttttttttttttttttttttttttt {
    xxxxxxxxx: 0,
    yyyyyyyyy: 0,
}
```

And the PR after that, for intelligent trailing commas (based on https://github.com/dtolnay/prettyplease/commit/e2a0297f1781b787b90bca5aba1bdb4966661882):

```console
Struct { x: 0, y: 0 }
Structtttttttttttttttttttttttttttttttttttttttttttttttttt {
    xxxxxxxxx: 0,
    yyyyyyyyy: 0,
}
```

2 years agoRollup merge of #93099 - tomkris:rustdoc-fix, r=jsha
Matthias Krüger [Thu, 20 Jan 2022 22:37:39 +0000 (23:37 +0100)]
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)

2 years agoRollup merge of #93098 - Aaron1011:def-path-hash-debug, r=oli-obk
Matthias Krüger [Thu, 20 Jan 2022 22:37:38 +0000 (23:37 +0100)]
Rollup merge of #93098 - Aaron1011:def-path-hash-debug, r=oli-obk

Show a more informative panic message when `DefPathHash` does not exist

This should hopefully make it easier to debug incremental compilation
bugs like #93096 without affecting performance.

2 years agoRollup merge of #93094 - Enselic:check-for-enum-tuple-struct-fields, r=CraftSpider
Matthias Krüger [Thu, 20 Jan 2022 22:37:37 +0000 (23:37 +0100)]
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.

2 years agoRollup merge of #93091 - pierwill:chalk-0.76, r=jackh726
Matthias Krüger [Thu, 20 Jan 2022 22:37:37 +0000 (23:37 +0100)]
Rollup merge of #93091 - pierwill:chalk-0.76, r=jackh726

⬆ chalk to 0.76.0

This update contains https://github.com/rust-lang/chalk/pull/740, which is needed for work on #90317.

2 years agoRollup merge of #93087 - ricobbe:alt-calling-convention-test-fix, r=Mark-Simulacrum
Matthias Krüger [Thu, 20 Jan 2022 22:37:36 +0000 (23:37 +0100)]
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.

2 years agoRollup merge of #93086 - c410-f3r:let-guard, r=Mark-Simulacrum
Matthias Krüger [Thu, 20 Jan 2022 22:37:35 +0000 (23:37 +0100)]
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`

2 years agoRollup merge of #93067 - jsha:fix-scroll-padding-top, r=GuillaumeGomez
Matthias Krüger [Thu, 20 Jan 2022 22:37:34 +0000 (23:37 +0100)]
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`

2 years agoRollup merge of #93061 - estebank:macr-suggestion, r=cjgillot
Matthias Krüger [Thu, 20 Jan 2022 22:37:33 +0000 (23:37 +0100)]
Rollup merge of #93061 - estebank:macr-suggestion, r=cjgillot

Only suggest adding `!` to expressions that can be macro invocation

2 years agoRollup merge of #93038 - GuillaumeGomez:block-doc-comments, r=notriddle
Matthias Krüger [Thu, 20 Jan 2022 22:37:32 +0000 (23:37 +0100)]
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``

2 years agoRollup merge of #92860 - CraftSpider:rustdoc-json-impl-ice, r=jsha
Matthias Krüger [Thu, 20 Jan 2022 22:37:31 +0000 (23:37 +0100)]
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.

2 years agoRollup merge of #92856 - GuillaumeGomez:exclude-test-doc_auto_cfg, r=Nemo157
Matthias Krüger [Thu, 20 Jan 2022 22:37:30 +0000 (23:37 +0100)]
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`

2 years agoRollup merge of #91032 - eholk:generator-drop-tracking, r=nikomatsakis
Matthias Krüger [Thu, 20 Jan 2022 22:37:29 +0000 (23:37 +0100)]
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`

2 years agobackport the 1.58.1 relnotes to master
Pietro Albini [Thu, 20 Jan 2022 21:59:54 +0000 (22:59 +0100)]
backport the 1.58.1 relnotes to master

2 years agoMore clean up
Guillaume Gomez [Thu, 20 Jan 2022 21:13:32 +0000 (22:13 +0100)]
More clean up

2 years agoExtra cfg_hide a bit to handle inner cfgs
Guillaume Gomez [Sun, 16 Jan 2022 20:03:16 +0000 (21:03 +0100)]
Extra cfg_hide a bit to handle inner cfgs

2 years agoUpdate doc_auto_cfg test
Guillaume Gomez [Thu, 13 Jan 2022 14:50:21 +0000 (15:50 +0100)]
Update doc_auto_cfg test

2 years agoExclude "test" from doc_auto_cfg rendering
Guillaume Gomez [Thu, 13 Jan 2022 14:50:11 +0000 (15:50 +0100)]
Exclude "test" from doc_auto_cfg rendering

2 years agoAuto merge of #93119 - matthiaskrgr:rollup-ku3cn5j, r=matthiaskrgr
bors [Thu, 20 Jan 2022 20:44:14 +0000 (20:44 +0000)]
Auto merge of #93119 - matthiaskrgr:rollup-ku3cn5j, r=matthiaskrgr

Rollup of 13 pull requests

Successful merges:

 - #89747 (Add MaybeUninit::(slice_)as_bytes(_mut))
 - #89764 (Fix variant index / discriminant confusion in uninhabited enum branching)
 - #91606 (Stabilize `-Z print-link-args` as `--print link-args`)
 - #91694 (rustdoc: decouple stability and const-stability)
 - #92183 (Point at correct argument when async fn output type lifetime disagrees with signature)
 - #92582 (improve `_` constants in item signature handling)
 - #92680 (intra-doc: Use the impl's assoc item where possible)
 - #92704 (Change lint message to be stronger for &T -> &mut T transmute)
 - #92861 (Rustdoc mobile: put out-of-band info on its own line)
 - #92992 (Help optimize out backtraces when disabled)
 - #93038 (Fix star handling in block doc comments)
 - #93108 (:arrow_up: rust-analyzer)
 - #93112 (Fix CVE-2022-21658)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup

2 years agoadd script to prevent point releases with same number as existing ones
Pietro Albini [Thu, 20 Jan 2022 20:18:04 +0000 (21:18 +0100)]
add script to prevent point releases with same number as existing ones

2 years agoRollup merge of #93112 - pietroalbini:pa-cve-2022-21658-nightly, r=pietroalbini
Matthias Krüger [Thu, 20 Jan 2022 16:10:43 +0000 (17:10 +0100)]
Rollup merge of #93112 - pietroalbini:pa-cve-2022-21658-nightly, r=pietroalbini

Fix CVE-2022-21658

See https://blog.rust-lang.org/2022/01/20/cve-2022-21658.html. Patches reviewed by `@m-ou-se.`

r? `@ghost`

2 years agoRollup merge of #93108 - lnicola:rust-analyzer-2022-01-20, r=lnicola
Matthias Krüger [Thu, 20 Jan 2022 16:10:42 +0000 (17:10 +0100)]
Rollup merge of #93108 - lnicola:rust-analyzer-2022-01-20, r=lnicola

:arrow_up: rust-analyzer

r? `@ghost`

2 years agoRollup merge of #93038 - GuillaumeGomez:block-doc-comments, r=notriddle
Matthias Krüger [Thu, 20 Jan 2022 16:10:41 +0000 (17:10 +0100)]
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`

2 years agoRollup merge of #92992 - kornelski:backtraceopt, r=Mark-Simulacrum
Matthias Krüger [Thu, 20 Jan 2022 16:10:40 +0000 (17:10 +0100)]
Rollup merge of #92992 - kornelski:backtraceopt, r=Mark-Simulacrum

Help optimize out backtraces when disabled

The comment in `rust_backtrace_env` says:

>    // If the `backtrace` feature of this crate isn't enabled quickly return
>   // `None` so this can be constant propagated all over the place to turn
>  // optimize away callers.

but this optimization has regressed, because the only caller of this function had an alternative path that unconditionally (and pointlessly) asked for a full backtrace, so the disabled state couldn't propagate.

I've added a getter for the full format that respects the feature flag, so that the caller will now be able to really optimize out the disabled backtrace path. I've also made `rust_backtrace_env` trivially inlineable when backtraces are disabled.

2 years agoRollup merge of #92861 - jsha:mobile-column-flex, r=GuillaumeGomez
Matthias Krüger [Thu, 20 Jan 2022 16:10:39 +0000 (17:10 +0100)]
Rollup merge of #92861 - jsha:mobile-column-flex, r=GuillaumeGomez

Rustdoc mobile: put out-of-band info on its own line

Before this, the item name and the stability, source link, and "collapse
all docs" would compete for room on a single line, resulting in awkward
wrapping behavior on mobile. This gives a separate line for that
out-of-band information. It also removes the "copy path" icon on mobile
to make a little more room.

Demo: https://rustdoc.crud.net/jsha/mobile-column-flex/std/string/struct.String.html

r? `@GuillaumeGomez`

2 years agoRollup merge of #92704 - 5225225:std_mem_transmute_ref_t_mut_t, r=michaelwoerister
Matthias Krüger [Thu, 20 Jan 2022 16:10:37 +0000 (17:10 +0100)]
Rollup merge of #92704 - 5225225:std_mem_transmute_ref_t_mut_t, r=michaelwoerister

Change lint message to be stronger for &T -> &mut T transmute

The old message implied that it's only UB if you use the reference to mutate, which (as far as I know) is not true. As in, the following program has UB, and a &T -> &mut T transmute is effectively an `unreachable_unchecked`.

```rust
fn main() {
    #[allow(mutable_transmutes)]
    unsafe {
        let _ = std::mem::transmute::<&i32, &mut i32>(&0);
    }
}
```

In the future, it might be a good idea to use the edition system to make this a hard error, since I don't think it is *ever* defined behaviour? Unless we rule that `&UnsafeCell<i32> -> &mut i32` is fine. (That, and you always could just use `.get()`, so you're not losing anything)

2 years agoRollup merge of #92680 - camelid:assoc-item-cleanup, r=petrochenkov
Matthias Krüger [Thu, 20 Jan 2022 16:10:36 +0000 (17:10 +0100)]
Rollup merge of #92680 - camelid:assoc-item-cleanup, r=petrochenkov

intra-doc: Use the impl's assoc item where possible

Before, the trait's associated item would be used. Now, the impl's
associated item is used. The only exception is for impls that use
default values for associated items set by the trait. In that case,
the trait's associated item is still used.

As an example of the old and new behavior, take this code:

    trait MyTrait {
        type AssocTy;
    }

    impl MyTrait for String {
        type AssocTy = u8;
    }

Before, when resolving a link to `String::AssocTy`,
`resolve_associated_trait_item` would return the associated item for
`MyTrait::AssocTy`. Now, it would return the associated item for
`<String as MyTrait>::AssocTy`, as it claims in its docs.

r? `@petrochenkov`

2 years agoRollup merge of #92582 - lcnr:generic-arg-infer, r=BoxyUwU
Matthias Krüger [Thu, 20 Jan 2022 16:10:35 +0000 (17:10 +0100)]
Rollup merge of #92582 - lcnr:generic-arg-infer, r=BoxyUwU

improve `_` constants in item signature handling

removing the "type" from the error messages does slightly worsen the error messages for types, but figuring out whether the placeholder is for a type or a constant and correctly dealing with that seemed fairly difficult to me so I took the easy way out :sparkles: Imo the error message is still clear enough.

r? `@BoxyUwU` cc `@estebank`

2 years agoRollup merge of #92183 - tmandry:issue-74256, r=estebank
Matthias Krüger [Thu, 20 Jan 2022 16:10:34 +0000 (17:10 +0100)]
Rollup merge of #92183 - tmandry:issue-74256, r=estebank

Point at correct argument when async fn output type lifetime disagrees with signature

Fixes most of #74256.

## Problems fixed

This PR fixes a couple of related problems in the error reporting code.

### Highlighting the wrong argument

First, the error reporting code was looking at the desugared return type of an `async fn` to decide which parameter to highlight. For example, a function like

```rust
async fn async_fn(self: &Struct, f: &u32) -> &u32
{ f }
```

desugars to

```rust
async fn async_fn<'a, 'b>(self: &'a Struct, f: &'b u32)
-> impl Future<Output = &'a u32> + 'a + 'b
{ f }
```

Since `f: &'b u32` is returned but the output type is `&'a u32`, the error would occur when checking that `'a: 'b`.

The reporting code would look to see if the "offending" lifetime `'b` was included in the return type, and because the code was looking at the desugared future type, it was included. So it defaulted to reporting that the source of the other lifetime `'a` (the `self` type) was the problem, when it was really the type of `f`. (Note that if it had chosen instead to look at `'a` first, it too would have been included in the output type, and it would have arbitrarily reported the error (correctly this time) on the type of `f`.)

Looking at the actual future type isn't useful for this reason; it captures all input lifetimes. Using the written return type for `async fn` solves this problem and results in less confusing error messages for the user.

This isn't a perfect fix, unfortunately; writing the "manually desugared" form of the above function still results in the wrong parameter being highlighted. Looking at the output type of every `impl Future` return type doesn't feel like a very principled approach, though it might work. The problem would remain for function signatures that look like the desugared one above but use different traits. There may be deeper changes required to pinpoint which part of each type is conflicting.

### Lying about await point capture causing lifetime conflicts

The second issue fixed by this PR is the unnecessary complexity in `try_report_anon_anon_conflict`. It turns out that the root cause I suggested in https://github.com/rust-lang/rust/issues/76547#issuecomment-692863608 wasn't really the root cause. Adding special handling to report that a variable was captured over an await point only made the error messages less correct and pointed to a problem other than the one that actually occurred.

Given the above discussion, it's easy to see why: `async fn`s capture all input lifetimes in their return type, so holding an argument across an await point should never cause a lifetime conflict! Removing the special handling simplified the code and improved the error messages (though they still aren't very good!)

## Future work

* Fix error reporting on the "desugared" form of this code
* Get the `suggest_adding_lifetime_params` suggestion firing on these examples
  * cc #42703, I think

r? `@estebank`

2 years agoRollup merge of #91694 - euclio:stability-improvements, r=GuillaumeGomez
Matthias Krüger [Thu, 20 Jan 2022 16:10:33 +0000 (17:10 +0100)]
Rollup merge of #91694 - euclio:stability-improvements, r=GuillaumeGomez

rustdoc: decouple stability and const-stability

This PR tweaks the stability rendering code to consider stability and const-stability separately. This fixes two issues:

- Stabilities that match the enclosing item are now always omitted, even if the item has const-stability as well (#90552)
- Const-stable unstable functions will now have their (const-) stability rendered.

Fixes #90552.

2 years agoRollup merge of #91606 - joshtriplett:stabilize-print-link-args, r=pnkfelix
Matthias Krüger [Thu, 20 Jan 2022 16:10:32 +0000 (17:10 +0100)]
Rollup merge of #91606 - joshtriplett:stabilize-print-link-args, r=pnkfelix

Stabilize `-Z print-link-args` as `--print link-args`

We have stable options for adding linker arguments; we should have a
stable option to help debug linker arguments.

Add documentation for the new option. In the documentation, make it clear that
the *exact* format of the output is not a stable guarantee.

2 years agoRollup merge of #89764 - tmiasko:uninhabited-enums, r=wesleywiser
Matthias Krüger [Thu, 20 Jan 2022 16:10:31 +0000 (17:10 +0100)]
Rollup merge of #89764 - tmiasko:uninhabited-enums, r=wesleywiser

Fix variant index / discriminant confusion in uninhabited enum branching

Fix confusion between variant index and variant discriminant. The pass
incorrectly assumed that for `Variants::Single` variant index is the same as
variant discriminant.

r? `@wesleywiser`

2 years agoRollup merge of #89747 - Amanieu:maybeuninit_bytes, r=m-ou-se
Matthias Krüger [Thu, 20 Jan 2022 16:10:30 +0000 (17:10 +0100)]
Rollup merge of #89747 - Amanieu:maybeuninit_bytes, r=m-ou-se

Add MaybeUninit::(slice_)as_bytes(_mut)

This adds methods to convert between `MaybeUninit<T>` and a slice of `MaybeUninit<u8>`. This is safe since `MaybeUninit<u8>` can correctly handle padding bytes in any `T`.

These methods are added:
```rust
impl<T> MaybeUninit<T> {
pub fn as_bytes(&self) -> &[MaybeUninit<u8>];
pub fn as_bytes_mut(&mut self) -> &mut [MaybeUninit<u8>];
pub fn slice_as_bytes(this: &[MaybeUninit<T>]) -> &[MaybeUninit<u8>];
pub fn slice_as_bytes_mut(this: &mut [MaybeUninit<T>]) -> &mut [MaybeUninit<u8>];
}
```

2 years agoFix compilation for a few tier 2 targets
Hans Kratz [Thu, 20 Jan 2022 11:43:54 +0000 (12:43 +0100)]
Fix compilation for a few tier 2 targets

2 years agoUpdate `thorin-dwp` to deduplicate `object`
Rémy Rakic [Thu, 20 Jan 2022 14:09:05 +0000 (15:09 +0100)]
Update `thorin-dwp` to deduplicate `object`

2 years agoupdate comments
lcnr [Thu, 20 Jan 2022 13:47:31 +0000 (14:47 +0100)]
update comments

2 years ago:arrow_up: rust-analyzer
Laurențiu Nicola [Thu, 20 Jan 2022 10:14:08 +0000 (12:14 +0200)]
:arrow_up: rust-analyzer

2 years agoAuto merge of #92138 - AngelicosPhosphoros:try_smarter_vec_from_iter_48994_2, r=Mark...
bors [Thu, 20 Jan 2022 06:50:14 +0000 (06:50 +0000)]
Auto merge of #92138 - AngelicosPhosphoros:try_smarter_vec_from_iter_48994_2, r=Mark-Simulacrum

Improve capacity estimation in Vec::from_iter

Iterates on the attempt made in #53086.

Closes #48994

2 years agorustdoc: auto create output directory when "--output-format json"
Artem Kryvokrysenko [Wed, 19 Jan 2022 08:59:44 +0000 (00:59 -0800)]
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)

2 years agoRustdoc mobile: put out-of-band on its own line
Jacob Hoffman-Andrews [Thu, 13 Jan 2022 17:54:44 +0000 (09:54 -0800)]
Rustdoc mobile: put out-of-band on its own line

Before this, the item name and the stability, source link, and "collapse
all docs" would compete for room on a single line, resulting in awkward
wrapping behavior on mobile. This gives a separate line for that
out-of-band information. It also removes the "copy path" icon on mobile
to make a little more room.

Also, switch to flex-wrap: wrap, so anytime there's not enough room for
`source`, it gets bumped to the next line.

2 years agoSupport --bless for pp-exact pretty printer tests
David Tolnay [Thu, 20 Jan 2022 04:12:31 +0000 (20:12 -0800)]
Support --bless for pp-exact pretty printer tests

2 years agoDeduplicate branches of print_break implementation
David Tolnay [Thu, 20 Jan 2022 02:58:33 +0000 (18:58 -0800)]
Deduplicate branches of print_break implementation

2 years agoInline print_newline function
David Tolnay [Thu, 20 Jan 2022 02:56:12 +0000 (18:56 -0800)]
Inline print_newline function

2 years agoInline indent function
David Tolnay [Thu, 20 Jan 2022 02:55:24 +0000 (18:55 -0800)]
Inline indent function

2 years agoEliminate offset number from Fits frames
David Tolnay [Thu, 20 Jan 2022 02:51:07 +0000 (18:51 -0800)]
Eliminate offset number from Fits frames

PrintStackElems with pbreak=PrintStackBreak::Fits always carried a
meaningless value offset=0. We can combine the two types PrintStackElem
+ PrintStackBreak into one PrintFrame enum that stores offset only for
Broken frames.

2 years agoTouch up print_string
David Tolnay [Thu, 20 Jan 2022 02:46:49 +0000 (18:46 -0800)]
Touch up print_string

2 years agoReplace all single character variable names
David Tolnay [Thu, 20 Jan 2022 02:44:17 +0000 (18:44 -0800)]
Replace all single character variable names

2 years agoCombine advance_left matches
David Tolnay [Thu, 20 Jan 2022 02:41:22 +0000 (18:41 -0800)]
Combine advance_left matches

2 years agoInline print into advance_left
David Tolnay [Thu, 20 Jan 2022 02:39:38 +0000 (18:39 -0800)]
Inline print into advance_left

2 years agoSimplify advance_left
David Tolnay [Thu, 20 Jan 2022 02:37:45 +0000 (18:37 -0800)]
Simplify advance_left

2 years agoSimplify left_total tracking
David Tolnay [Thu, 20 Jan 2022 02:36:29 +0000 (18:36 -0800)]
Simplify left_total tracking

2 years agoEliminate a token clone from advance_left
David Tolnay [Thu, 20 Jan 2022 02:35:02 +0000 (18:35 -0800)]
Eliminate a token clone from advance_left

2 years agoGrow scan_stack in the conventional direction
David Tolnay [Thu, 20 Jan 2022 02:27:26 +0000 (18:27 -0800)]
Grow scan_stack in the conventional direction

The pretty printer algorithm involves 2 VecDeques: a ring-buffer of
tokens and a deque of ring-buffer indices. Confusingly, those two deques
were being grown in opposite directions for no good reason. Ring-buffer
pushes would go on the "back" of the ring-buffer (i.e. higher indices)
while scan_stack pushes would go on the "front" (i.e. lower indices).
This commit flips the scan_stack accesses to grow the scan_stack and
ring-buffer in the same direction, where push does the same
operation as a Vec push i.e. inserting on the high-index end.

2 years agoDelete unused Display for pretty printer Token
David Tolnay [Thu, 20 Jan 2022 02:26:16 +0000 (18:26 -0800)]
Delete unused Display for pretty printer Token

2 years agoShow a more informative panic message when `DefPathHash` does not exist
Aaron Hill [Wed, 19 Jan 2022 22:36:44 +0000 (17:36 -0500)]
Show a more informative panic message when `DefPathHash` does not exist

This should hopefully make it easier to debug incremental compilation
bugs like #93096 without affecting performance.

2 years agoAuto merge of #93085 - matthiaskrgr:rollup-mgpu2ju, r=matthiaskrgr
bors [Wed, 19 Jan 2022 22:34:55 +0000 (22:34 +0000)]
Auto merge of #93085 - matthiaskrgr:rollup-mgpu2ju, r=matthiaskrgr

Rollup of 6 pull requests

Successful merges:

 - #92316 (mangling_v0: Skip extern blocks during mangling)
 - #92630 (Change PhantomData type for `BuildHasherDefault` (and more))
 - #92800 (Add manifest docs fallback.)
 - #93005 (Move back templates into html folder)
 - #93065 (Pretty printer algorithm revamp step 2)
 - #93077 (remove `List::is_noop`)

Failed merges:

 - #93068 (Fix spacing for `·` between stability and source)

r? `@ghost`
`@rustbot` modify labels: rollup

2 years agoSimplify error reporting code, remove await point wording
Tyler Mandry [Fri, 10 Dec 2021 00:01:05 +0000 (00:01 +0000)]
Simplify error reporting code, remove await point wording

2 years agoNiceRegionError: Use written return type for async fn
Tyler Mandry [Sat, 20 Nov 2021 02:48:29 +0000 (02:48 +0000)]
NiceRegionError: Use written return type for async fn

2 years agoProperly account for binders in get_impl_future_output_ty
Tyler Mandry [Tue, 21 Dec 2021 22:08:47 +0000 (22:08 +0000)]
Properly account for binders in get_impl_future_output_ty

2 years agoAdd MaybeUninit::as_bytes
Amanieu d'Antras [Sun, 10 Oct 2021 18:19:52 +0000 (19:19 +0100)]
Add MaybeUninit::as_bytes

2 years agosrc/test/rustdoc-json: Check for `struct_field`s in `variant_tuple_struct.rs`
Martin Nordholts [Wed, 19 Jan 2022 21:03:08 +0000 (22:03 +0100)]
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`.

2 years agoFix scroll offset when jumping to internal id
Jacob Hoffman-Andrews [Wed, 19 Jan 2022 06:05:17 +0000 (22:05 -0800)]
Fix scroll offset when jumping to internal id

2 years ago⬆ chalk to 0.76.0
pierwill [Wed, 19 Jan 2022 19:44:43 +0000 (13:44 -0600)]
⬆ chalk to 0.76.0

2 years agoAdd tests to ensure that let_chains works with if_let_guard
Caio [Wed, 19 Jan 2022 19:23:44 +0000 (16:23 -0300)]
Add tests to ensure that let_chains works with if_let_guard

2 years agoFix test directives; comment out calls broken on windows-gnu
Richard Cobbe [Mon, 29 Nov 2021 19:28:41 +0000 (11:28 -0800)]
Fix test directives; comment out calls broken on windows-gnu

2 years agoRollup merge of #93077 - lcnr:write_substs, r=oli-obk
Matthias Krüger [Wed, 19 Jan 2022 18:19:52 +0000 (19:19 +0100)]
Rollup merge of #93077 - lcnr:write_substs, r=oli-obk

remove `List::is_noop`

think that `is_noop` is actually less clear than just using `is_empty`

2 years agoRollup merge of #93065 - dtolnay:ringbuffer, r=lcnr
Matthias Krüger [Wed, 19 Jan 2022 18:19:51 +0000 (19:19 +0100)]
Rollup merge of #93065 - dtolnay:ringbuffer, r=lcnr

Pretty printer algorithm revamp step 2

This PR follows #92923 as a second chunk of modernizations backported from https://github.com/dtolnay/prettyplease into rustc_ast_pretty.

I've broken this up into atomic commits that hopefully are sensible in isolation. At every commit, the pretty printer is compilable and has runtime behavior that is identical to before and after the PR. None of the refactoring so far changes behavior.

The general theme of this chunk of commits is: the logic in the old pretty printer is doing some very basic things (pushing and popping tokens on a ring buffer) but expressed in a too-low-level way that I found makes it quite complicated/subtle to reason about. There are a number of obvious invariants that are "almost true" -- things like `self.left == self.buf.offset` and `self.right == self.buf.offset + self.buf.data.len()` and `self.right_total == self.left_total + self.buf.data.sum()`. The reason these things are "almost true" is the implementation tends to put updating one side of the invariant unreasonably far apart from updating the other side, leaving the invariant broken while unrelated stuff happens in between. The following code from master is an example of this:

https://github.com/rust-lang/rust/blob/e5e2b0be26ea177527b60d355bd8f56cd473bd00/compiler/rustc_ast_pretty/src/pp.rs#L314-L317

In this code the `advance_right` is reserving an entry into which to write a next token on the right side of the ring buffer, the `check_stack` is doing something totally unrelated to the right boundary of the ring buffer, and the `scan_push` is actually writing the token we previously reserved space for. Much of what this PR is doing is rearranging code to shrink the amount of stuff in between when an invariant is broken to when it is restored, until the whole thing can be factored out into one indivisible method call on the RingBuffer type.

The end state of the PR is that we can entirely eliminate `self.left` (because it's now just equal to `self.buf.offset` always) and `self.right` (because it's equal to `self.buf.offset + self.buf.data.len()` always) and the whole `Token::Eof` state which used to be the value of tokens that have been reserved space for but not yet written.

I found without these changes the pretty printer implementation to be hard to reason about and I wasn't able to confidently introduce improvements like trailing commas in `prettyplease` until after this refactor. The logic here is 43 years old at this point (Graydon translated it as directly as possible from the 1979 pretty printing paper) and while there are advantages to following the paper as closely as possible, in `prettyplease` I decided if we're going to adapt the algorithm to work better for Rust syntax, it was worthwhile making it easier to follow than the original.

2 years agoRollup merge of #93005 - GuillaumeGomez:templates-in-html, r=notriddle
Matthias Krüger [Wed, 19 Jan 2022 18:19:49 +0000 (19:19 +0100)]
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`

2 years agoRollup merge of #92800 - ehuss:docs-fallback, r=Mark-Simulacrum
Matthias Krüger [Wed, 19 Jan 2022 18:19:48 +0000 (19:19 +0100)]
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

2 years agoRollup merge of #92630 - steffahn:lift_bounds_on_BuildHasherDefault, r=yaahc
Matthias Krüger [Wed, 19 Jan 2022 18:19:47 +0000 (19:19 +0100)]
Rollup merge of #92630 - steffahn:lift_bounds_on_BuildHasherDefault, r=yaahc

Change PhantomData type for `BuildHasherDefault` (and more)

Changes `PhantomData<H>` to `PhantomData<fn() -> H>` for `BuildHasherDefault`. This preserves the covariance of `H`, while it lifts the currently inferred unnecessary bounds like [`H: Send` for `BuildHasherDefault<H>: Send`](https://doc.rust-lang.org/1.57.0/std/hash/struct.BuildHasherDefault.html#impl-Send), etc.

_Edit:_ Also does a similar change for `iter::Empty` and `future::Pending`.

2 years agoRollup merge of #92316 - petrochenkov:extmangle, r=wesleywiser
Matthias Krüger [Wed, 19 Jan 2022 18:19:45 +0000 (19:19 +0100)]
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.)

2 years agoOnly suggest adding `!` to expressions that can be macro invocation
Esteban Kuber [Wed, 19 Jan 2022 02:27:15 +0000 (02:27 +0000)]
Only suggest adding `!` to expressions that can be macro invocation

2 years agoAdd assert that fallback targets must be available.
Eric Huss [Wed, 19 Jan 2022 17:41:04 +0000 (09:41 -0800)]
Add assert that fallback targets must be available.

2 years agoAuto merge of #93069 - matthiaskrgr:rollup-gx1vkp7, r=matthiaskrgr
bors [Wed, 19 Jan 2022 15:01:10 +0000 (15:01 +0000)]
Auto merge of #93069 - matthiaskrgr:rollup-gx1vkp7, r=matthiaskrgr

Rollup of 10 pull requests

Successful merges:

 - #88642 (Formally implement let chains)
 - #89621 (doc: guarantee call order for sort_by_cached_key)
 - #91278 (Use iterator instead of recursion in `codegen_place`)
 - #92124 (Little improves in CString `new` when creating from slice)
 - #92783 (Annotate dead code lint with notes about ignored derived impls)
 - #92797 (Remove horizontal lines at top of page)
 - #92920 (Move expr- and item-related pretty printing functions to modules)
 - #93041 (Remove some unused ordering derivations based on `DefId`)
 - #93051 (Add Option::is_some_with and Result::is_{ok,err}_with)
 - #93062 (Update books)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup

2 years agoUpdate std::fs::remove_dir_all documentation
Pietro Albini [Wed, 19 Jan 2022 12:14:24 +0000 (13:14 +0100)]
Update std::fs::remove_dir_all documentation

2 years agoFix CVE-2022-21658 for WASI
Alex Crichton [Tue, 4 Jan 2022 16:44:15 +0000 (08:44 -0800)]
Fix CVE-2022-21658 for WASI

2 years agoFix CVE-2022-21658 for UNIX-like
Hans Kratz [Sat, 18 Dec 2021 14:30:30 +0000 (15:30 +0100)]
Fix CVE-2022-21658 for UNIX-like

2 years agoFix CVE-2022-21658 for Windows
Chris Denton [Thu, 6 Jan 2022 02:47:36 +0000 (02:47 +0000)]
Fix CVE-2022-21658 for Windows

2 years agoImprove estimation of capacity in Vec::from_iter
AngelicosPhosphoros [Mon, 20 Dec 2021 20:58:45 +0000 (23:58 +0300)]
Improve estimation of capacity in Vec::from_iter

Closes #48994

2 years agoremove `is_noop`
lcnr [Wed, 19 Jan 2022 09:33:23 +0000 (10:33 +0100)]
remove `is_noop`

2 years agoAdd test for block doc comments
Guillaume Gomez [Tue, 18 Jan 2022 15:56:37 +0000 (16:56 +0100)]
Add test for block doc comments

2 years agoCorrectly handle starts in block doc comments
Guillaume Gomez [Tue, 18 Jan 2022 15:56:16 +0000 (16:56 +0100)]
Correctly handle starts in block doc comments