Commit graph

152825 commits

Author SHA1 Message Date
bors
6fe0886723 Auto merge of #87736 - the8472:inline-advance-by, r=Mark-Simulacrum
#[inline] slice::Iter::advance_by

https://github.com/rust-lang/rust/pull/87387#issuecomment-891942661 was marked as a regression. One of the methods in the PR was missing an inline annotation unlike all the other methods on slice iterators.

Let's see if that makes a difference.
2021-08-04 15:39:20 +00:00
Alex Crichton
bb68c66c40 Fix assertions in coverage-reports test
Update some `C-unwind` bits and then
2021-08-04 07:47:09 -07:00
Hans Kratz
5ff06fb77f Fix overflow in rustc happening if the err_count() is reduced in a stage.
This can happen if stashed diagnostics are removed or replaced with fewer errors. The semantics stay the same if built without overflow. Fixes #84219.
2021-08-04 14:25:45 +00:00
Tomasz Miąsko
8e0df32ad6 Replace LLVMConstInBoundsGEP with LLVMConstInBoundsGEP2*
A custom reimplementation of LLVMConstInBoundsGEP2 is used, since the
LLVM contains a declaration of LLVMConstInBoundsGEP2 but not the
implementation.
2021-08-04 15:51:30 +02:00
Tomasz Miąsko
77e5e17231 Prepare inbounds_gep for opaque pointers
Implement inbounds_gep using LLVMBuildInBoundsGEP2 which takes an
explicit type argument instead of deriving it from a pointer type.
2021-08-04 15:51:30 +02:00
Tomasz Miąsko
4013e094f5 Prepare gep for opaque pointers
Implement gep using LLVMBuildGEP2 which takes an explicit type argument
instead of deriving it from a pointer type.
2021-08-04 15:51:30 +02:00
Tomasz Miąsko
838042aa4e Prepare struct_gep for opaque pointers
Imlement struct_gep using LLVMBuildStructGEP2 which takes an explicit
type argument instead of deriving it from a pointer type.
2021-08-04 15:51:30 +02:00
Jan-Erik Rediger
94ffa00ddb Promote aarch64-apple-ios-sim to Tier 2
As per MCP#428[1] this target becomes Tier 2.

[1]: https://github.com/rust-lang/compiler-team/issues/428
2021-08-04 15:06:26 +02:00
bors
7f3dc04644 Auto merge of #87150 - rusticstuff:simplify_wrapping_neg, r=m-ou-se
Make wrapping_neg() use wrapping_sub(), #[inline(always)]

This is a follow-up change to the fix for #75598. It simplifies the implementation of wrapping_neg() for all integer types by just calling 0.wrapping_sub(self) and always inlines it. This leads to much less assembly code being emitted for opt-level≤1 and thus much better performance for debug-compiled code.

Background is [this discussion on the internals forum](https://internals.rust-lang.org/t/why-does-rust-generate-10x-as-much-unoptimized-assembly-as-gcc/14930).
2021-08-04 12:58:31 +00:00
Mara Bos
f280a126b2 Re-use std::sealed::Sealed in os/linux/process. 2021-08-04 14:15:05 +02:00
bors
87d713ff2b Auto merge of #86197 - FabianWolff:trailing-whitespace, r=JohnTitor
Remove unnecessary trailing whitespace from error messages

Some error messages currently contain unnecessary trailing whitespace. There are some legitimate reasons for having trailing whitespace in the output, such as for uniform indentation of possibly-empty input lines, but the whitespace I have addressed here occurs in a line used only for spacing, and I see no reason why that should have trailing whitespace (spacing lines inserted in other places also don't have trailing whitespace).

I have also removed a superfluous call to `buffer.putc()`, which has no effect because the same character is already placed there by `draw_col_separator()`.

Use `git diff --ignore-space-at-eol` to see my changes; otherwise the diff is quite large due to the whitespace removed from expected outputs in `src/test/ui/`.
2021-08-04 09:58:16 +00:00
Amanieu d'Antras
1247f9b829 Add back -Zno-profiler-runtime
This was removed by #85284 in favor of -Zprofiler-runtime=<name>.
However the suggested -Zprofiler-runtime=None doesn't work because
"None" is treated as a crate name.
2021-08-04 10:47:59 +01:00
Fabian Wolff
f8372f876c Remove trailing whitespace from error messages 2021-08-04 10:48:30 +02:00
Gheorghe Anghelescu
f9c5bbba6b
change instructions for manually compiling y.rs (#1191)
This prevents an error on windows where the `build_sysroot` function was trying to delete `y.exe`.
2021-08-04 09:23:27 +02:00
bors
49ca3d9796 Auto merge of #87026 - FabianWolff:issue-86948, r=estebank
Allow labeled loops as value expressions for `break`

Fixes #86948. This is currently allowed:
```rust
return 'label: loop { break 'label 42; };
break ('label: loop { break 'label 42; });
break 1 + 'label: loop { break 'label 42; };
break 'outer 'inner: loop { break 'inner 42; };
```
But not this:
```rust
break 'label: loop { break 'label 42; };
```
I have fixed this, so that the above now parses as an unlabeled break with a labeled loop as its value expression.
2021-08-04 07:17:25 +00:00
bors
71ff9b41e9 Auto merge of #87712 - est31:line-column-1-based, r=petrochenkov
Proc macro spans: make columns 1 based

This makes proc macro spans consistent with the `column!()` macro as well as `std::panic::Location`, as both are 1-based.

https://github.com/rust-lang/rust/issues/54725#issuecomment-497246753
2021-08-04 04:27:35 +00:00
bors
bb744e1e9f Auto merge of #87568 - petrochenkov:localevel, r=cjgillot
rustc: Replace `HirId`s with `LocalDefId`s in `AccessLevels` tables

and passes using those tables - primarily privacy checking, stability checking and dead code checking.

All these passes work with definitions rather than with arbitrary HIR nodes.
r? `@cjgillot`
cc `@lambinoo` (#87487)
2021-08-04 02:04:04 +00:00
bors
2b8de6f212 Auto merge of #87746 - JohnTitor:rollup-zaapqgl, r=JohnTitor
Rollup of 8 pull requests

Successful merges:

 - #81797 (Add `core::stream::from_iter`)
 - #87267 (Remove space after negative sign in Literal to_string)
 - #87663 (Rustdoc accessibility: use an icon for the [-]/[+] controls)
 - #87720 (don't use .into() to convert types to identical types (clippy::useless_conversion))
 - #87723 (Use .contains instead of manual reimplementation.)
 - #87729 (Remove the aarch64 `crypto` target_feature)
 - #87731 (Update cargo)
 - #87734 (Test dropping union fields more)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-08-03 23:07:07 +00:00
Smitty
b7e9b1ad7f Add x.py option to --force-rerun compiletest tests 2021-08-03 19:06:12 -04:00
Yuki Okushi
7c5588edf5
Rollup merge of #87734 - Smittyvb:more-union-tests, r=LeSeulArtichaut
Test dropping union fields more

Now that #87403 is merged, a few more tests can be added for reads/writes to dropping union fields.

r? ``@LeSeulArtichaut``
2021-08-04 08:05:58 +09:00
Yuki Okushi
1666c26d90
Rollup merge of #87731 - ehuss:update-cargo, r=ehuss
Update cargo

11 commits in d21c22870e58499d6c31f1bef3bf1255eb021666..cc17afbb0067b1f57d8882640f63b2168d5b7624
2021-07-26 20:23:21 +0000 to 2021-08-02 20:28:08 +0000
- Stabilize the rust-version field (rust-lang/cargo#9732)
- Remove nbsp characters. (rust-lang/cargo#9751)
- Update unstable documentation TOC. (rust-lang/cargo#9750)
- Some minor updates for package/publish package selection. (rust-lang/cargo#9749)
- Bump to 0.57.0, update changelog (rust-lang/cargo#9748)
- Stabilize `[env]` sections (rust-lang/cargo#9411)
- doc: Clarify [doc].browser docs, document PathAndArgs better (rust-lang/cargo#9747)
- Bump cargo-util version. (rust-lang/cargo#9745)
- Make clippy happy (rust-lang/cargo#9736)
- Fix typo in features doc (rust-lang/cargo#9737)
- doc test supports silent output (rust-lang/cargo#9730)
2021-08-04 08:05:57 +09:00
Yuki Okushi
519c5a24e1
Rollup merge of #87729 - adamgemmell:dev/deprecate-crypto, r=Amanieu
Remove the aarch64 `crypto` target_feature

The subfeatures `aes` or `sha2` should be used instead.

This can't yet be done for ARM targets as some LLVM intrinsics still require `crypto`.

Also update the runtime feature detection tests in `library/std` to mirror the updates in `stdarch`. This also helps https://github.com/rust-lang/rust/issues/86941

r? ``@Amanieu``
2021-08-04 08:05:56 +09:00
Yuki Okushi
af8c99a235
Rollup merge of #87723 - frogtd:patch-3, r=JohnTitor
Use .contains instead of manual reimplementation.

It's also significantly easier to read.
2021-08-04 08:05:55 +09:00
Yuki Okushi
917c047c33
Rollup merge of #87720 - matthiaskrgr:clippy_into, r=jyn514
don't use .into() to convert types to identical types (clippy::useless_conversion)

Example:
let _x: String = String::from("hello world").into();
2021-08-04 08:05:54 +09:00
Yuki Okushi
75e14873b8
Rollup merge of #87663 - GuillaumeGomez:rustdoc-brace-minus-brace, r=notriddle
Rustdoc accessibility: use an icon for the [-]/[+] controls

This is a reopening of #87207 with improvement for the way of generating the `background-image` CSS property.

I quote from the original PR:

> This way, we can show the plus and minus buttons on screens, while voice
> control will read off actual words "Collapse" and "Expand" instead of reading
> "open brace minus close brace" and "open brace plus close brace".

Part of #87059

r? ``@notriddle``
2021-08-04 08:05:53 +09:00
Yuki Okushi
87c820573a
Rollup merge of #87267 - dtolnay:negspace, r=Aaron1011
Remove space after negative sign in Literal to_string

Negative proc macro literal tokens used to be printed with a space between the minus sign and the magnitude. That's because `impl ToString for Literal` used to convert the Literal into a TokenStream, which splits the minus sign into a separate Punct token.

```rust
Literal::isize_unsuffixed(-10).to_string()  // "- 10"
```

This PR updates the ToString impl to directly use `rustc_ast::token::Lit`'s ToString, which matches the way Rust negative numbers are idiomatically written without a space.

```rust
Literal::isize_unsuffixed(-10).to_string()  // "-10"
```
2021-08-04 08:05:50 +09:00
Yuki Okushi
ad74828b50
Rollup merge of #81797 - yoshuawuyts:stream_from_iter, r=dtolnay
Add `core::stream::from_iter`

_Tracking issue: https://github.com/rust-lang/rust/issues/81798_

This_ PR implements `std::stream::from_iter`, as outlined in the _"Converting an Iterator to a Stream"_ section of the [Stream RFC](https://github.com/nellshamrell/rfcs/blob/add-async-stream-rfc/text/0000-async-stream.md#converting-an-iterator-to-a-stream). This function enables converting an `Iterator` to a `Stream` by wrapping each item in the iterator with a `Poll::Ready` instance.

r? `@tmandry`

cc/ `@rust-lang/libs` `@rust-lang/wg-async-foundations`

## Example

Being able to convert from an iterator into a stream is useful when refactoring from iterative loops into a more functional adapter-based style. This is fairly common when using more complex `filter` / `map` / `find` chains. In its basic form this conversion looks like this:

**before**
```rust
let mut output = vec![];
for item in my_vec {
    let out = do_io(item).await?;
    output.push(out);
}
```
**after**
```rust
use std::stream;

let output = stream::from_iter(my_vec.iter())
    .map(async |item| do_io(item).await)
    .collect()?;
```

Having a way to convert an `Iterator` to a `Stream` is essential in enabling this flow.

## Implementation Notes

This PR makes use of `unsafe {}` to pin an item. Currently we're having conversations on the libs stream in Zulip how to bring `pin-project` in as a dependency to `core` so we can omit the `unsafe {}`.

This PR also includes a documentation block which references `Stream::next` which currently doesn't exist in the stdlib (originally included in the RFC and PR, but later omitted because of an unresolved issue). `stream::from_iter` can't stabilize before `Stream` does, and there's still a chance we may stabilize `Stream` with a `next` method. So this PR includes documentation referencing that method, which we can remove as part of stabilization if by any chance we don't have `Stream::next`.

## Alternatives Considered

### `impl IntoStream for T: IntoIterator`

An obvious question would be whether we could make it so every iterator can automatically be converted into a stream by calling `into_stream` on it. The answer is: "perhaps, but it could cause type issues". Types like `std::collections` may want to opt to create manual implementations for `IntoStream` and `IntoIter`, which wouldn't be possible if it was implemented through a catch-all trait.

Possibly an alternative such as `impl IntoStream for T: Iterator` could work, but it feels somewhat restrictive. In the end, converting an iterator to a stream is likely to be a bit of a niche case. And even then, **adding a standalone function to convert an `Iterator` into a `Stream` would not be mutually exclusive with a blanket implementation**.

### Naming

The exact name can be debated in the period before stabilization. But I've chosen `stream::from_iter` rather than `stream::iter` because we are _creating a stream from an iterator_ rather than _iterating a stream_. We also expect to add a stream counterpart to `iter::from_fn` later on (blocked on async closures), and having `stream::from_fn` and `stream::from_iter` would feel like a consistent pair. It also has prior art in `async_std::stream::from_iter`.

## Future Directions
### Stream conversions for collections

This is a building block towards implementing `stream/stream_mut/into_stream` methods for `std::collections`, `std::vec`, and more. This would allow even quicker refactorings from using loops to using iterator adapters by omitting the import altogether:

**before**
```rust
use std::stream;

let output = stream::from_iter(my_vec.iter())
    .map(async |item| do_io(item).await)
    .collect()?;
```
**after**
```rust
let output = my_vec
    .stream()
    .map(async |item| do_io(item).await)
    .collect()?;
```
2021-08-04 08:05:50 +09:00
Nathaniel McCallum
a96fd577a4 Validate FFI-safety warnings on naked functions
Test that FFI-safety warnings don't get accidentally dropped on naked
functions. The big picture is that if you implement a naked function
with the Rust ABI you'll get a warning. Further, if you implement a
naked function with a standardized ABI, but use non-FFI-safe types you
will still get a warning.

rust-lang/rfcs#2774
rust-lang/rfcs#2972
2021-08-03 17:50:50 -04:00
Léo Lanteri Thauvin
2b169ccc96 Only compute is_freeze for layout-constrained ADTs
Places are usually shallow and quick to visit. By contrast, computing
`is_freeze` can be much costlier, involving inference and trait
solving. Making sure to call `is_freeze` only when necessary should be
beneficial for performance in most cases.
2021-08-03 22:04:37 +02:00
bors
a6ece56152 Auto merge of #86400 - FabianWolff:issue-85735, r=estebank
Remove invalid suggestion involving `Fn` trait bound

This pull request closes #85735. The actual issue is a duplicate of #21974, but #85735 contains a further problem, which is an invalid suggestion if `Fn`/`FnMut`/`FnOnce` trait bounds are involved: The suggestion code checks whether the trait bound ends with `>` to determine whether it has any generic arguments, but the `Fn*` traits have a special syntax for generic arguments that doesn't involve angle brackets. The example given in #85735:
```rust
trait Foo {}
impl<'a, 'b, T> Foo for T
where
    T: FnMut(&'a ()),
    T: FnMut(&'b ()), {

    }
```
currently produces:
```
error[E0283]: type annotations needed
   --> src/lib.rs:4:8
    |
4   |       T: FnMut(&'a ()),
    |          ^^^^^^^^^^^^^ cannot infer type for type parameter `T`
    |
    = note: cannot satisfy `T: FnMut<(&'a (),)>`
help: consider specifying the type arguments in the function call
    |
4   |     T: FnMut(&'a ())::<Self, Args>,
    |                     ^^^^^^^^^^^^^^

error: aborting due to previous error
```
which is incorrect, because there is no function call, and applying the suggestion would lead to a parse error. With my changes, I get:
```
error[E0283]: type annotations needed
   --> test.rs:4:8
    |
4   |     T: FnMut(&'a ()),
    |        ^^^^^^^^^^^^^ cannot infer type for type parameter `T`
    |
   ::: [...]/library/core/src/ops/function.rs:147:1
    |
147 | pub trait FnMut<Args>: FnOnce<Args> {
    | ----------------------------------- required by this bound in `FnMut`
    |
    = note: cannot satisfy `T: FnMut<(&'a (),)>`

error: aborting due to previous error
```
i.e. I have added a check to prevent the invalid suggestion from being issued for `Fn*` bounds, while the underlying issue #21974 remains for now.
2021-08-03 19:48:54 +00:00
The8472
e44d39a5b7 #[inline] slice::advance_by 2021-08-03 21:32:36 +02:00
Fabian Wolff
f8c10ff8b7 Remove invalid suggestion involving Fn trait bound 2021-08-03 21:31:34 +02:00
Fabian Wolff
7c81132a60 Use a multipart suggestion for the parentheses 2021-08-03 21:23:29 +02:00
Smitty
6953f17aec Test dropping union fields more 2021-08-03 15:11:04 -04:00
Guillaume Gomez
6fe09722ea Simplify usage of CSS background-image 2021-08-03 20:03:07 +02:00
David Tolnay
3744dc8687
Remove space after negative sign in Literal to_string 2021-08-03 10:40:52 -07:00
bors
0f83ac19f0 Auto merge of #87515 - crlf0710:trait_upcasting_part2, r=bjorn3
Trait upcasting coercion (part2)

This is the second part of trait upcasting coercion implementation.

Currently this is blocked on #86264 .

The third part might be implemented using unsafety checking

r? `@bjorn3`
2021-08-03 16:58:56 +00:00
bors
c6bc102fea Auto merge of #87515 - crlf0710:trait_upcasting_part2, r=bjorn3
Trait upcasting coercion (part2)

This is the second part of trait upcasting coercion implementation.

Currently this is blocked on #86264 .

The third part might be implemented using unsafety checking

r? `@bjorn3`
2021-08-03 16:58:56 +00:00
Eric Huss
6698cdc5a5 Update cargo 2021-08-03 08:50:52 -07:00
Alex Crichton
37c85ec939 Relax a codegen test
nounwind is no longer emitted but the test still passes
2021-08-03 07:59:59 -07:00
Alex Crichton
fb939ed91d Make simplify_cfg test more consistent
Force it to always use panic=abort which means that all targets should
produce the same MIR now.
2021-08-03 07:06:19 -07:00
Alex Crichton
0168dfec6d Use predefined helper instead of a new one 2021-08-03 07:06:19 -07:00
Alex Crichton
30bc5a936b Move abort_unwinding_calls earlier 2021-08-03 07:06:19 -07:00
Alex Crichton
1c07096a45 rustc: Fill out remaining parts of C-unwind ABI
This commit intends to fill out some of the remaining pieces of the
C-unwind ABI. This has a number of other changes with it though to move
this design space forward a bit. Notably contained within here is:

* On `panic=unwind`, the `extern "C"` ABI is now considered as "may
  unwind". This fixes a longstanding soundness issue where if you
  `panic!()` in an `extern "C"` function defined in Rust that's actually
  UB because the LLVM representation for the function has the `nounwind`
  attribute, but then you unwind.

* Whether or not a function unwinds now mainly considers the ABI of the
  function instead of first checking the panic strategy. This fixes a
  miscompile of `extern "C-unwind"` with `panic=abort` because that ABI
  can still unwind.

* The aborting stub for non-unwinding ABIs with `panic=unwind` has been
  reimplemented. Previously this was done as a small tweak during MIR
  generation, but this has been moved to a separate and dedicated MIR
  pass. This new pass will, for appropriate functions and function
  calls, insert a `cleanup` landing pad for any function call that may
  unwind within a function that is itself not allowed to unwind. Note
  that this subtly changes some behavior from before where previously on
  an unwind which was caught-to-abort it would run active destructors in
  the function, and now it simply immediately aborts the process.

* The `#[unwind]` attribute has been removed and all users in tests and
  such are now using `C-unwind` and `#![feature(c_unwind)]`.

I think this is largely the last piece of the RFC to implement.
Unfortunately I believe this is still not stabilizable as-is because
activating the feature gate changes the behavior of the existing `extern
"C"` ABI in a way that has no replacement. My thinking for how to enable
this is that we add support for the `C-unwind` ABI on stable Rust first,
and then after it hits stable we change the behavior of the `C` ABI.
That way anyone straddling stable/beta/nightly can switch to `C-unwind`
safely.
2021-08-03 07:06:19 -07:00
Brandon H. Gomes
2f85aa6590 remove trailing newline 2021-08-03 09:25:18 -04:00
bors
d5fd37f00f Auto merge of #86338 - JohnTitor:issue-86162, r=estebank
Do not suggest impl traits as type arguments

Fixes #86162
2021-08-03 13:23:31 +00:00
Michael Howell
64c9903660 Use empty string instead of single space 2021-08-03 14:35:38 +02:00
Michael Howell
59460a6556 Pull the "Expand" / "Collapse" text to the end of the line, instead of start 2021-08-03 14:35:38 +02:00
Michael Howell
c58246efe4 Rustdoc accessibility: use an icon for the [-]/[+] controls
This way, we can show the plus and minus buttons on screens, while voice
control will read off actual words "Collapse" and "Expand" instead of reading
"open brace minus close brace" and "open brace plus close brace".

Part of #87059
2021-08-03 14:35:38 +02:00
Adam Gemmell
e817b50541 Update aarch64 runtime feature detection tests 2021-08-03 12:07:56 +00:00