Commit graph

165751 commits

Author SHA1 Message Date
ohno418 de237823e0 Suggest only when all fields impl the trait 2022-04-05 11:40:25 +09:00
ohno418 0ff2f58330 Suggest only when Rhs for PartialEq and PartialOrd is the same type as self 2022-04-05 11:31:11 +09:00
ohno418 0d2a00058b Suggest derivable trait on E0277 2022-04-05 11:14:32 +09:00
bors 60e50fc1cf Auto merge of #95653 - Dylan-DPC:rollup-2p9hzi3, r=Dylan-DPC
Rollup of 7 pull requests

Successful merges:

 - #92942 (stabilize windows_process_extensions_raw_arg)
 - #94817 (Release notes for 1.60.0)
 - #95343 (Reduce unnecessary escaping in proc_macro::Literal::character/string)
 - #95431 (Stabilize total_cmp)
 - #95438 (Add SyncUnsafeCell.)
 - #95467 (Windows: Synchronize asynchronous pipe reads and writes)
 - #95609 (Suggest borrowing when trying to coerce unsized type into `dyn Trait`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-04-04 19:51:52 +00:00
Dylan DPC 0c5f879203
Rollup merge of #95609 - compiler-errors:borrow-unsized-to-dyn, r=nagisa
Suggest borrowing when trying to coerce unsized type into `dyn Trait`

A helpful error in response to #95598, since we can't coerce e.g. `&str` into `&dyn Display`, but we can coerce `&&str` into `&dyn Display` :)

Not sure if the suggestion message needs some help. Let me know, and I can refine this PR.
2022-04-04 20:41:34 +02:00
Dylan DPC 4cbc003577
Rollup merge of #95467 - ChrisDenton:async-read-pipe, r=joshtriplett
Windows: Synchronize asynchronous pipe reads and writes

On Windows, the pipes used for spawned processes are opened for asynchronous access but `read` and `write` are done using the standard methods that assume synchronous access. This means that the buffer (and variables on the stack) may be read/written to after the function returns.

This PR ensures reads/writes complete before returning. Note that this only applies to pipes we create and does not affect the standard file read/write methods.

Fixes #95411
2022-04-04 20:41:33 +02:00
Dylan DPC 4d7d9d422b
Rollup merge of #95438 - m-ou-se:sync-unsafe-cell, r=joshtriplett
Add SyncUnsafeCell.

This adds `SyncUnsafeCell`, which is just `UnsafeCell` except it implements `Sync`.

This was first proposed under the name `RacyUnsafeCell` here: https://github.com/rust-lang/rust/issues/53639#issuecomment-415515748 and here: https://github.com/rust-lang/rust/issues/53639#issuecomment-432741659 and here: https://github.com/rust-lang/rust/issues/53639#issuecomment-888435728

It allows you to create an UnsafeCell that is Sync without having to wrap it in a struct first (and then implement Sync for that struct).

E.g. `static X: SyncUnsafeCell<i32>`. Using a regular `UnsafeCell` as `static` is not possible, because it isn't `Sync`. We have a language workaround for it called `static mut`, but it's nice to be able to use the proper type for such unsafety instead.

It also makes implementing synchronization primitives based on unsafe cells slightly less verbose, because by using `SyncUnsafeCell` for `UnsafeCell`s that are shared between threads, you don't need a separate `impl<..> Sync for ..`. Using this type also clearly documents that the cell is expected to be accessed from multiple threads.
2022-04-04 20:41:32 +02:00
Dylan DPC 73148eee31
Rollup merge of #95431 - golddranks:stabilize_total_cmp, r=scottmcm
Stabilize total_cmp

Stabilises `total_cmp` for Rust 1.61.0. Tracking issue: https://github.com/rust-lang/rust/issues/72599
2022-04-04 20:41:31 +02:00
Dylan DPC 2d1496a8f6
Rollup merge of #95343 - dtolnay:literals, r=petrochenkov
Reduce unnecessary escaping in proc_macro::Literal::character/string

I noticed that https://doc.rust-lang.org/proc_macro/struct.Literal.html#method.character is producing unreadable literals that make macro-expanded code unnecessarily hard to read. Since the proc macro server was using `escape_unicode()`, every char is escaped using `\u{…}` regardless of whether there is any need to do so. For example `Literal::character('=')` would previously produce `'\u{3d}'` which unnecessarily obscures the meaning when reading the macro-expanded code.

I've changed Literal::string also in this PR because `str`'s `Debug` impl is also smarter than just calling `escape_debug` on every char. For example `Literal::string("ferris's")` would previously produce `"ferris\'s"` but will now produce `"ferris's"`.
2022-04-04 20:41:30 +02:00
Dylan DPC 98168925f6
Rollup merge of #94817 - cuviper:relnotes-1.60.0, r=pietroalbini,m-ou-se
Release notes for 1.60.0
2022-04-04 20:41:28 +02:00
Dylan DPC c56cbf976c
Rollup merge of #92942 - Xaeroxe:raw_arg, r=dtolnay
stabilize windows_process_extensions_raw_arg

Stabilizes the feature tracked at https://github.com/rust-lang/rust/issues/92939
2022-04-04 20:41:27 +02:00
Chris Denton cbbcd875e1
Correct calling convention 2022-04-04 19:37:11 +01:00
bors 6a9080b25e Auto merge of #95555 - nnethercote:parse_tt-new-representation, r=petrochenkov
A new matcher representation for use in `parse_tt`

By transforming the matcher into a different form, `parse_tt` can run faster and be easier to understand.

r? `@petrochenkov`
2022-04-04 17:27:48 +00:00
David Tolnay 66e05c2f7c
Bump windows CommandExt::raw_arg to 1.62 2022-04-04 10:15:28 -07:00
bors d5139f4469 Auto merge of #95119 - OliverMD:method_suggestions, r=davidtwco
Improve method name suggestions

Attempts to improve method name suggestions when a matching method name
is not found. The approach taken is use the Levenshtein distance and
account for substrings having a high distance but can sometimes be very
close to the intended method (eg. empty vs is_empty).

resolves #94747
2022-04-04 13:00:25 +00:00
Pyry Kontio 1b9cd5bb62 Stabilize total_cmp 2022-04-04 18:57:49 +09:00
Pietro Albini 82eedae66b
improve 92630 wording 2022-04-04 10:38:41 +02:00
Pietro Albini af8b6b6ef9
add compat note about instant changes 2022-04-04 10:33:21 +02:00
Pietro Albini 9c0de7bb99
add future compatibility notes for linux-gnu baseline bump 2022-04-04 10:13:21 +02:00
Pietro Albini 91beb32328
reword the docs on tier 2 platforms docs 2022-04-04 10:09:57 +02:00
Pietro Albini e393ed7219
move 2021 libs to internal changes 2022-04-04 09:48:56 +02:00
Pietro Albini b81d430c6b
link target tier policy to new targets 2022-04-04 09:48:20 +02:00
bors 2ed6786404 Auto merge of #95636 - pietroalbini:pa-version-1.62.0, r=pietroalbini
Bump version number to 1.62.0
2022-04-04 07:22:34 +00:00
Pietro Albini 3d3e01a014
bump version to 1.62.0 2022-04-04 09:21:03 +02:00
Nicholas Nethercote 0bd47e8a39 Reorder match arms in parse_tt_inner.
To match the order the variants are declared in.
2022-04-04 17:03:36 +10:00
Nicholas Nethercote 88f8fbcce0 A new matcher representation for use in parse_tt.
`parse_tt` currently traverses a `&[TokenTree]` to do matching. But this
is a bad representation for the traversal.
- `TokenTree` is nested, and there's a bunch of expensive and fiddly
  state required to handle entering and exiting nested submatchers.
- There are three positions (sequence separators, sequence Kleene ops,
  and end of the matcher) that are represented by an index that exceeds
  the end of the `&[TokenTree]`, which is clumsy and error-prone.

This commit introduces a new representation called `MatcherLoc` that is
designed specifically for matching. It fixes all the above problems,
making the code much easier to read. A `&[TokenTree]` is converted to a
`&[MatcherLoc]` before matching begins. Despite the cost of the
conversion, it's still a net performance win, because various pieces of
traversal state are computed once up-front, rather than having to be
recomputed repeatedly during the macro matching.

Some improvements worth noting.
- `parse_tt_inner` is *much* easier to read. No more having to compare
  `idx` against `len` and read comments to understand what the result
  means.
- The handling of `Delimited` in `parse_tt_inner` is now trivial.
- The three end-of-sequence cases in `parse_tt_inner` are now handled in
  three separate match arms, and the control flow is much simpler.
- `nameize` is no longer recursive.
- There were two places that issued "missing fragment specifier" errors:
  one in `parse_tt_inner()`, and one in `nameize()`. Presumably the
  latter was never executed. There's now a single place issuing these
  errors, in `compute_locs()`.
- The number of heap allocations done for a `check full` build of
  `async-std-1.10.0` (an extreme example of heavy macro use) drops from
  11.8M to 2.6M, and most of these occur outside of macro matching.
- The size of `MatcherPos` drops from 64 bytes to 16 bytes. Small enough
  that it no longer needs boxing, which partly accounts for the
  reduction in allocations.
- The rest of the drop in allocations is due to the removal of
  `MatcherKind`, because we no longer need to record anything for the
  parent matcher when entering a submatcher.
- Overall it reduces code size by 45 lines.
2022-04-04 17:01:28 +10:00
Chris Denton 62f37da611
Update library/std/src/sys/windows/pipe.rs 2022-04-04 05:59:51 +01:00
bors ec667fbcfc Auto merge of #95031 - compiler-errors:param-env-cache, r=Aaron1011
Do not use `ParamEnv::and` when building a cache key from a param-env and trait eval candidate

Do not use `ParamEnv::and` to cache a param-env with a selection/evaluation candidate.

This is because if the param-env is `RevealAll` mode, and the candidate looks global (i.e. it has erased regions, which can show up when we normalize a projection type under a binder<sup>1</sup>), then when we use `ParamEnv::and` to pair the candidate and the param-env for use as a cache key, we will throw away the param-env's caller bounds, and we'll end up caching a candidate that we inferred from the param-env with a empty param-env, which may cause cache-hit later when we have an empty param-env, and possibly mess with normalization like we see in the referenced issue during codegen.

Not sure how to trigger this with a more structured test, but changing `check-pass` to `build-pass` triggers the case that https://github.com/rust-lang/rust/issues/94903 detected.

<sup>1.</sup> That is, we will replace the late-bound region with a placeholder, which gets canonicalized and turned into an infererence variable, which gets erased during region freshening right before we cache the result. Sorry, it's quite a few steps.

Fixes #94903
r? `@Aaron1011` (or reassign as you see fit)
2022-04-04 04:48:36 +00:00
bors ac4b3450ed Auto merge of #95606 - petrochenkov:linkregr, r=wesleywiser
linker: Implicitly link native libs as whole-archive in some more cases

Partially revert changes from https://github.com/rust-lang/rust/pull/93901 to address regressions like https://github.com/rust-lang/rust/issues/95561.

Fixes https://github.com/rust-lang/rust/issues/95561
r? `@wesleywiser`
2022-04-04 02:23:15 +00:00
bors 596deceaac Auto merge of #95619 - bjorn3:inline_location_caller, r=scottmcm
Mark Location::caller() as #[inline]

This function gets compiled to a single register move as it actually gets it's return value passed in as argument.
2022-04-03 23:42:31 +00:00
bors 6af09d2505 Auto merge of #95624 - Dylan-DPC:rollup-r8w7ui3, r=Dylan-DPC
Rollup of 5 pull requests

Successful merges:

 - #95202 (Reduce the cost of loading all built-ins targets)
 - #95553 (Don't emit non-asm contents error for naked function composed of errors)
 - #95613 (Fix rustdoc attribute display)
 - #95617 (Fix &mut invalidation in ptr::swap doctest)
 - #95618 (core: document that the align_of* functions return the alignment in bytes)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-04-03 21:22:50 +00:00
Dylan DPC 1ea6e93610
Rollup merge of #95618 - adamse:master, r=dtolnay
core: document that the align_of* functions return the alignment in bytes
2022-04-03 23:21:45 +02:00
Dylan DPC f7f2d83eda
Rollup merge of #95617 - saethlin:swap-test-invalidation, r=Dylan-DPC
Fix &mut invalidation in ptr::swap doctest

Under Stacked Borrows with raw pointer tagging, the previous code was UB
because the code which creates the the second pointer borrows the array
through a tag in the borrow stacks below the Unique tag that our first
pointer is based on, thus invalidating the first pointer.

This is not definitely a bug and may never be real UB, but I desperately
want people to write code that conforms to SB with raw pointer tagging
so that I can write good diagnostics. The alternative aliasing models
aren't possible to diagnose well due to state space explosion.
Therefore, it would be super cool if the standard library nudged people
towards writing code that is valid with respect to SB with raw pointer
tagging.

The diagnostics that I want to write are implemented in a branch of Miri and the one for this case is below:
```
error: Undefined Behavior: attempting a read access using <2170> at alloc1068[0x0], but that tag does not exist in the borrow stack for this location
    --> /home/ben/rust/library/core/src/intrinsics.rs:2103:14
     |
2103 |     unsafe { copy_nonoverlapping(src, dst, count) }
     |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     |              |
     |              attempting a read access using <2170> at alloc1068[0x0], but that tag does not exist in the borrow stack for this location
     |              this error occurs as part of an access at alloc1068[0x0..0x8]
     |
     = help: this indicates a potential bug in the program: it performed an invalid operation, but the rules it violated are still experimental
     = help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information
help: <2170> was created due to a retag at offsets [0x0..0x10]
    --> ../libcore/src/ptr/mod.rs:640:9
     |
8    | let x = array[0..].as_mut_ptr() as *mut [u32; 2]; // this is `array[0..2]`
     |         ^^^^^^^^^^^^^^^^^^^^^^^
help: <2170> was later invalidated due to a retag at offsets [0x0..0x10]
    --> ../libcore/src/ptr/mod.rs:641:9
     |
9    | let y = array[2..].as_mut_ptr() as *mut [u32; 2]; // this is `array[2..4]`
     |         ^^^^^
     = note: inside `std::intrinsics::copy_nonoverlapping::<[u32; 2]>` at /home/ben/rust/library/core/src/intrinsics.rs:2103:14
     = note: inside `std::ptr::swap::<[u32; 2]>` at /home/ben/rust/library/core/src/ptr/mod.rs:685:9
note: inside `main::_doctest_main____libcore_src_ptr_mod_rs_635_0` at ../libcore/src/ptr/mod.rs:12:5
    --> ../libcore/src/ptr/mod.rs:644:5
     |
12   |     ptr::swap(x, y);
     |     ^^^^^^^^^^^^^^^
note: inside `main` at ../libcore/src/ptr/mod.rs:15:3
    --> ../libcore/src/ptr/mod.rs:647:3
     |
15   | } _doctest_main____libcore_src_ptr_mod_rs_635_0() }
     |   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace

error: aborting due to previous error
```
2022-04-03 23:21:43 +02:00
Dylan DPC 5925c8ee79
Rollup merge of #95613 - GuillaumeGomez:fix-rustdoc-attr-display, r=notriddle
Fix rustdoc attribute display

Fixes #81482.

r? `@notriddle`
2022-04-03 23:21:43 +02:00
Dylan DPC 19a90c7018
Rollup merge of #95553 - jam1garner:naked-function-compile-error, r=tmiasko
Don't emit non-asm contents error for naked function composed of errors

## Motivation

For naked functions an error is emitted when they are composed of anything other than a single asm!() block. However, this error triggers in a couple situations in which it adds no additional information or is actively misleading.

One example is if you do have an asm!() block but simply one with a syntax error:
```rust
#[naked]
unsafe extern "C" fn compiler_errors() {
    asm!(invalid_syntax)
}
```

This results in two errors, one for the syntax error itself and another telling you that you need an asm block in your function:

```rust
error[E0787]: naked functions must contain a single asm block
 --> src/main.rs:6:1
  |
6 | / unsafe extern "C" fn naked_compile_error() {
7 | |     asm!(blah)
8 | | }
  | |_^
```

This issue also comes up when [utilizing `compile_error!()` for improving your diagnostics](https://twitter.com/steveklabnik/status/1509538243020218372), such as raising a compiler error when compiling for an unsupported target.

## Implementation

The rules this PR implements are as follows:

1. If any non-erroneous  non-asm statement is included, an error will still occur
2. If multiple asm statements are included, an error will still occur
3. If 0 or 1 asm statements are present, as well as any non-zero number of erroneous statements, then this error will *not* be raised as it is likely either redundant or incorrect

The rule of thumb is effectively "if an error is present and its correction could change things, don't raise an error".
2022-04-03 23:21:42 +02:00
Dylan DPC 796bc7e9aa
Rollup merge of #95202 - Urgau:check-cfg-perf-well-known-values, r=petrochenkov
Reduce the cost of loading all built-ins targets

This PR started by measuring the exact slowdown of checking of well known conditional values.
Than this PR implemented some technics to reduce the cost of loading all built-ins targets.

cf. https://github.com/rust-lang/rust/issues/82450#issuecomment-1073992323
2022-04-03 23:21:41 +02:00
Ben Kimock f4a7ed4338 Fix &mut invalidation in ptr::swap doctest
Under Stacked Borrows with raw pointer tagging, the previous code was UB
because the code which creates the the second pointer borrows the array
through a tag in the borrow stacks below the Unique tag that our first
pointer is based on, thus invalidating the first pointer.

This is not definitely a bug and may never be real UB, but I desperately
want people to write code that conforms to SB with raw pointer tagging
so that I can write good diagnostics. The alternative aliasing models
aren't possible to diagnose well due to state space explosion.
Therefore, it would be super cool if the standard library nudged people
towards writing code that is valid with respect to SB with raw pointer
tagging.
2022-04-03 16:16:33 -04:00
Loïc BRANSTETT 1a1f5b89a4 Cleanup after some refactoring in rustc_target 2022-04-03 21:29:57 +02:00
Loïc BRANSTETT c16a558f24 Replace LinkArgs with Cow<'static, str> 2022-04-03 21:29:57 +02:00
Loïc BRANSTETT ce61d4044d Replace every Vec in Target(Options) with it's Cow equivalent 2022-04-03 21:29:57 +02:00
Loïc BRANSTETT ccff48f97b Replace every String in Target(Options) with Cow<'static, str> 2022-04-03 21:29:57 +02:00
bors 2ad4eb207b Auto merge of #95610 - createyourpersonalaccount:derefmut-docfix, r=Dylan-DPC
Improve doc example of DerefMut

It is more illustrative, after using `*x` to modify the field, to show
in the assertion that the field has indeed been modified.
2022-04-03 19:06:20 +00:00
bjorn3 6d0b61e2f5 Mark Location::caller() as #[inline]
This function gets compiled to a single register move as it actually
gets it's return value passed in as argument.
2022-04-03 20:32:39 +02:00
Adam Sandberg Ericsson 9d4d5a4eeb core: document that the align_of* functions return the alignment in bytes 2022-04-03 19:06:21 +01:00
bors 168a020900 Auto merge of #92686 - saethlin:unsafe-debug-asserts, r=Amanieu
Add debug assertions to some unsafe functions

As suggested by https://github.com/rust-lang/rust/issues/51713

~~Some similar code calls `abort()` instead of `panic!()` but aborting doesn't work in a `const fn`, and the intrinsic for doing dispatch based on whether execution is in a const is unstable.~~

This picked up some invalid uses of `get_unchecked` in the compiler, and fixes them.

I can confirm that they do in fact pick up invalid uses of `get_unchecked` in the wild, though the user experience is less-than-awesome:
```
     Running unittests (target/x86_64-unknown-linux-gnu/debug/deps/rle_decode_fast-04b7918da2001b50)

running 6 tests
error: test failed, to rerun pass '--lib'

Caused by:
  process didn't exit successfully: `/home/ben/rle-decode-helper/target/x86_64-unknown-linux-gnu/debug/deps/rle_decode_fast-04b7918da2001b50` (signal: 4, SIGILL: illegal instruction)
```

~~As best I can tell these changes produce a 6% regression in the runtime of `./x.py test` when `[rust] debug = true` is set.~~
Latest commit (6894d559bd) brings the additional overhead from this PR down to 0.5%, while also adding a few more assertions. I think this actually covers all the places in `core` that it is reasonable to check for safety requirements at runtime.

Thoughts?
2022-04-03 16:04:47 +00:00
Oliver Downard e2dfa23eac Improve method name suggestions
Attempts to improve method name suggestions when a matching method name
is not found. The approach taken is use the Levenshtein distance and
account for substrings having a high distance but can sometimes be very
close to the intended method (eg. empty vs is_empty).
2022-04-03 16:38:57 +01:00
Guillaume Gomez 995513c929 Add test for attribute display in rustdoc 2022-04-03 13:41:12 +02:00
Guillaume Gomez 78698dd0fb Fix display of attributes in rustdoc 2022-04-03 13:40:43 +02:00
bors 15a242a432 Auto merge of #90791 - drmorr0:drmorr-memcmp-cint-cfg, r=petrochenkov
make memcmp return a value of c_int_width instead of i32

This is an attempt to fix #32610 and #78022, namely, that `memcmp` always returns an `i32` regardless of the platform.  I'm running into some issues and was hoping I could get some help.

Here's what I've been attempting so far:

1. Build the stage0 compiler with all the changes _expect_ for the changes in `library/core/src/slice/cmp.rs` and `compiler/rustc_codegen_llvm/src/context.rs`; this is because `target_c_int_width` isn't passed through and recognized as a valid config option yet.  I'm building with `./x.py build --stage 0 library/core library/proc_macro compiler/rustc`
2. Next I add in the `#[cfg(c_int_width = ...)]` params to `cmp.rs` and `context.rs` and build the stage 1 compiler by running `./x.py build --keep-stage 0 --stage 1 library/core library/proc_macro compiler/rustc`.  This step now runs successfully.
3. Lastly, I try to build the test program for AVR mentioned in #78022 with `RUSTFLAGS="--emit llvm-ir" cargo build --release`, and look at the resulting llvm IR, which still shows:

```
...
%11 = call addrspace(1) i32 `@memcmp(i8*` nonnull %5, i8* nonnull %10, i16 5) #7, !dbg !1191                                                                                                                                                                                                                                %.not = icmp eq i32 %11, 0, !dbg !1191
...
; Function Attrs: nounwind optsize                                                                                                                                                                                                                                                                                          declare i32 `@memcmp(i8*,` i8*, i16) local_unnamed_addr addrspace(1) #4
```

Any ideas what I'm missing here?  Alternately, if this is totally the wrong approach I'm open to other suggestions.

cc `@Rahix`
2022-04-03 11:16:22 +00:00
bors ec7b753ea9 Auto merge of #85321 - cjgillot:mir-cycle, r=bjorn3
Use DefPathHash instead of HirId to break inlining cycles.

The `DefPathHash` is stable across incremental compilation sessions, so provides a total order on `LocalDefId`. Using it instead of `HirId` ensures the MIR inliner has the same behaviour for incremental and non-incremental compilation.

A downside is that the cycle tie break is not as predictable is with `HirId`.
2022-04-03 07:53:10 +00:00