]> git.lizzy.rs Git - rust.git/log
rust.git
15 months agoRollup merge of #107656 - jonhoo:bump-rust-installer, r=Mark-Simulacrum
Matthias Krüger [Wed, 8 Feb 2023 06:13:26 +0000 (07:13 +0100)]
Rollup merge of #107656 - jonhoo:bump-rust-installer, r=Mark-Simulacrum

Bump rust-installer

Makes generation of `manifest.in` deterministic:
https://github.com/rust-lang/rust-installer/pull/120

15 months agoAuto merge of #107688 - lukas-code:projection-with-lifetime, r=jackh726
bors [Wed, 8 Feb 2023 00:34:18 +0000 (00:34 +0000)]
Auto merge of #107688 - lukas-code:projection-with-lifetime, r=jackh726

ReErased regions are local

fix https://github.com/rust-lang/rust/issues/107678
fix https://github.com/rust-lang/rust/issues/107684
fix https://github.com/rust-lang/rust/issues/107686
fix https://github.com/rust-lang/rust/issues/107691
fix https://github.com/rust-lang/rust/issues/107730

15 months agoAuto merge of #107768 - matthiaskrgr:rollup-9u4cal4, r=matthiaskrgr
bors [Tue, 7 Feb 2023 20:58:20 +0000 (20:58 +0000)]
Auto merge of #107768 - matthiaskrgr:rollup-9u4cal4, r=matthiaskrgr

Rollup of 8 pull requests

Successful merges:

 - #107719 (Remove `arena_cache` modifier from `upstream_monomorphizations_for`)
 - #107740 (Avoid locking the global context across the `after_expansion` callback)
 - #107746 (Split fn_ctxt/adjust_fulfillment_errors from fn_ctxt/checks)
 - #107749 (allow quick-edit convenience)
 - #107750 (make more readable)
 - #107755 (remove binder from query constraints)
 - #107756 (miri: fix ICE when running out of address space)
 - #107764 (llvm-16: Use Triple.h from new header location.)

Failed merges:

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

15 months agoAuto merge of #107767 - matthiaskrgr:rollup-9m1qfso, r=matthiaskrgr
bors [Tue, 7 Feb 2023 17:19:47 +0000 (17:19 +0000)]
Auto merge of #107767 - matthiaskrgr:rollup-9m1qfso, r=matthiaskrgr

Rollup of 8 pull requests

Successful merges:

 - #100599 (Add compiler error E0523 long description and test)
 - #107471 (rustdoc: do not include empty default-settings tag in HTML)
 - #107555 (Modify existing bounds if they exist)
 - #107662 (Turn projections into copies in CopyProp.)
 - #107695 (Add test for Future inflating arg size to 3x )
 - #107700 (Run the tools builder on all PRs)
 - #107706 (Mark 'atomic_mut_ptr' methods const)
 - #107709 (Fix problem noticed in PR106859 with char -> u8 suggestion)

Failed merges:

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

15 months agoRollup merge of #107764 - maurer:llvm-16, r=cuviper
Matthias Krüger [Tue, 7 Feb 2023 16:57:18 +0000 (17:57 +0100)]
Rollup merge of #107764 - maurer:llvm-16, r=cuviper

llvm-16: Use Triple.h from new header location.

LLVM 16 has moved Triple.h from ADT and into TargetParser.

LLVM [landed a commit](https://github.com/llvm/llvm-project/commit/62c7f035b4392c1933550eead6ddab35122720bc) this morning moving the header. This change should make rustc continue to build against LLVM main.

15 months agoRollup merge of #107756 - RalfJung:miri-out-of-addresses, r=oli-obk
Matthias Krüger [Tue, 7 Feb 2023 16:57:18 +0000 (17:57 +0100)]
Rollup merge of #107756 - RalfJung:miri-out-of-addresses, r=oli-obk

miri: fix ICE when running out of address space

Fixes https://github.com/rust-lang/miri/issues/2769
r? `@oli-obk`

I didn't add a test since that requires https://github.com/oli-obk/ui_test/issues/38 (host must be 64bit and target 32bit). Also the test takes ~30s, so I am not sure if we want to have it in the test suite?

15 months agoRollup merge of #107709 - tialaramex:master, r=compiler-errors
Matthias Krüger [Tue, 7 Feb 2023 16:57:17 +0000 (17:57 +0100)]
Rollup merge of #107709 - tialaramex:master, r=compiler-errors

Fix problem noticed in PR106859 with char -> u8 suggestion

HN reader `@ayosec` noticed that my #106859 a few weeks back, malfunctions if you have a Unicode escape, the code suggested b'\u{0}' if you tried to use '\u{0}' where a byte should be, when of course b'\u{0}' is not a byte literal, regardless of the codepoint you can't write Unicode escapes in a byte literal at all.

My proposed fix here just checks that the "character" you wrote is fewer than 5 bytes, thus allowing \x7F and similar escapes but conveniently forbidding even the smallest Unicode escape \u{0} before offering the suggestion as before.

I have provided an updated test which includes examples which do and don't work because of this additional rule.

15 months agoRollup merge of #107755 - lcnr:no-binder, r=oli-obk
Matthias Krüger [Tue, 7 Feb 2023 16:57:17 +0000 (17:57 +0100)]
Rollup merge of #107755 - lcnr:no-binder, r=oli-obk

remove binder from query constraints

r? types

15 months agoRollup merge of #107750 - tshepang:readability, r=GuillaumeGomez
Matthias Krüger [Tue, 7 Feb 2023 16:57:17 +0000 (17:57 +0100)]
Rollup merge of #107750 - tshepang:readability, r=GuillaumeGomez

make more readable

15 months agoRollup merge of #107706 - tgross35:atomic-as-mut-ptr, r=m-ou-se
Matthias Krüger [Tue, 7 Feb 2023 16:57:16 +0000 (17:57 +0100)]
Rollup merge of #107706 - tgross35:atomic-as-mut-ptr, r=m-ou-se

Mark 'atomic_mut_ptr' methods const

There's nothing that would block these methods from being const (just an UnsafeCell get), and it would be helpful for FFI interfaces in static contexts

Related tracking issue: #66893

15 months agoRollup merge of #107749 - tshepang:editing-convenience, r=michaelwoerister
Matthias Krüger [Tue, 7 Feb 2023 16:57:16 +0000 (17:57 +0100)]
Rollup merge of #107749 - tshepang:editing-convenience, r=michaelwoerister

allow quick-edit convenience

15 months agoRollup merge of #107700 - jyn514:tools-builder, r=Mark-Simulacrum
Matthias Krüger [Tue, 7 Feb 2023 16:57:16 +0000 (17:57 +0100)]
Rollup merge of #107700 - jyn514:tools-builder, r=Mark-Simulacrum

Run the tools builder on all PRs

Previously, it would only run on changes to subtrees, submodules, or select directories. That made it so that changes to the compiler that broke tools would only be detected on a full bors merge. This makes it so the tools builder runs by default, making it easier to catch breaking changes to clippy (which was the most affected).

r? ``@Mark-Simulacrum`` cc ``@pietroalbini`` ``@flip1995`` ``@m-ou-se``

15 months agoRollup merge of #107746 - Nathan-Fenner:nathanf/clean-up-adjust_fulfillment_errors...
Matthias Krüger [Tue, 7 Feb 2023 16:57:16 +0000 (17:57 +0100)]
Rollup merge of #107746 - Nathan-Fenner:nathanf/clean-up-adjust_fulfillment_errors, r=compiler-errors

Split fn_ctxt/adjust_fulfillment_errors from fn_ctxt/checks

This is a follow-up from #106477, addressing a small number of the `FIXME`s that were added, by moving some functions into the new(er) `adjust_fulfillment_errors` module.

More cleanup is possible for this file (and I'll hopefully get around to doing some of that soon) but the very first thing is to just move these functions out.

There should be no "real" changes in this PR, besides minor adjustments to imports and the functions being transferred.

15 months agoRollup merge of #107695 - Swatinem:futcallx3, r=compiler-errors
Matthias Krüger [Tue, 7 Feb 2023 16:57:15 +0000 (17:57 +0100)]
Rollup merge of #107695 - Swatinem:futcallx3, r=compiler-errors

Add test for Future inflating arg size to 3x

This adds one more test that should track improvements to generator
layout, like https://github.com/rust-lang/rust/issues/62958 and https://github.com/rust-lang/rust/issues/62575.

In particular, this test highlights suboptimal layout, as the storage
for the argument future is not being reused across its usage as `upvar`,
`local` and `awaitee` (being polled to completion).

This is on top of https://github.com/rust-lang/rust/pull/107692 (as those would conflict with each other)

It is a minimal repro for code mentioned in https://github.com/moka-rs/moka/issues/212#issuecomment-1416914616 (CC `@tatsuya6502)`

15 months agoRollup merge of #107740 - oli-obk:lock_tcx, r=petrochenkov
Matthias Krüger [Tue, 7 Feb 2023 16:57:15 +0000 (17:57 +0100)]
Rollup merge of #107740 - oli-obk:lock_tcx, r=petrochenkov

Avoid locking the global context across the `after_expansion` callback

r? `@petrochenkov`

This was noticed in https://github.com/model-checking/kani/pull/2184#issuecomment-1416566982

This didn't have a perf impact, as it's just an additional 2 or 3 RefCell locks being created.

15 months agoRollup merge of #107662 - cjgillot:copy-projection, r=oli-obk
Matthias Krüger [Tue, 7 Feb 2023 16:57:15 +0000 (17:57 +0100)]
Rollup merge of #107662 - cjgillot:copy-projection, r=oli-obk

Turn projections into copies in CopyProp.

The current implementation can leave behind projections that are moved out several times.

This PR widens the check to turn such moves into copies: a move out of a projection of a copy is equivalent to a copy of the original projection.

15 months agoRollup merge of #107719 - WaffleLapkin:de-arena-allocates-you-UwU, r=cjgillot
Matthias Krüger [Tue, 7 Feb 2023 16:57:15 +0000 (17:57 +0100)]
Rollup merge of #107719 - WaffleLapkin:de-arena-allocates-you-UwU, r=cjgillot

Remove `arena_cache` modifier from `upstream_monomorphizations_for`

Arena-caching a pointer is pretty meaningless as far as I can tell.

15 months agoRollup merge of #107555 - edward-shen:edward-shen/dup-trait-suggestion, r=compiler...
Matthias Krüger [Tue, 7 Feb 2023 16:57:14 +0000 (17:57 +0100)]
Rollup merge of #107555 - edward-shen:edward-shen/dup-trait-suggestion, r=compiler-errors

Modify existing bounds if they exist

Fixes #107335.

This implementation is kinda gross but I don't really see a better way to do it.

This primarily does two things: Modifies `suggest_constraining_type_param` to accept a new parameter that indicates a span to be replaced instead of added, if presented, and limit the additive suggestions to either suggest a new bound on an existing bound (see newly added unit test) or add the generics argument if a generics argument wasn't found.

The former change is required to retain the capability to add an entirely new bounds if it was entirely omitted.

r? ``@compiler-errors``

15 months agoRollup merge of #107471 - notriddle:notriddle/default-settings, r=GuillaumeGomez
Matthias Krüger [Tue, 7 Feb 2023 16:57:14 +0000 (17:57 +0100)]
Rollup merge of #107471 - notriddle:notriddle/default-settings, r=GuillaumeGomez

rustdoc: do not include empty default-settings tag in HTML

15 months agoRollup merge of #100599 - MatthewPeterKelly:add-E0523-description-and-test, r=compile...
Matthias Krüger [Tue, 7 Feb 2023 16:57:13 +0000 (17:57 +0100)]
Rollup merge of #100599 - MatthewPeterKelly:add-E0523-description-and-test, r=compiler-errors,GuillaumeGomez

Add compiler error E0523 long description and test

This PR is one step towards addressing:  https://github.com/rust-lang/rust/issues/61137.

15 months agollvm-16: Use Triple.h from new header location.
Matthew Maurer [Tue, 7 Feb 2023 14:48:54 +0000 (06:48 -0800)]
llvm-16: Use Triple.h from new header location.

LLVM 16 has moved Triple.h from ADT and into TargetParser

15 months agoAuto merge of #107671 - CastilloDel:master, r=estebank
bors [Tue, 7 Feb 2023 13:29:45 +0000 (13:29 +0000)]
Auto merge of #107671 - CastilloDel:master, r=estebank

Fix suggestions rendering when the diff span is multiline

Fixes #92741

cc `@estebank`

I think, I finally fixed. I still want to go back and try to clean up the code a bit. I'm open to suggestions.

Some examples of the new suggestions:

```
help: consider removing the borrow
  |
2 -     &
  |
```
```
help: consider removing the borrow
  |
2 -     &
3 -     mut
  |
```
```
help: consider removing the borrow
  |
2 -     &
3 -     mut if true { true } else { false }
2 +     if true { true } else { false }
  |
```

Should we add a test to ensure this behavior doesn't disappear in the future?

15 months agomiri: fix ICE when running out of address space
Ralf Jung [Tue, 7 Feb 2023 10:39:07 +0000 (11:39 +0100)]
miri: fix ICE when running out of address space

15 months agoremove binder from query constraints
lcnr [Tue, 7 Feb 2023 09:59:18 +0000 (10:59 +0100)]
remove binder from query constraints

15 months agoAuto merge of #107704 - jyn514:tidy-ci, r=Mark-Simulacrum
bors [Tue, 7 Feb 2023 09:58:58 +0000 (09:58 +0000)]
Auto merge of #107704 - jyn514:tidy-ci, r=Mark-Simulacrum

Run `expand-yaml-anchors` in `x test tidy`

Previously, the pre-commit hook which runs `x test tidy` could pass only to have CI fail within the first 30 seconds. This adds about 30 seconds to `test tidy` (for an initial run, much less after the tool is built the first time) in exchange for catching errors in `.github/workflows/ci.yml` before they're pushed.

15 months agoAdd test for Future inflating arg size to 3x
Arpad Borsos [Sun, 5 Feb 2023 16:32:52 +0000 (17:32 +0100)]
Add test for Future inflating arg size to 3x

This adds one more test that should track improvements to generator
layout, like #62958 and #62575.

In particular, this test highlights suboptimal layout, as the storage
for the argument future is not being reused across its usage as `upvar`,
`local` and `awaitee` (being polled to completion).

15 months agoAuto merge of #106180 - RalfJung:dereferenceable-generators, r=nbdd0121
bors [Tue, 7 Feb 2023 03:35:10 +0000 (03:35 +0000)]
Auto merge of #106180 - RalfJung:dereferenceable-generators, r=nbdd0121

make &mut !Unpin not dereferenceable, and Box<!Unpin> not noalias

See https://github.com/rust-lang/unsafe-code-guidelines/issues/381 and [this LLVM discussion](https://discourse.llvm.org/t/interaction-of-noalias-and-dereferenceable/66979). The exact semantics of how `noalias` and `dereferenceable` interact are unclear, and `@comex` found a case of LLVM actually exploiting that ambiguity for optimizations. I think for now we should treat LLVM `dereferenceable` as implying a "fake read" to happen immediately at the top of the function (standing in for the spurious reads that LLVM might introduce), and that fake read is subject to all the usual `noalias` restrictions. This means we cannot put `dereferenceable` on `&mut !Unpin` references as those references can alias with other references that are being read and written inside the function (e.g. for self-referential generators), meaning the fake read introduces aliasing conflicts with those other accesses.

For `&` this is already not a problem due to https://github.com/rust-lang/rust/pull/98017 which removed the `dereferenceable` attribute for other reasons.

Regular `&mut Unpin` references are unaffected, so I hope the impact of this is going to be tiny.

The first commit does some refactoring of the `PointerKind` enum since I found the old code very confusing each time I had to touch it. It doesn't change behavior.

Fixes https://github.com/rust-lang/miri/issues/2714

EDIT: Turns out our `Box<!Unpin>` treatment was incorrect, too, so the PR also fixes that now (in codegen and Miri): we do not put `noalias` on these boxes any more.

15 months agomake more readable
Tshepang Mbambo [Tue, 7 Feb 2023 02:54:01 +0000 (04:54 +0200)]
make more readable

15 months agoallow quick-edit convenience
Tshepang Mbambo [Tue, 7 Feb 2023 02:41:13 +0000 (04:41 +0200)]
allow quick-edit convenience

15 months agoSplit fn_ctxt/adjust_fulfillment_errors from fn_ctxt/checks
Nathan Fenner [Tue, 7 Feb 2023 01:21:16 +0000 (17:21 -0800)]
Split fn_ctxt/adjust_fulfillment_errors from fn_ctxt/checks

15 months agoAuto merge of #107693 - petrochenkov:metable, r=oli-obk
bors [Tue, 7 Feb 2023 00:03:02 +0000 (00:03 +0000)]
Auto merge of #107693 - petrochenkov:metable, r=oli-obk

rustc_metadata: Encode/decode some `LazyArrays` without an `Option`

and a couple of related changes, see individual commits.

Addresses comments in https://github.com/rust-lang/rust/pull/107166#discussion_r1083417124 and https://github.com/rust-lang/rust/pull/107166#discussion_r1083768417, cc `@cjgillot` `@oli-obk.`

15 months agoFix problem noticed in PR106859 with char -> u8 suggestion
Nick Lamb [Sun, 5 Feb 2023 23:37:47 +0000 (23:37 +0000)]
Fix problem noticed in PR106859 with char -> u8 suggestion

15 months agoAvoid locking the global context across the `after_expansion` callback
Oli Scherer [Mon, 6 Feb 2023 21:11:03 +0000 (21:11 +0000)]
Avoid locking the global context across the `after_expansion` callback

15 months agoAuto merge of #107738 - matthiaskrgr:rollup-o18lzi8, r=matthiaskrgr
bors [Mon, 6 Feb 2023 20:20:53 +0000 (20:20 +0000)]
Auto merge of #107738 - matthiaskrgr:rollup-o18lzi8, r=matthiaskrgr

Rollup of 9 pull requests

Successful merges:

 - #106477 (Refine error spans for "The trait bound `T: Trait` is not satisfied" when passing literal structs/tuples)
 - #107596 (Add nicer output to PGO build timer)
 - #107692 (Sort Generator `print-type-sizes` according to their yield points)
 - #107714 (Clarify wording on f64::round() and f32::round())
 - #107720 (end entry paragraph with a period (.))
 - #107724 (remove unused rustc_* imports)
 - #107725 (Turn MarkdownWithToc into a struct with named fields)
 - #107731 (interpret: move discriminant reading and writing to separate file)
 - #107735 (Add mailmap for commits made by xes@meta.com)

Failed merges:

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

15 months agoRollup merge of #107735 - edward-shen:edward-shen/mailmap, r=dtolnay
Matthias Krüger [Mon, 6 Feb 2023 20:16:43 +0000 (21:16 +0100)]
Rollup merge of #107735 - edward-shen:edward-shen/mailmap, r=dtolnay

Add mailmap for commits made by xes@meta.com

Saw my contributions split at https://thanks.rust-lang.org/rust/1.69.0/

I assume it's because I committed with my work and personal email?

15 months agoRollup merge of #107731 - RalfJung:interpret-discriminant, r=cjgillot
Matthias Krüger [Mon, 6 Feb 2023 20:16:43 +0000 (21:16 +0100)]
Rollup merge of #107731 - RalfJung:interpret-discriminant, r=cjgillot

interpret: move discriminant reading and writing to separate file

This is quite different from the otherwise fairly general read and write functions in place.rs and operand.rs, and also it's nice to have these two functions close together as they are basically inverses of each other.

15 months agoRollup merge of #107725 - GuillaumeGomez:turn-markdownwithtoc-into-struct, r=notriddle
Matthias Krüger [Mon, 6 Feb 2023 20:16:42 +0000 (21:16 +0100)]
Rollup merge of #107725 - GuillaumeGomez:turn-markdownwithtoc-into-struct, r=notriddle

Turn MarkdownWithToc into a struct with named fields

Extracted the commit from https://github.com/rust-lang/rust/pull/107640.

r? `@notriddle`

15 months agoRollup merge of #107724 - klensy:imports, r=Mark-Simulacrum
Matthias Krüger [Mon, 6 Feb 2023 20:16:42 +0000 (21:16 +0100)]
Rollup merge of #107724 - klensy:imports, r=Mark-Simulacrum

remove unused rustc_* imports

15 months agoRollup merge of #107720 - tshepang:consistency, r=Mark-Simulacrum
Matthias Krüger [Mon, 6 Feb 2023 20:16:42 +0000 (21:16 +0100)]
Rollup merge of #107720 - tshepang:consistency, r=Mark-Simulacrum

end entry paragraph with a period (.)

15 months agoRollup merge of #107714 - Wilfred:round_docs, r=m-ou-se
Matthias Krüger [Mon, 6 Feb 2023 20:16:41 +0000 (21:16 +0100)]
Rollup merge of #107714 - Wilfred:round_docs, r=m-ou-se

Clarify wording on f64::round() and f32::round()

"Round half-way cases" is a little confusing (it's a 'garden path sentence' as it's not immediately clear whether round is an adjective or verb).

Make this sentence longer and clearer.

15 months agoRollup merge of #107692 - Swatinem:printsizeyield, r=compiler-errors
Matthias Krüger [Mon, 6 Feb 2023 20:16:41 +0000 (21:16 +0100)]
Rollup merge of #107692 - Swatinem:printsizeyield, r=compiler-errors

Sort Generator `print-type-sizes` according to their yield points

Especially when trying to diagnose runaway future sizes, it might be more intuitive to sort the variants according to the control flow (aka their yield points) rather than the size of the variants.

15 months agoRollup merge of #107596 - Kobzol:stage-build-timer, r=Mark-Simulacrum
Matthias Krüger [Mon, 6 Feb 2023 20:16:40 +0000 (21:16 +0100)]
Rollup merge of #107596 - Kobzol:stage-build-timer, r=Mark-Simulacrum

Add nicer output to PGO build timer

This PR modifies the timer used in the PGO build script to contain nicer, hierarchical output of the individual build steps. It's not trivial to test locally, so I'll fire up a dist build right away.

r? ``@Mark-Simulacrum``

15 months agoRollup merge of #106477 - Nathan-Fenner:nathanf/refined-error-span-trait-impl, r...
Matthias Krüger [Mon, 6 Feb 2023 20:16:39 +0000 (21:16 +0100)]
Rollup merge of #106477 - Nathan-Fenner:nathanf/refined-error-span-trait-impl, r=compiler-errors

Refine error spans for "The trait bound `T: Trait` is not satisfied" when passing literal structs/tuples

This PR adds a new heuristic which refines the error span reported for "`T: Trait` is not satisfied" errors, by "drilling down" into individual fields of structs/enums/tuples to point to the "problematic" value.

Here's a self-contained example of the difference in error span:

```rs
struct Burrito<Filling> {
    filling: Filling,
}
impl <Filling: Delicious> Delicious for Burrito<Filling> {}
fn eat_delicious_food<Food: Delicious>(food: Food) {}
fn will_type_error() {
    eat_delicious_food(Burrito { filling: Kale });
    //                 ^~~~~~~~~~~~~~~~~~~~~~~~~ (before) The trait bound `Kale: Delicious` is not satisfied
    //                                    ^~~~   (after)  The trait bound `Kale: Delicious` is not satisfied
}
```
(kale is fine, this is just a silly food-based example)

Before this PR, the error span is identified as the entire argument to the generic function `eat_delicious_food`. However, since only `Kale` is the "problematic" part, we can point at it specifically. In particular, the primary error message itself mentions the missing `Kale: Delicious` trait bound, so it's much clearer if this part is called out explicitly.

---

The _existing_ heuristic tries to label the right function argument in `point_at_arg_if_possible`. It goes something like this:
- Look at the broken base trait `Food: Delicious` and find which generics it mentions (in this case, only `Food`)
- Look at the parameter type definitions and find which of them mention `Filling` (in this case, only `food`)
- If there is exactly one relevant parameter, label the corresponding argument with the error span, instead of the entire call

This PR extends this heuristic by further refining the resulting expression span in the new `point_at_specific_expr_if_possible` function. For each `impl` in the (broken) chain, we apply the following strategy:

The strategy to determine this span involves connecting information about our generic `impl`
with information about our (struct) type and the (struct) literal expression:
- Find the `impl` (`impl <Filling: Delicious> Delicious for Burrito<Filling>`)
  that links our obligation (`Kale: Delicious`) with the parent obligation (`Burrito<Kale>: Delicious`)
- Find the "original" predicate constraint in the impl (`Filling: Delicious`) which produced our obligation.
- Find all of the generics that are mentioned in the predicate (`Filling`).
- Examine the `Self` type in the `impl`, and see which of its type argument(s) mention any of those generics.
- Examing the definition for the `Self` type, and identify (for each of its variants) if there's a unique field
  which uses those generic arguments.
- If there is a unique field mentioning the "blameable" arguments, use that field for the error span.

Before we do any of this logic, we recursively call `point_at_specific_expr_if_possible` on the parent
obligation. Hence we refine the `expr` "outwards-in" and bail at the first kind of expression/impl we don't recognize.

This function returns a `Result<&Expr, &Expr>` - either way, it returns the `Expr` whose span should be
reported as an error. If it is `Ok`, then it means it refined successfull. If it is `Err`, then it may be
only a partial success - but it cannot be refined even further.

---

I added a new test file which exercises this new behavior. A few existing tests were affected, since their error spans are now different. In one case, this leads to a different code suggestion for the autofix - although the new suggestion isn't _wrong_, it is different from what used to be.

This change doesn't create any new errors or remove any existing ones, it just adjusts the spans where they're presented.

---

Some considerations: right now, this check occurs in addition to some similar logic in `adjust_fulfillment_error_for_expr_obligation` function, which tidies up various kinds of error spans (not just trait-fulfillment error). It's possible that this new code would be better integrated into that function (or another one) - but I haven't looked into this yet.

Although this code only occurs when there's a type error, it's definitely not as efficient as possible. In particular, there are definitely some cases where it degrades to quadratic performance (e.g. for a trait `impl` with 100+ generic parameters or 100 levels deep nesting of generic types). I'm not sure if these are realistic enough to worry about optimizing yet.

There's also still a lot of repetition in some of the logic, where the behavior for different types (namely, `struct` vs `enum` variant) is _similar_ but not the same.

---

I think the biggest win here is better targeting for tuples; in particular, if you're using tuples + traits to express variadic-like functions, the compiler can't tell you which part of a tuple has the wrong type, since the span will cover the entire argument. This change allows the individual field in the tuple to be highlighted, as in this example:

```
// NEW
LL |     want(Wrapper { value: (3, q) });
   |     ----                      ^ the trait `T3` is not implemented for `Q`

// OLD
LL |     want(Wrapper { value: (3, q) });
   |     ---- ^~~~~~~~~~~~~~~~~~~~~~~~~ the trait `T3` is not implemented for `Q`
```
Especially with large tuples, the existing error spans are not very effective at quickly narrowing down the source of the problem.

15 months agoModify existing bounds if they exist
Edward Shen [Sun, 5 Feb 2023 01:09:19 +0000 (17:09 -0800)]
Modify existing bounds if they exist

15 months agoAdd mailmap for commits made by xes@meta.com
Edward Shen [Mon, 6 Feb 2023 18:35:40 +0000 (10:35 -0800)]
Add mailmap for commits made by xes@meta.com

15 months agoComment move->copy transform.
Camille Gillot [Mon, 6 Feb 2023 17:14:24 +0000 (18:14 +0100)]
Comment move->copy transform.

15 months agoAuto merge of #107727 - Dylan-DPC:rollup-b1yexcl, r=Dylan-DPC
bors [Mon, 6 Feb 2023 16:28:18 +0000 (16:28 +0000)]
Auto merge of #107727 - Dylan-DPC:rollup-b1yexcl, r=Dylan-DPC

Rollup of 5 pull requests

Successful merges:

 - #107553 (Suggest std::ptr::null if literal 0 is given to a raw pointer function argument)
 - #107580 (Recover from lifetimes with default lifetimes in generic args)
 - #107669 (rustdoc: combine duplicate rules in ayu CSS)
 - #107685 (Suggest adding a return type for async functions)
 - #107687 (Adapt SROA MIR opt for aggregated MIR)

Failed merges:

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

15 months agointerpret: move discriminant reading and writing to separate file
Ralf Jung [Mon, 6 Feb 2023 16:08:34 +0000 (17:08 +0100)]
interpret: move discriminant reading and writing to separate file

15 months agoTurn MarkdownWithToc into a struct with named fields
Guillaume Gomez [Fri, 3 Feb 2023 15:04:10 +0000 (16:04 +0100)]
Turn MarkdownWithToc into a struct with named fields

15 months agoremove unused imports
klensy [Mon, 6 Feb 2023 13:26:31 +0000 (16:26 +0300)]
remove unused imports

15 months agoAdd `run-rustfix` to tests/ui/issues/issue-92741.rs
CastilloDel [Mon, 6 Feb 2023 14:33:54 +0000 (15:33 +0100)]
Add `run-rustfix` to tests/ui/issues/issue-92741.rs

15 months agoAdd more test cases to tests/ui/issues/issue-92741.rs
CastilloDel [Mon, 6 Feb 2023 14:30:29 +0000 (15:30 +0100)]
Add more test cases to tests/ui/issues/issue-92741.rs

15 months agoRollup merge of #107687 - cjgillot:sroa-2, r=oli-obk
Dylan DPC [Mon, 6 Feb 2023 14:24:15 +0000 (19:54 +0530)]
Rollup merge of #107687 - cjgillot:sroa-2, r=oli-obk

Adapt SROA MIR opt for aggregated MIR

The pass was broken by https://github.com/rust-lang/rust/pull/107267.

This PR extends it to replace:
```
x = Struct { 0: a, 1: b }
y = move? x
```

by assignment between locals
```
x_0 = a
x_1 = b
y_0 = move? x_0
y_1 = move? x_1
```

The improved pass runs to fixpoint, so we can flatten nested field accesses.

15 months agoRollup merge of #107685 - jieyouxu:issue-90027, r=compiler-errors
Dylan DPC [Mon, 6 Feb 2023 14:24:15 +0000 (19:54 +0530)]
Rollup merge of #107685 - jieyouxu:issue-90027, r=compiler-errors

Suggest adding a return type for async functions

Fixes #90027.

15 months agoRollup merge of #107669 - notriddle:notriddle/ayu-smaller, r=GuillaumeGomez
Dylan DPC [Mon, 6 Feb 2023 14:24:14 +0000 (19:54 +0530)]
Rollup merge of #107669 - notriddle:notriddle/ayu-smaller, r=GuillaumeGomez

rustdoc: combine duplicate rules in ayu CSS

15 months agoRollup merge of #107580 - lenko-d:default_value_for_a_lifetime_generic_parameter_prod...
Dylan DPC [Mon, 6 Feb 2023 14:24:14 +0000 (19:54 +0530)]
Rollup merge of #107580 - lenko-d:default_value_for_a_lifetime_generic_parameter_produces_confusing_diagnostic, r=compiler-errors

Recover from lifetimes with default lifetimes in generic args

Fixes [#107492](https://github.com/rust-lang/rust/issues/107492)

15 months agoRollup merge of #107553 - edward-shen:edward-shen/suggest-null-ptr, r=WaffleLapkin
Dylan DPC [Mon, 6 Feb 2023 14:24:13 +0000 (19:54 +0530)]
Rollup merge of #107553 - edward-shen:edward-shen/suggest-null-ptr, r=WaffleLapkin

Suggest std::ptr::null if literal 0 is given to a raw pointer function argument

Implementation feels a little sus (we're parsing the span for a `0`) but it seems to fall in line the string-expected-found-char condition right above this check, so I think it's fine.

Feedback appreciated on help text? I think it's consistent but it does sound a little awkward maybe?

Fixes #107517

15 months agoAuto merge of #103761 - chenyukang:yukang/fix-103320-must-use, r=compiler-errors
bors [Mon, 6 Feb 2023 12:57:37 +0000 (12:57 +0000)]
Auto merge of #103761 - chenyukang:yukang/fix-103320-must-use, r=compiler-errors

Add explanatory message for [#must_use] in ops

Fixes #103320

15 months agoAdd extended error message for E0523
Matthew Kelly [Sat, 4 Feb 2023 18:01:49 +0000 (13:01 -0500)]
Add extended error message for E0523

Adds the extended error documentation for E0523 to indicate that the
error is no longer produced by the compiler.

Update the E0464 documentation to include example code that produces the
error.

Remove the error message E0523 from the compiler and replace it with an
internal compiler error.

15 months agoalso do not add noalias on not-Unpin Box
Ralf Jung [Mon, 2 Jan 2023 13:09:01 +0000 (14:09 +0100)]
also do not add noalias on not-Unpin Box

15 months agomake &mut !Unpin not dereferenceable
Ralf Jung [Tue, 27 Dec 2022 11:46:08 +0000 (12:46 +0100)]
make &mut !Unpin not dereferenceable

See https://github.com/rust-lang/unsafe-code-guidelines/issues/381 for discussion.

15 months agomake PointerKind directly reflect pointer types
Ralf Jung [Tue, 27 Dec 2022 11:31:17 +0000 (12:31 +0100)]
make PointerKind directly reflect pointer types

The code that consumes PointerKind (`adjust_for_rust_scalar` in rustc_ty_utils)
ended up using PointerKind variants to talk about Rust reference types (& and
&mut) anyway, making the old code structure quite confusing: one always had to
keep in mind which PointerKind corresponds to which type. So this changes
PointerKind to directly reflect the type.

This does not change behavior.

15 months agoend entry paragprah with a period (.)
Tshepang Mbambo [Mon, 6 Feb 2023 09:22:44 +0000 (11:22 +0200)]
end entry paragprah with a period (.)

15 months agoAuto merge of #107667 - cjgillot:no-on-hit, r=lcnr,Zoxc
bors [Mon, 6 Feb 2023 09:09:09 +0000 (09:09 +0000)]
Auto merge of #107667 - cjgillot:no-on-hit, r=lcnr,Zoxc

Remove `OnHit` callback from query caches.

This is not useful now that query results are `Copy`.

15 months agoRemove `arena_cache` modifier from `upstream_monomorphizations_for`
Maybe Waffle [Mon, 6 Feb 2023 09:06:01 +0000 (09:06 +0000)]
Remove `arena_cache` modifier from `upstream_monomorphizations_for`

15 months agoAuto merge of #107697 - kiranshila:patch-1, r=the8472
bors [Mon, 6 Feb 2023 05:03:06 +0000 (05:03 +0000)]
Auto merge of #107697 - kiranshila:patch-1, r=the8472

Fix typo in HashMap::with_capacity

15 months agoSuggest return type for async function without return type
许杰友 Jieyou Xu (Joe) [Sun, 5 Feb 2023 06:22:41 +0000 (14:22 +0800)]
Suggest return type for async function without return type

15 months agoClarify wording on f64::round() and f32::round()
Wilfred Hughes [Mon, 6 Feb 2023 03:38:08 +0000 (19:38 -0800)]
Clarify wording on f64::round() and f32::round()

"Round half-way cases" is a little confusing (it's a 'garden path
sentence' as it's not immediately clear whether round is an adjective
or verb).

Make this sentence longer and clearer.

15 months agoAuto merge of #107141 - notriddle:notriddle/max-lev-distance-2023, r=GuillaumeGomez
bors [Mon, 6 Feb 2023 02:09:00 +0000 (02:09 +0000)]
Auto merge of #107141 - notriddle:notriddle/max-lev-distance-2023, r=GuillaumeGomez

rustdoc: compute maximum Levenshtein distance based on the query

Preview: https://notriddle.com/notriddle-rustdoc-demos/search-lev-distance-2023/std/index.html?search=regex

The heuristic is pretty close to the name resolver, maxLevDistance = `Math.floor(queryLen / 3)`.

Fixes #103357
Fixes #82131

Similar to https://github.com/rust-lang/rust/pull/103710, but following the suggestion in https://github.com/rust-lang/rust/pull/103710#issuecomment-1296360267 to use `floor` instead of `ceil`, and unblocked now that https://github.com/rust-lang/rust/pull/105796 made it so that setting the max lev distance to `0` doesn't cause substring matches to be removed.

15 months agoAuto merge of #107627 - nnethercote:optimize-fold_ty, r=compiler-errors
bors [Sun, 5 Feb 2023 23:13:41 +0000 (23:13 +0000)]
Auto merge of #107627 - nnethercote:optimize-fold_ty, r=compiler-errors

Optimize `fold_ty`

Micro-optimizing the heck out of the important `fold_ty` methods.

r? `@oli-obk`

15 months agoSplit and inline `TypeFreshener::fold_ty`.
Nicholas Nethercote [Fri, 3 Feb 2023 00:36:32 +0000 (11:36 +1100)]
Split and inline `TypeFreshener::fold_ty`.

15 months agoMark 'atomic_mut_ptr' methods const
Trevor Gross [Sun, 5 Feb 2023 22:03:16 +0000 (17:03 -0500)]
Mark 'atomic_mut_ptr' methods const

15 months agoSplit and inline `ShallowResolver::fold_ty`.
Nicholas Nethercote [Fri, 3 Feb 2023 01:36:44 +0000 (12:36 +1100)]
Split and inline `ShallowResolver::fold_ty`.

15 months agoInline `OpportunisticVarResolver::fold_ty`.
Nicholas Nethercote [Thu, 2 Feb 2023 23:31:11 +0000 (10:31 +1100)]
Inline `OpportunisticVarResolver::fold_ty`.

15 months agoImprove early bailout test in `resolve_vars_if_possible`.
Nicholas Nethercote [Thu, 2 Feb 2023 23:15:24 +0000 (10:15 +1100)]
Improve early bailout test in `resolve_vars_if_possible`.

`!t.has_non_region_infer()` is the test used in
`OpportunisticVarResolver`, and catches a few cases that
`!t.needs_infer()` misses.

15 months agoyet another ui test
Lukas Markeffsky [Sun, 5 Feb 2023 21:51:37 +0000 (22:51 +0100)]
yet another ui test

15 months agoPut a `ShallowResolver` within `OpportunisticVarResolver`.
Nicholas Nethercote [Thu, 2 Feb 2023 22:00:56 +0000 (09:00 +1100)]
Put a `ShallowResolver` within `OpportunisticVarResolver`.

So one doesn't have to be constructed every time.

15 months agoRun `expand-yaml-anchors` in `x test tidy`
Joshua Nelson [Sun, 5 Feb 2023 20:43:26 +0000 (14:43 -0600)]
Run `expand-yaml-anchors` in `x test tidy`

Previously, the pre-commit hook which runs `x test tidy` could pass only to have CI fail within the first 30 seconds.
This adds about 30 seconds to `test tidy` (for an initial run, much less after the tool is built the first time)
in exchange for catching errors in `.github/workflows/ci.yml` before they're pushed.

15 months agoAuto merge of #107526 - obeis:for-missing-iterator, r=estebank,compiler-errors
bors [Sun, 5 Feb 2023 20:33:05 +0000 (20:33 +0000)]
Auto merge of #107526 - obeis:for-missing-iterator, r=estebank,compiler-errors

Recover form missing expression in `for` loop

Close #78537
r? `@estebank`

15 months agoRun the tools builder on all PRs
Joshua Nelson [Sun, 5 Feb 2023 19:53:39 +0000 (13:53 -0600)]
Run the tools builder on all PRs

Previously, it would only run on changes to subtrees, submodules, or select directories.
That made it so that changes to the compiler that broke tools would only be detected on a full bors merge.
This makes it so the tools builder runs by default, making it easier to catch breaking changes to clippy (which was the most effected).

15 months agoFix typo in HashMap::with_capacity
Kiran Shila [Sun, 5 Feb 2023 18:13:30 +0000 (10:13 -0800)]
Fix typo in HashMap::with_capacity

15 months agoAdd UI test for issue #92741
CastilloDel [Sun, 5 Feb 2023 16:30:00 +0000 (17:30 +0100)]
Add UI test for issue #92741

15 months agoClean up and comment EmitterWriter.draw_code_line
CastilloDel [Sun, 5 Feb 2023 17:59:31 +0000 (18:59 +0100)]
Clean up and comment EmitterWriter.draw_code_line

15 months agoAuto merge of #107663 - matthiaskrgr:107423-point-at-EOF-code, r=compiler-errors
bors [Sun, 5 Feb 2023 17:32:26 +0000 (17:32 +0000)]
Auto merge of #107663 - matthiaskrgr:107423-point-at-EOF-code, r=compiler-errors

don't point at nonexisting code beyond EOF when warning about delims

Previously we would show this:
```
warning: unnecessary braces around block return value
 --> /tmp/bad.rs:1:8
  |
1 | fn a(){{{
  |        ^  ^
  |
  = note: `#[warn(unused_braces)]` on by default
help: remove these braces
  |
1 - fn a(){{{
1 + fn a(){{
  |
```

which is now hidden in this case.
We would create a span spanning between the pair of redundant {}s but there is only EOF instead of the `}` so we would previously point at nothing. This would cause the debug assertion ice to trigger. I would have loved to just only point at the second delim and say "you can remove that" but I'm not sure how to do that without refactoring the entire diagnostic which seems tricky. :( But given that this does not seem to regress any other tests we have, I think this edge-casey enough be acceptable.

Fixes https://github.com/rust-lang/rust/issues/107423

r? `@compiler-errors`

15 months agoSort Generator `print-type-sizes` according to their yield points
Arpad Borsos [Sun, 5 Feb 2023 15:26:51 +0000 (16:26 +0100)]
Sort Generator `print-type-sizes` according to their yield points

Especially when trying to diagnose runaway future sizes, it might be
more intuitive to sort the variants according to the control flow
(aka their yield points) rather than the size of the variants.

15 months agorustc_metadata: Encode/decode `DefPathHash`es without an `Option`
Vadim Petrochenkov [Sun, 5 Feb 2023 14:53:47 +0000 (18:53 +0400)]
rustc_metadata: Encode/decode `DefPathHash`es without an `Option`

15 months agoAdd ui test for missing expression in for loop
Obei Sideg [Fri, 3 Feb 2023 09:25:01 +0000 (12:25 +0300)]
Add ui test for missing expression in for loop

15 months agoRecover from missing expression in for loop
Obei Sideg [Fri, 3 Feb 2023 09:23:37 +0000 (12:23 +0300)]
Recover from missing expression in for loop

15 months agoReErased regions are local
Lukas Markeffsky [Sun, 5 Feb 2023 14:29:07 +0000 (15:29 +0100)]
ReErased regions are local

15 months agorustc_metadata: Encode/decode some `LazyArray`s without an `Option`
Vadim Petrochenkov [Sun, 5 Feb 2023 12:28:12 +0000 (16:28 +0400)]
rustc_metadata: Encode/decode some `LazyArray`s without an `Option`

Also add asserts to decoding `LazyArray`s with `Option`

15 months agorustc_metadata: Support encoding/decoding `LazyArray` without an `Option`
Vadim Petrochenkov [Fri, 27 Jan 2023 19:28:33 +0000 (23:28 +0400)]
rustc_metadata: Support encoding/decoding `LazyArray` without an `Option`

15 months agorustc_metadata: Refactor lazy table reading/writing
Vadim Petrochenkov [Thu, 26 Jan 2023 14:23:14 +0000 (18:23 +0400)]
rustc_metadata: Refactor lazy table reading/writing

Change wording from "nullable" to "default".
Introduce a trait `IsDefault` for detecting values that are encoded as zeros or not encoded at all.
Add panics to impossible cases.
Some other minor cleanups.

15 months agoAuto merge of #102842 - rol1510:issue-85566-fix, r=notriddle
bors [Sun, 5 Feb 2023 14:01:49 +0000 (14:01 +0000)]
Auto merge of #102842 - rol1510:issue-85566-fix, r=notriddle

rustdoc: change trait bound formatting

Fixes #85566

Before
<img width="268" alt="image" src="https://user-images.githubusercontent.com/29011024/208326689-cc9b4bae-529c-473c-81e2-fc5ddb738f07.png">

Now
<img width="268" alt="image" src="https://user-images.githubusercontent.com/29011024/216216918-d7923787-3e3b-486d-9735-4cecd2988dba.png">

15 months agoBless 32bit tests.
Camille GILLOT [Sun, 5 Feb 2023 13:51:37 +0000 (13:51 +0000)]
Bless 32bit tests.

15 months agoSimplify ReplacementMap.
Camille GILLOT [Sun, 5 Feb 2023 13:35:33 +0000 (13:35 +0000)]
Simplify ReplacementMap.

15 months agoRun SROA to fixpoint.
Camille GILLOT [Sun, 5 Feb 2023 12:08:42 +0000 (12:08 +0000)]
Run SROA to fixpoint.

15 months agoSimplify construction of replacement map.
Camille GILLOT [Sun, 5 Feb 2023 11:37:44 +0000 (11:37 +0000)]
Simplify construction of replacement map.

15 months agoIntroduce helper.
Camille GILLOT [Sun, 5 Feb 2023 10:40:21 +0000 (10:40 +0000)]
Introduce helper.

15 months agoMake SROA expand assignments.
Camille GILLOT [Sun, 5 Feb 2023 09:31:27 +0000 (09:31 +0000)]
Make SROA expand assignments.

15 months agoAuto merge of #107679 - est31:less_import_overhead, r=compiler-errors
bors [Sun, 5 Feb 2023 11:10:11 +0000 (11:10 +0000)]
Auto merge of #107679 - est31:less_import_overhead, r=compiler-errors

Less import overhead for errors

This removes huge (3+ lines) import lists found in files that had their error reporting migrated. These lists are bad for developer workflows as adding, removing, or editing a single error's name might cause a chain reaction that bloats the git diff. As the error struct names are long, the likelihood of such chain reactions is high.

Follows the suggestion by `@Nilstrieb` in the [zulip thread](https://rust-lang.zulipchat.com/#narrow/stream/147480-t-compiler.2Fwg-diagnostics/topic/massive.20use.20statements) to replace the `use errors::{FooErr, BarErr};` with `use errors;` and then changing to `errors::FooErr` on the usage sites.

I have used sed to do most of the changes, i.e. something like:

```
sed -i -E 's/(create_err|create_feature_err|emit_err|create_note|emit_fatal|emit_warning)\(([[:alnum:]]+|[A-Z][[:alnum:]:]*)( \{|\))/\1(errors::\2\3/' path/to/file.rs
```

& then I manually fixed the errors that occured. Most manual changes were required in `compiler/rustc_parse/src/parser/expr.rs`.

r? `@compiler-errors`