Commit Graph

10056 Commits

Author SHA1 Message Date
Markus Reiter
bd8e565e16
Use generic NonZero. 2024-05-08 21:37:55 +02:00
Markus Reiter
7531eafa7e
Simplify suggestion. 2024-05-08 21:37:54 +02:00
Matthias Krüger
5347652fdf
Rollup merge of #124864 - notriddle:notriddle/feature-flags-are-not-stability-markers, r=fmease
rustdoc: use stability, instead of features, to decide what to show

Fixes #124635

To decide if internal items should be inlined in a doc page, check if the crate is itself internal, rather than if it has the rustc_private feature flag. The standard library uses internal items, but is not itself internal and should not show internal items on its docs pages.
2024-05-08 17:03:10 +02:00
Matthias Krüger
9fce3dc685
Rollup merge of #124761 - Urgau:ref-casting_bigger_slice_index, r=jieyouxu
Fix insufficient logic when searching for the underlying allocation

This PR fixes the logic inside the `invalid_reference_casting` lint, when trying to lint on bigger memory layout casts.

More specifically when looking for the "underlying allocation" we were wrongly assuming that when we got `&mut slice[index]` that `slice[index]` was the allocation, but it's not.

Fixes https://github.com/rust-lang/rust/issues/124685
2024-05-08 17:03:09 +02:00
Matthias Krüger
e997508ecb
Rollup merge of #124548 - gurry:113272-ice-failed-to-normalize, r=compiler-errors
Handle normalization failure in `struct_tail_erasing_lifetimes`

Fixes #113272

The ICE occurred because the struct being normalized had an error. This PR adds some defensive code to guard against that.
2024-05-08 17:03:08 +02:00
Guillaume Gomez
c078a44247 Migrate run-make/rustdoc-map-file to rmake 2024-05-08 16:58:12 +02:00
Michael Howell
6d6f67a98c rustdoc: use stability, instead of features, to decide what to show
To decide if internal items should be inlined in a doc page,
check if the crate is itself internal, rather than if it has
the rustc_private feature flag. The standard library uses
internal items, but is not itself internal and should not show
internal items on its docs pages.
2024-05-07 20:47:19 -07:00
Michael Goulet
7dbdbaaa8e Fix ICEs in diagnostic::on_unimplemented 2024-05-07 23:13:44 -04:00
Michael Goulet
a8f2e33eec Add more ICEs due to malformed diagnostic::on_unimplemented 2024-05-07 23:13:44 -04:00
Julien
79cf61a9ae Update Makefiles with explanatory comments 2024-05-07 22:12:36 -04:00
bors
a60f077c38 Auto merge of #124683 - estebank:issue-124651, r=compiler-errors
Do not ICE on foreign malformed `diagnostic::on_unimplemented`

Fix #124651.
2024-05-08 00:54:38 +00:00
Michael Goulet
1d9d6715ae Make sure we don't deny macro vars w keyword names 2024-05-07 19:13:33 -04:00
Esteban Küber
758e459427 Add test for #124651 2024-05-07 22:31:22 +00:00
bors
5486f0c1c2 Auto merge of #124223 - Zalathar:conditional-let, r=compiler-errors
coverage: Branch coverage support for let-else and if-let

This PR adds branch coverage instrumentation for let-else and if-let, including let-chains.

This lifts two of the limitations listed at #124118.
2024-05-07 22:28:51 +00:00
Veera
4271383e1d Update Tests 2024-05-07 16:56:54 -04:00
bors
faefc618cf Auto merge of #124219 - gurry:122989-ice-unexpected-anon-const, r=compiler-errors
Do not ICE on `AnonConst`s in `diagnostic_hir_wf_check`

Fixes #122989

Below is the snippet from #122989 that ICEs:
```rust
trait Traitor<const N: N<2> = 1, const N: N<2> = N> {
    fn N(&N) -> N<2> {
        M
    }
}

trait N<const N: Traitor<2> = 12> {}
```

The `AnonConst` that triggers the ICE is the `2` in the param `const N: N<2> = 1`. The currently existing code in `diagnostic_hir_wf_check` deals only with `AnonConst`s that are default values of some param, but  the `2` is not a default value. It is just an `AnonConst` HIR node inside a `TraitRef` HIR node corresponding to `N<2>`. Therefore the existing code cannot handle it and this PR ensures that it does.
2024-05-07 20:01:18 +00:00
bors
b923ea4924 Auto merge of #124849 - matthiaskrgr:rollup-68humsk, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - #124738 (rustdoc: dedup search form HTML)
 - #124827 (generalize hr alias: avoid unconstrainable infer vars)
 - #124832 (narrow down visibilities in `rustc_parse::lexer`)
 - #124842 (replace another Option<Span> by DUMMY_SP)
 - #124846 (Don't ICE when we cannot eval a const to a valtree in the new solver)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-05-07 17:44:06 +00:00
Matthias Krüger
067f6327a5
Rollup merge of #124846 - compiler-errors:const-eval, r=lcnr
Don't ICE when we cannot eval a const to a valtree in the new solver

Use `const_eval_resolve` instead of `try_const_eval_resolve` because naming aside, the former doesn't ICE when a value can't be evaluated to a valtree.

r? lcnr
2024-05-07 18:12:56 +02:00
Matthias Krüger
4a5bf7b06e
Rollup merge of #124827 - lcnr:generalize-incomplete, r=compiler-errors
generalize hr alias: avoid unconstrainable infer vars

fixes https://github.com/rust-lang/trait-system-refactor-initiative/issues/108

see inline comments for more details

r? `@compiler-errors` cc `@BoxyUwU`
2024-05-07 18:12:55 +02:00
Matthias Krüger
7af9ad1465
Rollup merge of #124738 - notriddle:notriddle/search-form-js, r=GuillaumeGomez
rustdoc: dedup search form HTML

This change constructs the search form HTML using JavaScript, instead of plain HTML. It uses a custom element because

- the [parser]'s insert algorithm runs the connected callback synchronously, so we won't get layout jank
- it requires very little HTML, so it's a real win in size

[parser]: https://html.spec.whatwg.org/multipage/parsing.html#create-an-element-for-the-token

This shrinks the standard library by about 60MiB, by my test.

There should be no visible changes. Just use less disk space.
2024-05-07 18:12:54 +02:00
lcnr
690d5aa417 generalize hr alias: avoid unconstrainable infer vars 2024-05-07 15:58:06 +00:00
Michael Goulet
b58f5a7800 Don't ICE when we cannot eval a const to a valtree in the new solver 2024-05-07 11:14:25 -04:00
bors
0f40f14b61 Auto merge of #123332 - Nadrieril:testkind-never, r=matthewjasper
never patterns: lower never patterns to `Unreachable` in MIR

This lowers a `!` pattern to "goto Unreachable". Ideally I'd like to read from the place to make it clear that the UB is coming from an invalid value, but that's tricky so I'm leaving it for later.

r? `@compiler-errors` how do you feel about a lil bit of MIR lowering
2024-05-07 15:14:20 +00:00
bors
60a7c191c6 Auto merge of #124781 - VladimirMakaev:lldb-enum-formatter, r=dtolnay
Implement lldb formatter for "clang encoded" enums (LLDB 18.1+) (V3)

This is a redo of PR (#124458) which was approved previously but force-pushed out. Then a V2 (#124745) failed `debuginfo\msvc-pretty-enums.rs` test during merge.

I've fixed the test and checked it to pass on Windows with `.\x.ps1 test .\tests\debuginfo\msvc-pretty-enums.rs`

Below is the original summary:

## Summary:

fixes #79530

I landed a fix last year to enable `DW_TAG_variant_part` encoding in LLDBs (https://reviews.llvm.org/D149213). This PR is a corresponding fix in synthetic formatters to decode that information.

This is in no way perfect implementation but at least it improves the status quo. But most types of enums will be visible and debuggable in some way.

I've also updated most of the existing tests that touch enums and re-enabled test cases based on LLDB for enums.

## Test Plan:
ran tests `./x test tests/debuginfo/`. Also tested manually in LLDB CLI and LLDB VSCode

## Other Thoughs:
A better approach would probably be adopting [formatters from codelldb](https://github.com/vadimcn/codelldb/blob/master/formatters/rust.py). There is some neat hack that hooks up summary provider via synthetic provider which can ultimately fix more display issues for Rust types and enums too. But getting it to work well might take more time that I have right now.
2024-05-07 08:05:34 +00:00
bors
5ae5d13537 Auto merge of #124830 - aeubanks:dbg, r=durin42
Adjust dbg.value/dbg.declare checks for LLVM update

https://github.com/llvm/llvm-project/pull/89799 changes llvm.dbg.value/declare intrinsics to be in a different, out-of-instruction-line representation. For example
  call void `@llvm.dbg.declare(...)`
becomes
  #dbg_declare(...)

Update tests accordingly to work with both the old and new way.
2024-05-07 00:03:52 +00:00
Arthur Eubanks
6c348aca4e Adjust dbg.value/dbg.declare checks for LLVM update
https://github.com/llvm/llvm-project/pull/89799 changes llvm.dbg.value/declare intrinsics to be in a different, out-of-instruction-line representation. For example
  call void @llvm.dbg.declare(...)
becomes
  #dbg_declare(...)

Update tests accordingly to work with both the old and new way.
2024-05-06 23:15:48 +00:00
Matthias Krüger
284b5530b8
Rollup merge of #124809 - lcnr:prepopulate-opaques, r=compiler-errors
borrowck: prepopulate opaque storage more eagerly

otherwise we ICE due to ambiguity when normalizing while computing implied bounds.

r? ``@compiler-errors``
2024-05-06 21:46:06 +02:00
Matthias Krüger
f76c8f7f77
Rollup merge of #124759 - compiler-errors:impl-args, r=lcnr
Record impl args in the proof tree in new solver

Rather than rematching them during select.

Also use `ImplSource::Param` instead of `ImplSource::Builtin` for alias-bound candidates, so we don't ICE in `Instance::resolve`.

r? lcnr
2024-05-06 21:46:05 +02:00
Michael Goulet
e34723997a Use correct ImplSource for alias bounds 2024-05-06 14:38:35 -04:00
bors
31110152e2 Auto merge of #124811 - matthiaskrgr:rollup-4zpov13, r=matthiaskrgr
Rollup of 4 pull requests

Successful merges:

 - #124520 (Document that `create_dir_all` calls `mkdir`/`CreateDirW` multiple times)
 - #124724 (Prefer lower vtable candidates in select in new solver)
 - #124771 (Don't consider candidates with no failing where clauses when refining obligation causes in new solver)
 - #124808 (Use `super_fold` in `RegionsToStatic` visitor)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-05-06 17:24:30 +00:00
Matthias Krüger
ad73b1623d
Rollup merge of #124808 - compiler-errors:super, r=lcnr
Use `super_fold` in `RegionsToStatic` visitor

so as to avoid an infinite stack cycle

fixes #124805
r? lcnr
2024-05-06 18:50:36 +02:00
Matthias Krüger
43de8225dc
Rollup merge of #124771 - compiler-errors:cand-has-failing-wc, r=lcnr
Don't consider candidates with no failing where clauses when refining obligation causes in new solver

Improves error messages when we have param-env candidates that don't deeply unify (i.e. after alias-bounds).

r? lcnr
2024-05-06 18:50:35 +02:00
Matthias Krüger
2d557ba9f4
Rollup merge of #124724 - compiler-errors:prefer-lower, r=lcnr
Prefer lower vtable candidates in select in new solver

Also, adjust the select visitor to only winnow when the *parent* goal is `Certainty::Yes`. This means that we won't winnow in cases when we have any ambiguous inference guidance from two candidates.

r? lcnr
2024-05-06 18:50:35 +02:00
Michael Goulet
116f95bb46 Use super_fold in RegionsToStatic visitor 2024-05-06 12:22:15 -04:00
lcnr
24ee32cf70 borrowck: more eagerly prepopulate opaques 2024-05-06 16:04:57 +00:00
Michael Goulet
4e3350d43b Don't consider candidates with no failing where clauses 2024-05-06 11:32:50 -04:00
Michael Goulet
a4ee20eb13 Prefer lower vtable candidates in select in new solver 2024-05-06 10:48:39 -04:00
bors
fc47cf38e5 Auto merge of #123850 - tspiteri:f16_f128_consts, r=Amanieu
Add constants for f16 and f128

- Commit 1 adds associated constants for `f16`, excluding NaN and infinities as these are implemented using arithmetic for `f32` and `f64`.
- Commit 2 adds associated constants for `f128`, excluding NaN and infinities.
- Commit 3 adds constants in `std::f16::consts`.
- Commit 4 adds constants in `std::f128::consts`.
2024-05-06 14:45:28 +00:00
beetrees
3769fddba2
Refactor float Primitives to a separate Float type 2024-05-06 14:56:10 +01:00
bors
25e3949aa1 Auto merge of #124753 - GuillaumeGomez:migrate-rustdoc-determinism, r=jieyouxu
Migrate `run-make/rustdoc-error-lines` to new `rmake.rs`

Part of https://github.com/rust-lang/rust/issues/121876.

There was a weird naming inconsistency with `input`/`output`. A few tests write `.arg("-o").arg(path)` and the `output` method was actually the command output. So instead, I renamed the original `output` into `command_output` so that I could create the `output` method with the expected effect (and updated the tests to use it too).

EDIT: The first two commits come from https://github.com/rust-lang/rust/pull/124711. Some weird things happened recently pparently. ^^'

r? `@jieyouxu`
2024-05-06 12:00:44 +00:00
bors
8cef37dbb6 Auto merge of #124497 - rytheo:move-std-tests-to-library, r=workingjubilee
Move some stdlib tests from `tests/ui` to `library/std/tests`

Related to #99417
2024-05-06 09:53:24 +00:00
Scott McMurray
61517dbbe6 Avoid a cast in ptr::slice_from_raw_parts(_mut)
Casting to `*const ()` or `*mut ()` just bloats the MIR, so let's not.

If ACP#362 goes through we can keep calling `ptr::from_raw_parts(_mut)` in these also without the cast, but that hasn't had any libs-api attention yet, so I'm not waiting on it.
2024-05-06 01:53:54 -07:00
bors
69f53f5e55 Auto merge of #124679 - Urgau:check-cfg-structured-cli-errors, r=nnethercote
Improve check-cfg CLI errors with more structured diagnostics

This PR improve check-cfg CLI errors with more structured diagnostics.

In particular it now shows the statement where the error occurred, what kind lit it is, as well as pointing users to the doc for more details.

`@rustbot` label +F-check-cfg
2024-05-06 07:46:27 +00:00
Guillaume Gomez
34fe2172b1 Migrate run-make/rustdoc-error-lines to rmake.rs 2024-05-06 09:16:35 +02:00
Guillaume Gomez
823b423d4c Add new output method to Rustc and Rustdoc types 2024-05-06 09:16:35 +02:00
Urgau
228496e4f5 Improve check-cfg CLI errors with more structured diagnostics 2024-05-06 07:44:41 +02:00
Matthias Krüger
b0fb3c56e0
Rollup merge of #124765 - GuillaumeGomez:fix-wrong-cog-colotr, r=notriddle
[rustdoc] Fix bad color for setting cog in ayu theme

Before:

![Screenshot from 2024-05-05 19-29-36](https://github.com/rust-lang/rust/assets/3050060/e1f078e5-7fb3-472d-91e7-b4bde551d411)

After:

![image](https://github.com/rust-lang/rust/assets/3050060/0aa115ac-dd69-48e1-b93e-067a39cf25d2)

r? ````@notriddle````
2024-05-06 06:21:04 +02:00
Matthias Krüger
3d97660f40
Rollup merge of #124742 - Urgau:check-cfg-rustfmt, r=fmease
Add `rustfmt` cfg to well known cfgs list

This PR adds the `rustfmt` cfg to the well known cfgs list.

Related to https://github.com/rust-lang/rust/issues/124735
2024-05-06 06:21:03 +02:00
bors
80420a693f Auto merge of #124747 - MasterAwesome:master, r=davidtwco
Support Result<T, E> across FFI when niche optimization can be used (v2)

This PR is identical to #122253, which was approved and merged but then removed from master by a force-push due to a [CI bug](https://rust-lang.zulipchat.com/#narrow/stream/242791-t-infra/topic/ci.20broken.3F).

r? ghost

Original PR description:

---

Allow allow enums like `Result<T, E>` to be used across FFI if the T/E can be niche optimized and the non-niche-optimized type is FFI safe.

Implementation of https://github.com/rust-lang/rfcs/pull/3391
Tracking issue: https://github.com/rust-lang/rust/issues/110503

Additional ABI and codegen tests were added in https://github.com/rust-lang/rust/pull/115372
2024-05-06 00:55:49 +00:00
Vladimir Makayev
fb2d9cdfc5 Implement lldb formattter for "clang encoded" enums (LLDB 18.1+)
Summary:
I landed a fix last year to enable `DW_TAG_variant_part` encoding in LLDBs (https://reviews.llvm.org/D149213). This PR is a corresponding fix in synthetic formatters to decode that information.
This is in no way perfect implementation but at least it improves the status quo. But most types of enums will be visible and debuggable in some way.
I've also updated most of the existing tests that touch enums and re-enabled test cases based on LLDB for enums.

Test Plan:
ran tests `./x test tests/debuginfo/`. Also tested manually in LLDB CLI and LLDB VSCode

Other Thoughs
A better approach would probably be adopting [formatters from codelldb](https://github.com/vadimcn/codelldb/blob/master/formatters/rust.py). There is some neat hack that hooks up summary provider via synthetic provider which can ultimately fix more display issues for Rust types and enums too. But getting it to work well might take more time that I have right now.
2024-05-05 17:53:02 -07:00
The 8472
295432b40e print walltime benchmarks with subnanosecond precision
example results when benchmarking 1-4 serialized ADD instructions

```
running 4 tests
test add  ... bench:           0.24 ns/iter (+/- 0.00)
test add2 ... bench:           0.48 ns/iter (+/- 0.01)
test add3 ... bench:           0.72 ns/iter (+/- 0.01)
test add4 ... bench:           0.96 ns/iter (+/- 0.01)
```
2024-05-06 00:25:00 +02:00
Matthias Krüger
397a35d081 crashes: add lastest batch of crash tests 2024-05-05 23:41:08 +02:00
Guillaume Gomez
e460901b13 Add GUI regression test for setting's cog color 2024-05-05 20:07:12 +02:00
Guillaume Gomez
0cbebd07ee Fix bad color for setting cog in ayu theme 2024-05-05 20:07:12 +02:00
Urgau
cd6a0c8c77 Fix insufficient logic when searching for the underlying allocation
in the `invalid_reference_casting` lint, when trying to lint on
bigger memory layout casts.
2024-05-05 19:14:20 +02:00
Michael Howell
eeb59f16a5 rustdoc: dedup search form HTML
This change constructs the search form HTML using JavaScript, instead of plain HTML. It uses a custom element because

- the [parser]'s insert algorithm runs the connected callback synchronously, so we won't get layout jank
- it requires very little HTML, so it's a real win in size

[parser]: https://html.spec.whatwg.org/multipage/parsing.html#create-an-element-for-the-token

This shrinks the standard library by about 60MiB, by my test.
2024-05-05 08:15:08 -07:00
bors
7c4ac0603e Auto merge of #124752 - GuillaumeGomez:rollup-a4qagbd, r=GuillaumeGomez
Rollup of 6 pull requests

Successful merges:

 - #124148 (rustdoc-search: search for references)
 - #124668 (Fix bootstrap panic when build from tarball)
 - #124736 (compiler: upgrade time from 0.3.34 to 0.3.36)
 - #124748 (Fix unwinding on 32-bit watchOS ARM (v2))
 - #124749 (Stabilize exclusive_range_pattern (v2))
 - #124750 (Document That `f16` And `f128` Hardware Support is Limited (v2))

r? `@ghost`
`@rustbot` modify labels: rollup
2024-05-05 14:59:34 +00:00
Guillaume Gomez
c04d09a76b Rename run-make-support library output method to command_output 2024-05-05 16:53:57 +02:00
Guillaume Gomez
3c2cf2e50b Migrate run-make/doctests-runtool to rmake 2024-05-05 16:53:57 +02:00
Guillaume Gomez
d3e042dc4e
Rollup merge of #124749 - RossSmyth:stable_range, r=davidtwco
Stabilize exclusive_range_pattern (v2)

This PR is identical to #124459, which was approved and merged but then removed from master by a force-push due to a [CI bug](https://rust-lang.zulipchat.com/#narrow/stream/242791-t-infra/topic/ci.20broken.3F).

r? ghost

Original PR description:

---

Stabilization report: https://github.com/rust-lang/rust/issues/37854#issuecomment-1842398130
FCP: https://github.com/rust-lang/rust/issues/37854#issuecomment-1872520294

Stabilization was blocked by a lint that was merged here: #118879

Documentation PR is here: rust-lang/reference#1484

`@rustbot` label +F-exclusive_range_pattern +T-lang
2024-05-05 16:42:48 +02:00
Guillaume Gomez
042d0f5266
Rollup merge of #124148 - notriddle:notriddle/reference, r=GuillaumeGomez
rustdoc-search: search for references

This feature extends rustdoc with syntax and search index information for searching borrow references. Part of https://github.com/rust-lang/rust/issues/60485

## Preview

- [`&mut`](https://notriddle.com/rustdoc-html-demo-11/reference/std/index.html?search=%26mut)
- [`&Option<T> -> Option<&T>`](https://notriddle.com/rustdoc-html-demo-11/reference/std/index.html?search=%26Option%3CT%3E%20-%3E%20Option%3C%26T%3E)
- [`&mut Option<T> -> Option<&mut T>`](https://notriddle.com/rustdoc-html-demo-11/reference/std/index.html?search=%26mut%20Option%3CT%3E%20-%3E%20Option%3C%26mut%20T%3E)

Updated chapter of the book: https://notriddle.com/rustdoc-html-demo-11/reference/rustdoc/read-documentation/search.html

## Motivation

See https://github.com/rust-lang/rust/pull/119676

## Guide-level explanation

You can't search by lifetimes, but other than that it's the same syntax references normally use.

## Reference-level description

<table>
<thead>
  <tr>
    <th>Shorthand</th>
    <th>Explicit names</th>
  </tr>
</thead>
<tbody>
  <tr><td colspan="2">Before this PR</td></tr>
  <tr>
    <td><code>[]</code></td>
    <td><code>primitive:slice</code> and/or <code>primitive:array</code></td>
  </tr>
  <tr>
    <td><code>[T]</code></td>
    <td><code>primitive:slice&lt;T&gt;</code> and/or <code>primitive:array&lt;T&gt;</code></td>
  </tr>
  <tr>
    <td><code>!</code></td>
    <td><code>primitive:never</code></td>
  </tr>
  <tr>
    <td><code>()</code></td>
    <td><code>primitive:unit</code> and/or <code>primitive:tuple</code></td>
  </tr>
  <tr>
    <td><code>(T)</code></td>
    <td><code>T</code></td>
  </tr>
  <tr>
    <td><code>(T,)</code></td>
    <td><code>primitive:tuple&lt;T&gt;</code></td>
  </tr>
  <tr>
    <td><code>(T, U -> V, W)</code></td>
    <td><code>fn(T, U) -> (V, W)</code>, Fn, FnMut, and FnOnce</td>
  </tr>
  <tr><td colspan="2">New additions with this PR</td></tr>
  <tr>
    <td><code>&</code></td>
    <td><code>primitive:reference</td>
  </tr>
  <tr>
    <td><code>&mut</code></td>
    <td><code>primitive:reference&lt;keyword:mut&gt;</td>
  </tr>
  <tr>
    <td><code>&T</code></td>
    <td><code>primitive:reference&lt;T&gt;</td>
  </tr>
  <tr>
    <td><code>&mut T</code></td>
    <td><code>primitive:reference&lt;keyword:mut, T&gt;</td>
  </tr>
</tbody>
</table>

### Search query grammar

<code><pre><strong>borrow-ref = AMP *WS [MUT] *WS [arg]</strong>
arg = [type-filter *WS COLON *WS] (path [generics] / slice-like / tuple-like / <strong>borrow-ref</strong>)</pre></code>

```
AMP = "&"
MUT = "mut"
```

## Future direction

As described in https://github.com/rust-lang/rust/pull/118194 and https://github.com/rust-lang/rust/pull/119676

* The remaining type expression grammar (this is another step in the type expression grammar: `ReferenceType` is now supported)
* Search subtyping and traits
2024-05-05 16:42:46 +02:00
bors
06e88c306a Auto merge of #123125 - gurry:122561-bad-note-non-zero-loop-iters-2, r=estebank
Remove suggestion about iteration count in coerce

Fixes #122561

The iteration count-centric suggestion was implemented in PR #100094, but it was based on the wrong assumption that the type mismatch error depends on the number of times the loop iterates. As it turns out, that is not true (see this comment for details: https://github.com/rust-lang/rust/pull/122679#issuecomment-2017432531)

This PR attempts to remedy the situation by changing the suggestion from the one centered on iteration count to a simple suggestion to add a return value.

It should also fix #100285 by simply making it redundant.
2024-05-05 12:51:37 +00:00
Urgau
f90b15b7fc Add rustfmt cfg to well known cfgs list 2024-05-05 14:30:35 +02:00
Matthias Krüger
07dc4aa837
Rollup merge of #124718 - compiler-errors:record-impl-args, r=lcnr
Record impl args in the proof tree

Weren't recording these since they went through a different infcx method

r? lcnr
2024-05-04 22:27:33 +02:00
Matthias Krüger
79071ee3a9
Rollup merge of #124717 - compiler-errors:do-not-recomment-next-solver, r=lcnr
Implement `do_not_recommend` in the new solver

Put the test into `diagnostic_namespace` test folder even though it's not in the diagnostic namespace, because it should be soon.

r? lcnr
cc `@weiznich`
2024-05-04 22:27:32 +02:00
Matthias Krüger
6ece08f41f
Rollup merge of #124713 - Urgau:check-cfg-update-cargo-diagnostics, r=jieyouxu
Update Cargo specific diagnostics in check-cfg

This PR updates the Cargo specific diagnostics for check-cfg/`unexpected_cfgs` lint.

Specifically it update to new url and use the double-column (instead of one) in the Cargo directive suggestion.

`@rustbot` label +F-check-cfg
cc `@weihanglo`
2024-05-04 22:27:32 +02:00
Michael Goulet
50338aa59a Record impl args in the proof tree 2024-05-04 12:57:01 -04:00
Michael Goulet
b33599485b Implement do_not_recommend in the new solver 2024-05-04 12:51:10 -04:00
Michael Goulet
6714216eaa Only consider ambiguous goals when finding best obligation for ambiguities 2024-05-04 12:05:36 -04:00
Urgau
dcf6853693 Update Cargo diagnostics in check-cfg 2024-05-04 17:26:15 +02:00
Nadrieril
57e8aebb6c Lower never patterns to Unreachable in mir 2024-05-04 16:30:01 +02:00
Nadrieril
92d65a92e2 Add tests 2024-05-04 16:20:47 +02:00
bors
d7ea27808d Auto merge of #124703 - matthiaskrgr:rollup-2lljptd, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #123356 (Reduce code size of `thread::set_current`)
 - #124159 (Move thread parking to `sys::sync`)
 - #124293 (Let miri and const eval execute intrinsics' fallback bodies)
 - #124677 (Set non-leaf frame pointers on Fuchsia targets)
 - #124692 (We do not coerce `&mut &mut T -> *mut mut T`)
 - #124698 (Rewrite `rustdoc-determinism` test in Rust)
 - #124700 (Remove an unnecessary cast)
 - #124701 (Docs: suggest `uN::checked_sub` instead of check-then-unchecked)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-05-04 12:41:40 +00:00
Matthias Krüger
b8711373cd
Rollup merge of #124698 - JoverZhang:test-rustdoc-determinism, r=jieyouxu
Rewrite `rustdoc-determinism` test in Rust

Rewrite the `rustdoc-determinism` test from #121876.

r? `@jieyouxu`
2024-05-04 12:37:23 +02:00
Matthias Krüger
b0715b4e57
Rollup merge of #124692 - workingjubilee:document-no-double-pointer-coercion-happens, r=compiler-errors
We do not coerce `&mut &mut T -> *mut mut T`

Resolves #34117 by declaring it to be "working as intended" until someone RFCs it or whatever other lang proposal would be required. It seems a bit of a footgun, but perhaps there are strong reasons to allow it anyways. Seeing as how I often have to be mindful to not allow a pointer to coerce the wrong way in my FFI work, I am inclined to think not, but perhaps it's fine in some use-case and that's actually more common?
2024-05-04 12:37:23 +02:00
bors
7dd170fccb Auto merge of #124345 - Urgau:compiletest-check-cfg, r=jieyouxu
Enable `--check-cfg` by default in UI tests

This PR enables-by-default `--check-cfg` in UI tests, now that it has become stable.

To do so this PR does 2 main things:
 - it introduce the `no-auto-check-cfg` directive to `compiletest`, to prevent any `--check-cfg` args (only to be used for `--check-cfg` tests)
 - it updates the _remaining_[^1] UI tests by either:
     - allowing the lint when neither expecting the lint nor giving the check-cfg args make sense
     - give the appropriate check-cfg args
     - or expect the lint, when it useful

[^1]: some preparation work was done in #123577 #123702

I highly recommend reviewing this PR commit-by-commit.

r? `@jieyouxu`
2024-05-04 10:31:49 +00:00
Urgau
d4e26fbb53 compiletest: add enable-by-default check-cfg 2024-05-04 11:30:38 +02:00
Urgau
517374150c compiletest: add no-auto-check-cfg directive
this directive prevents compiletest from adding any implicit and
automatic --check-cfg arguments
2024-05-04 11:30:38 +02:00
Urgau
ed81578820 tests/ui: prepare some tests for --check-cfg by default 2024-05-04 11:30:38 +02:00
Jover Zhang
2f4861c0e6 Rewrite rustdoc-determinism test in Rust 2024-05-04 15:52:42 +08:00
Michael Goulet
b2ca667939
Rollup merge of #124658 - GuillaumeGomez:migrate-to-run-make, r=jieyouxu
Migrate `run-make/doctests-keep-binaries` to new rmake.rs format

r? ```@jieyouxu```
2024-05-03 23:34:23 -04:00
Michael Goulet
9dfd527c6f
Rollup merge of #124480 - Enselic:on-broken-pipe, r=jieyouxu
Change `SIGPIPE` ui from `#[unix_sigpipe = "..."]` to `-Zon-broken-pipe=...`

In the stabilization [attempt](https://github.com/rust-lang/rust/pull/120832) of `#[unix_sigpipe = "sig_dfl"]`, a concern was [raised ](https://github.com/rust-lang/rust/pull/120832#issuecomment-2007394609) related to using a language attribute for the feature: Long term, we want `fn lang_start()` to be definable by any crate, not just libstd. Having a special language attribute in that case becomes awkward.

So as a first step towards the next stabilization attempt, this PR changes the `#[unix_sigpipe = "..."]` attribute to a compiler flag `-Zon-broken-pipe=...` to remove that concern, since now the language is not "contaminated" by this feature.

Another point was [also raised](https://github.com/rust-lang/rust/pull/120832#issuecomment-1987023484), namely that the ui should not leak **how** it does things, but rather what the **end effect** is. The new flag uses the proposed naming. This is of course something that can be iterated on further before stabilization.

Tracking issue: https://github.com/rust-lang/rust/issues/97889
2024-05-03 23:34:22 -04:00
Michael Goulet
e3bf0a13cf
Rollup merge of #124418 - compiler-errors:better-cause, r=lcnr
Use a proof tree visitor to refine the `Obligation` for error reporting in new solver

With the magic of `ProofTreeVisitor`, we can close the gap that we have on `ObligationCause`s being not as descriptive in the new trait solver.

r? lcnr

Needs some work and obviously documentation.
2024-05-03 23:34:21 -04:00
Jubilee Young
e404e7a8bd We do not coerce &mut &mut T -> *mut mut T 2024-05-03 20:19:20 -07:00
bors
09cd00fea4 Auto merge of #124401 - oli-obk:some_hir_cleanups, r=cjgillot
Some hir cleanups

It seemed odd to not put `AnonConst` in the arena, compared with the other types that we did put into an arena. This way we can also give it a `Span` without growing a lot of other HIR data structures because of the extra field.

r? compiler
2024-05-04 00:32:27 +00:00
bors
d2d24e395a Auto merge of #123602 - cjgillot:gvn-borrowed, r=oli-obk
Account for immutably borrowed locals in MIR copy-prop and GVN

For the most part, we consider that immutably borrowed `Freeze` locals still fulfill SSA conditions. As the borrow is immutable, any use of the local will have the value given by the single assignment, and there can be no surprise.

This allows copy-prop to merge a non-borrowed local with a borrowed local. We chose to keep copy-classes heads unborrowed, as those may be easier to optimize in later passes.

This also allows to GVN the value behind an immutable borrow. If a SSA local is borrowed, dereferencing that borrow is equivalent to copying the local's value: re-executing the assignment between the borrow and the dereference would be UB.

r? `@ghost` for perf
2024-05-03 21:50:13 +00:00
Guillaume Gomez
5ea65c8ccb Migrate run-make/doctests-keep-binaries to new rmake.rs format 2024-05-03 21:27:52 +02:00
Matthias Krüger
bd305e10c2
Rollup merge of #124510 - linyihai:raw-ident-in-typo-suggestion, r=fmease
Add raw identifier in a typo suggestion

Fixes #68962
2024-05-03 20:33:45 +02:00
Matthias Krüger
82030f2dd4
Rollup merge of #124613 - GuillaumeGomez:fmt-run-make, r=onur-ozkan
Allow fmt to run on rmake.rs test files

As discussed with `@jieyouxu,` `rmake.rs` from the `run-make` testsuite would benefit from being formatted as well.

Only thing needed to be done for it to work: allow support for `!` in our `rustfmt.toml` file parsing.

r? `@onur-ozkan`
2024-05-03 15:26:11 +02:00
Matthias Krüger
c27d3d5d2a
Rollup merge of #124612 - Urgau:run-make-stdin, r=jieyouxu
Add support for inputing via stdin with run-make-support

This PR adds the facility to set a input bytes that will be passed via the standard input.

This is useful for testing `rustc -` (and soon `rustdoc -`).

In #124611 took the approach of having a dedicated `run` method but it is not very convenient to use and would necessitate many functions, one for success, one for fail, ...

Instead this PR takes a different approach and allows setting the input bytes as if it were a parameter and when calling the (now custom) `output` function, we write the input bytes into stdin. I think this gives us maximum flexibility in the implementation and a simple interface for users.

To test this new logic I ported `tests/run-make/stdin-non-utf8/` to an `rmake.rs` one.

r? `@jieyouxu`
2024-05-03 15:26:10 +02:00
Guillaume Gomez
8f47f9773d Allow fmt to run on rmake.rs test files 2024-05-03 11:05:58 +02:00
Urgau
2c4214e0a0 run-make: port stdin-rustc to Rust-based rmake.rs 2024-05-03 08:09:57 +02:00
Michael Goulet
34e91ece90 Higher ranked goal source, do overflow handling less badly 2024-05-02 21:56:14 -04:00
Michael Goulet
3e03b1b190 Use a proof tree visitor to refine the Obligation for error reporting 2024-05-02 21:56:14 -04:00
Ross Smyth
6967d1c0fc Stabilize exclusive_range 2024-05-02 19:42:31 -04:00
Martin Nordholts
cde0cde151 Change SIGPIPE ui from #[unix_sigpipe = "..."] to -Zon-broken-pipe=...
In the stabilization attempt of `#[unix_sigpipe = "sig_dfl"]`, a concern
was raised related to using a language attribute for the feature: Long
term, we want `fn lang_start()` to be definable by any crate, not just
libstd. Having a special language attribute in that case becomes
awkward.

So as a first step towards towards the next stabilization attempt, this
PR changes the `#[unix_sigpipe = "..."]` attribute to a compiler flag
`-Zon-broken-pipe=...` to remove that concern, since now the language
is not "contaminated" by this feature.

Another point was also raised, namely that the ui should not leak
**how** it does things, but rather what the **end effect** is. The new
flag uses the proposed naming. This is of course something that can be
iterated on further before stabilization.
2024-05-02 19:48:29 +02:00
Matthias Krüger
6cc3959230
Rollup merge of #124622 - fmease:yeet-extern-crate-run_make_support, r=jieyouxu
Cleanup: Rid the `rmake` test runners of `extern crate run_make_support;`

`run_make_support` is part of the *extern prelude* of `rmake` test runners rendering `extern crate run_make_support` redundant:

80451a485b/src/tools/compiletest/src/runtest.rs (L3826-L3827)

~~Contains some fmt'ing changes because I've enabled format-on-save in my editor and because we don't run `x fmt` for `rmake` test runners yet (this gets addressed by #124613). I can revert those if you'd like me to.~~ (reverted)

r? jieyouxu or testing-devex(?) or boostrap(?)
2024-05-02 19:42:49 +02:00
Matthias Krüger
f01e99f191
Rollup merge of #124138 - mati865:ignore-llvm-abi-in-dlltool-tests, r=davidtwco
Ignore LLVM ABI in dlltool tests since those targets don't use dlltool

Otherwise those two tests fail when running `./x.py test` with this target.
2024-05-02 19:42:47 +02:00
León Orell Valerian Liehr
09aa77299b
Cleanup: Rid the rmake test runners of extern crate run_make_support; 2024-05-02 17:57:23 +02:00
Trevor Spiteri
d8e6b81b59 update error messages in ui tests 2024-05-02 15:13:30 +02:00
Guillaume Gomez
1b0972cc61
Rollup merge of #124597 - cuviper:x86-64-v3, r=workingjubilee
Use an explicit x86-64 cpu in tests that are sensitive to it

There are a few tests that depend on some target features **not** being
enabled by default, and usually they are correct with the default x86-64
target CPU. However, in downstream builds we have modified the default
to fit our distros -- `x86-64-v2` in RHEL 9 and `x86-64-v3` in RHEL 10
-- and the latter especially trips tests that expect not to have AVX.

These cases are few enough that we can just set them back explicitly.
2024-05-02 15:11:23 +02:00
Guillaume Gomez
df9f8d0153
Rollup merge of #124568 - Urgau:non-local-defs-doctest, r=michaelwoerister,GuillaumeGomez
Adjust `#[macro_export]`/doctest help suggestion for non_local_defs lint

This PR adjust the help suggestion of the `non_local_definitions` lint when encountering a `#[macro_export]` at top-level doctest.

So instead of a non-sentential help suggestion to move the `macro_rules!` up above the `rustdoc`-generated function. We now suggest users to declare their own function.

Fixes *(partially, needs backport)* #124534
2024-05-02 15:11:22 +02:00
bors
fcc06c894b Auto merge of #123939 - WaffleLapkin:never-fallback-unsafe-lint, r=compiler-errors
Add a lint against never type fallback affecting unsafe code

~~I'm not very happy with the code quality... `VecGraph` not allowing you to get predecessors is very annoying. This should work though, so there is that.~~ (ended up updating `VecGraph` to support getting predecessors)

~~First few commits are from https://github.com/rust-lang/rust/pull/123934 https://github.com/rust-lang/rust/pull/123980~~
2024-05-02 02:41:40 +00:00
Waffle Lapkin
0df43db50c Add proper support for all kinds of unsafe ops to the lint
(never_type_fallback_flowing_into_unsafe)
2024-05-02 03:49:49 +02:00
Maybe Waffle
aa0a916c81 Add a lint against never type fallback affecting unsafe code 2024-05-02 03:47:32 +02:00
bors
f92d49b7fe Auto merge of #124529 - compiler-errors:select, r=lcnr
Rewrite select (in the new solver) to use a `ProofTreeVisitor`

We can use a proof tree visitor rather than collecting and recomputing all the nested goals ourselves.

Based on #124415
2024-05-02 00:36:38 +00:00
Josh Stone
393d9334d9 Use an outlandish target feature for the negative case 2024-05-01 16:55:10 -07:00
Josh Stone
1b79bb937f Add inline comments why we're forcing the target cpu 2024-05-01 16:54:20 -07:00
Josh Stone
706f06c39a Use an explicit x86-64 cpu in tests that are sensitive to it
There are a few tests that depend on some target features **not** being
enabled by default, and usually they are correct with the default x86-64
target CPU. However, in downstream builds we have modified the default
to fit our distros -- `x86-64-v2` in RHEL 9 and `x86-64-v3` in RHEL 10
-- and the latter especially trips tests that expect not to have AVX.

These cases are few enough that we can just set them back explicitly.
2024-05-01 15:25:26 -07:00
Michael Goulet
9834c8307f Rewrite select to use a ProofTreeVisitor 2024-05-01 14:19:34 -04:00
Matthias Krüger
0dbe07f201
Rollup merge of #124566 - lcnr:normalizes-to-proof-tree, r=compiler-errors
fix `NormalizesTo` proof tree issue

fixes #124422
cc #121848

r? ``@compiler-errors``
2024-05-01 20:05:26 +02:00
Urgau
712560cd03 Adjust #[macro_export]/doctest help suggestion for non_local_defs lint 2024-05-01 16:57:20 +02:00
bors
378a43a065 Auto merge of #124539 - Urgau:non-local-defs_modulo_modules, r=lcnr
Consider inner modules to be local in the `non_local_definitions` lint

This PR implements the [proposed fix](https://github.com/rust-lang/rust/issues/124396#issuecomment-2079553642) for #124396, that is to consider inner modules to be local in the `non_local_definitions` lint.

This PR is voluntarily kept as minimal as possible so it can be backported easily.

T-lang [nomination](https://github.com/rust-lang/rust/issues/124396#issuecomment-2079692820) will need to be removed before this can be merged.

Fixes *(nearly, needs backport)* https://github.com/rust-lang/rust/issues/124396
2024-05-01 06:21:31 +00:00
Gurinder Singh
0c71c9d74b Handle normalization failure in struct_tail_erasing_lifetimes
Fixes an ICE that occurred when the struct in question has an error
2024-05-01 09:29:33 +05:30
bors
f5355b93ba Auto merge of #124356 - fmease:fewer-magic-numbers-in-names, r=lcnr
Cleanup: Replace item names referencing GitHub issues or error codes with something more meaningful

**lcnr** in https://github.com/rust-lang/rust/pull/117164#pullrequestreview-1969935387:

> […] while I know that there's precendent to name things `Issue69420`, I really dislike this as it requires looking up the issue to figure out the purpose of such a variant. Actually referring to the underlying issue, e.g. `AliasMayNormToUncovered` or whatever and then linking to the issue in a doc comment feels a lot more desirable to me. We should ideally rename all the functions and enums which currently use issue numbers.

I've grepped through `compiler/` like crazy and think that I've found all instances of this pattern.
However, I haven't renamed `compute_2229_migrations_*`. Should I?

The first commit introduces an abhorrent and super long name for an item because naming is hard but also scary looking / unwelcoming names are good for things related to temporary-ish backcompat hacks. I'll let you discover it by yourself.

Contains a bit of drive-by cleanup and a diag migration bc that was the simplest option.

r? lcnr or compiler
2024-05-01 00:04:36 +00:00
bors
f705de5962 Auto merge of #117164 - fmease:orphan-norm, r=lcnr
Lazily normalize inside trait ref during orphan check & consider ty params in rigid alias types to be uncovered

Fixes #99554, fixes rust-lang/types-team#104.
Fixes #114061.

Supersedes #100555.

Tracking issue for the future compatibility lint: #124559.

r? lcnr
2024-04-30 20:51:46 +00:00
León Orell Valerian Liehr
2a1d748254
Replace item names containing an error code with something more meaningful
or inline such functions if useless.
2024-04-30 22:27:19 +02:00
lcnr
da969d41a3 fix NormalizesTo proof tree issue 2024-04-30 20:03:33 +00:00
León Orell Valerian Liehr
951e902562
Normalize trait ref before orphan check & consider ty params in alias types to be uncovered 2024-04-30 21:54:54 +02:00
许杰友 Jieyou Xu (Joe)
4b6c1918ee
Rollup merge of #124299 - clubby789:106269-test, r=nikic
Add test for issue 106269

Closes #106269

Made this an assembly test as the LLVM codegen is still quite verbose and doesn't really indicate the behaviour we want
2024-04-30 19:29:51 +01:00
许杰友 Jieyou Xu (Joe)
ce18639b92
Rollup merge of #124280 - beetrees:repr128-test-rmake, r=jieyouxu
Port repr128-dwarf run-make test to rmake

This PR ports the repr128-dwarf run-make test to rmake, using the `gimli` crate instead of the `llvm-dwarfdump` command.

Note that this PR changes `rmake.rs` files to be compiled with the 2021 edition (previously no edition was passed to `rustc`, meaning they were compiled with the 2015 edition). This means that `panic!("{variable}")` will now work as expected in `rmake.rs` files (there's already a usage in the [wasm-symbols-not-exported test](aca749eefc/tests/run-make/wasm-symbols-not-exported/rmake.rs (L34)) that this will fix).

Tracking issue: #121876
2024-04-30 19:29:51 +01:00
beetrees
c2fd6ed235
Port repr128-dwarf run-make test to rmake 2024-04-30 17:50:49 +01:00
clubby789
7032c92b33 Add test for efficient codegen of manual eq implementations of a small struct 2024-04-30 13:21:08 +00:00
Zalathar
7c87ad0430 coverage: Add branch coverage support for if-let and let-chains 2024-04-30 22:35:55 +10:00
Zalathar
c9dd07dd5e coverage: Add branch coverage support for let-else 2024-04-30 22:35:54 +10:00
Gurinder Singh
6289ed8428 Remove note about iteration count in coerce
and replace it with a simple note suggesting
returning a value.

The type mismatch error was never due to
how many times the loop iterates. It is more
because of the peculiar structure of what the for
loop desugars to. So the note talking about
iteration count didn't make sense
2024-04-30 12:46:59 +05:30
bors
f973a15a10 Auto merge of #124547 - matthiaskrgr:rollup-9tv8upg, r=matthiaskrgr
Rollup of 4 pull requests

Successful merges:

 - #124519 (adapt a codegen test for llvm 19)
 - #124524 (Add StaticForeignItem and use it on ForeignItemKind)
 - #124540 (Give proof tree visitors the ability to instantiate nested goals directly)
 - #124543 (codegen tests: Tolerate `range()` qualifications in enum tests)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-04-30 04:52:01 +00:00
Matthias Krüger
d81e444c8e
Rollup merge of #124543 - maurer:llvm-range, r=nikic
codegen tests: Tolerate `range()` qualifications in enum tests

Current LLVM can infer range bounds on the i8s involved with these tests, and annotates it. Accept these bounds if present.

`@rustbot` label: +llvm-main

cc `@durin42`
2024-04-30 06:43:43 +02:00
Matthias Krüger
ea3d99eaa8
Rollup merge of #124524 - spastorino:make-foreign-static-use-struct, r=oli-obk
Add StaticForeignItem and use it on ForeignItemKind

This is in preparation for unsafe extern blocks that adds a safe variant for functions inside extern blocks.

r? `@oli-obk`
cc `@compiler-errors`
2024-04-30 06:43:42 +02:00
Matthias Krüger
f4c9f29f27
Rollup merge of #124519 - krasimirgg:test-ranges, r=nikic
adapt a codegen test for llvm 19

No functional changes intended.

Found by our experimental rust + LLVM @ HEAD bot:
https://buildkite.com/llvm-project/rust-llvm-integrate-prototype/builds/27747#018f2570-018c-4b12-9c5a-38cf81453683/957-965

`@rustbot` label: +llvm-main
r? `@durin42`
2024-04-30 06:43:42 +02:00
bors
f9dca46218 Auto merge of #124507 - Zalathar:coverage-level, r=compiler-errors
coverage: Replace boolean options with a `CoverageLevel` enum

After #123409, and some discussion at https://github.com/rust-lang/rust/issues/79649#issuecomment-2042093553 and #124120, it became clear to me that we should have a unified concept of “coverage level”, instead of having several separate boolean flags that aren't actually independent.

This PR therefore introduces a `CoverageLevel` enum, to replace the existing boolean flags for `branch` and `mcdc`.

The `no-branch` value (for `-Zcoverage-options`) has been renamed to `block`, instructing the compiler to only instrument for block coverage, with no branch coverage or MD/DC instrumentation.

`@rustbot` label +A-code-coverage
cc `@ZhuUx` `@Lambdaris` `@RenjiSann`
2024-04-30 02:47:25 +00:00
bors
74a8df6c65 Auto merge of #124398 - klensy:trailing-ws, r=compiler-errors
tests: remove some trailing ws

Cleans one more case of trailing whitespace in tests.
2024-04-30 00:42:32 +00:00
Matthew Maurer
8101884b37 codegen tests: Tolerate range() qualifications in enum tests
Current LLVM can infer range bounds on the i8s involved with these
tests, and annotates it. Accept these bounds if present.
2024-04-30 00:02:49 +00:00
Urgau
21c688af86 Consider inner modules to be local in the non_local_definitions lint 2024-04-29 22:54:04 +02:00
Matthias Krüger
42ab090be9
Rollup merge of #124488 - est31:arbitrary_expressions_error, r=pnkfelix
Add a note to the ArbitraryExpressionInPattern error

The current "arbitrary expressions aren't allowed in patterns" error is confusing, as it fires for code where it *looks* like a pattern but the compiler still treats it as an expression. That this is due to the `:expr` fragment specifier forcing the expression-ness property on the code.

In the test suite, the "arbitrary expressions aren't allowed in patterns" error can only be found in combination with macro_rules macros that force expression-ness of their content, namely via `:expr` metavariables. I also can't come up with cases where there would be an expression instead of a pattern, so I think it's always coming from an `:expr`.

In order to make the error less confusing, this adds a note explaining the weird `:expr` fragment behaviour.

Fixes #99380
2024-04-29 22:37:51 +02:00
许杰友 Jieyou Xu (Joe)
ebce31a053
Rollup merge of #124522 - blyxyas:refactor-is-loaded, r=jieyouxu
[Refactor] Rename `Lint` and `LintGroup`'s `is_loaded` to `is_externally_loaded`

The field being named `is_loaded` was very confusing. Turns out it's true for lints that are registered by external tools like Clippy (I had to look at https://github.com/rust-lang/rust/pull/116412 to know what the variable meant). So I renamed `is_loaded` to `is_externally_loaded` and added some docs.
2024-04-29 18:03:25 +01:00
许杰友 Jieyou Xu (Joe)
43265f5721
Rollup merge of #124504 - gurry:123710-union-ICE, r=oli-obk
Mark unions non-const-propagatable in `KnownPanicsLint` without calling layout

Fixes #123710

The ICE occurs during the layout calculation of the union `InvalidTag` in #123710 because the following assert fails:5fe8b697e7/compiler/rustc_abi/src/layout.rs (L289-L292)

The layout calculation is invoked by `KnownPanicsLint` when it is trying to figure out which locals it can const prop. Since `KnownPanicsLint` is never actually going to const props unions thanks to PR https://github.com/rust-lang/rust/pull/121628 there's no point calling layout to check if it can. So in this fix I skip the call to layout and just mark the local non-const propagatable if it is a union.
2024-04-29 18:03:24 +01:00
许杰友 Jieyou Xu (Joe)
0580588ec6
Rollup merge of #124484 - GKFX:offset_of_must_use, r=jieyouxu
Fix #124478 - offset_of! returns a temporary

This was due to the must_use() call. Adding HIR's `OffsetOf` to the must_use checking within the compiler avoids this issue while maintaining the lint output.

Fixes #124478. `@tgross35`
2024-04-29 18:03:24 +01:00
许杰友 Jieyou Xu (Joe)
f1c53da1cf
Rollup merge of #124269 - scrabsha:sasha/fix-124206, r=dtolnay
Pretty-print parenthesis around binary in postfix match

Fixes #124206.
2024-04-29 18:03:22 +01:00
Santiago Pastorino
f06e0f7837
Add StaticForeignItem and use it on ForeignItemKind 2024-04-29 13:15:51 -03:00
blyxyas
d31b7db8e4 [Refactor] Rename Lint and LintGroup\'s is_loaded to is_externally_loaded 2024-04-29 15:57:09 +02:00
Krasimir Georgiev
52ea73a540 adapt a codegen test for llvm 19
No functional changes intended.

Found by our experimental rust + LLVM @ HEAD bot:
https://buildkite.com/llvm-project/rust-llvm-integrate-prototype/builds/27747#018f2570-018c-4b12-9c5a-38cf81453683/957-965
2024-04-29 13:03:45 +00:00
est31
c6e946d0f0 Change wording 2024-04-29 14:53:38 +02:00
bors
7a58674259 Auto merge of #124255 - RenjiSann:renji/mcdc-nested-expressions, r=Zalathar
MCDC coverage: support nested decision coverage

#123409 provided the initial MCDC coverage implementation.

As referenced in #124144, it does not currently support "nested" decisions, like the following example :

```rust
fn nested_if_in_condition(a: bool, b: bool, c: bool) {
    if a && if b || c { true } else { false } {
        say("yes");
    } else {
        say("no");
    }
}
```

Note that there is an if-expression (`if b || c ...`) embedded inside a boolean expression in the decision of an outer if-expression.

This PR proposes a workaround for this cases, by introducing a Decision context stack, and by handing several `temporary condition bitmaps` instead of just one.
When instrumenting boolean expressions, if the current node is a leaf condition (i.e. not a `||`/`&&` logical operator nor a `!` not operator), we insert a new decision context, such that if there are more boolean expressions inside the condition, they are handled as separate expressions.

On the codegen LLVM side, we allocate as many `temp_cond_bitmap`s as necessary to handle the maximum encountered decision depth.
2024-04-29 11:54:49 +00:00
Zalathar
f9263374fb coverage: Replace boolean options with a CoverageLevel enum 2024-04-29 20:04:22 +10:00
Sasha Pourcelot
c8ff8a4dc7 Pretty-print parenthesis around binary in postfix match
Signed-off-by: Sasha Pourcelot <sasha.pourcelot@protonmail.com>
2024-04-29 11:34:22 +02:00
bors
90846015cc Auto merge of #124505 - Enselic:aux-bin-fix, r=jieyouxu
aux-bin: Avoid old .so files from old tests; clean auxiliary dir root

Also fix the typo pointed out [here](https://github.com/rust-lang/rust/pull/123316/files#r1577081531).

Closes #124465
2024-04-29 09:14:09 +00:00
Dorian Péron
eb422d5c7e tests(mcdc-coverage): Add tests for nested decision structures in mcdc_nested_if.rs 2024-04-29 09:13:41 +00:00
Oli Scherer
90704199fa Bless ui tests 2024-04-29 08:30:05 +00:00
Lin Yihai
589c2fe24d Add raw identifier in a typo suggestion 2024-04-29 15:02:12 +08:00
Martin Nordholts
448d527fd8 Typo fix: exec:ing -> exec'ing 2024-04-29 06:49:39 +02:00
Gurinder Singh
254a9fbe86 Prohibit const prop of unions in KnownPanicsLint
as they have a potential to ICE during layout calculation
2024-04-29 08:16:26 +05:30
bors
1fffb2a355 Auto merge of #124431 - chenyukang:yukang-fix-rustdoc-124363, r=Nadrieril
Fix the assertion crash from rustdoc document indent widths

Fixes #124363
2024-04-28 21:20:07 +00:00
Ryan Lowe
ed9d6e0c03 Move various stdlib tests to library/std/tests 2024-04-28 16:10:12 -04:00
George Bateman
2348eb271c
Update mir-opt tests, add proper regression test 2024-04-28 21:10:09 +01:00
est31
4284bca720 Add a note to the ArbitraryExpressionInPattern error 2024-04-28 21:27:26 +02:00
Matthias Krüger
6edb721a9d
Rollup merge of #124473 - Urgau:port-print-cfg, r=jieyouxu
Port `print-cfg` run-make test to Rust-based rmake.rs

This PR port the `print-cfg` run-make test to Rust-based rmake.rs tests.

The actual test is now split in two:
 - the first part for the `--print=cfg` part
 - and the second part for the `=PATH` part of `--print`

Part of #121876.

r? `@jieyouxu`
2024-04-28 21:02:59 +02:00
George Bateman
ca79086c87
Fix #124478 - offset_of! returns a temporary
This was due to the must_use() call. Adding HIR's OffsetOf to the must_use
checking within the compiler avoids this issue.
2024-04-28 18:36:08 +01:00
Urgau
006c94cfa1 Use named struct arguments instead of comment named args 2024-04-28 17:17:22 +02:00
Urgau
607497d57c Port print-cfg run-make to Rust-based rmake.rs 2024-04-28 17:17:22 +02:00
Matthias Krüger
a15996c9f1 try to fix tests on windows where the "file not found" error is different from linux 2024-04-28 11:07:00 +02:00
Matthias Krüger
f536a06a5a add test for ice expected-type-of-closure-body-to-be-a-closure-or-coroutine-ice-113776.stderr
Fixes https://github.com/rust-lang/rust/issues/113776
2024-04-28 10:23:11 +02:00
Matthias Krüger
27338f2fe0 add test for ice future has no bound vars.
Fixes https://github.com/rust-lang/rust/issues/112347
2024-04-28 10:23:11 +02:00
Matthias Krüger
bb4769532b add test for const generic ty's with lifetimes cause opaque types to ICE
Fixes https://github.com/rust-lang/rust/issues/111911
2024-04-28 10:23:11 +02:00
Matthias Krüger
f483971b87 add test for ICE failed to resolve instance for <[f32; 2] as CrossProduct
Fixes https://github.com/rust-lang/rust/issues/111667
2024-04-28 10:23:10 +02:00
Matthias Krüger
012f9e26ac add test for Inconsistent rustc_transmute::is_transmutable(...) result, got Yes
Fixes https://github.com/rust-lang/rust/issues/110969
2024-04-28 10:23:10 +02:00
Matthias Krüger
c32e2fe179 add test for https://github.com/rust-lang/rust/issues/109812 2024-04-28 10:23:10 +02:00
Matthias Krüger
c968b8b777 add test for ICE: tcx.resolutions(()) is not supported for local crate -Zunpretty=mir on invalid module path with staged_ap
Fixes https://github.com/rust-lang/rust/issues/108697
2024-04-28 10:23:10 +02:00
yukang
6faedd381b Fix the assertion crash from rustdoc document indent widths 2024-04-28 11:17:09 +08:00
Matthias Krüger
289bf549ad
Rollup merge of #124165 - matthiaskrgr:slice-pattern-const-ice-incr, r=Mark-Simulacrum
add test for incremental ICE: slice-pattern-const.rs #83085

Fixes #83085
2024-04-28 01:25:00 +02:00
Matthias Krüger
0430e743e4
Rollup merge of #124425 - saethlin:ceci-nest-pas-une-ice, r=compiler-errors
Do not ICE on invalid consts when walking mono-reachable blocks

The `bug!` here was written under the logic of "this condition is impossible, right?" except that of course, if the compiler is given code that results in an compile error, then the situation is possible.

So now we just direct errors into the already-existing path for when we can't do a mono-time optimization.
2024-04-27 20:46:08 +02:00
Matthias Krüger
aeb4c0413c
Rollup merge of #124394 - gurry:123863-ice-unexpected-region, r=lcnr
Fix ICE on invalid const param types

Fixes ICE #123863 which occurs because the const param has a type which is not a `bool`, `char` or an integral type.

The ICEing code path begins here in `typeck_with_fallback`: cb3752d20e/compiler/rustc_hir_typeck/src/lib.rs (L167)

The `fallback` invokes the `type_of` query and that eventually ends up calling `ct_infer` from the lowering code over here:
cb3752d20e/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs (L561) and `ct_infer` ICEs at this location: cb3752d20e/compiler/rustc_hir_analysis/src/collect.rs (L392)

To fix the ICE it I'm triggering a `span_delayed_bug` before we hit `ct_infer` if the type of the const param is not one of the supported types

### Edit
On `@lcnr's` suggestion I've changed the approach to not let `ReStatic` region hit the `bug!` in `ct_infer` instead of triggering a `span_delayed_bug`.
2024-04-27 20:46:08 +02:00
Matthias Krüger
52ce43e9ac
Rollup merge of #124370 - ShE3py:substitution-part-offset, r=fee1-dead
Fix substitution parts having a shifted underline in some cases

If two suggestions parts are side by side, the underline's offset:
(WIP PR as an example, not yet pushed)
```
error: expected a pattern, found an expression
 --> ./main.rs:4:9
  |
4 |         1 + 2 => 3
  |         ^^^^^ arbitrary expressions are not allowed in patterns
  |
help: check the value in an arm guard
  |
4 |         n if n == 1 + 2 => 3
  |         ~     +++++++++++++
```
The emitter didn't take into account that the string had shrunk/grown if two substitution parts were side-by-side (surprisingly, there was only one case in the ui testsuite.)

```
help: check the value in an arm guard
  |
4 |         n if n == 1 + 2 => 3
  |         ~ +++++++++++++
```

``@rustbot`` label +A-suggestion-diagnostics
2024-04-27 20:46:07 +02:00
klensy
411607bec4 tests: remove some trailing ws 2024-04-27 10:54:31 +03:00
Matthias Krüger
9a6bfc7bfc
Rollup merge of #124427 - gurry:122191-unhandled-type, r=matthiaskrgr
Add missing tests for an ICE

Fixes #122191
2024-04-27 07:55:38 +02:00
Matthias Krüger
cf07246ae9
Rollup merge of #124382 - petrochenkov:itemvisit, r=lcnr
ast: Generalize item kind visiting

And avoid duplicating logic for visiting `Item`s with different kinds (regular, associated, foreign).

The diff is better viewed with whitespace ignored.
2024-04-27 07:55:37 +02:00
Gurinder Singh
fc73b4c344 Add missing tests for an ICE 2024-04-27 11:02:15 +05:30
Gurinder Singh
c62bc31b16 Fix ICE on invalid const param types 2024-04-27 09:36:38 +05:30
Ben Kimock
82cc02a60b Do not ICE on invalid consts when walking mono-reachable blocks 2024-04-26 23:06:21 -04:00
Jacob Pratt
7cb7337c1b
Rollup merge of #124408 - matthiaskrgr:loltest, r=jieyouxu
crashes: add more tests
2024-04-26 19:25:56 -04:00
Jacob Pratt
c8beab7f46
Rollup merge of #124383 - Urgau:port-print-native-static-libs, r=jieyouxu
Port run-make `--print=native-static-libs` to rmake.rs

This PR port the run-make `--print=native-static-libs` test to rmake.rs

The dedup was really awful in the `Makefile`, I'm glad to finally have a proper dedup detection for this.

Related to https://github.com/rust-lang/rust/issues/121876

r? `@jieyouxu`
2024-04-26 19:25:55 -04:00
Urgau
7688f798d5 Also support MSVC in print-native-static-libs test 2024-04-27 00:26:06 +02:00
Urgau
74cbc09fc9 Port run-make --print=native-static-libs to rmake.rs 2024-04-26 19:45:45 +02:00
bors
1b3a32958b Auto merge of #122385 - lcnr:analyze-obligations-for-infer, r=compiler-errors
`obligations_for_self_ty`: use `ProofTreeVisitor` for nested goals

As always, dealing with proof trees continues to be a hacked together mess. After this PR and #124380 the only remaining blocker for core is https://github.com/rust-lang/trait-system-refactor-initiative/issues/90. There is also a `ProofTreeVisitor` issue causing an ICE when compiling `alloc` which I will handle in a separate PR. This issue likely affects coherence diagnostics more generally.

The core idea is to extend the proof tree visitor to support visiting nested candidates without using a `probe`. We then simply recurse into nested candidates if they are the only potentially applicable candidate for a given goal and check whether the self type matches the expected one.

For that to work, we need to improve `CanonicalState` to also handle unconstrained inference variables created inside of the trait solver. This is done by extending the `var_values` of `CanoncalState` with each fresh inference variables. Furthermore, we also store the state of all inference variables at the end of each probe. When recursing into `InspectCandidates` we then unify the values of all these states.

r? `@compiler-errors`
2024-04-26 15:37:05 +00:00
Matthias Krüger
60c0fa1285 crashes: add more tests 2024-04-26 17:20:16 +02:00
bors
6acb9e75eb Auto merge of #120845 - petrochenkov:debmac, r=oli-obk
debuginfo: Stabilize `-Z debug-macros`, `-Z collapse-macro-debuginfo` and `#[collapse_debuginfo]`

`-Z debug-macros` is "stabilized" by enabling it by default and removing.

`-Z collapse-macro-debuginfo` is stabilized as `-C collapse-macro-debuginfo`.
It now supports all typical boolean values (`parse_opt_bool`) in addition to just yes/no.

Default value of `collapse_debuginfo` was changed from `false` to `external` (i.e. collapsed if external, not collapsed if local) - https://github.com/rust-lang/rust/issues/100758#issuecomment-1935815625 describes some debugging scenarios that motivate this default as reasonable.
`#[collapse_debuginfo]` attribute without a value is no longer supported to avoid guessing the default.

Stabilization report: https://github.com/rust-lang/rust/pull/120845#issuecomment-1939145242

Closes https://github.com/rust-lang/rust/issues/100758
Closes https://github.com/rust-lang/rust/issues/41743
Closes https://github.com/rust-lang/rust/issues/39153
2024-04-26 02:13:08 +00:00
Vadim Petrochenkov
683ad6b607 Update lldb only tests 2024-04-26 04:11:05 +03:00
Michael Goulet
ef5e42af59
Rollup merge of #124378 - dpaoliello:keeplib, r=jieyouxu
Keep the LIB env var in the compiler-builtins test

The `tests/run-make/compiler-builtins` test was failing for me with Visual Studio 2022, complaining that it couldn't find `kernel32.lib`.

For whatever reason, with VS 2022 we need to keep the `LIB` environment variable when invoking Cargo so that the linker can find the Windows SDK libs.
2024-04-25 20:07:41 -04:00
Daniel Paoliello
29f2e27156 Keep the LIB env var in the compiler-builtins test 2024-04-25 13:49:46 -07:00
bors
3a36386dc1 Auto merge of #124386 - matthiaskrgr:rollup-0a6yr00, r=matthiaskrgr
Rollup of 3 pull requests

Successful merges:

 - #124313 (Detect borrow error involving sub-slices and suggest `split_at_mut`)
 - #124374 (Don't ICE when `codegen_select_candidate` returns ambiguity in new solver)
 - #124380 (`Range` iteration specialization: remove trivial bounds)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-04-25 20:31:14 +00:00
Vadim Petrochenkov
5be9fdd636 ast: Generalize item kind visiting
And avoid duplicating logic for visiting `Item`s with different kinds (regular, associated, foreign).
2024-04-25 22:49:58 +03:00
lcnr
03878c682a hir typeck: look into nested goals
uses a `ProofTreeVisitor` to look into nested
goals when looking at the pending obligations
during hir typeck. Used by closure signature
inference, coercion, and for async functions.
2024-04-25 19:44:00 +00:00
Vadim Petrochenkov
98804c1786 debuginfo: Stabilize -Z debug-macros, -Z collapse-macro-debuginfo and #[collapse_debuginfo]
`-Z debug-macros` is "stabilized" by enabling it by default and removing.

`-Z collapse-macro-debuginfo` is stabilized as `-C collapse-macro-debuginfo`.
It now supports all typical boolean values (`parse_opt_bool`) in addition to just yes/no.

Default value of `collapse_debuginfo` was changed from `false` to `external` (i.e. collapsed if external, not collapsed if local).
`#[collapse_debuginfo]` attribute without a value is no longer supported to avoid guessing the default.
2024-04-25 22:14:47 +03:00
Matthias Krüger
6c21abf291
Rollup merge of #124374 - compiler-errors:fix-ambiguity-ice, r=lcnr
Don't ICE when `codegen_select_candidate` returns ambiguity in new solver

Because we merge identical candidates, we may have >1 impl candidate to in `codegen_select_error` but *not* have a trait error.

r? lcnr
2024-04-25 21:12:17 +02:00
Matthias Krüger
60c825f1e1
Rollup merge of #124313 - estebank:split-at-mut, r=fee1-dead
Detect borrow error involving sub-slices and suggest `split_at_mut`

```
error[E0499]: cannot borrow `foo` as mutable more than once at a time
  --> $DIR/suggest-split-at-mut.rs:13:18
   |
LL |     let a = &mut foo[..2];
   |                  --- first mutable borrow occurs here
LL |     let b = &mut foo[2..];
   |                  ^^^ second mutable borrow occurs here
LL |     a[0] = 5;
   |     ---- first borrow later used here
   |
   = help: use `.split_at_mut(position)` or similar method to obtain two mutable non-overlapping sub-slices
```

Address most of #58792.

For follow up work, we should emit a structured suggestion for cases where we can identify the exact `let (a, b) = foo.split_at_mut(2);` call that is needed.
2024-04-25 21:12:17 +02:00
bors
38dd569150 Auto merge of #124377 - matthiaskrgr:rollup-ajxjq35, r=matthiaskrgr
Rollup of 2 pull requests

Successful merges:

 - #124287 (Improved code with clippy)
 - #124326 (tests: remove few ignore-stage2)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-04-25 17:12:29 +00:00
Matthias Krüger
c125e9d9e0
Rollup merge of #124326 - klensy:ignore-stage2, r=compiler-errors
tests: remove few ignore-stage2

beta was branched long ago, so can be removed
2024-04-25 18:57:56 +02:00
Esteban Küber
abdb64d4ea Check equivalence of indices in more cases 2024-04-25 16:55:33 +00:00
Esteban Küber
ad6ae61246 Don't suggest split_at_mut when the multiple borrows have the same index 2024-04-25 16:55:33 +00:00
Esteban Küber
9f9f0aa534 Mention split_at_mut when mixing mutability in indexing ops
Emit suggestion when encountering

```rust
let a = &mut foo[0];
let b = &foo[1];
a.use_mut();
```
2024-04-25 16:55:33 +00:00