Commit graph

157081 commits

Author SHA1 Message Date
Chris Denton
07f54d94e6
Use "rustc" for testing Command args
"echo" is not an application on Windows so `Command` tests could fail even if that's not what's being tested for.
2021-10-30 12:03:49 +01:00
bors
2b643e9871 Auto merge of #89174 - ChrisDenton:automatic-verbatim-paths, r=dtolnay
Automatically convert paths to verbatim for filesystem operations that support it

This allows using longer paths without the user needing to `canonicalize` or manually prefix paths. If the path is already verbatim then this has no effect.

Fixes: #32689
2021-10-30 07:21:21 +00:00
bors
22f1ad75e9 Auto merge of #88268 - GuillaumeGomez:generics-search-index, r=notriddle,camelid,jyn514
rustdoc: Fix generics generation in search index

The generics were not added to the search index as they should, instead they were added as arguments. I used this opportunity to allow generics to have generics themselves (will come in very handy for my current rewrite of the search engine!).

r? `@jyn514`
2021-10-30 04:12:40 +00:00
bors
021947d37a Auto merge of #90403 - michaelwoerister:odht-0.3.1, r=Mark-Simulacrum
Update odht crate to 0.3.1 (big-endian bugfix)

Update `odht` to 0.3.1 in order to get https://github.com/rust-lang/odht/pull/20 which fixes issue https://github.com/rust-lang/rust/issues/90123.
2021-10-30 01:01:19 +00:00
bors
6d42707cde Auto merge of #90346 - ferrocene:pa-short-circuit, r=oli-obk
Replace some operators in libcore with their short-circuiting equivalents

In libcore there are a few occurrences of bitwise operators used in boolean expressions instead of their short-circuiting equivalents. This makes it harder to perform some kinds of source code analysis over libcore, for example [MC/DC] code coverage (a requirement in safety-critical environments).

This PR aims to remove as many bitwise operators in boolean expressions from libcore as possible, without any performance regression and without other changes. This means not all bitwise operators are removed, only the ones that don't have any difference with their short-circuiting counterparts. This already simplifies achieving MC/DC coverage, and the other functions can be changed in future PRs.

The PR is best reviewed commit-by-commit, and each commit has the resulting assembly in the message.

## Checked integer methods

These methods recently switched to bitwise operators in PRs https://github.com/rust-lang/rust/pull/89459 and https://github.com/rust-lang/rust/pull/89351. I confirmed bitwise operators are needed in most of the functions, except these two:

* `{integer}::checked_div` ([Godbolt link (nightly)](https://rust.godbolt.org/z/17efh5jPc))
* `{integer}::checked_rem` ([Godbolt link (nightly)](https://rust.godbolt.org/z/85qGWc94K))

`@tspiteri` already mentioned this was the case in https://github.com/rust-lang/rust/pull/89459#issuecomment-932728384, but opted to also switch those two to bitwise operators for consistency. As that makes MC/DC analysis harder this PR proposes switching those two back to short-circuiting operators.

## `{unsigned_ints}::carrying_add`

[Godbolt link (1.56.0)](https://rust.godbolt.org/z/vG9vx8x48)

In this instance replacing the `|` with `||` produces the exact same assembly when optimizations are enabled, so switching to the short-circuiting operator shouldn't have any impact.

## `{unsigned_ints}::borrowing_sub`

[Godbolt link (1.56.0)](https://rust.godbolt.org/z/asEfKaGE4)

In this instance replacing the `|` with `||` produces the exact same assembly when optimizations are enabled, so switching to the short-circuiting operator shouldn't have any impact.

## String UTF-8 validation

[Godbolt link (1.56.0)](https://rust.godbolt.org/z/a4rEbTvvx)

In this instance replacing the `|` with `||` produces practically the same assembly, with the two operands for the "or" swapped:

```asm
; Old
mov  rax, qword ptr [rdi + rdx + 8]
or   rax, qword ptr [rdi + rdx]
test rax, r9
je   .LBB0_7

; New
mov  rax, qword ptr [rdi + rdx]
or   rax, qword ptr [rdi + rdx + 8]
test rax, r8
je   .LBB0_7
```

[MC/DC]: https://en.wikipedia.org/wiki/Modified_condition/decision_coverage
2021-10-29 21:50:46 +00:00
Guillaume Gomez
355e6eddfe Fix invalid handling of generics 2021-10-29 20:54:15 +02:00
bors
e99963c554 Auto merge of #90390 - umanwizard:update-miri, r=RalfJung
Update miri

Fixes https://github.com/rust-lang/rust/issues/90298
2021-10-29 18:41:17 +00:00
Michael Woerister
6771ac3f19 Update odht crate to 0.3.1 (big-endian bugfix) 2021-10-29 18:05:15 +02:00
bors
deb4572923 Auto merge of #90389 - camelid:rustdoc-rayon, r=jyn514
rustdoc: Switch to mainline rayon

The rustc fork of rayon integrates with Cargo's jobserver to limit the
amount of parallelism. However, rustdoc's use case is concurrent I/O,
which is not CPU-heavy, so it should be able to use mainline rayon.

See [this discussion][1] for more details.

[1]: https://github.com/rust-lang/rust/issues/90227#issuecomment-952468618

Note: I chose rayon 1.3.1 so that the rayon version used elsewhere in
the workspace does not change.

r? `@Mark-Simulacrum`
cc `@jyn514`
2021-10-29 15:31:37 +00:00
bors
9ed5b94b28 Auto merge of #90373 - tmiasko:union-qualification, r=oli-obk
Use type based qualification for unions

Union field access is currently qualified based on the qualification of
a value previously assigned to the union. At the same time, every union
access transmutes the content of the union, which might result in a
different qualification.

For example, consider constants A and B as defined below, under the
current rules neither contains interior mutability, since a value used
in the initial assignment did not contain `UnsafeCell` constructor.

```rust
#![feature(untagged_unions)]

union U { i: u32, c: std::cell::Cell<u32> }
const A: U = U { i: 0 };
const B: std::cell::Cell<u32> = unsafe { U { i: 0 }.c };
```

To avoid the issue, the changes here propose to consider the content of
a union as opaque and use type based qualification for union types.

Fixes #90268.

`@rust-lang/wg-const-eval`
2021-10-29 12:21:09 +00:00
bors
37f70a0e1e Auto merge of #90214 - tmiasko:indirect-mutation-qualif, r=ecstatic-morse,oli-obk
Consider indirect mutation during const qualification dataflow

Previously a local would be qualified if either one of two separate data
flow computations indicated so. First determined if a local could
contain the qualif, but ignored any forms of indirect mutation. Second
determined if a local could be mutably borrowed (and so indirectly
mutated), but which in turn ignored the qualif.

The end result was incorrect because the effect of indirect mutation was
effectivelly ignored in the all but the final stage of computation.

In the new implementation the indirect mutation is directly incorporated
into the qualif data flow. The local variable becomes immediately
qualified once it is mutably borrowed and borrowed place type can
contain the qualif.

In general we will now reject additional programs, program that were
prevously unintentionally accepted.

There are also some cases which are now accepted but were previously
rejected, because previous implementation didn't consider whether
borrowed place could have the qualif under the consideration.

Fixes #90124.

r? `@ecstatic-morse`
2021-10-29 08:38:39 +00:00
bors
88a5a984fe Auto merge of #90380 - Mark-Simulacrum:revert-89558-query-stable-lint, r=lcnr
Revert "Add rustc lint, warning when iterating over hashmaps"

Fixes perf regressions introduced in https://github.com/rust-lang/rust/pull/90235 by temporarily reverting the relevant PR.
2021-10-29 04:55:51 +00:00
bors
a9f664f37d Auto merge of #90363 - camelid:build-impl-perf, r=jyn514
Improve perf measurements of `build_extern_trait_impl`

Before, it was only measuring one callsite of `build_impl`, and it
incremented the call count even if `build_impl` returned early because
the `did` was already inlined.

Now, it measures all calls, minus calls that return early.
2021-10-29 01:50:08 +00:00
Noah Lev
581dc75888 rustdoc: Remove a single-use macro
I think the new code is simpler and easier to understand.
2021-10-28 18:39:32 -07:00
Brennan Vincent
2b66af1e74 Update miri 2021-10-28 21:38:43 -04:00
Noah Lev
7865a85eb6 rustdoc: Switch to mainline rayon
The rustc fork of rayon integrates with Cargo's jobserver to limit the
amount of parallelism. However, rustdoc's use case is concurrent I/O,
which is not CPU-heavy, so it should be able to use mainline rayon.

See this discussion [1] for more details.

[1]: https://github.com/rust-lang/rust/issues/90227#issuecomment-952468618

Note: I chose rayon 1.3.1 so that the rayon version used elsewhere in
the workspace does not change.
2021-10-28 18:26:57 -07:00
bors
df76418f1e Auto merge of #90387 - matthiaskrgr:rollup-b2x8v0x, r=matthiaskrgr
Rollup of 3 pull requests

Successful merges:

 - #90082 (Fix minor typos)
 - #90336 (Remove extra lines in examples for `Duration::try_from_secs_*`)
 - #90376 (Various cleanups around opaque types)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-10-28 22:44:45 +00:00
Matthias Krüger
bcee0a6ecc
Rollup merge of #90376 - oli-obk:🧹, r=spastorino
Various cleanups around opaque types

Best reviewed commit by commit.

This PR has no functional changes.

Mostly it's moving logic from an extension trait in rustc_trait_selection to inherent impls on rustc_infer.
2021-10-29 00:30:31 +02:00
Matthias Krüger
ae244d8b78
Rollup merge of #90336 - mbartlett21:patch-4, r=Mark-Simulacrum
Remove extra lines in examples for `Duration::try_from_secs_*`

None of the other examples have extra lines below the `#![feature(...)]` statements, so I thought it appropriate that these examples shouldn't either.
2021-10-29 00:30:30 +02:00
Matthias Krüger
dbe7141ac0
Rollup merge of #90082 - noncombatant:patch-1, r=GuillaumeGomez
Fix minor typos
2021-10-29 00:30:30 +02:00
bors
c390d69a61 Auto merge of #90281 - xldenis:public-borrow-set, r=nikomatsakis
Add BorrowSet to public api

This PR adds `BorrowSet` to the public api so that verification tools can obtain the activation and reservation points of two phase borrows without having to redo calculations themselves (and thus potentially differently from rustc).

Turns out we already can obtain `MoveData` thanks to the public `HasMoveData` trait, so constructing a `BorrowSet` should not provide much of an issue. However, I can't speak to the soundness of this approach, is it safe to take an under-approximation of `MoveData`?

r? `@nikomatsakis`
2021-10-28 19:34:01 +00:00
bors
85c0558d03 Auto merge of #90218 - JakobDegen:adt_significant_drop_fix, r=nikomatsakis
Fixes incorrect handling of ADT's drop requirements

Fixes #90024 and a bunch of duplicates.

The main issue was just that the contract of `NeedsDropTypes::adt_components` was inconsistent; the list of types it might return were the generic parameters themselves or the fields of the ADT, depending on the nature of the drop impl. This meant that the caller could not determine whether a `.subst()` call was still needed on those types; it called `.subst()` in all cases, and this led to ICEs when the returned types were the generic params.

First contribution of more than a few lines, so feedback definitely appreciated.
2021-10-28 16:03:13 +00:00
Mark Rousskov
3215eeb99f
Revert "Add rustc lint, warning when iterating over hashmaps" 2021-10-28 11:01:42 -04:00
Oli Scherer
bc552fc417 Move instantiate_opaque_types to rustc_infer.
It does not depend on anything from rustc_trait_selection anymore.
2021-10-28 14:12:24 +00:00
Oli Scherer
a8f06b249b Move some functions into rustc_infer.
They don't depend on trait selection anymore, so there is no need for an extension trait.
2021-10-28 13:54:11 +00:00
Oli Scherer
849b73b8d9 Manually inline a function that is only ever called at the end of another function 2021-10-28 13:42:16 +00:00
Oli Scherer
f1a2f2098f Remove dead code.
We don't do member constraint checks in regionck anymore.
All member constraint checks are done in mir borrowck.
2021-10-28 13:38:41 +00:00
bors
c4ff03f689 Auto merge of #90145 - cjgillot:sorted-map, r=michaelwoerister
Use SortedMap in HIR.

Closes https://github.com/rust-lang/rust/issues/89788
r? `@ghost`
2021-10-28 13:04:40 +00:00
bors
f2707fec04 Auto merge of #90339 - GuillaumeGomez:doc-alias-doc, r=GuillaumeGomez
Add missing documentation for doc alias
2021-10-28 09:50:16 +00:00
Guillaume Gomez
47786d3642 Add missing documentation for doc alias 2021-10-28 10:43:34 +02:00
Noah Lev
eb713d272c Improve perf measurements of build_extern_trait_impl
Before, it was only measuring one callsite of `build_impl`, and it
incremented the call count even if `build_impl` returned early because
the `did` was already inlined.

Now, it measures all calls, minus calls that return early.
2021-10-27 20:15:00 -07:00
Tomasz Miąsko
3f778f31b6 Use type based qualification for unions
Union field access is currently qualified based on the qualification of
a value previously assigned to the union. At the same time, every union
access transmutes the content of the union, which might result in a
different qualification.

For example, consider constants A and B as defined below, under the
current rules neither contains interior mutability, since a value used
in the initial assignment did not contain `UnsafeCell` constructor.

```rust
#![feature(untagged_unions)]

union U { i: u32, c: std::cell::Cell<u32> }
const A: U = U { i: 0 };
const B: std::cell::Cell<u32> = unsafe { U { i: 0 }.c };
```

To avoid the issue, the changes here propose to consider the content of
a union as opaque and use type based qualification for union types.
2021-10-28 00:00:00 +00:00
bors
4e0d3973fa Auto merge of #90347 - matthiaskrgr:rollup-rp2ms7j, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - #90239 (Consistent big O notation in map.rs)
 - #90267 (fix: inner attribute followed by outer attribute causing ICE)
 - #90288 (Add hint for people missing `TryFrom`, `TryInto`, `FromIterator` import pre-2021)
 - #90304 (Add regression test for #75961)
 - #90344 (Add tracking issue number to const_cstr_unchecked)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-10-27 18:42:13 +00:00
Matthias Krüger
623c3e144e
Rollup merge of #90344 - xfix:tracking-issue-const_cstr_unchecked, r=Mark-Simulacrum
Add tracking issue number to const_cstr_unchecked

Also created a tracking issue, see #90343.

I think it makes sense to stabilize this somewhat soon considering abuse of `transmute` to have this feature in constants, see https://crates.io/crates/cstr for an example. Code can be rewritten to use `mem::transmute` to work on stable.
2021-10-27 18:25:47 +02:00
Matthias Krüger
f32c09b82a
Rollup merge of #90304 - vandenheuvel:test_issue_75961, r=Mark-Simulacrum
Add regression test for #75961

Closes #75961.
Closes #21203.
2021-10-27 18:25:46 +02:00
Matthias Krüger
83d5c24071
Rollup merge of #90288 - JakobDegen:import_diagnostics, r=davidtwco
Add hint for people missing `TryFrom`, `TryInto`, `FromIterator` import pre-2021

Adds a hint anytime a `TryFrom`, `TryInto`, `FromIterator` import is suggested noting that these traits are automatically imported in Edition 2021.
2021-10-27 18:25:46 +02:00
Matthias Krüger
17d1742028
Rollup merge of #90267 - EliseZeroTwo:elisezerotwo/fix_invalid_attrs_ice, r=Aaron1011
fix: inner attribute followed by outer attribute causing ICE

Fixes #87936, #88938, and #89971.

This removes the assertion that validates that there are no outer attributes following inner attributes. Where the inner attribute is invalid you get an actual error.
2021-10-27 18:25:44 +02:00
Matthias Krüger
088dc91e0a
Rollup merge of #90239 - r00ster91:patch-1, r=fee1-dead
Consistent big O notation in map.rs

Follow up to #89216
2021-10-27 18:25:43 +02:00
r00ster91
b1b4c6cb00 Remove big O notation 2021-10-27 17:43:14 +02:00
bors
dd757b9e06 Auto merge of #90273 - nbdd0121:const, r=fee1-dead
Clean up special function const checks

Mark them as const and `#[rustc_do_not_const_check]` instead of hard-coding them in const-eval checks.

r? `@oli-obk`
`@rustbot` label A-const-eval T-compiler
2021-10-27 15:32:42 +00:00
Pietro Albini
68a4460b61
replace & with && in {integer}::checked_rem
Using short-circuit operators makes it easier to perform some kinds of
source code analysis, like MC/DC code coverage (a requirement in
safety-critical environments). The optimized x86 assembly is the same
between the old and new versions:

```
xor eax, eax
test esi, esi
je .LBB0_1
cmp edi, -2147483648
jne .LBB0_4
cmp esi, -1
jne .LBB0_4
ret
.LBB0_1:
ret
.LBB0_4:
mov eax, edi
cdq
idiv esi
mov eax, 1
ret
```
2021-10-27 17:01:05 +02:00
Pietro Albini
81130fe188
replace & with && in {integer}::checked_div
Using short-circuit operators makes it easier to perform some kinds of
source code analysis, like MC/DC code coverage (a requirement in
safety-critical environments). The optimized x86 assembly is the same
between the old and new versions:

```
xor eax, eax
test esi, esi
je .LBB0_1
cmp edi, -2147483648
jne .LBB0_4
cmp esi, -1
jne .LBB0_4
ret
.LBB0_1:
ret
.LBB0_4:
mov eax, edi
cdq
idiv esi
mov edx, eax
mov eax, 1
ret
```
2021-10-27 17:00:57 +02:00
Pietro Albini
a5a8bb0125
replace | with || in string validation
Using short-circuiting operators makes it easier to perform some kinds
of source code analysis, like MC/DC code coverage (a requirement in
safety-critical environments). The optimized x86_64 assembly is
equivalent between the old and new versions.

Old assembly of that condition:

```
mov  rax, qword ptr [rdi + rdx + 8]
or   rax, qword ptr [rdi + rdx]
test rax, r9
je   .LBB0_7
```

New assembly of that condition:

```
mov  rax, qword ptr [rdi + rdx]
or   rax, qword ptr [rdi + rdx + 8]
test rax, r8
je   .LBB0_7
```
2021-10-27 17:00:49 +02:00
Pietro Albini
9fb66969e3
replace | with || in {unsigned_int}::borrowing_sub
Using short-circuiting operators makes it easier to perform some kinds
of source code analysis, like MC/DC code coverage (a requirement in
safety-critical environments). The optimized x86_64 assembly is the same
between the old and new versions:

```
mov eax, edi
add dl, -1
sbb eax, esi
setb dl
ret
```
2021-10-27 17:00:46 +02:00
Pietro Albini
5913ef6660
replace | with || in {unsigned_int}::carrying_add
Using short-circuiting operators makes it easier to perform some kinds
of source code analysis, like MC/DC code coverage (a requirement in
safety-critical environments). The optimized x86_64 assembly is the same
between the old and new versions:

```
mov eax, edi
add dl, -1
adc eax, esi
setb dl
ret
```
2021-10-27 17:00:36 +02:00
Konrad Borowski
50ca08c5f5 Add tracking issue number to const_cstr_unchecked 2021-10-27 15:18:25 +02:00
bors
337e1565d3 Auto merge of #90186 - jsha:fix-header-sizes, r=GuillaumeGomez
Fix documentation header sizes

And add a rustdoc-gui test confirming various header sizes.

Split off from #90156. This fixes a regression in #89506 where the heading level of titles within Markdown was too high (h2) for docblocks under structs, unions, and enum impls.

r? `@camelid`

Demo: https://jacob.hoffman-andrews.com/rust/fix-header-sizes/std/string/struct.String.html#impl-Add%3C%26%27_%20str%3E
Stable: https://doc.rust-lang.org/stable/std/string/struct.String.html#impl-Add%3C%26%27_%20str%3E
Beta: https://doc.rust-lang.org/beta/std/string/struct.String.html#impl-Add%3C%26%27_%20str%3E
2021-10-27 12:27:47 +00:00
bors
a8f6e614f8 Auto merge of #89652 - rcvalle:rust-cfi, r=nagisa
Add LLVM CFI support to the Rust compiler

This PR adds LLVM Control Flow Integrity (CFI) support to the Rust compiler. It initially provides forward-edge control flow protection for Rust-compiled code only by aggregating function pointers in groups identified by their number of arguments.

Forward-edge control flow protection for C or C++ and Rust -compiled code "mixed binaries" (i.e., for when C or C++ and Rust -compiled code share the same virtual address space) will be provided in later work as part of this project by defining and using compatible type identifiers (see Type metadata in the design document in the tracking issue #89653).

LLVM CFI can be enabled with -Zsanitizer=cfi and requires LTO (i.e., -Clto).

Thank you, `@eddyb` and `@pcc,` for all the help!
2021-10-27 09:19:42 +00:00
EliseZeroTwo
7f0d43a003
test: add test for inner attribute followed by outer attribute causing ICE 2021-10-27 10:13:25 +02:00
Ramon de C Valle
c5708caf6a Add documentation for LLVM CFI support
This commit adds initial documentation for LLVM Control Flow Integrity
(CFI) support to the Rust compiler (see #89652 and #89653).
2021-10-26 23:33:55 -07:00