]> git.lizzy.rs Git - rust.git/log
rust.git
2 years agotidy: add fluent dependencies to whitelist
David Wood [Sun, 3 Apr 2022 04:05:36 +0000 (05:05 +0100)]
tidy: add fluent dependencies to whitelist

Unfortunately, fluent comes with a lot of dependencies and these need to
be added to the whitelist.

Signed-off-by: David Wood <david.wood@huawei.com>
2 years agoerrors: use `impl Into<FluentId>`
David Wood [Sun, 3 Apr 2022 03:58:57 +0000 (04:58 +0100)]
errors: use `impl Into<FluentId>`

`FluentId` is the type alias that is used everywhere else so it should
be used here too so that this doesn't need updated if the alias changes.

Signed-off-by: David Wood <david.wood@huawei.com>
2 years agosession: opt for enabling directionality markers
David Wood [Sun, 3 Apr 2022 03:53:01 +0000 (04:53 +0100)]
session: opt for enabling directionality markers

Add an option for enabling and disabling Fluent's directionality
isolation markers in output. Disabled by default as these can render in
some terminals and applications.

Signed-off-by: David Wood <david.wood@huawei.com>
2 years agoerrors: add links to fluent documentation
David Wood [Sat, 2 Apr 2022 05:21:27 +0000 (06:21 +0100)]
errors: add links to fluent documentation

Add some links to the Fluent documentation to
`DiagnosticMessage::FluentIdentifier` which explain what a Fluent
message and attribute are.

Signed-off-by: David Wood <david.wood@huawei.com>
2 years agotypeck: remove now-unnecessary parameter from diag
David Wood [Sat, 2 Apr 2022 05:18:48 +0000 (06:18 +0100)]
typeck: remove now-unnecessary parameter from diag

Removes `expected_pluralize` parameter from diagnostic struct which is
no longer necessary as the Fluent message can determine the correct
pluralization.

Signed-off-by: David Wood <david.wood@huawei.com>
2 years agoerrors: don't try load default locale from sysroot
David Wood [Sat, 2 Apr 2022 05:09:43 +0000 (06:09 +0100)]
errors: don't try load default locale from sysroot

If the user requests a diagnostic locale of "en-US" then it doesn't make
sense to try and load that from the `$sysroot` because it is just the
default built-in locale.

Signed-off-by: David Wood <david.wood@huawei.com>
2 years agomacros: support translatable suggestions
David Wood [Thu, 31 Mar 2022 12:10:13 +0000 (13:10 +0100)]
macros: support translatable suggestions

Extends support for generating `DiagnosticMessage::FluentIdentifier`
messages from `SessionDiagnostic` derive to `#[suggestion]`.

Signed-off-by: David Wood <david.wood@huawei.com>
2 years agomacros: note/help in `SessionDiagnostic` derive
David Wood [Thu, 31 Mar 2022 11:10:00 +0000 (12:10 +0100)]
macros: note/help in `SessionDiagnostic` derive

Signed-off-by: David Wood <david.wood@huawei.com>
2 years agomacros: support translatable labels
David Wood [Thu, 31 Mar 2022 09:24:46 +0000 (10:24 +0100)]
macros: support translatable labels

Extends support for generating `DiagnosticMessage::FluentIdentifier`
messages from `SessionDiagnostic` derive to `#[label]`.

Signed-off-by: David Wood <david.wood@huawei.com>
2 years agomacros: optional error codes
David Wood [Thu, 31 Mar 2022 08:21:42 +0000 (09:21 +0100)]
macros: optional error codes

In an effort to make it easier to port diagnostics to
`SessionDiagnostic` (for translation) and since translation slugs could
replace error codes, make error codes optional in the
`SessionDiagnostic` derive.

Signed-off-by: David Wood <david.wood@huawei.com>
2 years agomacros: add `#[no_arg]` to skip `set_arg` call
David Wood [Thu, 31 Mar 2022 08:02:31 +0000 (09:02 +0100)]
macros: add `#[no_arg]` to skip `set_arg` call

A call to `set_arg` is generated for every field of a
`SessionDiagnostic` struct without attributes, but not all types support
being an argument, so `#[no_arg]` is introduced to skip these fields.

Signed-off-by: David Wood <david.wood@huawei.com>
2 years agomacros: rename `#[message]` to `#[primary_span]`
David Wood [Thu, 31 Mar 2022 07:50:45 +0000 (08:50 +0100)]
macros: rename `#[message]` to `#[primary_span]`

Small commit renaming `#[message]` to `#[primary_span]` as this more
accurately reflects what it does now.

Signed-off-by: David Wood <david.wood@huawei.com>
2 years agomacros: translatable struct attrs and warnings
David Wood [Thu, 31 Mar 2022 07:35:17 +0000 (08:35 +0100)]
macros: translatable struct attrs and warnings

Signed-off-by: David Wood <david.wood@huawei.com>
2 years agomacros: update session diagnostic errors
David Wood [Wed, 30 Mar 2022 09:04:03 +0000 (10:04 +0100)]
macros: update session diagnostic errors

Small commit adding backticks around types and annotations in the error
messages from the session diagnostic derive.

Signed-off-by: David Wood <david.wood@huawei.com>
2 years agoerrors: disable directionality isolation markers
David Wood [Thu, 31 Mar 2022 09:14:21 +0000 (10:14 +0100)]
errors: disable directionality isolation markers

Fluent diagnostics can insert directionality isolation markers around
interpolated variables indicating that there may be a shift from
right-to-left to left-to-right text (or vice-versa). These are disabled
because they are sometimes visible in the error output, but may be worth
investigating in future (for example: if type names are left-to-right
and the surrounding diagnostic messages are right-to-left, then these
might be helpful).

Signed-off-by: David Wood <david.wood@huawei.com>
2 years agomacros: add args for non-subdiagnostic fields
David Wood [Wed, 30 Mar 2022 08:45:36 +0000 (09:45 +0100)]
macros: add args for non-subdiagnostic fields

Non-subdiagnostic fields (i.e. those that don't have `#[label]`
attributes or similar and are just additional context) have to be added
as arguments for Fluent messages to refer them. This commit extends the
`SessionDiagnostic` derive to do this for all fields that do not have
attributes and introduces an `IntoDiagnosticArg` trait that is
implemented on all types that can be converted to a argument for Fluent.

Signed-off-by: David Wood <david.wood@huawei.com>
2 years agomacros: move suggestion type handling to fn
David Wood [Wed, 30 Mar 2022 02:08:58 +0000 (03:08 +0100)]
macros: move suggestion type handling to fn

Move the handling of `Span` or `(Span, Applicability)` types in
`#[suggestion]` attributes to its own function.

Signed-off-by: David Wood <david.wood@huawei.com>
2 years agomacros: update comments
David Wood [Wed, 30 Mar 2022 02:00:54 +0000 (03:00 +0100)]
macros: update comments

Various small changes to comments, like wrapping code in backticks,
changing comments to doc comments and adding newlines.

Signed-off-by: David Wood <david.wood@huawei.com>
2 years agoerrors: implement sysroot/testing bundle loading
David Wood [Mon, 28 Mar 2022 08:36:20 +0000 (09:36 +0100)]
errors: implement sysroot/testing bundle loading

Extend loading of Fluent bundles so that bundles can be loaded from the
sysroot based on the language requested by the user, or using a nightly
flag.

Sysroot bundles are loaded from `$sysroot/share/locale/$locale/*.ftl`.

Signed-off-by: David Wood <david.wood@huawei.com>
2 years agoerrors: implement fallback diagnostic translation
David Wood [Sat, 26 Mar 2022 07:27:43 +0000 (07:27 +0000)]
errors: implement fallback diagnostic translation

This commit updates the signatures of all diagnostic functions to accept
types that can be converted into a `DiagnosticMessage`. This enables
existing diagnostic calls to continue to work as before and Fluent
identifiers to be provided. The `SessionDiagnostic` derive just
generates normal diagnostic calls, so these APIs had to be modified to
accept Fluent identifiers.

In addition, loading of the "fallback" Fluent bundle, which contains the
built-in English messages, has been implemented.

Each diagnostic now has "arguments" which correspond to variables in the
Fluent messages (necessary to render a Fluent message) but no API for
adding arguments has been added yet. Therefore, diagnostics (that do not
require interpolation) can be converted to use Fluent identifiers and
will be output as before.

2 years agospan: move `MultiSpan`
David Wood [Thu, 24 Mar 2022 02:03:04 +0000 (02:03 +0000)]
span: move `MultiSpan`

`MultiSpan` contains labels, which are more complicated with the
introduction of diagnostic translation and will use types from
`rustc_errors` - however, `rustc_errors` depends on `rustc_span` so
`rustc_span` cannot use types like `DiagnosticMessage` without
dependency cycles. Introduce a new `rustc_error_messages` crate that can
contain `DiagnosticMessage` and `MultiSpan`.

Signed-off-by: David Wood <david.wood@huawei.com>
2 years agoerrors: introduce `DiagnosticMessage`
David Wood [Wed, 23 Mar 2022 07:34:20 +0000 (07:34 +0000)]
errors: introduce `DiagnosticMessage`

Introduce a `DiagnosticMessage` type that will enable diagnostic
messages to be simple strings or Fluent identifiers.
`DiagnosticMessage` is now used in the implementation of the standard
`DiagnosticBuilder` APIs.

Signed-off-by: David Wood <david.wood@huawei.com>
2 years agoAuto merge of #95662 - Dylan-DPC:rollup-fo7jsr6, r=Dylan-DPC
bors [Tue, 5 Apr 2022 02:21:13 +0000 (02:21 +0000)]
Auto merge of #95662 - Dylan-DPC:rollup-fo7jsr6, r=Dylan-DPC

Rollup of 7 pull requests

Successful merges:

 - #91873 (Mention implementers of unsatisfied trait)
 - #95588 (explicitly distinguish pointer::addr and pointer::expose_addr)
 - #95603 (Fix late-bound ICE in `dyn` return type suggestion)
 - #95620 (interpret: remove MemoryExtra in favor of giving access to the Machine)
 - #95630 (Update `NonNull` pointer provenance methods' documentation)
 - #95631 (Refactor: remove unnecessary nested blocks)
 - #95642 (`CandidateSource::XCandidate` -> `CandidateSource::X`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup

2 years agoRollup merge of #95642 - lcnr:probe-smol, r=compiler-errors
Dylan DPC [Mon, 4 Apr 2022 23:53:36 +0000 (01:53 +0200)]
Rollup merge of #95642 - lcnr:probe-smol, r=compiler-errors

`CandidateSource::XCandidate` -> `CandidateSource::X`

2 years agoRollup merge of #95631 - TaKO8Ki:remove-unnecessary-nested-blocks, r=davidtwco
Dylan DPC [Mon, 4 Apr 2022 23:53:35 +0000 (01:53 +0200)]
Rollup merge of #95631 - TaKO8Ki:remove-unnecessary-nested-blocks, r=davidtwco

Refactor: remove unnecessary nested blocks

2 years agoRollup merge of #95630 - declanvk:update-nonnull-doc, r=RalfJung
Dylan DPC [Mon, 4 Apr 2022 23:53:34 +0000 (01:53 +0200)]
Rollup merge of #95630 - declanvk:update-nonnull-doc, r=RalfJung

Update `NonNull` pointer provenance methods' documentation

 - Add links to equivalent methods on raw pointers

2 years agoRollup merge of #95620 - RalfJung:memory-no-extras, r=oli-obk
Dylan DPC [Mon, 4 Apr 2022 23:53:33 +0000 (01:53 +0200)]
Rollup merge of #95620 - RalfJung:memory-no-extras, r=oli-obk

interpret: remove MemoryExtra in favor of giving access to the Machine

The Miri PR for this is upcoming.

r? ``@oli-obk``

2 years agoRollup merge of #95603 - compiler-errors:dyn-return, r=oli-obk
Dylan DPC [Mon, 4 Apr 2022 23:53:32 +0000 (01:53 +0200)]
Rollup merge of #95603 - compiler-errors:dyn-return, r=oli-obk

Fix late-bound ICE in `dyn` return type suggestion

This fixes the root-cause of the attached issues -- the root problem is that we're using the return type from a signature with late-bound instead of early-bound regions. The change on line 1087 (`let Some(liberated_sig) = typeck_results.liberated_fn_sigs().get(fn_hir_id) else { return false; };`) makes sure we're grabbing the _right_ return type for this suggestion to check the `dyn` predicates with.

Fixes #91801
Fixes #91803

This fix also includes some drive-by changes, specifically:

1. Don't suggest boxing when we have `-> dyn Trait` and are already returning `Box<T>` where `T: Trait` (before we always boxed the value).
2. Suggestion applies even when the return type is a type alias (e.g. `type Foo = dyn Trait`). This does cause the suggestion to expand to the aliased type, but I think it's still beneficial.
3. Split up the multipart suggestion because there's a 6-line max in the printed output...

I am open to splitting out the above changes, if we just want to fix the ICE first.

cc: ```@terrarier2111``` and #92289

2 years agoRollup merge of #95588 - RalfJung:strict-provenance, r=scottmcm
Dylan DPC [Mon, 4 Apr 2022 23:53:31 +0000 (01:53 +0200)]
Rollup merge of #95588 - RalfJung:strict-provenance, r=scottmcm

explicitly distinguish pointer::addr and pointer::expose_addr

``@bgeron`` pointed out that the current docs promise that `ptr.addr()` and `ptr as usize` are equivalent. I don't think that is a promise we want to make. (Conceptually, `ptr as usize` might 'escape' the provenance to enable future `usize as ptr` casts, but `ptr.addr()` dertainly does not do that.)

So I propose we word the docs a bit more carefully here. ``@Gankra`` what do you think?

2 years agoRollup merge of #91873 - estebank:mention-impls-for-unsatisfied-trait, r=davidtwco
Dylan DPC [Mon, 4 Apr 2022 23:53:31 +0000 (01:53 +0200)]
Rollup merge of #91873 - estebank:mention-impls-for-unsatisfied-trait, r=davidtwco

Mention implementers of unsatisfied trait

When encountering an unsatisfied trait bound, if there are no other
suggestions, mention all the types that *do* implement that trait:

```
error[E0277]: the trait bound `f32: Foo` is not satisfied
  --> $DIR/impl_wf.rs:22:6
   |
LL | impl Baz<f32> for f32 { }
   |      ^^^^^^^^ the trait `Foo` is not implemented for `f32`
   |
   = help: the trait `Foo` is implemented for `i32`
note: required by a bound in `Baz`
  --> $DIR/impl_wf.rs:18:31
   |
LL | trait Baz<U: ?Sized> where U: Foo { }
   |                               ^^^ required by this bound in `Baz`
```
```
error[E0277]: the trait bound `u32: Foo` is not satisfied
  --> $DIR/associated-types-path-2.rs:29:5
   |
LL |     f1(2u32, 4u32);
   |     ^^ the trait `Foo` is not implemented for `u32`
   |
   = help: the trait `Foo` is implemented for `i32`
note: required by a bound in `f1`
  --> $DIR/associated-types-path-2.rs:13:14
   |
LL | pub fn f1<T: Foo>(a: T, x: T::A) {}
   |              ^^^ required by this bound in `f1`
```

Suggest dereferencing in more cases.

Fix #87437, fix #90970.

2 years agoexplicitly distinguish pointer::addr and pointer::expose_addr
Ralf Jung [Sun, 3 Apr 2022 17:37:03 +0000 (13:37 -0400)]
explicitly distinguish pointer::addr and pointer::expose_addr

2 years agoRemove hack, fix fmt and tests
Esteban Kuber [Sun, 27 Mar 2022 02:14:54 +0000 (02:14 +0000)]
Remove hack, fix fmt and tests

2 years agoHighlight `is` in the message for emphasis
Esteban Kuber [Sun, 27 Mar 2022 02:08:58 +0000 (02:08 +0000)]
Highlight `is` in the message for emphasis

2 years agoRefer to the TraitRef::identity in the message to be clearer
Esteban Kuber [Sun, 27 Mar 2022 02:02:07 +0000 (02:02 +0000)]
Refer to the TraitRef::identity in the message to be clearer

2 years agoDedup logic and improve output for other types that impl trait
Esteban Kuber [Sun, 27 Mar 2022 01:49:01 +0000 (01:49 +0000)]
Dedup logic and improve output for other types that impl trait

2 years agoFix list length
Esteban Kuber [Sat, 26 Mar 2022 23:14:47 +0000 (23:14 +0000)]
Fix list length

2 years agoSuggest dereferncing when possible in E0277, fix #87437
Esteban Kuber [Sat, 26 Mar 2022 23:01:29 +0000 (23:01 +0000)]
Suggest dereferncing when possible in E0277, fix #87437

2 years agoFix #90970, doesn't address #87437
Esteban Kuber [Sat, 26 Mar 2022 21:26:02 +0000 (21:26 +0000)]
Fix #90970, doesn't address #87437

2 years agoMention implementers of unsatisfied trait
Esteban Kuber [Mon, 13 Dec 2021 20:56:40 +0000 (20:56 +0000)]
Mention implementers of unsatisfied trait

When encountering an unsatisfied trait bound, if there are no other
suggestions, mention all the types that *do* implement that trait:

```
error[E0277]: the trait bound `f32: Foo` is not satisfied
  --> $DIR/impl_wf.rs:22:6
   |
LL | impl Baz<f32> for f32 { }
   |      ^^^^^^^^ the trait `Foo` is not implemented for `f32`
   |
   = help: the following other types implement trait `Foo`:
             Option<T>
             i32
             str
note: required by a bound in `Baz`
  --> $DIR/impl_wf.rs:18:31
   |
LL | trait Baz<U: ?Sized> where U: Foo { }
   |                               ^^^ required by this bound in `Baz`
```

Mention implementers of traits in `ImplObligation`s.

Do not mention other `impl`s for closures, ranges and `?`.

2 years agoAuto merge of #95653 - Dylan-DPC:rollup-2p9hzi3, r=Dylan-DPC
bors [Mon, 4 Apr 2022 19:51:52 +0000 (19:51 +0000)]
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

2 years agoRollup merge of #95609 - compiler-errors:borrow-unsized-to-dyn, r=nagisa
Dylan DPC [Mon, 4 Apr 2022 18:41:34 +0000 (20:41 +0200)]
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.

2 years agoRollup merge of #95467 - ChrisDenton:async-read-pipe, r=joshtriplett
Dylan DPC [Mon, 4 Apr 2022 18:41:33 +0000 (20:41 +0200)]
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

2 years agoRollup merge of #95438 - m-ou-se:sync-unsafe-cell, r=joshtriplett
Dylan DPC [Mon, 4 Apr 2022 18:41:32 +0000 (20:41 +0200)]
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.

2 years agoRollup merge of #95431 - golddranks:stabilize_total_cmp, r=scottmcm
Dylan DPC [Mon, 4 Apr 2022 18:41:31 +0000 (20:41 +0200)]
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

2 years agoRollup merge of #95343 - dtolnay:literals, r=petrochenkov
Dylan DPC [Mon, 4 Apr 2022 18:41:30 +0000 (20:41 +0200)]
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"`.

2 years agoRollup merge of #94817 - cuviper:relnotes-1.60.0, r=pietroalbini,m-ou-se
Dylan DPC [Mon, 4 Apr 2022 18:41:28 +0000 (20:41 +0200)]
Rollup merge of #94817 - cuviper:relnotes-1.60.0, r=pietroalbini,m-ou-se

Release notes for 1.60.0

2 years agoRollup merge of #92942 - Xaeroxe:raw_arg, r=dtolnay
Dylan DPC [Mon, 4 Apr 2022 18:41:27 +0000 (20:41 +0200)]
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

2 years agoCorrect calling convention
Chris Denton [Mon, 4 Apr 2022 18:37:11 +0000 (19:37 +0100)]
Correct calling convention

2 years agoAuto merge of #95555 - nnethercote:parse_tt-new-representation, r=petrochenkov
bors [Mon, 4 Apr 2022 17:27:48 +0000 (17:27 +0000)]
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`

2 years agoBump windows CommandExt::raw_arg to 1.62
David Tolnay [Mon, 4 Apr 2022 17:15:28 +0000 (10:15 -0700)]
Bump windows CommandExt::raw_arg to 1.62

2 years agoAuto merge of #95119 - OliverMD:method_suggestions, r=davidtwco
bors [Mon, 4 Apr 2022 13:00:25 +0000 (13:00 +0000)]
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

2 years agoStabilize total_cmp
Pyry Kontio [Tue, 29 Mar 2022 12:43:24 +0000 (21:43 +0900)]
Stabilize total_cmp

2 years agoCandidateSource::XCandidate -> CandidateSource::X
lcnr [Mon, 4 Apr 2022 09:48:47 +0000 (11:48 +0200)]
CandidateSource::XCandidate -> CandidateSource::X

2 years agoimprove 92630 wording
Pietro Albini [Mon, 4 Apr 2022 08:38:41 +0000 (10:38 +0200)]
improve 92630 wording

2 years agoadd compat note about instant changes
Pietro Albini [Mon, 4 Apr 2022 08:33:21 +0000 (10:33 +0200)]
add compat note about instant changes

2 years agoadd future compatibility notes for linux-gnu baseline bump
Pietro Albini [Mon, 4 Apr 2022 08:13:21 +0000 (10:13 +0200)]
add future compatibility notes for linux-gnu baseline bump

2 years agoreword the docs on tier 2 platforms docs
Pietro Albini [Mon, 4 Apr 2022 08:09:57 +0000 (10:09 +0200)]
reword the docs on tier 2 platforms docs

2 years agomove 2021 libs to internal changes
Pietro Albini [Mon, 4 Apr 2022 07:48:56 +0000 (09:48 +0200)]
move 2021 libs to internal changes

2 years agolink target tier policy to new targets
Pietro Albini [Mon, 4 Apr 2022 07:48:20 +0000 (09:48 +0200)]
link target tier policy to new targets

2 years agoAuto merge of #95636 - pietroalbini:pa-version-1.62.0, r=pietroalbini
bors [Mon, 4 Apr 2022 07:22:34 +0000 (07:22 +0000)]
Auto merge of #95636 - pietroalbini:pa-version-1.62.0, r=pietroalbini

Bump version number to 1.62.0

2 years agobump version to 1.62.0
Pietro Albini [Mon, 4 Apr 2022 07:21:03 +0000 (09:21 +0200)]
bump version to 1.62.0

2 years agoReorder match arms in `parse_tt_inner`.
Nicholas Nethercote [Mon, 4 Apr 2022 05:47:53 +0000 (15:47 +1000)]
Reorder match arms in `parse_tt_inner`.

To match the order the variants are declared in.

2 years agoA new matcher representation for use in `parse_tt`.
Nicholas Nethercote [Thu, 31 Mar 2022 23:19:16 +0000 (10:19 +1100)]
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.

2 years agoUpdate library/std/src/sys/windows/pipe.rs
Chris Denton [Mon, 4 Apr 2022 04:59:51 +0000 (05:59 +0100)]
Update library/std/src/sys/windows/pipe.rs

2 years agoAuto merge of #95031 - compiler-errors:param-env-cache, r=Aaron1011
bors [Mon, 4 Apr 2022 04:48:36 +0000 (04:48 +0000)]
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)

2 years agoAdd doc links referencing raw pointer methods
Declan Kelly [Mon, 4 Apr 2022 00:39:02 +0000 (17:39 -0700)]
Add doc links referencing raw pointer methods

2 years agoformat cond
Takayuki Maeda [Mon, 4 Apr 2022 03:49:02 +0000 (12:49 +0900)]
format cond

2 years agoAuto merge of #95606 - petrochenkov:linkregr, r=wesleywiser
bors [Mon, 4 Apr 2022 02:23:15 +0000 (02:23 +0000)]
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`

2 years agoremove unnecessary nested blocks
Takayuki Maeda [Mon, 4 Apr 2022 02:10:40 +0000 (11:10 +0900)]
remove unnecessary nested blocks

2 years agoAuto merge of #95619 - bjorn3:inline_location_caller, r=scottmcm
bors [Sun, 3 Apr 2022 23:42:31 +0000 (23:42 +0000)]
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.

2 years agoAuto merge of #95624 - Dylan-DPC:rollup-r8w7ui3, r=Dylan-DPC
bors [Sun, 3 Apr 2022 21:22:50 +0000 (21:22 +0000)]
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

2 years agoRollup merge of #95618 - adamse:master, r=dtolnay
Dylan DPC [Sun, 3 Apr 2022 21:21:45 +0000 (23:21 +0200)]
Rollup merge of #95618 - adamse:master, r=dtolnay

core: document that the align_of* functions return the alignment in bytes

2 years agoRollup merge of #95617 - saethlin:swap-test-invalidation, r=Dylan-DPC
Dylan DPC [Sun, 3 Apr 2022 21:21:43 +0000 (23:21 +0200)]
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
```

2 years agoRollup merge of #95613 - GuillaumeGomez:fix-rustdoc-attr-display, r=notriddle
Dylan DPC [Sun, 3 Apr 2022 21:21:43 +0000 (23:21 +0200)]
Rollup merge of #95613 - GuillaumeGomez:fix-rustdoc-attr-display, r=notriddle

Fix rustdoc attribute display

Fixes #81482.

r? `@notriddle`

2 years agoRollup merge of #95553 - jam1garner:naked-function-compile-error, r=tmiasko
Dylan DPC [Sun, 3 Apr 2022 21:21:42 +0000 (23:21 +0200)]
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".

2 years agoRollup merge of #95202 - Urgau:check-cfg-perf-well-known-values, r=petrochenkov
Dylan DPC [Sun, 3 Apr 2022 21:21:41 +0000 (23:21 +0200)]
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

2 years agoFix &mut invalidation in ptr::swap doctest
Ben Kimock [Sun, 3 Apr 2022 17:23:27 +0000 (13:23 -0400)]
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.

2 years agotweak some function names
Ralf Jung [Sun, 3 Apr 2022 19:29:19 +0000 (15:29 -0400)]
tweak some function names

2 years agoCleanup after some refactoring in rustc_target
Loïc BRANSTETT [Sun, 3 Apr 2022 16:42:39 +0000 (18:42 +0200)]
Cleanup after some refactoring in rustc_target

2 years agoReplace LinkArgs with Cow<'static, str>
Loïc BRANSTETT [Mon, 28 Mar 2022 13:06:46 +0000 (15:06 +0200)]
Replace LinkArgs with Cow<'static, str>

2 years agoReplace every Vec in Target(Options) with it's Cow equivalent
Loïc BRANSTETT [Sun, 27 Mar 2022 23:08:17 +0000 (01:08 +0200)]
Replace every Vec in Target(Options) with it's Cow equivalent

2 years agoReplace every `String` in Target(Options) with `Cow<'static, str>`
Loïc BRANSTETT [Tue, 22 Mar 2022 10:43:05 +0000 (11:43 +0100)]
Replace every `String` in Target(Options) with `Cow<'static, str>`

2 years agointerpret: remove MemoryExtra in favor of giving access to the Machine
Ralf Jung [Sun, 3 Apr 2022 17:05:49 +0000 (13:05 -0400)]
interpret: remove MemoryExtra in favor of giving access to the Machine

2 years agoAuto merge of #95610 - createyourpersonalaccount:derefmut-docfix, r=Dylan-DPC
bors [Sun, 3 Apr 2022 19:06:20 +0000 (19:06 +0000)]
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.

2 years agoMark Location::caller() as #[inline]
bjorn3 [Sun, 3 Apr 2022 18:27:54 +0000 (20:27 +0200)]
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.

2 years agocore: document that the align_of* functions return the alignment in bytes
Adam Sandberg Ericsson [Sun, 3 Apr 2022 18:03:34 +0000 (19:03 +0100)]
core: document that the align_of* functions return the alignment in bytes

2 years agoAuto merge of #92686 - saethlin:unsafe-debug-asserts, r=Amanieu
bors [Sun, 3 Apr 2022 16:04:47 +0000 (16:04 +0000)]
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 (https://github.com/rust-lang/rust/pull/92686/commits/6894d559bdb4365243b3f4bf73f18e4b1bed04d1) 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?

2 years agoImprove method name suggestions
Oliver Downard [Mon, 14 Mar 2022 21:07:19 +0000 (21:07 +0000)]
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).

2 years agoAdd test for attribute display in rustdoc
Guillaume Gomez [Sun, 3 Apr 2022 11:41:12 +0000 (13:41 +0200)]
Add test for attribute display in rustdoc

2 years agoFix display of attributes in rustdoc
Guillaume Gomez [Sun, 3 Apr 2022 11:40:43 +0000 (13:40 +0200)]
Fix display of attributes in rustdoc

2 years agoAuto merge of #90791 - drmorr0:drmorr-memcmp-cint-cfg, r=petrochenkov
bors [Sun, 3 Apr 2022 11:16:22 +0000 (11:16 +0000)]
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`

2 years agoAuto merge of #85321 - cjgillot:mir-cycle, r=bjorn3
bors [Sun, 3 Apr 2022 07:53:10 +0000 (07:53 +0000)]
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`.

2 years agoAuto merge of #88672 - camelid:inc-parser-sugg, r=davidtwco
bors [Sun, 3 Apr 2022 05:24:20 +0000 (05:24 +0000)]
Auto merge of #88672 - camelid:inc-parser-sugg, r=davidtwco

Suggest `i += 1` when we see `i++` or `++i`

Closes #83502 (for `i++` and `++i`; `--i` should be covered by #82987, and `i--`
is tricky to handle).

This is a continuation of #83536.

r? `@estebank`

2 years agoImprove doc example of DerefMut
Nikolaos Chatzikonstantinou [Sun, 3 Apr 2022 03:42:19 +0000 (12:42 +0900)]
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.

2 years agomake memcmp return a value of c_int_width instead of i32
David Morrison [Thu, 11 Nov 2021 04:14:23 +0000 (20:14 -0800)]
make memcmp return a value of c_int_width instead of i32

2 years agoSuggest borrowing when trying to coerce unsized type into dyn Trait
Michael Goulet [Sat, 2 Apr 2022 23:43:17 +0000 (16:43 -0700)]
Suggest borrowing when trying to coerce unsized type into dyn Trait

2 years agoAuto merge of #95590 - GuillaumeGomez:multi-line-attr-handling-doctest, r=notriddle
bors [Sat, 2 Apr 2022 23:39:25 +0000 (23:39 +0000)]
Auto merge of #95590 - GuillaumeGomez:multi-line-attr-handling-doctest, r=notriddle

Fix multiline attributes handling in doctests

Fixes #55713.

I needed to have access to the `unclosed_delims` field in order to check that the attribute was completely parsed and didn't have missing parts, so I created a getter for it.

r? `@notriddle`

2 years agoFix late-bound ICE in unsized return suggestion
Michael Goulet [Sat, 2 Apr 2022 21:22:35 +0000 (14:22 -0700)]
Fix late-bound ICE in unsized return suggestion

2 years agolinker: Implicitly link native libs as whole-archive in some more cases
Vadim Petrochenkov [Sat, 2 Apr 2022 11:31:34 +0000 (14:31 +0300)]
linker: Implicitly link native libs as whole-archive in some more cases

2 years agoLess manipulation of the callee_def_id.
Camille GILLOT [Sat, 2 Apr 2022 21:28:09 +0000 (23:28 +0200)]
Less manipulation of the callee_def_id.