Commit graph

7506 commits

Author SHA1 Message Date
Matthias Krüger 176c4ba5c3
Rollup merge of #120423 - RalfJung:indirect-structural-match, r=petrochenkov
update indirect structural match lints to match RFC and to show up for dependencies

This is a large step towards implementing https://github.com/rust-lang/rfcs/pull/3535.
We currently have five lints related to "the structural match situation":
- nontrivial_structural_match
- indirect_structural_match
- pointer_structural_match
- const_patterns_without_partial_eq
- illegal_floating_point_literal_pattern

This PR concerns the first 3 of them. (The 4th already is set up to show for dependencies, and the 5th is removed by https://github.com/rust-lang/rust/pull/116284.) nontrivial_structural_match is being removed as per the RFC; the other two are enabled to show up in dependencies.

Fixes https://github.com/rust-lang/rust/issues/73448 by removing the affected analysis.
2024-02-06 22:45:41 +01:00
Matthias Krüger a0c3b87823
Rollup merge of #120396 - estebank:method-on-unbounded-type-param, r=nnethercote
Account for unbounded type param receiver in suggestions

When encountering

```rust
fn f<T>(a: T, b: T) -> std::cmp::Ordering {
    a.cmp(&b) //~ ERROR E0599
}
```

output

```
error[E0599]: no method named `cmp` found for type parameter `T` in the current scope
  --> $DIR/method-on-unbounded-type-param.rs:2:7
   |
LL | fn f<T>(a: T, b: T) -> std::cmp::Ordering {
   |      - method `cmp` not found for this type parameter
LL |     a.cmp(&b)
   |       ^^^ method cannot be called on `T` due to unsatisfied trait bounds
   |
   = help: items from traits can only be used if the type parameter is bounded by the trait
help: the following traits define an item `cmp`, perhaps you need to restrict type parameter `T` with one of them:
   |
LL | fn f<T: Ord>(a: T, b: T) -> std::cmp::Ordering {
   |       +++++
LL | fn f<T: Iterator>(a: T, b: T) -> std::cmp::Ordering {
   |       ++++++++++
```

Fix #120186.
2024-02-06 22:45:40 +01:00
Matthias Krüger 3c52832375
Rollup merge of #119939 - clubby789:static-const-generic-note, r=compiler-errors
Improve 'generic param from outer item' error for `Self` and inside `static`/`const` items

Fixes #109596
Fixes #119936
2024-02-06 22:45:39 +01:00
Matthias Krüger d98a8a1185
Rollup merge of #120713 - compiler-errors:async-bounds-on-tests, r=fmease
Make async closures test use async bound modifier

Cosmetic change, separates the `AsyncFn` definitions from the tests.
2024-02-06 19:40:11 +01:00
Matthias Krüger eae477d4e8
Rollup merge of #120632 - trevyn:issue-109195, r=oli-obk
For E0223, suggest associated functions that are similar to the path

e.g. for `String::from::utf8`, suggest `String::from_utf8`

Closes #109195
2024-02-06 19:40:09 +01:00
Matthias Krüger 89aa85d805
Rollup merge of #120597 - fmease:sugg-on-js-style-spread-op-in-pat, r=estebank
Suggest `[tail @ ..]` on `[..tail]` and `[...tail]` where `tail` is unresolved

Fixes #120591.
~~Will conflict with #120570~~ (rebased).

r? estebank or compiler
2024-02-06 19:40:07 +01:00
Matthias Krüger 5587be8164
Rollup merge of #120520 - nnethercote:rename-good-path, r=oli-obk
Some cleanups around diagnostic levels.

Plus some refactoring in and around diagnostic levels and emission. Details in the individual commit logs.

r? ````@oli-obk````
2024-02-06 19:40:06 +01:00
Michael Goulet f1308783b4 Make async closures test use async bound modifier 2024-02-06 17:41:48 +00:00
bors 4a2fe4491e Auto merge of #120361 - compiler-errors:async-closures, r=oli-obk
Rework support for async closures; allow them to return futures that borrow from the closure's captures

This PR implements a new lowering for async closures via `TyKind::CoroutineClosure` which handles the curious relationship between the closure and the coroutine that it returns.

I wrote up a bunch in [this hackmd](https://hackmd.io/`@compiler-errors/S1HvqQxca)` which will be copied to the dev guide after this PR lands, and hopefully left sufficient comments in the source code explaining why this change is as large as it is.

This also necessitates that they begin implementing the `AsyncFn`-family of traits, rather than the `Fn`-family of traits -- if you need `Fn` implementations, you should probably use the non-sugar `|| async {}` syntax instead.

Notably this PR does not yet implement `async Fn()` syntax sugar for bounds, but I expect to add those soon (**edit:** #120392). For now, users must use `AsyncFn()` traits directly, which necessitates adding the `async_fn_traits` feature gate as well. I will add this as a follow-up very soon.

r? oli-obk

This is based on top of #120322, but that PR is minimal.
2024-02-06 15:04:01 +00:00
bors ff95e52665 Auto merge of #120326 - tmandry:abort-in-tests, r=cuviper
Actually abort in -Zpanic-abort-tests

When a test fails in panic=abort, it can be useful to have a debugger or other tooling hook into the `abort()` call for debugging. Doing this some other way would require it to hard code details of Rust's panic machinery.

There's no reason we couldn't have done this in the first place; using a single exit code for "success" or "failed" was just simpler. Now we are aware of the special exit codes for posix and windows platforms, logging a special error if an unrecognized code is used on those platforms, and falling back to just "failure" on other platforms.

This continues to account for `#[should_panic]` inside the test process itself, so there's no risk of misinterpreting a random call to `abort()` as an expected panic. Any exit code besides `TR_OK` is logged as a test failure.

As an added benefit, this would allow us to support panic=immediate_abort (but not `#[should_panic]`), without noise about unexpected exit codes when a test fails.
2024-02-06 04:15:41 +00:00
trevyn 0b6af718d8 Create helper maybe_report_similar_assoc_fn 2024-02-05 18:53:28 -08:00
Michael Goulet ed7fca1f88 Fudge coroutine argument for CoroutineKindShim in fn_sig_for_fn_abi 2024-02-06 02:53:06 +00:00
Michael Goulet ca44416023 Fix drop shim for AsyncFnOnce closure, AsyncFnMut shim for AsyncFn closure 2024-02-06 02:22:58 +00:00
Michael Goulet 37184e86ea Add some tests 2024-02-06 02:22:58 +00:00
Michael Goulet 881b6b5149 Bless tests, add comments 2024-02-06 02:22:58 +00:00
Michael Goulet 427896dd7e Construct body for by-move coroutine closure output 2024-02-06 02:22:58 +00:00
Michael Goulet c567eddec2 Add CoroutineClosure to TyKind, AggregateKind, UpvarArgs 2024-02-06 02:22:58 +00:00
Michael Goulet b2bb51734c Make sure that async closures (and fns) only capture their parent callable's parameters by move, and nothing else 2024-02-06 02:22:57 +00:00
bors f3b9d47a46 Auto merge of #120392 - compiler-errors:async-bound-modifier, r=davidtwco,fmease
Introduce support for `async` bound modifier on `Fn*` traits

Adds `async` to the list of `TraitBoundModifiers`, which instructs AST lowering to map the trait to an async flavor of the trait. For now, this is only supported for `Fn*` to `AsyncFn*`, and I expect that this manual mapping via lang items will be replaced with a better system in the future.

The motivation for adding these bounds is to separate the users of async closures from the exact trait desugaring of their callable bounds. Instead of users needing to be concerned with the `AsyncFn` trait, they should be able to write `async Fn()` and it will desugar to whatever underlying trait we decide is best for the lowering of async closures.

Note: rustfmt support can be done in the rustfmt repo after a subtree sync.
2024-02-06 00:45:11 +00:00
Ralf Jung e00df17abd merge the accepted-structural-match tests into one 2024-02-05 20:36:11 +01:00
Ralf Jung 45d01b8131 update the tracking issue for structural match violations
and bless a test I missed
2024-02-05 20:36:11 +01:00
Ralf Jung 48abca761a show indirect_structural_match and pointer_structural_match in future compat reports 2024-02-05 20:36:11 +01:00
Ralf Jung 9f58cf43c7 get rid of nontrivial_structural_match lint and custom_eq const qualif 2024-02-05 20:36:09 +01:00
bors ea37e8091f Auto merge of #117372 - Amanieu:stdarch_update, r=Mark-Simulacrum
Update stdarch submodule

Splits up #27731 into multiple tracking issues.

Closes #27731
2024-02-05 15:41:40 +00:00
Matthias Krüger 2624bfbc0d
Rollup merge of #120384 - wackbyte:array-equality-generics, r=Mark-Simulacrum
Use `<T, U>` for array/slice equality `impl`s

Makes the trait implementation documentation for arrays and slices appear more consistent.

[Example](https://doc.rust-lang.org/1.75.0/std/primitive.array.html): mixed `A`, `B`, and `U`.
![List of PartialEq implementations for arrays](https://github.com/wackbyte/rust/assets/29505620/823c010e-ee57-4de1-885b-a1cd6dcaf85f)

This change makes them all `U`.
2024-02-05 11:07:27 +01:00
Matthias Krüger ed27148812
Rollup merge of #116284 - RalfJung:no-nan-match, r=cjgillot
make matching on NaN a hard error, and remove the rest of illegal_floating_point_literal_pattern

These arms would never be hit anyway, so the pattern makes little sense. We have had a future-compat lint against float matches in general for a *long* time, so I hope we can get away with immediately making this a hard error.

This is part of implementing https://github.com/rust-lang/rfcs/pull/3535.

Closes https://github.com/rust-lang/rust/issues/41620 by removing the lint.

https://github.com/rust-lang/reference/pull/1456 updates the reference to match.
2024-02-05 11:07:26 +01:00
Matthias Krüger 7294c15f41
Rollup merge of #120569 - Zalathar:fn-sig, r=oli-obk
coverage: Improve handling of function/closure spans

This is a combination of some loosely-related changes that touch the same code:

1. Make unexpansion of closure bodies more precise, by unexpanding back to the context of the closure declaration, instead of unexpanding all the way back to the top-level context. This preserves the way we handle async desugaring and closures containing a single bang-macro, while also giving better results for closures defined in macros.
2. Skip the normal span-refinement code when dealing with the trivial outer part of an async function.
3. Be more explicit about the fact that `fn_sig_span` has been extended to the start of the function body, and is not necessarily present.

---

`@rustbot` label +A-code-coverage
2024-02-05 06:37:15 +01:00
Zalathar dd6d7f27e4 coverage: Make unexpansion of closure bodies more precise
This improves the coverage instrumentation of closures declared in macros, as
seen in `closure_macro.rs` and `closure_macro_async.rs`.
2024-02-05 10:09:46 +11:00
Zalathar 8dd2b37462 coverage: Add a test for #[coverage(..)] on closures 2024-02-05 10:07:19 +11:00
Zalathar fe420dc46e coverage: Test for closure body that is a single bang-macro 2024-02-05 10:07:18 +11:00
Nicholas Nethercote 59e0bc2de7 Split Level::DelayedBug in two.
The two kinds of delayed bug have quite different semantics so a
stronger conceptual separation is nice. (`is_error` is a good example,
because the two kinds have different behaviour.)

The commit also moves the `DelayedBug` variant after `Error` in `Level`,
to reflect the fact that it's weaker than `Error` -- it might trigger an
error but also might not. (The pre-existing `downgrade_to_delayed_bug`
function also reflects the notion that delayed bugs are lower/after
normal errors.)

Plus it condenses some of the comments on `Level` into a table, for
easier reading, and introduces `can_be_top_or_sub` to indicate which
levels can be used in top-level diagnostics vs. subdiagnostics.

Finally, it renames `DiagCtxtInner::span_delayed_bugs` as
`DiagCtxtInner::delayed_bugs`. The `span_` prefix is unnecessary because
some delayed bugs don't have a span.
2024-02-05 10:03:01 +11:00
bors 4d87c4ad62 Auto merge of #120649 - matthiaskrgr:rollup-ek80j61, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #119759 (Add FileCheck annotations to dataflow-const-prop tests)
 - #120323 (On E0277 be clearer about implicit `Sized` bounds on type params and assoc types)
 - #120473 (Only suggest removal of `as_*` and `to_` conversion methods on E0308)
 - #120540 (add test for try-block-in-match-arm)
 - #120547 (`#![feature(inline_const_pat)]` is no longer incomplete)
 - #120552 (Correctly check `never_type` feature gating)
 - #120555 (put pnkfelix (me) back on the review queue.)
 - #120556 (Improve the diagnostics for unused generic parameters)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-02-04 22:55:40 +00:00
León Orell Valerian Liehr 285d8c225d
Suggest [tail @ ..] on [..tail] and [...tail] where tail is unresolved 2024-02-04 22:16:21 +01:00
bors 268dbbbc4b Auto merge of #120624 - matthiaskrgr:rollup-3gvcl20, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #120484 (Avoid ICE when is_val_statically_known is not of a supported type)
 - #120516 (pattern_analysis: cleanup manual impls)
 - #120517 (never patterns: It is correct to lower `!` to `_`.)
 - #120523 (Improve `io::Read::read_buf_exact` error case)
 - #120528 (Store SHOULD_CAPTURE as AtomicU8)
 - #120529 (Update data layouts in custom target tests for LLVM 18)
 - #120531 (Remove a bunch of `has_errors` checks that have no meaningful or the wrong effect)
 - #120533 (Correct paths for hexagon-unknown-none-elf platform doc)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-02-04 20:51:28 +00:00
Matthias Krüger 7fa99bfb71
Rollup merge of #120556 - fmease:improve-unused-generic-param-diags, r=oli-obk
Improve the diagnostics for unused generic parameters

* Don't emit two errors (namely E0091 *and* E0392) for unused type parameters on *lazy* type aliases
* Fix the diagnostic help message of E0392 for *lazy* type aliases: Don't talk about the “fields” of lazy type aliases (use the term “body” instead) and don't suggest `PhantomData` for them, it doesn't make much sense
* Consolidate the diagnostics for E0091 (unused type parameters in type aliases) and E0392 (unused generic parameters due to bivariance) and make it translatable
  * Still keep the error codes distinct (for now)
  * Naturally leads to better diagnostics for E0091

r? ```@oli-obk``` (to ballast your review load :P) or compiler
2024-02-04 19:42:12 +01:00
Matthias Krüger c2ad283f4e
Rollup merge of #120552 - GuillaumeGomez:never-type-feature-gate, r=compiler-errors
Correctly check `never_type` feature gating

Fixes #120542.

The feature wasn't tested on return type of a generic function type, so it got under the radar in https://github.com/rust-lang/rust/pull/120316.

r? ```@compiler-errors```
2024-02-04 19:42:11 +01:00
Matthias Krüger fa7d3e9af1
Rollup merge of #120547 - matthewjasper:complete-inline-const-pat, r=compiler-errors
`#![feature(inline_const_pat)]` is no longer incomplete

Now that borrow checking and safety checking is implemented for inline constant patterns, the incomplete feature status is not necessary. Stabilizing this feature requires more testing and has some of the same unresolved questions as inline constants.

cc #76001
2024-02-04 19:42:11 +01:00
Matthias Krüger 592beb1c25
Rollup merge of #120540 - Fishrock123:test-try-block-in-match-arm, r=compiler-errors
add test for try-block-in-match-arm

This is noted as an implementation concern under the tracking issue for `?` and `try` blocks. (Issue 31436)

Refs: https://github.com/rust-lang/rust/issues/31436
2024-02-04 19:42:10 +01:00
Matthias Krüger b23945c9b2
Rollup merge of #120473 - estebank:issue-114329, r=TaKO8Ki
Only suggest removal of `as_*` and `to_` conversion methods on E0308

Instead of

```
error[E0308]: mismatched types
 --> tests/ui/suggestions/only-suggest-removal-of-conversion-method-calls.rs:9:5
  |
4 | fn get_name() -> String {
  |                  ------ expected `String` because of return type
...
9 |     your_name.trim()
  |     ^^^^^^^^^^^^^^^^ expected `String`, found `&str`
  |
help: try removing the method call
  |
9 -     your_name.trim()
9 +     your_name
```

output

```
error[E0308]: mismatched types
  --> $DIR/only-suggest-removal-of-conversion-method-calls.rs:9:5
   |
LL | fn get_name() -> String {
   |                  ------ expected `String` because of return type
...
LL |     your_name.trim()
   |     ^^^^^^^^^^^^^^^^- help: try using a conversion method: `.to_string()`
   |     |
   |     expected `String`, found `&str`
```

Fix #114329.
2024-02-04 19:42:10 +01:00
Matthias Krüger 6af04583a6
Rollup merge of #120323 - estebank:issue-120178, r=fmease
On E0277 be clearer about implicit `Sized` bounds on type params and assoc types

```
error[E0277]: the size for values of type `[i32]` cannot be known at compilation time
   --> f100.rs:2:33
    |
2   |     let _ = std::mem::size_of::<[i32]>();
    |                                 ^^^^^ doesn't have a size known at compile-time
    |
    = help: the trait `Sized` is not implemented for `[i32]`
note: required by an implicit `Sized` bound in `std::mem::size_of`
   --> /home/gh-estebank/rust/library/core/src/mem/mod.rs:312:22
    |
312 | pub const fn size_of<T>() -> usize {
    |                      ^ required by the implicit `Sized` requirement on this bound in `size_of`
```

Fix #120178.
2024-02-04 19:42:09 +01:00
Matthias Krüger 2b259577aa
Rollup merge of #119759 - sfzhu93:master, r=cjgillot
Add FileCheck annotations to dataflow-const-prop tests

part of #116971.

A few shadowing variable names are changed, so that it is easier to match the variable names in MIR using FileCheck syntax.

Also, there's a FIXME in [enum.rs](https://github.com/rust-lang/rust/pull/119759/files#diff-7621f55327838e489a95ac99ae1e6126b37c57aff582594e6bee9d7e7e56fc58) because the MIR looks suspicious to me. It has been explained in the comments.

r? cjgillot
2024-02-04 19:42:09 +01:00
trevyn a4cb55f2ac For E0223, suggest methods that look similar to the path 2024-02-03 19:29:28 -08:00
Matthias Krüger 7d516c57df
Rollup merge of #120531 - oli-obk:track_errors7, r=estebank
Remove a bunch of `has_errors` checks that have no meaningful or the wrong effect

r? `@nnethercote`
2024-02-03 22:25:16 +01:00
Matthias Krüger 69920786ba
Rollup merge of #120529 - nikic:llvm-18-datalayout-fixes, r=cuviper
Update data layouts in custom target tests for LLVM 18

Apply the data layout changes from https://github.com/rust-lang/rust/pull/116672 to custom target specs as well, as we started validating them since https://github.com/rust-lang/rust/pull/120062.

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

r? ```@cuviper```
2024-02-03 22:25:16 +01:00
Matthias Krüger 6f24836a5b
Rollup merge of #120484 - Teapot4195:issue-120480-fix, r=compiler-errors
Avoid ICE when is_val_statically_known is not of a supported type

2 ICE with 1 stone!
1. Implement `llvm.is.constant.ptr` to avoid first ICE in linked issue.
2. return `false` when the argument is not one of `i*`/`f*`/`ptr` to avoid second ICE.

fixes #120480
2024-02-03 22:25:14 +01:00
Matthias Krüger 326839bf7f
Rollup merge of #120616 - fmease:fix-ice-const-eval-fail-undef-field-access, r=compiler-errors
Fix ICE on field access on a tainted type after const-eval failure

Fixes #120615.

r? oli-obk or compiler
2024-02-03 21:29:45 +01:00
Matthias Krüger b9c87b41d3
Rollup merge of #120571 - nnethercote:misc-diagnostics, r=oli-obk
Miscellaneous diagnostics cleanups

All found while working on some speculative, invasive changes, but worth doing in their own right.

r? `@oli-obk`
2024-02-03 21:29:42 +01:00
Matthias Krüger 7c932d9940
Rollup merge of #120570 - fmease:change-ty-to-ct-param-sugg, r=compiler-errors
Suggest changing type to const parameters if we encounter a type in the trait bound position

The first commit is just drive-by cleanup.

Provide a structured suggestion if the user forgot to prefix a “const parameter” with `const`, e.g., in `struct Tagged<TAG: u64>;`. This happens to me from time to time. Maybe C++ devs are also prone to this mistake given template syntax looks like `template<typename T, uint32_t N>`.
2024-02-03 21:29:42 +01:00
Matthias Krüger 892b0fd787
Rollup merge of #120566 - Zalathar:edition, r=compiler-errors
coverage: Use normal `edition:` headers in coverage tests

Some of these tests were originally written as part of a custom `run-make` test, so at that time they weren't able to use the normal compiletest header directive parser.

Now that they're properly integrated, there's no need for them to use `compile-flags` to specify the edition, since they can use `edition` instead.

In most cases the `.cov-map` snapshot isn't affected at all, but in a few cases we add or remove a line, which slightly disturbs the first line number in each instrumented function.
2024-02-03 21:29:41 +01:00
Matthias Krüger 977945d285
Rollup merge of #120562 - oli-obk:revert_stuff, r=cuviper
Revert unsound libcore changes

fixes #120537

these were introduced in #119911
2024-02-03 21:29:41 +01:00