Commit Graph

249807 Commits

Author SHA1 Message Date
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
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
beetrees
36514015ff
Move option_env! and env! tests to the env-macro directory 2024-03-17 21:59:40 +00:00
Esteban Küber
3b237d7d8a Move suggest_hoisting_call_outside_loop out of suggest_cloning 2024-03-17 21:52:12 +00:00
Esteban Küber
da2364d746 Move Visitor impl out to the mod level 2024-03-17 21:46:52 +00:00
Esteban Küber
f216bac861 Add HELP to test 2024-03-17 21:45:03 +00:00
Esteban Küber
78d29ad8d6 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 #92531.
2024-03-17 21:32:26 +00:00
Esteban Küber
14473adf42 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 #121466.
2024-03-17 21:32:26 +00:00
bors
eb45c84440 Auto merge of #122653 - matthiaskrgr:rollup-28h37ym, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #120640 (Mark UEFI std support as WIP)
 - #121862 (Add release notes for 1.77.0)
 - #122572 (add test for #122301 to cover behavior that's on stable)
 - #122578 (Only invoke `decorate` if the diag can eventually be emitted)
 - #122615 (Mention Zalathar for coverage changes)
 - #122636 (some minor code simplifications)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-03-17 21:06:23 +00:00
Ralf Jung
23a4ad12ce simplify_cfg: rename some passes so that they make more sense 2024-03-17 19:59:15 +01:00
Ralf Jung
872781b226 interpret/memory: explain why we use == on bool 2024-03-17 19:32:03 +01:00
Matthias Krüger
1588d9bdc8
Rollup merge of #122636 - matthiaskrgr:compl3, r=compiler-errors
some minor code simplifications
2024-03-17 19:26:23 +01:00
Matthias Krüger
0589ffb902
Rollup merge of #122615 - Zalathar:triagebot, r=Mark-Simulacrum
Mention Zalathar for coverage changes

Hopefully I don't regret all the extra notifications. 🤞
2024-03-17 19:26:22 +01:00
Matthias Krüger
8e748c0a41
Rollup merge of #122578 - jieyouxu:guard-decorate, r=fee1-dead
Only invoke `decorate` if the diag can eventually be emitted

Lints can call [`trimmed_def_paths`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/print/fn.trimmed_def_paths.html#), such as through manual implementations of `LintDiagnostic` and calling `def_path_str`.

05a2be3def/compiler/rustc_lint/src/lints.rs (L1834-L1839)

The emission of a lint eventually relies on [`TyCtxt::node_lint`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/context/struct.TyCtxt.html#method.node_lint), which has a `decorate` closure which is responsible for decorating the diagnostic with "lint stuff". `node_lint` in turn relies on [`lint_level`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/lint/fn.lint_level.html). Within `lint_level`, `decorate` is eventually called just before `Diag::emit` is called to decorate the diagnostic. However, if `-A warnings` or `--cap-lint=allow` are set, or if the unused_must_use lint is explicitly allowed, then `decorate` would be called, which would call `def_path_str`, but the diagnostic would never be emitted and hence would trigger the `must_produce_diag` ICE.

To avoid calling `decorate` when we don't eventually emit the diagnostic, we check that:

- if `--force-warn` is specified, then call `decorate`; otherwise
- if we can emit warnings (or higher), then call `decorate`.

Fixes #121774.
2024-03-17 19:26:22 +01:00
Matthias Krüger
3fbe203cc1
Rollup merge of #122572 - the8472:test-const-deadness, r=RalfJung
add test for #122301 to cover behavior that's on stable

If this ought to be broken it should at least happen intentionally

See #122301
2024-03-17 19:26:21 +01:00
Matthias Krüger
5c761d8cfe
Rollup merge of #121862 - cuviper:relnotes-1.77.0, r=Mark-Simulacrum
Add release notes for 1.77.0

cc `@rust-lang/release`
r? `@Mark-Simulacrum`
2024-03-17 19:26:21 +01:00
Matthias Krüger
3d1b04e031
Rollup merge of #120640 - Ayush1325:uefi-doc, r=Nilstrieb
Mark UEFI std support as WIP

Currently stdio and alloc support is present with open PRs for some of the other portions.

A prototype of almost all of std support can be found [here](https://github.com/tianocore/rust/tree/uefi-master). I will be up-streaming as much stuff as possible from there.
2024-03-17 19:26:20 +01:00
Josh Stone
87c9349e1b Sort the remaining T-types relnotes 2024-03-17 09:58:28 -07:00
Josh Stone
8953306016 No compatibility notes raised in 1.77.0 2024-03-17 09:58:28 -07:00
Josh Stone
4a2f0f6c99 The const-eval change is now future-compat 2024-03-17 09:58:28 -07:00
Josh Stone
213e598fae Move a couple issues to Language notes 2024-03-17 09:58:27 -07:00
Josh Stone
0ac3d4df6d Apply suggestions from code review
Co-authored-by: Urgau <3616612+Urgau@users.noreply.github.com>
Co-authored-by: Michael Howell <michael@notriddle.com>
2024-03-17 09:58:27 -07:00
Josh Stone
01864e282a Add release notes for 1.77.0 2024-03-17 09:58:27 -07:00
Ayush Singh
c1cf422140
Mark UEFI std support as WIP
Signed-off-by: Ayush Singh <ayushdevel1325@gmail.com>
2024-03-17 21:32:50 +05:30
许杰友 Jieyou Xu (Joe)
bdab02ca99
Guard decorate on when not to skip instead 2024-03-17 15:07:22 +00:00
许杰友 Jieyou Xu (Joe)
60de7554de
Invoke decorate when error level is beyond warning, including error 2024-03-17 14:41:37 +00:00
许杰友 Jieyou Xu (Joe)
772d8598d2
Only invoke decorate if the diag can eventually be emitted 2024-03-17 14:41:36 +00:00
Ralf Jung
ee746fb8ed collector: move ensure_sufficient_stack out of the loop 2024-03-17 15:17:00 +01:00
The 8472
fefd06dc02 add test for #122301 to cover behavior that's on stable
if this ought to be broken it should at least happen intentionally
2024-03-17 14:58:22 +01:00
bors
35dfc67d94 Auto merge of #122637 - matthiaskrgr:rollup-bczj5bp, r=matthiaskrgr
Rollup of 3 pull requests

Successful merges:

 - #121236 (Don't show suggestion if slice pattern is not top-level)
 - #121787 (run change tracker even when config parse fails)
 - #122633 (avoid unnecessary collect())

r? `@ghost`
`@rustbot` modify labels: rollup
2024-03-17 13:55:27 +00:00
omahs
758f642c29
fix typo 2024-03-17 14:25:24 +01:00
omahs
96e3c2c1ac
fix typo 2024-03-17 14:25:06 +01:00
Matthias Krüger
12137462b4
Rollup merge of #122633 - matthiaskrgr:col, r=fmease
avoid unnecessary collect()
2024-03-17 14:04:15 +01:00
Matthias Krüger
2448162729
Rollup merge of #121787 - onur-ozkan:improve-change-tracker, r=albertlarsan68
run change tracker even when config parse fails

Please note that we are currently validating the build configuration on two entry points (e.g., profile validation is handled on the python side), and change tracker system is handled on the rust side. Once #94829 is completed (scheduled for 2024), we will be able to handle this more effectively.

Fixes #121756
2024-03-17 14:04:14 +01:00
Matthias Krüger
3ec2b7bd1d
Rollup merge of #121236 - long-long-float:rust-fix-consider-slicing, r=Nadrieril
Don't show suggestion if slice pattern is not top-level

Close #120605

Don't show suggestion to add slicing (`[..]`) if the slice pattern is enclosed by struct like `Struct { a: [] }`.

For example, current rustc makes a suggestion as a comment. However, the pattern `a: []` is wrong, not scrutinee `&self.a`.
In this case, the structure type `a: Vec<Struct>` and the pattern `a: []` are different so I think the pattern should be fixed, not the scrutinee.
If the parent of the pattern that was the target of the error is a structure, I made the compiler not show a suggestion.

```rs
pub struct Struct {
    a: Vec<Struct>,
}

impl Struct {
    pub fn test(&self) {
        if let [Struct { a: [] }] = &self.a {
//             ^^^^^^^^^^^^^^^^^^   ------- help: consider slicing here: `&self.a[..]`
            println!("matches!")
        }
    }
}
```

Note:

* ~~I created `PatInfo.history` to store parent-child relationships for patterns, but this may be inefficient.~~
  * I use two fields `parent_kind` and `current_kind` instead of vec. It may not performance issue.
* Currently only looking at direct parents, but may need to look at deeper ancestry.
2024-03-17 14:04:14 +01:00
Matthias Krüger
0437a0c372 some minor code simplifications 2024-03-17 13:44:44 +01:00
bors
a0c20d52e0 Auto merge of #122628 - lnicola:sync-from-ra, r=lnicola
Subtree update of `rust-analyzer`
2024-03-17 11:53:08 +00:00
Zalathar
36f8d67c92 Mention Zalathar for coverage changes 2024-03-17 22:41:55 +11:00
Matthias Krüger
b8db431f37 avoid unnecessary collect() 2024-03-17 12:19:46 +01:00
long-long-float
78e94cba77 Don't show suggestion if slice pattern is enclosed by any patterns 2024-03-17 19:21:13 +09:00
Laurențiu Nicola
20ecf0744d Merge commit '5ecace48f693afaa6adf8cb23086b651db3aec96' into sync-from-ra 2024-03-17 11:04:52 +02:00
bors
ecdea9e943 Auto merge of #122625 - matthiaskrgr:rollup-ue4dmnx, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - #119411 (Add as_(mut_)ptr and as_(mut_)slice to raw array pointers)
 - #122248 (Respect stage0 sysroot when compiling rmake.rs with COMPILETEST_FORCE_STAGE0)
 - #122295 (mir-opt: always run tests for the current target)
 - #122574 (Register LLVM handlers for bad-alloc / OOM)
 - #122608 (Move check-cfg diagnostic logic into a separate file)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-03-17 08:44:44 +00:00
Matthias Krüger
325678c979
Rollup merge of #122608 - Urgau:check-cfg-move-diagnostic-logic, r=fmease
Move check-cfg diagnostic logic into a separate file

as well as adding some triagebot mentions (for me) for check-cfg related files.

``@rustbot`` label +F-check-cfg
2024-03-17 08:23:26 +01:00
Matthias Krüger
33b4ed225a
Rollup merge of #122574 - cuviper:llvm-oom, r=nikic
Register LLVM handlers for bad-alloc / OOM

LLVM's default bad-alloc handler may throw if exceptions are enabled,
and `operator new` isn't hooked at all by default. Now we register our
own handler that prints a message similar to fatal errors, then aborts.
We also call the function that registers the C++ `std::new_handler`.

Fixes #121305
Cc llvm/llvm-project#85281
r? ``@nikic``
2024-03-17 08:23:26 +01:00
Matthias Krüger
ea0745604f
Rollup merge of #122295 - Nadrieril:mir-opt-run-current-target, r=Mark-Simulacrum
mir-opt: always run tests for the current target

Currently, `./x.py test tests/mir-opt` runs only the tests for the current target, and `./x.py test tests/mir-opt --bless` runs tests for a representative set of targets. That representative set does not include the current target however, which means `--bless` can succeed when tests fail without it. This PR ensures we run the current target always.

Fixes https://github.com/rust-lang/rust/issues/122292
cc ``@RalfJung``
2024-03-17 08:23:26 +01:00
Matthias Krüger
a5dbdc2fa9
Rollup merge of #122248 - jieyouxu:rmake-sysroot, r=Mark-Simulacrum
Respect stage0 sysroot when compiling rmake.rs with COMPILETEST_FORCE_STAGE0

Context: <https://rust-lang.zulipchat.com/#narrow/stream/326414-t-infra.2Fbootstrap/topic/stage0.20compiletest.20broken>.
> cg_clif uses `COMPILETEST_FORCE_STAGE0=1 ./x.py test --stage 0` for running the rustc test suite. With the introduction of rmake.rs this broke. `librun_make_support.rlib` is compiled using the bootstrap rustc wrapper which sets `--sysroot build/aarch64-unknown-linux-gnu/stage0-sysroot`, but then compiletest will compile `rmake.rs` using the sysroot of the bootstrap compiler causing it to not find the `libstd.rlib` against which `librun_make_support.rlib` is compiled.

cc ``@bjorn3``

Fixes #122196.
2024-03-17 08:23:25 +01:00