Commit Graph

362 Commits

Author SHA1 Message Date
Matthias Krüger
2e54f7f0a1 Rollup merge of #142569 - xizheyin:139253, r=davidtwco
Suggest clone in user-write-code instead of inside macro

Fixes rust-lang/rust#139253

Inspired by rust-lang/rust#142543

r? ````@fmease````
2025-07-25 11:16:32 +02:00
Matthias Krüger
61285e211b Rollup merge of #138554 - xizheyin:issue-138401, r=chenyukang
Distinguish delim kind to decide whether to emit unexpected closing delimiter

Fixes #138401
2025-07-18 19:14:42 +02:00
xizheyin
181c1bda0e Deduplicate unmatched_delims in rustc_parse to reduce confusion
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-07-18 20:34:58 +08:00
Kivooeo
98934707eb cleaned up some tests
Additionally, remove unused `tests/ui/auxiliary/svh-*` crates that are duplicates of `tests/ui/svh/auxiliary/svh-*`.
2025-07-13 00:03:31 +05:00
Kivooeo
47b8a32ca3 moved tests 2025-07-13 00:03:31 +05:00
Esteban Küber
0674eca2f0 Make Diag::multipart_suggestions always verbose 2025-07-10 17:23:29 +00: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
Jana Dönszelmann
0aaac883de Rollup merge of #143038 - Qelxiros:142676-private-dependency-traits, r=tgross35
avoid suggesting traits from private dependencies

fixes rust-lang/rust#142676
fixes rust-lang/rust#138191

r? ``@tgross35``
2025-07-03 13:29:36 +02:00
Jeremy Smart
6b824e8143 avoid suggesting traits from private dependencies 2025-07-02 22:04:51 -04:00
bors
4e97337005 Auto merge of #142030 - oli-obk:wfck-less-hir, r=compiler-errors
Start moving wf checking away from HIR

I'm trying to only access the HIR in the error path. My hope is that once we move significant portions of wfcheck off HIR that incremental will be able to cache wfcheck queries significantly better.

I think I am reaching a blocker because we normally need to provide good spans to `ObligationCause`, so that the trait solver can report good errors. In some cases I have been able to use bad spans and improve them depending on the `ObligationCauseCode` (by loading HIR in the case where we actually want to error). To scale that further we'll likely need to remove spans from the `ObligationCause` entirely (leaving it to some variants of `ObligationCauseCode` to have a span when they can't recompute the information later). Unsure this is the right approach, but we've already been using it. I will create an MCP about it, but that should not affect this PR, which is fairly limited in where it does those kind of tricks.

Especially b862d8828e is interesting here, because I think it improves spans in all cases
2025-07-01 14:59:58 +00:00
Kivooeo
986f1c9b69 moved tests 2025-07-01 18:21:05 +05:00
Jeremy Smart
3bf650f980 add failing test, bless incorrect output 2025-06-30 18:03:39 -04:00
Guillaume Gomez
76df2656df Replace ItemCtxt::report_placeholder_type_error match with a call to TyCtxt::def_descr 2025-06-30 20:36:16 +02:00
Oli Scherer
9b5d57d0a9 Unconditionally run check_item_type on all items 2025-06-30 08:06:08 +00:00
Oli Scherer
c51f05be30 Report infer ty errors during hir ty lowering
This centralizes the placeholder type error reporting in one location, but it also exposes the granularity at which we convert things from hir to ty more. E.g. previously infer types in where bounds were errored together with the function signature, but now they are independent.
2025-06-27 07:51:38 +00:00
Michael Goulet
59e1a3cbf5 Simplify IfCause 2025-06-26 03:43:01 +00:00
Jana Dönszelmann
131a2e47fb Rollup merge of #142200 - Kivooeo:tf8, r=jieyouxu
`tests/ui`: A New Order [8/N]

Some `tests/ui/` housekeeping, to trim down number of tests directly under `tests/ui/`. Part of rust-lang/rust#133895.
2025-06-25 22:14:54 +02:00
Vadim Petrochenkov
7a4f09c224 compiletest: Improve diagnostics for line annotation mismatches 2025-06-23 21:30:56 +03:00
Kivooeo
793607059b cleaned up some tests 2025-06-23 18:53:56 +05:00
mejrs
b1d18129d1 Implement DesugaringKind::FormatLiteral 2025-06-22 10:58:25 +02:00
xizheyin
fd9c1b962a Find correct span when suggesting using clone
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-06-17 23:48:47 +08:00
xizheyin
02dac5cd78 add test suggest-clone-in-macro-issue-139253.rs
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-06-17 23:42:57 +08:00
Oli Scherer
7f4093e78b Loop check anon consts on their own 2025-06-10 08:41:23 +00:00
Jonathan Brouwer
b1a1df2efe Fix consider borrowing for else-if 2025-05-31 18:34:35 +02:00
Jonathan Brouwer
a261d167ac Failing tests for "consider borrowing" 2025-05-31 18:32:50 +02:00
Noratrieb
01503d0c1e Avoid extra path trimming in method not found error
Method errors have an extra check that force trim paths whenever the
normal string is longer than 10 characters, which can be quite unhelpful
when multiple items have the same name (for example an `Error`).

A user reported this force trimming as being quite unhelpful when they
had a method error where the precise path of the `Error` mattered.

The code uses `tcx.short_string` already to get the normal path, which
tries to be clever around trimming paths if necessary, so there is no
reason for this extra force trimming.
2025-05-24 23:31:07 +02:00
Matthias Krüger
3216098e53 Rollup merge of #140218 - fmease:hirtylo-clean-up-path-low, r=compiler-errors
HIR ty lowering: Clean up & refactor the lowering of type-relative paths

While rebasing #126651 I realized that HIR ty lowering could benefit from some *spring cleaning* now that it's been extended to handle RTN and mGCA paths.

More seriously, similar to my merged PR #118668 which unified the handling of all *associated item constraints* (assoc ty, const (ACE) & fn (RTN)), this PR (commit 695fcf517d) partially[^1] deduplicates the resolution code for all *type-relative paths* (assoc ty, const (mGCA) & fn (RTN)).

**Why**? DRY'ing that part of the code means PR #126651 will automatically support RTN paths like `Ty::AssocTy::assoc_fn(..)` and it also implies shared diagnostic code and thus better diagnostics for RTN.

---

The other commits represent cleanups, renamings, moves. More notably, I've renamed path lowering methods to be a lot more descriptive, so ones lowering `QPath(Resolved)` paths now have `_resolved_` in their name and ones lowering `QPath(TypeRelative)` paths now have `_type_relative_` in their name. This should make it stupidly obvious what their purpose is.

---

Best reviewed commit by commit. The changes are close to trivial but the diff might make it look hairier.
r? compiler-errors

[^1]: Sadly, I couldn't unify as much compared to the other PR without introducing unnecessary `unreachable!()`s or rendering the code otherwise illegible with flags and micro helper traits.
2025-05-22 16:02:28 +02:00
Matthias Krüger
3529341afd Rollup merge of #135562 - chenyukang:yukang-fix-128561, r=compiler-errors
Add ignore value suggestion in closure body

Fixes #128561

r? `@estebank`
2025-05-22 16:02:23 +02:00
Matthias Krüger
14f3ef997f Rollup merge of #141070 - xizheyin:issue-140659, r=chenyukang
Do not emit help when shorthand from macro when suggest `?` or `expect`

Fixes #140659

I didn't fully minimize the original bug, but I found a similar test case, and they have perhaps the same root cause. For the bug mentioned in #140659 , I also tested it locally and passed it.

Jieyou has worked on this part before, maybe r? `@jieyouxu`
2025-05-17 10:33:12 +02:00
xizheyin
1c17324c7d Create tests/ui/typeck/suggestions/ and move some tests in tests/ui/typeck/ to it
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-05-17 01:01:58 +08:00
xizheyin
742c27bc52 Do not emit help when shorthand from macro when suggest ? or expect
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-05-17 01:01:54 +08:00
xizheyin
43ff8855ac Add ui test macro-shorthand-issue-140659
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-05-16 17:03:55 +08:00
Michael Goulet
a4707a4f3b Do not ICE when reassigning in GatherLocalsVisitor on the bad path 2025-05-09 14:42:19 +00:00
León Orell Valerian Liehr
8c37c8c3e6 Preserve generic args in suggestions for ambiguous associated items
Most notably, this preserves the `(..)` of ambiguous RTN paths.
2025-05-06 17:04:03 +02:00
Vadim Petrochenkov
20faf8532b compiletest: Make diagnostic kind mandatory on line annotations 2025-04-30 10:44:24 +03:00
Chris Denton
8f42ac0043 Rollup merge of #140094 - Kivooeo:raw-pointer-assignment-suggestion, r=compiler-errors
Improve diagnostics for pointer arithmetic += and -= (fixes #137391)

**Description**:

This PR improves the diagnostic message for cases where a binary assignment operation like `ptr += offset` or `ptr -= offset` is attempted on `*mut T`. These operations are not allowed, and the compiler previously suggested calling `.add()` or `.wrapping_add()`, which is misleading if not assigned.

This PR updates the diagnostics to suggest assigning the result of `.wrapping_add()` or `.wrapping_sub()` back to the pointer, e.g.:

**Examples**

For this code
```rust
let mut arr = [0u8; 10];
let mut ptr = arr.as_mut_ptr();

ptr += 2;
```
it will say:
```rust
10 |     ptr += 2;
   |     ---^^^^^
   |     |
   |     cannot use `+=` on type `*mut u8`
   |
help: consider replacing `ptr += offset` with `ptr = ptr.wrapping_add(offset)` or `ptr.add(offset)`
   |
10 -     ptr += 2;
10 +     ptr = ptr.wrapping_add(2);
```

**Related issue**: #137391
cc `@nabijaczleweli` for context (issue author)
2025-04-22 01:22:13 +00:00
Kivooeo
834e476a0c Add diagnostics and suggestions for raw pointer arithmetic assignments 2025-04-21 22:14:44 +05:00
reddevilmidzy
dd2d6b222b Cleaned up 5 tests in tests/ui 2025-04-21 16:16:38 +09:00
Vadim Petrochenkov
06dd9e2d20 compiletest: Trim the value of dont-require-annotations 2025-04-10 23:48:57 +03:00
Vadim Petrochenkov
0ca31277f3 compiletest: Make SUGGESTION annotations viral 2025-04-10 23:48:57 +03:00
Matthias Krüger
b131828f0d Rollup merge of #139423 - compiler-errors:field-autoderef, r=oli-obk
Suppress missing field error when autoderef bottoms out in infer

I see this error repeatedly when doing refactorings, and it's pretty misleading b/c it's not the source of the error.
2025-04-10 11:10:14 +02:00
Matthias Krüger
7494bd9a4f Rollup merge of #139364 - Kohei316:feat/doc-hidden-suggestion, r=nnethercote
Make the compiler suggest actual paths instead of visible paths if the visible paths are through any doc hidden path.

close #127011
Currently, when emitting a diagnostic about a valid trait, the compiler suggestes using visible paths of the trait even if they are through a doc hidden path. This PR updates the compiler to suggest actual paths in these cases.
2025-04-09 14:52:37 +02:00
Vadim Petrochenkov
b3f75353a2 UI tests: add missing diagnostic kinds where possible 2025-04-08 23:06:31 +03:00
Bennet Bleßmann
7dd57f085c update/bless tests 2025-04-06 21:41:47 +02:00
Michael Goulet
b8c4c163f0 Suppress missing field error when autoderef bottoms out in infer 2025-04-05 20:37:56 +00:00
morine0122
d0591827dd Make the compiler suggest actual paths instead of visible paths if the visible paths are through any doc hidden path. 2025-04-04 20:50:16 +09:00
Vadim Petrochenkov
4d64990690 compiletest: Require //~ annotations even if error-pattern is specified 2025-04-03 11:08:55 +03:00
Nicholas Nethercote
958bc7b365 Handle _ properly in a couple of places.
Currently (PatKind::Wild` (i.e. `_`) gets turned by
`lower_fn_params_to_names` into an empty identifier, which means it is
printed incorrectly by HIR pretty printing.

And likewise for `lower_fn_params_to_names`, which affects some error
messages.

This commit fixes them. This requires a slight tweak in a couple of
places to continue using parameter numbers in some error messages. And
it improves the output of `tests/ui/typeck/cyclic_type_ice.rs`:
`/* _ */` is a better suggestion than `/*  */`.
2025-03-14 09:45:38 +11:00
Oli Scherer
cb4751d4b8 Implement #[define_opaque] attribute for functions. 2025-03-11 12:05:02 +00:00