Commit graph

148621 commits

Author SHA1 Message Date
bors
747a5d2a5d Auto merge of #85316 - eddyb:cg-ssa-on-demand-cleanuppad, r=nagisa
rustc_codegen_ssa: generate MSVC cleanup pads on demand, like GNU landing pads.

This unblocks #84993 in terms of codegen tests, as it brings the MSVC-style (`cleanup_pad`) EH (LLVM) block order in line with the GNU-style (`landing_pad`) EH (LLVM) block order, by having both of them be on-demand (instead of MSVC-style being eager and GNU-style lazy/on-demand).

It also unifies the two implementations a bit, similar to #84699, but in the opposite direction (as that attempt made both kinds of EH pads eagerly built).

~~Opening as draft because I haven't done enough Windows testing just yet, of both this PR, and of #84993 rebased on it.~~ (**EDIT**: seems to be working as expected)

r? `@nagisa`
2021-05-16 12:30:07 +00:00
bors
3f46b82d29 Auto merge of #85332 - RalfJung:ptr-in-str, r=oli-obk
CTFE validation: handle pointers in str

I also finally learned how I can match *some* NOTEs in a ui test without matching all of them, and applied that to some const tests in the 2nd commit where I added NOTE because I did not know what I was doing. I can separate this into its own PR if you prefer.

Fixes https://github.com/rust-lang/rust/issues/83182
r? `@oli-obk`
2021-05-16 09:49:12 +00:00
bors
94ecdfd115 Auto merge of #85304 - Stupremee:crates-in-sidebar-in-root, r=Nemo157
rustdoc: Call `initSidebarItems` in root module of crate

r? `@jsha`

Resolves #85301
2021-05-16 07:32:57 +00:00
Luqman Aden
45225d24bf Windows mingw targets use gcc as the linker so the target spec should also indicate linker_is_gnu. 2021-05-15 22:09:34 -07:00
bors
e78bccfbc0 Auto merge of #85279 - DrChat:asm_powerpc64, r=Amanieu
Add asm!() support for PowerPC64

I was anticipating this to be difficult so I didn't do it as part of #84732... but this was pretty easy to do 👀
2021-05-16 04:47:52 +00:00
Jack Huey
c6e4284f8b Add comments to opportunistic resolve functions 2021-05-15 23:36:10 -04:00
Amanieu d'Antras
1605e0ec4e Fix comments in tests 2021-05-16 03:54:08 +01:00
hi-rustin
2cb1ba3671 More tests for issue-85255 2021-05-16 10:18:28 +08:00
bors
6d525d5028 Auto merge of #85259 - Smittyvb:thir-unsafeck-inline-asm, r=nikomatsakis
Check for inline assembly in THIR unsafeck

#83129 was merged recently and added a THIR unsafe checker. This adds a check for inline assembly. (and this is 2x simpler than the MIR version, which has to check for `asm` and `llvm_asm` in two separate spots!)

 see also rust-lang/project-thir-unsafeck#7
2021-05-16 00:54:01 +00:00
Jonas Schievink
bd16825767 Allow async {} expressions in const contexts 2021-05-16 02:06:40 +02:00
Igor Matuszewski
9235446518 Update RLS 2021-05-16 01:30:39 +02:00
Eric Huss
5bbc240ffb Fix unused attributes on macro_rules. 2021-05-15 16:13:46 -07:00
bors
d565c74887 Auto merge of #81858 - ijackson:fork-no-unwind, r=m-ou-se
Do not allocate or unwind after fork

### Objective scenarios

 * Make (simple) panics safe in `Command::pre_exec_hook`, including most `panic!` calls, `Option::unwrap`, and array bounds check failures.
 * Make it possible to `libc::fork` and then safely panic in the child (needed for the above, but this requirement means exposing the new raw hook API which the `Command` implementation needs).
 * In singlethreaded programs, where panic in `pre_exec_hook` is already memory-safe, prevent the double-unwinding malfunction #79740.

I think we want to make panic after fork safe even though the post-fork child environment is only experienced by users of `unsafe`, beause the subset of Rust in which any panic is UB is really far too hazardous and unnatural.

#### Approach

 * Provide a way for a program to, at runtime, switch to having panics abort.  This makes it possible to panic without making *any* heap allocations, which is needed because on some platforms malloc is UB in a child forked from a multithreaded program (see https://github.com/rust-lang/rust/pull/80263#issuecomment-774272370, and maybe also the SuS [spec](https://pubs.opengroup.org/onlinepubs/9699919799/functions/fork.html)).
 * Make that change in the child spawned by `Command`.
 * Document the rules comprehensively enough that a programmer has a fighting chance of writing correct code.
 * Test that this all works as expected (and in particular, that there aren't any heap allocations we missed)

Fixes #79740

#### Rejected (or previously attempted) approaches

 * Change the panic machinery to be able to unwind without allocating, at least when the payload and message are both `'static`.  This seems like it would be even more subtle.  Also that is a potentially-hot path which I don't want to mess with.
 * Change the existing panic hook mechanism to not convert the message to a `String` before calling the hook.  This would be a surprising change for existing code and would not be detected by the type system.
 * Provide a `raw_panic_hook` function to intercept panics in a way that doesn't allocate.  (That was an earlier version of this MR.)

### History

This MR could be considered a v2 of #80263.  Thanks to everyone who commented there.  In particular, thanks to `@m-ou-se,` `@Mark-Simulacrum` and `@hyd-dev.`  (Tagging you since I think you might be interested in this new MR.)  Compared to #80263, this MR has very substantial changes and additions.

Additionally, I have recently (2021-04-20) completely revised this series following very helpful comments from `@m-ou-se.`

r? `@m-ou-se`
2021-05-15 22:27:09 +00:00
bors
8cf990c9b5 Auto merge of #84920 - Aaron1011:pretty-print-rental, r=petrochenkov
Remove some unncessary spaces from pretty-printed tokenstream output

In addition to making the output look nicer for all crates, this also
aligns the pretty-printing output with what the `rental` crate expects.
This will allow us to eventually disable a backwards-compat hack in a
follow-up PR.

See https://github.com/rust-lang/rust/issues/84428 for some background information about why we want to make this change. Note that this change would be desirable (but not particularly necessary) even if `rental` didn't exist, so we're not adding any crate-specific hacks into the compiler.
2021-05-15 19:58:59 +00:00
Jack Huey
0daabbee2d Change to just use first binders and add test 2021-05-15 15:52:39 -04:00
Fabian Wolff
7217d767b2 Report an error if a lang item has the wrong number of generic arguments 2021-05-15 19:53:16 +02:00
bors
50f2bf6a57 Auto merge of #85335 - GuillaumeGomez:rollup-0tvc14g, r=GuillaumeGomez
Rollup of 4 pull requests

Successful merges:

 - #84751 (str::is_char_boundary - slight optimization)
 - #85185 (Generate not more docs than necessary)
 - #85324 (Warn about unused `pub` fields in non-`pub` structs)
 - #85329 (fix version_str comment)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-05-15 17:37:18 +00:00
Ryan Lopopolo
963bd3b643
Implement more Iterator methods on core::iter::Repeat
`core::iter::Repeat` always returns the same element, which means we can
do better than implementing most `Iterator` methods in terms of
`Iterator::next`.

Fixes #81292.
2021-05-15 10:37:05 -07:00
Justus K
aaf0ff83fb
Call initSidebarItems in root module of crate 2021-05-15 19:26:36 +02:00
Ralf Jung
70c1cf151e 32bit bless 2021-05-15 18:42:35 +02:00
Jack Huey
909d0e83d6 Missed a couple things 2021-05-15 12:26:50 -04:00
Jack Huey
d2554776b8 Add comment 2021-05-15 12:12:56 -04:00
Jack Huey
fb6cec440a Revert to only using opportunistic_resolve_vars for existing places 2021-05-15 12:10:56 -04:00
Aaron Hill
357c013ff5
Remove some unncessary spaces from pretty-printed tokenstream output
In addition to making the output look nicer for all crates, this also
aligns the pretty-printing output with what the `rental` crate expects.
This will allow us to eventually disable a backwards-compat hack in a
follow-up PR.
2021-05-15 12:05:03 -04:00
Ralf Jung
8af76cb64d split ui test stderr by bitwidth 2021-05-15 18:02:39 +02:00
Guillaume Gomez
8ea8252ca5
Rollup merge of #85329 - RalfJung:version, r=Mark-Simulacrum
fix version_str comment

This version string is ultimately generated here
87423fbc6a/src/bootstrap/channel.rs (L72)
and I don't think it includes the `rustc` prefix. That also matches its use here
ac923d94f8/compiler/rustc_driver/src/lib.rs (L758)
2021-05-15 17:56:50 +02:00
Guillaume Gomez
7a6a25eb2e
Rollup merge of #85324 - FabianWolff:issue-85255, r=varkor
Warn about unused `pub` fields in non-`pub` structs

This pull request fixes #85255. The current implementation of dead code analysis is too prudent because it marks all `pub` fields of structs as live, even though they cannot be accessed from outside of the current crate if the struct itself only has restricted or private visibility.

I have changed this behavior to take the containing struct's visibility into account when looking at field visibility and liveness. This also makes dead code warnings more consistent; consider the example given in #85255:
```rust
struct Foo {
    a: i32,
    pub b: i32,
}

struct Bar;

impl Bar {
    fn a(&self) -> i32 { 5 }
    pub fn b(&self) -> i32 { 6 }
}

fn main() {
    let _ = Foo { a: 1, b: 2 };
    let _ = Bar;
}
```
Current nightly already warns about `Bar::b()`, even though it is `pub` (but `Bar` is not). It should therefore also warn about `Foo::b`, which it does with the changes in this PR.
2021-05-15 17:56:49 +02:00
Guillaume Gomez
f851f97e87
Rollup merge of #85185 - GuillaumeGomez:generate-not-more-docs-than-necessary, r=Mark-Simulacrum
Generate not more docs than necessary

This is something that `@Nemo157` was talking about: they wanted that when using `x.py doc std`, it only generated `std` (and the crates "before" it).

r? `@Mark-Simulacrum`
2021-05-15 17:56:48 +02:00
Guillaume Gomez
62b834fb9f
Rollup merge of #84751 - Soveu:is_char_boundary_opt, r=Amanieu
str::is_char_boundary - slight optimization

Current `str::is_char_boundary` implementation emits slightly more instructions, because it includes an additional branch for `index == s.len()`
```rust
pub fn is_char_boundary(s: &str, index: usize) -> bool {
    if index == 0 || index == s.len() {
        return true;
    }
    match s.as_bytes().get(index) {
        None => false,
        Some(&b) => (b as i8) >= -0x40,
    }
}
```
Just changing the place of `index == s.len()` merges it with `index < s.len()` from `s.as_bytes().get(index)`
```rust
pub fn is_char_boundary2(s: &str, index: usize) -> bool {
    if index == 0 {
        return true;
    }

    match s.as_bytes().get(index) {
        // For some reason, LLVM likes this comparison here more
        None => index == s.len(),
        // This is bit magic equivalent to: b < 128 || b >= 192
        Some(&b) => (b as i8) >= -0x40,
    }
}
```
This one has better codegen on every platform, except powerpc
<details><summary>x86 codegen</summary>
<p>

```nasm
example::is_char_boundary:
        mov     al, 1
        test    rdx, rdx
        je      .LBB0_5
        cmp     rsi, rdx
        je      .LBB0_5
        cmp     rsi, rdx
        jbe     .LBB0_3
        cmp     byte ptr [rdi + rdx], -65
        setg    al
.LBB0_5:
        ret
.LBB0_3:
        xor     eax, eax
        ret

example::is_char_boundary2:
        test    rdx, rdx
        je      .LBB1_1
        cmp     rsi, rdx
        jbe     .LBB1_4
        cmp     byte ptr [rdi + rdx], -65
        setg    al
        ret
.LBB1_1:  ; technically this branch is the same as LBB1_4
        mov     al, 1
        ret
.LBB1_4:
        sete    al
        ret
 ```
</p>
</details>

<details><summary>aarch64 codegen</summary>
<p>

```as
example::is_char_boundary:
        mov     x8, x0
        mov     w0, #1
        cbz     x2, .LBB0_4
        cmp     x1, x2
        b.eq    .LBB0_4
        b.ls    .LBB0_5
        ldrsb   w8, [x8, x2]
        cmn     w8, #65
        cset    w0, gt
.LBB0_4:
        ret
.LBB0_5:
        mov     w0, wzr
        ret

example::is_char_boundary2:
        cbz     x2, .LBB1_3
        cmp     x1, x2
        b.ls    .LBB1_4
        ldrsb   w8, [x0, x2]
        cmn     w8, #65
        cset    w0, gt
        ret
.LBB1_3:
        mov     w0, #1
        ret
.LBB1_4:
        cset    w0, eq
        ret
```

</p>
</details>

<details><summary>riscv64gc codegen</summary>
<p>

example::is_char_boundary:
        seqz    a3, a2
        xor     a4, a1, a2
        seqz    a4, a4
        or      a4, a4, a3
        addi    a3, zero, 1
        bnez    a4, .LBB0_3
        bgeu    a2, a1, .LBB0_4
        add     a0, a0, a2
        lb      a0, 0(a0)
        addi    a1, zero, -65
        slt     a3, a1, a0
.LBB0_3:
        mv      a0, a3
        ret
.LBB0_4:
        mv      a0, zero
        ret

example::is_char_boundary2:
        beqz    a2, .LBB1_3
        bgeu    a2, a1, .LBB1_4
        add     a0, a0, a2
        lb      a0, 0(a0)
        addi    a1, zero, -65
        slt     a0, a1, a0
        ret
.LBB1_3:
        addi    a0, zero, 1
        ret
.LBB1_4:
        xor     a0, a1, a2
        seqz    a0, a0
        ret

</p>
</details>

[Link to godbolt](https://godbolt.org/z/K8avEz8Gr)

`@rustbot` label: A-codegen
2021-05-15 17:56:47 +02:00
Guillaume Gomez
b9b67b7d5b Don't generate more docs than necessary 2021-05-15 17:21:12 +02:00
bors
eac3c7c5bd Auto merge of #82208 - jyn514:rustfmt-subtree, r=Mark-Simulacrum
Convert rustfmt from a submodule to a subtree

r? `@calebcartwright` cc `@Manishearth` `@Mark-Simulacrum`

The motivation is that submodule updates cause rustfmt to not be available on nightly a lot; most recently it was unavailable for over 10 days, causing the beta release to be delayed. Additionally this is much less work on the part of the rustfmt maintainers to keep the rustfmt compiling, since now people making breaking changes will be responsible for fixing them.

I kept the rustfmt git history so it looks like there are thousands of commits. The important commits are 851dee3af9~..pull/82208/head. This adds about 10 MB of git history, which is not terribly much compared to the 702 MB that already exist.

- Add `src/tools/rustfmt` to `x.py check`
- Fix CRLF issues with rustfmt tests (see commit for details)
- Use `rustc_private` instead of crates.io dependencies

  This was already switched upstream and would have landed in the next submodule bump anyway. This just updates Cargo.lock for rust-lang/rust.

- Add `yansi-term` to the list of allowed dependencies.

  This is a false positive - rustc doesn't actually use it, only rustfmt, but because it's activated by the cargo feature of a dependency, tidy gets confused. It's fairly innocuous in any case, it's used for color printing.
  This would have happened in the next submodule bump.

- Remove rustfmt from the list of toolstate tools.
- Give a hard error if testing or building rustfmt fails.
-  Update log to 0.4.14

   This avoids a warning about semicolons in macros; see the commit for details.

- Don't add tools to the sysroot when they finish building.

  This is the only change that could be considered a regression - this avoids a "colliding StableCrateId" error due to a bug in resolve (https://github.com/rust-lang/rust/issues/56935). The regression is that this rebuilds dependencies more often than strictly necessary. See the commit for details.

Fixes https://github.com/rust-lang/rust/issues/85226 (permanently). Closes https://github.com/rust-lang/rust/issues/82385. Helps with https://github.com/rust-lang/rust/issues/70651. Helps with https://github.com/rust-lang/rust/issues/80639.
2021-05-15 14:55:56 +00:00
Ralf Jung
f1fdbe2b7b get rid of a bunch of unnecessary NOTE in const tests 2021-05-15 15:10:14 +02:00
Ralf Jung
a1507b80c2 handle pointers in str 2021-05-15 15:04:41 +02:00
bors
2a245f40a1 Auto merge of #85328 - GuillaumeGomez:rollup-exe9nbj, r=GuillaumeGomez
Rollup of 12 pull requests

Successful merges:

 - #84461 (rustdoc: Remove unnecessary `StripItem` wrapper)
 - #85067 (Minimize amount of fake `DefId`s used in rustdoc)
 - #85207 (Fix typo in comment)
 - #85215 (coverage bug fixes and some refactoring)
 - #85221 (dbg macro: Discuss use in tests, and slightly clarify)
 - #85246 (Miner code formatting)
 - #85253 (swap function order for better read flow)
 - #85256 (Fix display for "implementors" section)
 - #85268 (Use my real name)
 - #85278 (Improve match statements)
 - #85289 (Fix toggle position on mobile)
 - #85323 (Fix eslint errors)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-05-15 12:41:28 +00:00
Ralf Jung
c96d531a92 fix version_str comment 2021-05-15 14:22:29 +02:00
Guillaume Gomez
46bc5526db
Rollup merge of #85323 - GuillaumeGomez:fix-eslint-errors, r=jsha
Fix eslint errors

I cherry-picked the two non-CI commits from #85285.

r? ```@jsha```
2021-05-15 13:29:57 +02:00
Guillaume Gomez
2b5ef25744
Rollup merge of #85289 - GuillaumeGomez:fix-toggle-position-mobile, r=jsha
Fix toggle position on mobile

Before:

![Screenshot from 2021-05-14 14-21-27](https://user-images.githubusercontent.com/3050060/118276475-fe210300-b4c7-11eb-94f8-4e2a4e10d91e.png)
![Screenshot from 2021-05-14 14-21-30](https://user-images.githubusercontent.com/3050060/118276479-feb99980-b4c7-11eb-85db-40e9df6e9abd.png)

After:

![Screenshot from 2021-05-14 15-16-54](https://user-images.githubusercontent.com/3050060/118276494-0416e400-b4c8-11eb-9479-d447928cfa62.png)
![Screenshot from 2021-05-14 15-16-59](https://user-images.githubusercontent.com/3050060/118276498-0416e400-b4c8-11eb-99f6-894276c62dfc.png)

r? ```@jsha```
2021-05-15 13:29:56 +02:00
Guillaume Gomez
cd3d166021
Rollup merge of #85278 - ayushmishra2005:code-refactoring, r=jackh726
Improve match statements
2021-05-15 13:29:55 +02:00
Guillaume Gomez
1a926bf3c5
Rollup merge of #85268 - camelid:real-name, r=Mark-Simulacrum
Use my real name
2021-05-15 13:29:54 +02:00
Guillaume Gomez
5bfbabc892
Rollup merge of #85256 - GuillaumeGomez:fix-implementors-display, r=notriddle
Fix display for "implementors" section

Just saw this problem when going through docs:

![Screenshot from 2021-05-13 15-20-52](https://user-images.githubusercontent.com/3050060/118131978-766fc180-b3ff-11eb-86a8-7f6d22afa675.png)

This fix puts it back to normal:

![Screenshot from 2021-05-13 15-23-29](https://user-images.githubusercontent.com/3050060/118132006-7e2f6600-b3ff-11eb-9985-025a7b7c5216.png)

You can see it on the `TryFrom` page for example.

r? ```@Nemo157```
2021-05-15 13:29:53 +02:00
Guillaume Gomez
36b3c28497
Rollup merge of #85253 - RafaelKr:patch-1, r=varkor
swap function order for better read flow

I was reading this error message for the first time.

I was a little bit confused when reading that part:
```
foo.bar(); // we can now use this method since i32 implements the Foo trait
```

At the time I was reading `// we can now use this method` I wasn't sure why. It only made sense when reading on. So swapping these parts results in a better read flow.
2021-05-15 13:29:52 +02:00
Guillaume Gomez
57aa0d812a
Rollup merge of #85246 - ayushmishra2005:minor-reactoring, r=petrochenkov
Miner code formatting
2021-05-15 13:29:51 +02:00
Guillaume Gomez
5a8619b435
Rollup merge of #85221 - ijackson:dbg-doc-re-tests, r=joshtriplett
dbg macro: Discuss use in tests, and slightly clarify

As discussed in a tangent in #82778.

I chose to use [semantic newlines](https://rhodesmill.org/brandon/2012/one-sentence-per-line/) in the source text but I don't mind reformatting it.
2021-05-15 13:29:50 +02:00
Guillaume Gomez
e611e64e3a
Rollup merge of #85215 - richkadel:ice-fixes-minus-dead-blocks, r=tmandry
coverage bug fixes and some refactoring

This replaces the relevant commits (2 and 3) from PR #85082, and also corrects an error querying for coverageinfo.

1. `coverageinfo` query needs to use the same MIR as codegen

I ran into an error trying to fix dead block coverage and realized the
`coverageinfo` query is getting a different MIR compared to the
codegenned MIR, which can sometimes be a problem during mapgen.

I changed that query to use the `InstandeDef` (which includes the
generic parameter substitutions, prosibly specific to const params)
instead of the `DefId` (without unknown/default const substitutions).

2. Simplified body_span and filtered span code

  Some code cleanup extracted from future (but unfinished) commit to fix
  coverage in attr macro functions.

3. Spanview needs the relevant body_span used for coverage

The coverage body_span doesn't always match the function body_span.

r? ```@tmandry```
2021-05-15 13:29:49 +02:00
Guillaume Gomez
c4f81c12ea
Rollup merge of #85207 - andrewhalle:typo-rootseparator, r=kennytm
Fix typo in comment

missing space in "rootseparator"
2021-05-15 13:29:48 +02:00
Guillaume Gomez
b68d5433c9
Rollup merge of #85067 - Stupremee:minimize-amount-of-fake-defids, r=jyn514,GuillaumeGomez
Minimize amount of fake `DefId`s used in rustdoc

Follow up from #84707, which minimizes the amount of fake defids to the smallest amount possible. Every `FakeDefId` that is now used in the rustdoc library must be preserved and can not be replaced with a normal `DefId`.
2021-05-15 13:29:47 +02:00
Guillaume Gomez
9682fa9dc4
Rollup merge of #84461 - jyn514:remove-strip-item, r=GuillaumeGomez
rustdoc: Remove unnecessary `StripItem` wrapper
2021-05-15 13:29:47 +02:00
Justus K
67d8d18b23
Minimize amount of fake DefIds used in rustdoc 2021-05-15 13:21:35 +02:00
Guillaume Gomez
18b7c0a00e Update rustdoc-js tools 2021-05-15 13:09:55 +02:00
Guillaume Gomez
ccabd4eedf Fix eslint errors 2021-05-15 13:09:28 +02:00