392 Commits

Author SHA1 Message Date
Karol Zwolak
d14b83e378 bless tests with new lint messages 2025-08-19 21:27:10 +02:00
Oneirical
75e0263af9 Rehome tests/ui/issues/ tests [5/?] 2025-08-17 13:01:02 -04:00
Jacob Pratt
5bd4e832d3
Rollup merge of #144553 - Oneirical:uncountable-integer-4, r=jieyouxu
Rehome 32 `tests/ui/issues/` tests to other subdirectories under `tests/ui/`

rust-lang/rust#143902 divided into smaller, easier to review chunks.

Part of rust-lang/rust#133895

Methodology:

1. Refer to the previously written `tests/ui/SUMMARY.md`
2. Find an appropriate category for the test, using the original issue thread and the test contents.
3. Add the issue URL at the bottom (not at the top, as that would mess up stderr line numbers)
4. Rename the tests to make their purpose clearer

Inspired by the methodology that `@Kivooeo` was using.

r? `@jieyouxu`
2025-08-10 15:43:52 -04:00
Oneirical
aa543963c6 Rehome tests/ui/issues/ tests [4/?] 2025-08-10 11:54:15 -04:00
Stuart Cook
62b406d4b1
Rollup merge of #144403 - Kivooeo:issue4, r=jieyouxu
`tests/ui/issues/`: The Issues Strike Back [4/N]

Some `tests/ui/issues/` housekeeping, to trim down number of tests directly under `tests/ui/issues/`. Part of https://github.com/rust-lang/rust/issues/133895.

r? ````````@jieyouxu````````
2025-08-10 19:45:48 +10:00
Kivooeo
16765639b3 comments 2025-08-09 16:27:20 +05:00
Trevor Gross
18abf3aa44
Rollup merge of #144545 - ChayimFriedman2:bool-witness-order, r=Nadrieril
In rustc_pattern_analysis, put `true` witnesses before `false` witnesses

In rustc it doesn't really matter what the order of the witnesses is, but I'm planning to use the witnesses for implementing the "add missing match arms" assist in rust-analyzer, and there `true` before `false` is the natural order (like `Some` before `None`), and also what the current assist does.

The current order doesn't seem to be intentional; the code was created when bool ctors became their own thing, not just int ctors, but for integer, 0 before 1 is indeed the natural order.

r? `@Nadrieril`
2025-08-08 14:22:44 -05:00
Stuart Cook
cb271d055e
Rollup merge of #144400 - Kivooeo:issue3, r=jieyouxu
`tests/ui/issues/`: The Issues Strike Back [3/N]

Some `tests/ui/issues/` housekeeping, to trim down number of tests directly under `tests/ui/issues/`. Part of https://github.com/rust-lang/rust/issues/133895.

r? ```@jieyouxu```
2025-08-08 12:52:49 +10:00
dianne
b7de539805 lower bindings in the order they're written 2025-08-06 12:13:40 -07:00
Kivooeo
b6e13e3591 comments 2025-08-05 19:34:46 +05:00
Kivooeo
62c92f30cf moved 35 tests to organized locations 2025-08-05 19:02:23 +05:00
Samuel Tardieu
58b00b088e
Rollup merge of #144548 - Oneirical:uncountable-integer-2, r=jieyouxu
Rehome 21 `tests/ui/issues/` tests to other subdirectories under `tests/ui/`

rust-lang/rust#143902 divided into smaller, easier to review chunks.

Part of rust-lang/rust#133895

Methodology:

1. Refer to the previously written `tests/ui/SUMMARY.md`
2. Find an appropriate category for the test, using the original issue thread and the test contents.
3. Add the issue URL at the bottom (not at the top, as that would mess up stderr line numbers)
4. Rename the tests to make their purpose clearer

Inspired by the methodology that ``@Kivooeo`` was using.

r? ``@jieyouxu``
2025-08-05 03:51:33 +02:00
Oneirical
807d3406c2 Rehome tests/ui/issues/ tests [2/?] 2025-08-02 15:29:16 -04:00
Matthias Krüger
a08ced3856
Rollup merge of #144151 - Kivooeo:issue1, r=jieyouxu
`tests/ui/issues/`: The Issues Strike Back [1/N]

I believe I’ve finally brought [my program](https://github.com/Kivooeo/test-manager) to life -- it now handles multiple test moves in one go: plain moves first, then a gentle touch on each file depends on given options. The process should be much smoother now.

Of course, I won’t rush through everything in a few days -- that would be unkind to `@Oneirical.` I’ll pace myself. And also I can't have more than one such PR because `issues.txt` will conflict with previous parts after merging them which is not fun as well.

This PR is just that: first commit - moves; second - regression comments and the occasional .stderr reblesses, also issue.txt and tidy changes. Nothing special, but progress nonetheless. This is for the purpose of preserving test file history during restructuring

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

r? `@jieyouxu`
2025-07-28 08:36:51 +02:00
Chayim Refael Friedman
6bf3cbe39e In rustc_pattern_analysis, put true witnesses before false witnesses
In rustc it doesn't really matter what the order of the witnesses is, but I'm planning to use the witnesses for implementing the "add missing match arms" assist in rust-analyzer, and there `true` before `false` is the natural order (like `Some` before `None`), and also what the current assist does.

The current order doesn't seem to be intentional; the code was created when bool ctors became their own thing, not just int ctors, but for integer, 0 before 1 is indeed the natural order.
2025-07-28 02:01:39 +03:00
Esteban Küber
11061831f7 Mention type that could be Clone but isn't in more cases
When encountering a moved value of a type that isn't `Clone` because of unmet obligations, but where all the unmet predicates reference crate-local types, mention them and suggest cloning, as we do in other cases already:

```
error[E0507]: cannot move out of `foo`, a captured variable in an `Fn` closure
  --> f111.rs:14:25
   |
13 | fn do_stuff(foo: Option<Foo>) {
   |             --- captured outer variable
14 |     require_fn_trait(|| async {
   |                      -- ^^^^^ `foo` is moved here
   |                      |
   |                      captured by this `Fn` closure
15 |         if foo.map_or(false, |f| f.foo()) {
   |            ---
   |            |
   |            variable moved due to use in coroutine
   |            move occurs because `foo` has type `Option<Foo>`, which does not implement the `Copy` trait
   |
note: if `Foo` implemented `Clone`, you could clone the value
  --> f111.rs:4:1
   |
4  | struct Foo;
   | ^^^^^^^^^^ consider implementing `Clone` for this type
...
15 |         if foo.map_or(false, |f| f.foo()) {
   |            --- you could clone this value
```
2025-07-25 18:34:10 +00:00
Kivooeo
e9959aa74e comments 2025-07-25 20:38:54 +05:00
Kivooeo
9f38ca97ea move 28 tests 2025-07-25 20:38:54 +05:00
Kivooeo
90bb5cacb5 moved 34 tests to organized locations 2025-07-25 15:34:28 +05:00
Matthias Krüger
7e0721b798
Rollup merge of #143519 - mu001999-contrib:dead-code/impl-items, r=petrochenkov
Check assoc consts and tys later like assoc fns

This PR
1. checks assoc consts and tys later like assoc fns
2. marks assoc consts appear in poly-trait-ref live

For assoc consts, considering
```rust
#![deny(dead_code)]

trait Tr { // ERROR trait `Tr` is never used
    const I: Self;
}

struct Foo; //~ ERROR struct `Foo` is never constructed

impl Tr for Foo {
    const I: Self = Foo;
}

fn main() {}
```

Current this will produce unused `I` instead of unused `Tr` and `Foo` ([play](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2024&gist=e0490d4a2d522cb70437b26e514a3d9c)), because `const I: Self = Foo;` will be added into the worklist at first:
```
error: associated constant `I` is never used
 --> src/main.rs:4:11
  |
3 | trait Tr { // ERROR trait `Tr` is never used
  |       -- associated constant in this trait
4 |     const I: Self;
  |           ^
  |
note: the lint level is defined here
 --> src/main.rs:1:9
  |
1 | #![deny(dead_code)]
  |         ^^^^^^^^^

error: could not compile `playground` (bin "playground") due to 1 previous error
```

This also happens to assoc tys, see the [new test](https://github.com/rust-lang/rust/compare/master...mu001999-contrib:rust:dead-code/impl-items?expand=1#diff-bf45fa403934a31c9d610a073ed2603d885e7e81572e8edf38b7f4e08a1f3531)

Fixes rust-lang/rust#126729

r? `````@petrochenkov`````
2025-07-13 15:15:57 +02:00
Mu001999
889582e704 Check assoc consts and tys later like assoc fns 2025-07-10 23:39:54 +08:00
bors
6b3ae3f6e4 Auto merge of #143472 - dianne:deref-pat-column-check, r=Nadrieril
`rustc_pattern_analysis`: always check that deref patterns don't match on the same place as normal constructors

In rust-lang/rust#140106, deref pattern validation was tied to the `deref_patterns` feature to temporarily avoid affecting perf. However:
- As of rust-lang/rust#143414, box patterns are represented as deref patterns in `rustc_pattern_analysis`. Since they can be used by enabling `box_patterns` instead of `deref_patterns`, it was possible for them to skip validation, resulting in an ICE. This fixes that and adds a regression test.
- External tooling (e.g. rust-analyzer) will also need to validate matches containing deref patterns, which was not possible. This fixes that by making `compute_match_usefulness` validate deref patterns by default.

In order to avoid doing an extra pass for anything with patterns, the second commit makes `RustcPatCtxt` keep track of whether it encounters a deref pattern, so that it only does the check if so. This is purely for performance. If the perf impact of the first commit is negligible and the complexity cost introduced by the second commit is significant, it may be worth dropping the latter.

r? `@Nadrieril`
2025-07-09 09:45:36 +00:00
dianne
50061f3b11 always check for mixed deref pattern and normal constructors
This makes it work for box patterns and in rust-analyzer.
2025-07-04 23:47:31 -07:00
Jubilee
069f571fad
Rollup merge of #143299 - Kivooeo:tf24, r=tgross35
`tests/ui`: A New Order [24/N]

> [!NOTE]
>
> Intermediate commits are intended to help review, but will be squashed prior to merge.

Some `tests/ui/` housekeeping, to trim down number of tests directly under `tests/ui/`. Part of rust-lang/rust#133895.

r? `@tgross35`
2025-07-04 23:26:23 -07:00
Kivooeo
b28806da23 cleaned up some tests 2025-07-05 00:45:24 +05:00
Kivooeo
986f1c9b69 moved tests 2025-07-01 18:21:05 +05:00
Cameron Steffen
dc9879cb3d Remove let_chains feature 2025-06-30 07:49:20 -05:00
Boxy
fe04ae7faf stabilize gai 2025-06-11 15:30:15 +01:00
Matthias Krüger
be2d382158
Rollup merge of #141960 - ferrocene:lw/2015-paths2, r=compiler-errors
Use non-2015 edition paths in tests that do not test for their resolution

This allows for testing these tests on editions other than 2015

Follow up to https://github.com/rust-lang/rust/pull/141888
2025-06-04 19:50:21 +02:00
Lukas Wirth
eae7fe1bdb Use non-2015 edition paths in tests that do not test for their resolution
This allows for testing these tests on editions other than 2015
2025-06-03 13:35:31 +02:00
Kivooeo
e7e884b0a4 cleaned up some tests 2025-06-03 07:38:06 +05:00
bors
52bf0cf795 Auto merge of #140553 - BoxyUwU:defer_type_system_ctfe, r=compiler-errors
Defer evaluating type system constants when they use infers or params

Split out of #137972, the parts necessary for associated const equality and min generic const args to make progress and have correct semantics around when CTFE is invoked. According to a [previous perf run](https://perf.rust-lang.org/compare.html?start=93257e2d20809d82d1bc0fcc1942480d1a66d7cd&end=01b4cbf0f47c3f782330db88fa5ba199bba1f8a2&stat=instructions:u) of adding the new `const_arg_kind` query we should expect minor regressions here.

I think this is acceptable as we should be able to remove this query relatively soon once mgca is more complete as we'll then be able to implement GCE in terms of mgca and rip out `GCEConst` at which point it's trivial to determine what kind of anon const we're dealing with (either it has generics and is a repeat expr hack, or it doesnt and is a normal anon const).

This should only affect unstable code as we handle repeat exprs specially and those are the only kinds of type system consts that are allowed to make use of generic parameters.

Fixes #133066
Fixes #133199
Fixes #136894
Fixes #137813

r? compiler-errors
2025-05-23 05:30:45 +00:00
Boxy
fdccb42167 Add test/comment about const patterns with unused params 2025-05-22 12:52:46 +01:00
Matthias Krüger
af081a4247
Rollup merge of #141267 - dianne:fix-141265, r=oli-obk
only resolve top-level guard patterns' guards once

We resolve guard patterns' guards in `resolve_pattern_inner`, so to avoid resolving them multiple times, we must avoid doing so earlier. To accomplish this, `LateResolutionVisitor::visit_pat` contains a case for guard patterns that avoids visiting their guards while walking patterns.

This PR fixes #141265, which was due to `visit::walk_pat` being used instead; this meant guards at the top level of a pattern would be visited twice. e.g. it would ICE on `for x if x in [] {}`, but not `for (x if x) in [] {}`. `visit_pat` was already used for the guard pattern in the second example, on account of the top-level pattern being parens.
2025-05-21 15:38:08 +02:00
dianne
c343b2a47c gather_locals: only visit guard pattern guards when checking the guard
When checking a pattern with guards in it, `GatherLocalsVisitor` will
visit both the pattern (when type-checking the let, arm, or param
containing it) and the guard expression (when checking the guard
itself). This keeps it from visiting the guard when visiting the
pattern, since otherwise it would gather locals from the guard twice,
which would lead to a delayed bug: "evaluated expression more than
once".
2025-05-19 23:18:08 -07:00
dianne
ed983c2184 only resolve top-level guard patterns' guards once
We resolve guard patterns' guards in `resolve_pattern_inner`, so to
avoid resolving them multiple times, we must avoid doing so earlier. To
accomplish this, `LateResolutionVisitor::visit_pat` contains a case for
guard patterns that avoids visiting their guards while walking patterns.
This fixes an ICE due to `visit::walk_pat` being used instead, which
meant guards at the top level of a pattern would be visited twice.
2025-05-19 18:02:54 -07:00
León Orell Valerian Liehr
4e5b1aa055
Rollup merge of #140746 - dianne:guard-pat-res, r=oli-obk
name resolution for guard patterns

This PR provides an initial implementation of name resolution for guard patterns [(RFC 3637)](https://github.com/rust-lang/rfcs/blob/master/text/3637-guard-patterns.md). This does not change the requirement that the bindings on either side of an or-pattern must be the same [(proposal here)](https://github.com/rust-lang/rfcs/blob/master/text/3637-guard-patterns.md#allowing-mismatching-bindings-when-possible); the code that handles that is separate from what this PR touches, so I'm saving it for a follow-up.

On a technical level, this separates "collecting the bindings in a pattern" (which was already done for or-patterns) from "introducing those bindings into scope". I believe the approach used here can be extended straightforwardly in the future to work with `if let` guard patterns, but I haven't tried it myself since we don't allow those yet.

Tracking issue for guard patterns: #129967

cc ``@Nadrieril``
2025-05-18 18:44:11 +02:00
dianne
f0b8ec1d71 name resolution for guard patterns 2025-05-18 04:21:57 -07:00
Michael Goulet
9af6ee50ed Structurally resolve in check_ref_cast and calc_adjust_mode 2025-05-08 15:00:17 +00:00
dianne
fb261a179d error early when mixing deref patterns with normal constructors
Without adding proper support for mixed exhaustiveness, mixing deref
patterns with normal constructors would either violate
`ConstructorSet::split`'s invariant 4 or 7. We'd either be ignoring rows
with normal constructors or we'd have problems in unspecialization from
non-disjoint constructors. Checking mixed exhaustivenss similarly to how
unions are currently checked should work, but the diagnostics for unions
are confusing. Since mixing deref patterns with normal constructors is
pretty niche (currently it only makes sense for `Cow`), emitting an
error lets us avoid committing to supporting mixed exhaustiveness
without a good answer for the diagnostics.
2025-05-06 18:53:55 -07:00
dianne
cf43bba1e5 add exhaustiveness/usefulness tests for deref patterns 2025-05-06 18:53:55 -07:00
dianne
b41d8bde00 let deref patterns participate in usefulness/exhaustiveness
This does not yet handle the case of mixed deref patterns with normal
constructors; it'll ICE in `Constructor::is_covered_by`. That'll be
fixed in a later commit.
2025-05-06 18:53:55 -07:00
dianne
17bb4bbc86 always peel &mut, to allow matching on &mut str 2025-05-05 04:29:33 -07:00
dianne
fe98130e0f match ergonomics for string and byte string literal patterns 2025-05-05 04:10:49 -07:00
bors
62c5f58f57 Auto merge of #140616 - petrochenkov:noannempty, r=jieyouxu
compiletest: Do not require annotations on empty labels and suggestions

Unlike other empty diagnostics, empty labels (only underlining spans) and empty suggestions (suggestions to remove something) are quite usual and do not require any special attention and annotations.

This effectively reverts a part of https://github.com/rust-lang/rust/pull/139485.

r? `@jieyouxu`
2025-05-04 09:38:17 +00:00
Vadim Petrochenkov
879b12e2ce compiletest: Do not require annotations on empty labels and suggestions 2025-05-03 22:49:23 +03:00
mejrs
9a574b0871 Move some tests out of tests/ui 2025-05-03 17:22:52 +02:00
Vadim Petrochenkov
20faf8532b compiletest: Make diagnostic kind mandatory on line annotations 2025-04-30 10:44:24 +03:00
Nadrieril
4e555fa52c Test partial moves via deref pats 2025-04-27 17:25:15 +02:00
dianne
0eb3b110f0 lower deref patterns on boxes using built-in derefs
This allows deref patterns to move out of boxes.

Implementation-wise, I've opted to put the information of whether a
deref pattern uses a built-in deref or a method call in the THIR. It'd
be a bit less code to check `.is_box()` everywhere, but I think this way
feels more robust (and we don't have a `mutability` field in the THIR
that we ignore when the smart pointer's a box). I'm not sure about the
naming (or using `ByRef`), though.
2025-04-24 14:25:27 -07:00