Commit Graph

161613 Commits

Author SHA1 Message Date
Matthias Krüger
9474c74fb6
Rollup merge of #93109 - JakobDegen:arc-docs, r=m-ou-se
Improve `Arc` and `Rc` documentation

This makes two changes (I can split the PR if necessary, but the changes are pretty small):
 1. A bunch of trait implementations claimed to be zero cost; however, they use the `Arc<T>: From<Box<T>>` impl which is definitely not free, especially for large dynamically sized `T`.
 2.  The code in deferred initialization examples unnecessarily used excessive amounts of `unsafe`. This has been reduced.
2022-01-21 22:03:18 +01:00
Matthias Krüger
ab19d4a515
Rollup merge of #93046 - est31:let_else, r=davidtwco
Use let_else in even more places

Followup of #89933, #91018, #91481.
2022-01-21 22:03:17 +01:00
Matthias Krüger
1f3a2dd0b1
Rollup merge of #92963 - terrarier2111:tuple-diagnostic, r=davidtwco
Implement tuple array diagnostic

Fixes https://github.com/rust-lang/rust/issues/92089
2022-01-21 22:03:16 +01:00
Matthias Krüger
430673f265
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";
      |                     +++++++++++
2022-01-21 22:03:15 +01:00
Matthias Krüger
e38cbc78aa
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`
2022-01-21 22:03:14 +01:00
Matthias Krüger
701a8330e8
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`
2022-01-21 22:03:13 +01:00
Matthias Krüger
10c9ec399e
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.
2022-01-21 22:03:12 +01:00
Matthias Krüger
fc694064e8
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`
2022-01-21 22:03:11 +01:00
bors
cbaeec14f9 Auto merge of #92983 - pietroalbini:pa-bump-runner-images, r=Mark-Simulacrum
Update Linux runners to Ubuntu 20.04

r? `@Mark-Simulacrum`
2022-01-21 17:43:39 +00:00
bors
4d8b66aefd 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`.
2022-01-21 14:33:17 +00:00
Cameron Steffen
b11733534d Remove a span from hir::ExprKind::MethodCall 2022-01-21 07:48:10 -06:00
bors
84e918971d 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.
2022-01-21 10:38:30 +00:00
Pietro Albini
b3ad40532d
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.
2022-01-21 09:33:43 +01:00
Pietro Albini
b27d59d083
replace paths in PathSet with a dedicated TaskPath struct 2022-01-21 09:33:38 +01:00
bors
0bcacb391b 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)],
    ));
};
```
2022-01-21 06:20:18 +00:00
bors
523be2e05d 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
2022-01-21 03:04:43 +00:00
Matthias Krüger
dd164313d5
Rollup merge of #93136 - pietroalbini:pa-1.58.1-relnotes-master, r=pietroalbini
Backport the 1.58.1 release notes to master

r? `@ghost`
2022-01-20 23:37:44 +01:00
Matthias Krüger
9ea966a275
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`
2022-01-20 23:37:43 +01:00
Matthias Krüger
b8df581ef8
Rollup merge of #93114 - lcnr:mk_array, r=RalfJung
update comment for `ensure_monomorphic_enough`

r? `@RalfJung`
2022-01-20 23:37:42 +01:00
Matthias Krüger
5e46f7dceb
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
2022-01-20 23:37:41 +01:00
Matthias Krüger
d4ec46444b
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 401d60c042):

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

And the PR after that, for intelligent trailing commas (based on e2a0297f17):

```console
Struct { x: 0, y: 0 }
Structtttttttttttttttttttttttttttttttttttttttttttttttttt {
    xxxxxxxxx: 0,
    yyyyyyyyy: 0,
}
```
2022-01-20 23:37:40 +01:00
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
e901b24310
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.
2022-01-20 23:37:38 +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
b1a405df19
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.
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
Pietro Albini
028a3e77f9
backport the 1.58.1 relnotes to master 2022-01-20 22:59:54 +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
bors
777bb86bcd 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 (⬆️ rust-analyzer)
 - #93112 (Fix CVE-2022-21658)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-01-20 20:44:14 +00:00
Pietro Albini
855c17643a
add script to prevent point releases with same number as existing ones 2022-01-20 21:27:17 +01:00
Matthias Krüger
dbc97490bb
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`
2022-01-20 17:10:43 +01:00
Matthias Krüger
d893b0ab32
Rollup merge of #93108 - lnicola:rust-analyzer-2022-01-20, r=lnicola
⬆️ rust-analyzer

r? `@ghost`
2022-01-20 17:10:42 +01:00
Matthias Krüger
6c627d25f6
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 17:10:41 +01:00
Matthias Krüger
1cb57e2d2b
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.
2022-01-20 17:10:40 +01:00
Matthias Krüger
ed3bf67db7
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`
2022-01-20 17:10:39 +01:00
Matthias Krüger
5c10dbd85f
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)
2022-01-20 17:10:37 +01:00
Matthias Krüger
1839829f0a
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`
2022-01-20 17:10:36 +01:00
Matthias Krüger
db1253f1d2
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  Imo the error message is still clear enough.

r? `@BoxyUwU` cc `@estebank`
2022-01-20 17:10:35 +01:00
Matthias Krüger
413f490677
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`
2022-01-20 17:10:34 +01:00
Matthias Krüger
405cf20442
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.
2022-01-20 17:10:33 +01:00