Commit Graph

249872 Commits

Author SHA1 Message Date
Gurinder Singh
3c70d60c4f Gracefully handle AnonConst in diagnostic_hir_wf_check()
when it is the default value of a generic param
2024-03-19 09:20:23 +05:30
bors
21d94a3d2c Auto merge of #122055 - compiler-errors:stabilize-atb, r=oli-obk
Stabilize associated type bounds (RFC 2289)

This PR stabilizes associated type bounds, which were laid out in [RFC 2289]. This gives us a shorthand to express nested type bounds that would otherwise need to be expressed with nested `impl Trait` or broken into several `where` clauses.

### What are we stabilizing?

We're stabilizing the associated item bounds syntax, which allows us to put bounds in associated type position within other bounds, i.e. `T: Trait<Assoc: Bounds...>`. See [RFC 2289] for motivation.

In all position, the associated type bound syntax expands into a set of two (or more) bounds, and never anything else (see "How does this differ[...]" section for more info).

Associated type bounds are stabilized in four positions:
* **`where` clauses (and APIT)** - This is equivalent to breaking up the bound into two (or more) `where` clauses. For example, `where T: Trait<Assoc: Bound>` is equivalent to `where T: Trait, <T as Trait>::Assoc: Bound`.
* **Supertraits** - Similar to above, `trait CopyIterator: Iterator<Item: Copy> {}`. This is almost equivalent to breaking up the bound into two (or more) `where` clauses; however, the bound on the associated item is implied whenever the trait is used. See #112573/#112629.
* **Associated type item bounds** - This allows constraining the *nested* rigid projections that are associated with a trait's associated types. e.g. `trait Trait { type Assoc: Trait2<Assoc2: Copy>; }`.
* **opaque item bounds (RPIT, TAIT)** - This allows constraining associated types that are associated with the opaque without having to *name* the opaque. For example, `impl Iterator<Item: Copy>` defines an iterator whose item is `Copy` without having to actually name that item bound.

The latter three are not expressible in surface Rust (though for associated type item bounds, this will change in #120752, which I don't believe should block this PR), so this does represent a slight expansion of what can be expressed in trait bounds.

### How does this differ from the RFC?

Compared to the RFC, the current implementation *always* desugars associated type bounds to sets of `ty::Clause`s internally. Specifically, it does *not* introduce a position-dependent desugaring as laid out in [RFC 2289], and in particular:
* It does *not* desugar to anonymous associated items in associated type item bounds.
* It does *not* desugar to nested RPITs in RPIT bounds, nor nested TAITs in TAIT bounds.

This position-dependent desugaring laid out in the RFC existed simply to side-step limitations of the trait solver, which have mostly been fixed in #120584. The desugaring laid out in the RFC also added unnecessary complication to the design of the feature, and introduces its own limitations to, for example:
* Conditionally lowering to nested `impl Trait` in certain positions such as RPIT and TAIT means that we inherit the limitations of RPIT/TAIT, namely lack of support for higher-ranked opaque inference. See this code example: https://github.com/rust-lang/rust/pull/120752#issuecomment-1979412531.
* Introducing anonymous associated types makes traits no longer object safe, since anonymous associated types are not nameable, and all associated types must be named in `dyn` types.

This last point motivates why this PR is *not* stabilizing support for associated type bounds in `dyn` types, e.g, `dyn Assoc<Item: Bound>`. Why? Because `dyn` types need to have *concrete* types for all associated items, this would necessitate a distinct lowering for associated type bounds, which seems both complicated and unnecessary compared to just requiring the user to write `impl Trait` themselves. See #120719.

### Implementation history:

Limited to the significant behavioral changes and fixes and relevant PRs, ping me if I left something out--
* #57428
* #108063
* #110512
* #112629
* #120719
* #120584

Closes #52662

[RFC 2289]: https://rust-lang.github.io/rfcs/2289-associated-type-bounds.html
2024-03-19 00:04:09 +00:00
bors
3c85e56249 Auto merge of #122713 - matthiaskrgr:rollup-81grkpm, r=matthiaskrgr
Rollup of 11 pull requests

Successful merges:

 - #121258 (Reject overly generic assoc const binding types)
 - #121823 (never patterns: suggest `!` patterns on non-exhaustive matches)
 - #122060 (Stabilize `imported_main`)
 - #122158 (Provide structured suggestion for `#![feature(foo)]`)
 - #122642 (Improve wording of `Vec::swap_remove`)
 - #122675 (core: document default attribute stabilization)
 - #122687 (`NormalizesTo`: return nested goals to caller)
 - #122693 (Fix heading anchors in doc pages.)
 - #122699 (Fix a typo in the 1.77.0 relnotes)
 - #122700 (Remove redundant files, rename base riscv32 file)
 - #122701 (Detect allocator for box in `must_not_suspend` lint)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-03-18 21:27:04 +00:00
Matthias Krüger
3c3b398b35
Rollup merge of #122701 - compiler-errors:allocator-suspend, r=oli-obk
Detect allocator for box in `must_not_suspend` lint

I don't expect this to happen in practice, but better to check than not.

Fixes #122643
2024-03-18 22:24:41 +01:00
Matthias Krüger
af48242054
Rollup merge of #122700 - esp-rs:remove-old-files, r=workingjubilee
Remove redundant files, rename base riscv32 file

Fixes a mistake I made in https://github.com/rust-lang/rust/pull/117874.
2024-03-18 22:24:41 +01:00
Matthias Krüger
2ef0df5c3a
Rollup merge of #122699 - cuviper:relnotes-1.77.0-as, r=ehuss
Fix a typo in the 1.77.0 relnotes
2024-03-18 22:24:40 +01:00
Matthias Krüger
417c5701ad
Rollup merge of #122693 - ehuss:rust-css-header, r=GuillaumeGomez
Fix heading anchors in doc pages.

This fixes the heading anchors on the standalone doc pages (the index, releases, etc.) so that the § symbol is only shown when the user hovers over the heading. This was changed in https://github.com/rust-lang/rust/pull/117662, but this CSS was not updated.
2024-03-18 22:24:40 +01:00
Matthias Krüger
e906205607
Rollup merge of #122687 - lcnr:normalizes-to-emit-nested-goals, r=compiler-errors
`NormalizesTo`: return nested goals to caller

Fixes the regression of `paperclip-core`. see https://hackmd.io/IsVAafiOTAaPIFcUxRJufw for more details.

r? ```@compiler-errors```
2024-03-18 22:24:39 +01:00
Matthias Krüger
e5b9a42e37
Rollup merge of #122675 - tmfink:doc-clarify, r=scottmcm
core: document default attribute stabilization

As of now, the first release which stabilized the `#[default]` macro for the deriving the `Default` trait for enus is not documented.
I have had to search the [`RELEASES.md`](https://github.com/rust-lang/rust/blob/master/RELEASES.md) when making sure my code would be accepted by an older Rust compiler.

I just added a line in the doc comment since, as far as I know, there's no option to pass to the `#[stable()]` attribute.

I am open to improvements in the wording.
2024-03-18 22:24:39 +01:00
Matthias Krüger
223c23c63f
Rollup merge of #122642 - pallix:improve-wording-for-vec-swap_remove, r=Amanieu
Improve wording of `Vec::swap_remove`

This improve the wording for  `Vec::swap_remove`.
2024-03-18 22:24:38 +01:00
Matthias Krüger
980248605a
Rollup merge of #122158 - estebank:feature-sugg, r=WaffleLapkin
Provide structured suggestion for `#![feature(foo)]`

```
error: `S2<'_>` is forbidden as the type of a const generic parameter
  --> $DIR/lifetime-in-const-param.rs:5:23
   |
LL | struct S<'a, const N: S2>(&'a ());
   |                       ^^
   |
   = note: the only supported types are integers, `bool` and `char`
help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types
   |
LL + #![feature(adt_const_params)]
   |
```

Fix #55941.
2024-03-18 22:24:38 +01:00
Matthias Krüger
b19c67c0fc
Rollup merge of #122060 - clubby789:stabilize-imported-main, r=lcnr
Stabilize `imported_main`

FCP: https://github.com/rust-lang/rust/issues/28937#issuecomment-1977822831
Docs: https://github.com/rust-lang/reference/pull/1461
2024-03-18 22:24:37 +01:00
Matthias Krüger
2d3dcfaade
Rollup merge of #121823 - Nadrieril:never-witnesses, r=compiler-errors
never patterns: suggest `!` patterns on non-exhaustive matches

When a match is non-exhaustive we now suggest never patterns whenever it makes sense.

r? ``@compiler-errors``
2024-03-18 22:24:36 +01:00
Matthias Krüger
05f763344d
Rollup merge of #121258 - fmease:assoc-const-eq-reject-overly-generic-tys, r=compiler-errors
Reject overly generic assoc const binding types

Split off from #119385 to make #119385 easier to review.

---

In the *instantiated* type of assoc const bindings

1. reject **early-bound generic params**
   * Provide a rich error message instead of ICE'ing ([#108271](https://github.com/rust-lang/rust/issues/108271)).
   * This is a temporary and semi-artificial restriction until the arrival of *generic const generics*.
   * It's quite possible that rustc could already perfectly support this subset of generic const generics if we just removed some checks (some `.no_bound_vars().expect(…)`) but even if that was the case, I'd rather gate it behind a new feature flag. Reporting an error instead of ICE'ing is a good first step towards an eventual feature gate error.
2. reject **escaping late-bound generic params**
   * They lead to ICEs before & I'm pretty sure that they remain incorrect even in a world with *generic const generics*

---

Together with #118668 & #119385, this supersedes #118360.
Fixes #108271.
2024-03-18 22:24:36 +01:00
Scott Mabin
9b0cbe3772 Remove redundant files, rename base risc32 file 2024-03-18 19:23:21 +00:00
Michael Goulet
0db06bf004 Detect allocator for box in must_not_suspend lint 2024-03-18 14:12:28 -04:00
Josh Stone
4739948c89 Fix a typo in the 1.77.0 relnotes
Co-authored-by: Mateusz Mikuła <mati865@gmail.com>
2024-03-18 10:30:22 -07:00
lcnr
0b29b71a2f cleanup + review 2024-03-18 18:13:25 +01:00
lcnr
7c5a99b6a8 improve comments 2024-03-18 18:13:25 +01:00
bors
d31b6fb8c0 Auto merge of #122690 - matthiaskrgr:rollup-43fggl0, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #122480 (Avoid various uses of `Option<Span>` in favor of using `DUMMY_SP` in the few cases that used `None`)
 - #122567 (Remove fixme about LLVM basic block naming)
 - #122588 (less useless filter calls in imported_source_file)
 - #122647 (add_retag: ensure box-to-raw-ptr casts are preserved for Miri)
 - #122649 (Update the minimum external LLVM to 17)
 - #122680 (Do not eat nested expressions' results in `MayContainYieldPoint` format args visitor)
 - #122683 (add missing test: expected paren or brace in macro)
 - #122689 (Add missing `try_visit` calls in visitors.)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-03-18 16:51:07 +00:00
Eric Huss
39f2d25090 Fix heading anchors in doc pages. 2024-03-18 09:13:18 -07:00
Esteban Küber
6c31f6ce12 Provide structured suggestion for #![feature(foo)]
```
error: `S2<'_>` is forbidden as the type of a const generic parameter
  --> $DIR/lifetime-in-const-param.rs:5:23
   |
LL | struct S<'a, const N: S2>(&'a ());
   |                       ^^
   |
   = note: the only supported types are integers, `bool` and `char`
help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types
   |
LL + #![feature(adt_const_params)]
   |
```

Fix #55941.
2024-03-18 16:08:58 +00:00
lcnr
efa4269e54 move tests 2024-03-18 16:29:00 +01:00
Matthias Krüger
9011e67c91
Rollup merge of #122689 - Jarcho:missing_try, r=compiler-errors
Add missing `try_visit` calls in visitors.
2024-03-18 16:27:11 +01:00
Matthias Krüger
1eb49ec5b6
Rollup merge of #122683 - tshepang:missing-test, r=Nadrieril
add missing test: expected paren or brace in macro
2024-03-18 16:27:10 +01:00
Matthias Krüger
72e2c7c45a
Rollup merge of #122680 - lqd:nested-await-args, r=compiler-errors
Do not eat nested expressions' results in `MayContainYieldPoint` format args visitor

#121563 unintentionally changed the `MayContainYieldPoint` format args visitor behavior, now missing yield points in nested expressions, as seen in #122674.

The walk can find a yield point in an expression but it was ignored.

r? ``@petrochenkov`` as the reviewer of #121563
cc ``@Jarcho`` as the author

Fixes #122674.
We're in the 1.77 release week. #121563 will land on 1.78 but beta is still 1.77.9: this PR will likely need to be backported soon after beta is cut.
2024-03-18 16:27:10 +01:00
Matthias Krüger
1ac0239bd2
Rollup merge of #122649 - cuviper:min-llvm-17, r=nikic
Update the minimum external LLVM to 17

With this change, we'll have stable support for LLVM 17 and 18.
For reference, the previous increase to LLVM 16 was #117947.
2024-03-18 16:27:09 +01:00
Matthias Krüger
3fa48ec849
Rollup merge of #122647 - RalfJung:box-to-raw-retag, r=oli-obk
add_retag: ensure box-to-raw-ptr casts are preserved for Miri

In https://github.com/rust-lang/rust/pull/122233 I added `retag_box_to_raw` not realizing that we can already do `addr_of_mut!(*bx)` to turn a box into a raw pointer without an intermediate reference. We just need to ensure this information is preserved past the ElaborateBoxDerefs pass.

r? ``@oli-obk``
2024-03-18 16:27:08 +01:00
Matthias Krüger
acc45ebf72
Rollup merge of #122588 - klensy:imported_source_file, r=michaelwoerister
less useless filter calls in imported_source_file

This reduces calls to `filter` greatly, giving 0.3% instructions win on some tests.
2024-03-18 16:27:08 +01:00
Matthias Krüger
87b5679ab0
Rollup merge of #122567 - erikdesjardins:noname, r=oli-obk
Remove fixme about LLVM basic block naming

~This may be a small perf win.~

Originally, this PR implemented the fixme, but it didn't have any measurable perf improvement.

r? ``@ghost``
2024-03-18 16:27:07 +01:00
Matthias Krüger
4608079604
Rollup merge of #122480 - oli-obk:const-eval-span-no-opt, r=RalfJung
Avoid various uses of `Option<Span>` in favor of using `DUMMY_SP` in the few cases that used `None`

based on #122471

`DUMMY_SP` is already the sentinel value we have that says "no span". We don't need to wrap these `Span`s in a separate `Option`.
2024-03-18 16:27:07 +01:00
Jason Newcomb
407b58cb77 Add missing try_visit calls in visitors. 2024-03-18 11:21:06 -04:00
lcnr
f26e1e8b63 NormalizesTo return nested goals 2024-03-18 15:53:16 +01:00
bors
3cdcdaf31b Auto merge of #122646 - saethlin:library-frame-pointers, r=onur-ozkan
Enable frame pointers for the standard library

There's been a few past experiments for enabling frame pointers for all our artifacts. I don't think that frame pointers in the distributed compiler are nearly as useful as frame pointers in the standard library. Our users are much more likely to be profiling apps written in Rust than they are profiling the Rust compiler.

So yeah it would be cool to have frame pointers in the compiler, but much more of the value is having them on the precompiled standard library. That's what this PR does.
2024-03-18 12:43:41 +00:00
Tshepang Mbambo
0550afd97e add missing test: expected paren or brace in macro 2024-03-18 14:25:50 +02:00
lcnr
33c274f658 move normalizes_to_hack to AliasRelate 2024-03-18 12:08:06 +01:00
Rémy Rakic
f3e9dfaed6 add non-regression test for issue 122674 2024-03-18 10:01:35 +00:00
bors
13abc0ac9b Auto merge of #122558 - kjetilkjeka:llvm_bitcode_linker_no_trigger_rebuild, r=onur-ozkan
LLVM bitcode linker: use --cfg=parallel_compiler to avoid invalidating the build cache of rustdoc

fixes #122491

`@rustbot` ready
2024-03-18 09:48:40 +00:00
Oli Scherer
adda9da604 Avoid various uses of Option<Span> in favor of using DUMMY_SP in the few cases that used None 2024-03-18 09:34:08 +00:00
Ralf Jung
bcf8015177 remove retag_box_to_raw, it is no longer needed 2024-03-18 10:32:25 +01:00
Ralf Jung
c96fa5e143 add_retag: ensure box-to-raw-ptr casts are preserved for Miri 2024-03-18 10:32:25 +01:00
Rémy Rakic
8beec62315 do not eat nested exprs result in format args visitor 2024-03-18 09:27:47 +00:00
bors
a42873e85b Auto merge of #122676 - matthiaskrgr:rollup-noti0vr, r=matthiaskrgr
Rollup of 4 pull requests

Successful merges:

 - #122639 (Fix typos)
 - #122654 (interpret/memory: explain why we use == on bool)
 - #122656 (simplify_cfg: rename some passes so that they make more sense)
 - #122657 (Move `option_env!` and `env!` tests to the `env-macro` directory)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-03-18 06:17:15 +00:00
Matthias Krüger
069b93335f
Rollup merge of #122657 - beetrees:option-env-tests, r=compiler-errors,Nilstrieb
Move `option_env!` and `env!` tests to the `env-macro` directory

This PR moves the `option_env!` tests to there own directory (`extoption_env`), matching the naming convention used by the tests for `env!` (which live in the `extenv` directory).
2024-03-18 06:58:50 +01:00
Matthias Krüger
3fc3142df1
Rollup merge of #122656 - RalfJung:simplify-cfg, r=compiler-errors
simplify_cfg: rename some passes so that they make more sense

I was extremely confused by `SimplifyCfg::ElaborateDrops`, since it runs way later than drop elaboration. It is used e.g. in `mir-opt/retag.rs` even though that pass doesn't care about drop elaboration at all.

"Early opt" is also very confusing since that makes it sounds like it runs early during optimizations, i.e. on runtime MIR, but actually it runs way before that.

So I decided to rename
- early-opt -> post-analysis
- elaborate-drops -> pre-optimizations

I am open to other suggestions.
2024-03-18 06:58:50 +01:00
Matthias Krüger
86bb0bc41d
Rollup merge of #122654 - RalfJung:interpret-comment, r=matthiaskrgr
interpret/memory: explain why we use == on bool

This came up in https://github.com/rust-lang/rust/pull/122636.
2024-03-18 06:58:49 +01:00
Matthias Krüger
d9b47c1f2b
Rollup merge of #122639 - omahs:patch-2, r=estebank
Fix typos

Fix typos
2024-03-18 06:58:49 +01:00
bors
80e5694d6f Auto merge of #121952 - JarvisCraft:master, r=workingjubilee
feat: implement `{Div,Rem}Assign<NonZero<X>>` on `X`

# Description

This PR implements `DivAssign<X>` and `RemAssign<X>` on `X` as suggested in rust-lang/libs-team#346.

Since this is just a trait implementation on an already stable type, for which non-assign operator traits are already stable, I suggest that it is an insta-stable feature.
2024-03-18 04:15:14 +00:00
bors
5608c7f9aa Auto merge of #121652 - estebank:move-in-loop-break-condition, r=Nadrieril
Detect when move of !Copy value occurs within loop and should likely not be cloned

When encountering a move error on a value within a loop of any kind,
identify if the moved value belongs to a call expression that should not
be cloned and avoid the semantically incorrect suggestion. Also try to
suggest moving the call expression outside of the loop instead.

```
error[E0382]: use of moved value: `vec`
  --> $DIR/recreating-value-in-loop-condition.rs:6:33
   |
LL |     let vec = vec!["one", "two", "three"];
   |         --- move occurs because `vec` has type `Vec<&str>`, which does not implement the `Copy` trait
LL |     while let Some(item) = iter(vec).next() {
   |     ----------------------------^^^--------
   |     |                           |
   |     |                           value moved here, in previous iteration of loop
   |     inside of this loop
   |
note: consider changing this parameter type in function `iter` to borrow instead if owning the value isn't necessary
  --> $DIR/recreating-value-in-loop-condition.rs:1:17
   |
LL | fn iter<T>(vec: Vec<T>) -> impl Iterator<Item = T> {
   |    ----         ^^^^^^ this parameter takes ownership of the value
   |    |
   |    in this function
help: consider moving the expression out of the loop so it is only moved once
   |
LL ~     let mut value = iter(vec);
LL ~     while let Some(item) = value.next() {
   |
```

We use the presence of a `break` in the loop that would be affected by
the moved value as a heuristic for "shouldn't be cloned".

Fix https://github.com/rust-lang/rust/issues/121466.

---

*Point at continue and break that might be in the wrong place*

Sometimes move errors are because of a misplaced `continue`, but we didn't
surface that anywhere. Now when there are more than one set of nested loops
we show them out and point at the `continue` and `break` expressions within
that might need to go elsewhere.

```
error[E0382]: use of moved value: `foo`
  --> $DIR/nested-loop-moved-value-wrong-continue.rs:46:18
   |
LL |     for foo in foos {
   |         ---
   |         |
   |         this reinitialization might get skipped
   |         move occurs because `foo` has type `String`, which does not implement the `Copy` trait
...
LL |         for bar in &bars {
   |         ---------------- inside of this loop
...
LL |                 baz.push(foo);
   |                          --- value moved here, in previous iteration of loop
...
LL |         qux.push(foo);
   |                  ^^^ value used here after move
   |
note: verify that your loop breaking logic is correct
  --> $DIR/nested-loop-moved-value-wrong-continue.rs:41:17
   |
LL |     for foo in foos {
   |     ---------------
...
LL |         for bar in &bars {
   |         ----------------
...
LL |                 continue;
   |                 ^^^^^^^^ this `continue` advances the loop at line 33
help: consider moving the expression out of the loop so it is only moved once
   |
LL ~         let mut value = baz.push(foo);
LL ~         for bar in &bars {
LL |
 ...
LL |             if foo == *bar {
LL ~                 value;
   |
help: consider cloning the value if the performance cost is acceptable
   |
LL |                 baz.push(foo.clone());
   |                             ++++++++
```

Fix https://github.com/rust-lang/rust/issues/92531.
2024-03-18 02:10:34 +00:00
bors
62f98b44cc Auto merge of #122627 - RalfJung:collector-stack-space, r=compiler-errors
collector: move ensure_sufficient_stack out of the loop

According to the docs this call has some overhead to putting it inside the loop doesn't seem like a good idea.

r? `@oli-obk`
2024-03-18 00:03:56 +00:00