Commit graph

199 commits

Author SHA1 Message Date
Esteban Küber 91b9ffeab0 Reorder fullfillment errors to keep more interesting ones first
In `report_fullfillment_errors` push back `T: Sized`, `T: WellFormed`
and coercion errors to the end of the list. The pre-existing
deduplication logic eliminates redundant errors better that way, keeping
the resulting output with fewer errors than before, while also having
more detail.
2023-10-04 02:04:14 +00:00
Michael Goulet 07851679cd Point out the actual mismatch error 2023-10-02 23:14:29 +00:00
Michael Goulet 8be12f4ed7 For a single impl candidate, try to unify it with error trait ref 2023-10-02 23:14:29 +00:00
bohan b83dfb5c5a fix(suggestion): insert projection to associated types 2023-09-29 18:51:59 +08:00
Esteban Küber 81bca5f5cf When suggesting self.x for S { x }, use S { x: self.x }
Tweak output.

Fix #115992.
2023-09-25 15:56:36 +00:00
Matthias Krüger 61b38b216a
Rollup merge of #116086 - estebank:issue-115992, r=compiler-errors
More accurate suggestion for `self.` and `Self::`

Detect that we can't suggest `self.` in an associated function without `&self` receiver.

Partially address #115992.

r? ``@compiler-errors``
2023-09-24 01:14:06 +02:00
Esteban Küber ac5e18756a Tweak wording and logic 2023-09-23 01:54:05 +00:00
Esteban Küber 0e98682576 When encountering method on Self that we can't suggest, mention it 2023-09-23 01:47:06 +00:00
Esteban Küber c4a4926083 More accurate suggestion for self. and Self::
Fix #115992.
2023-09-23 01:34:50 +00:00
Ralf Jung c4ec12f4b7 adjust how closure/generator types and rvalues are printed 2023-09-21 22:20:58 +02:00
Michael Goulet 30e6cea0ae Point out if a local trait has no implementations 2023-09-10 21:20:36 +00:00
David Tolnay 823bacb6e3
Revert "Suggest using Arc on !Send/!Sync types"
This reverts commit 9de1a472b6.
2023-08-28 03:16:48 -07:00
Esteban Küber b6494a7bb4 More accurately point at arguments 2023-08-26 19:25:46 +00:00
Esteban Küber 120c24dab5 Point at appropriate type parameter in more trait bound errors 2023-08-26 01:07:05 +00:00
Josh Stone 5861815559
Rollup merge of #114931 - Urgau:revert-114052, r=compiler-errors
Revert PR #114052 to fix invalid suggestion

This PR reverts https://github.com/rust-lang/rust/pull/114052 to fix the invalid suggestion produced by the PR.

Unfortunately the invalid suggestion cannot be improved from the current position where it's emitted since we lack enough information (is an assignment?, left or right?, ...) to be able to fix it here. Furthermore the previous wasn't wrong, just suboptimal, contrary to the current one which is just wrong.

Added a regression test and commented out some code instead of removing it so we can use it later.

Reopens https://github.com/rust-lang/rust/issues/114050
Fixes https://github.com/rust-lang/rust/issues/114925
2023-08-17 15:40:09 -07:00
bors 0768872680 Auto merge of #114802 - chenyukang:yukang-fix-114979-bad-parens-dyn, r=estebank
Fix bad suggestion when wrong parentheses around a dyn trait

Fixes #114797
2023-08-17 17:54:50 +00:00
Urgau 1c73248b67 Revert PR #114052 to fix invalid suggestion 2023-08-17 14:33:33 +02:00
Matthias Krüger 8f1c8116f6
Rollup merge of #114779 - MU001999:fix/114701, r=petrochenkov
Add check before suggest removing parens

Fixes #114701
2023-08-16 08:43:51 +02:00
Matthias Krüger 8db5a6d8ee
Rollup merge of #114819 - estebank:issue-78124, r=compiler-errors
Point at return type when it influences non-first `match` arm

When encountering code like

```rust
fn foo() -> i32 {
    match 0 {
        1 => return 0,
        2 => "",
        _ => 1,
    }
}
```

Point at the return type and not at the prior arm, as that arm has type `!` which isn't influencing the arm corresponding to arm `2`.

Fix #78124.
2023-08-15 20:34:25 +02:00
yukang ddcd7cac41 Fix bad suggestion when wrong parentheses around a dyn trait 2023-08-16 00:26:10 +08:00
r0cky 860fc24608 Remove extra errors 2023-08-15 10:58:33 +00:00
Esteban Küber 55f8c66a60 Point at return type when it influences non-first match arm
When encountering code like

```rust
fn foo() -> i32 {
    match 0 {
        1 => return 0,
        2 => "",
        _ => 1,
    }
}
```

Point at the return type and not at the prior arm, as that arm has type
`!` which isn't influencing the arm corresponding to arm `2`.

Fix #78124.
2023-08-14 21:43:56 +00:00
dirreke e676afbafe fix the error check 2023-08-15 00:57:18 +08:00
Mu001999 b1ddd57b5c Add check before suggest removing parens 2023-08-13 20:34:36 +08:00
bors 439d066bcf Auto merge of #114474 - estebank:missing-semi, r=compiler-errors
Detect missing `;` that parses as function call

Fix #106515.
2023-08-10 20:30:18 +00:00
Esteban Kuber 9de1a472b6 Suggest using Arc on !Send/!Sync types 2023-08-09 14:04:10 +00:00
Esteban Küber 8ecb486add Detect missing ; that parses as function call
Fix #106515.
2023-08-08 15:11:23 +00:00
bohan 2195fa6a9b fix the span in the suggestion of remove question mark 2023-08-03 16:44:02 +08:00
bors f9f674f2bc Auto merge of #114150 - clubby789:improve-option-ref-suggestion, r=WaffleLapkin
Refactor + improve diagnostics for `&mut T`/`T` mismatch inside Option/Result

Follow up to #114052. This also makes the diagnostics structured + translatable.

r? `@WaffleLapkin`
2023-07-29 13:15:56 +00:00
León Orell Valerian Liehr 55aba32ac5
Update existing UI tests 2023-07-28 22:23:21 +02:00
clubby789 fafc3d2d0e Handle exclusive refs in suggestion to copy/clone 2023-07-27 23:13:26 +00:00
clubby789 683b2656bf Refactor suggest_copied_cloned_or_as_ref 2023-07-27 23:13:25 +00:00
clubby789 c83dfe9aed Suggest {Option,Result}::as_ref() instead of cloned() in some cases 2023-07-25 13:19:27 +00:00
Matthias Krüger 0ed5f091a6
Rollup merge of #112508 - compiler-errors:trait-sig-lifetime-sugg-ice, r=cjgillot
Tweak spans for self arg, fix borrow suggestion for signature mismatch

1. Adjust a suggestion message that was annoying me
2. Fix #112503 by recording the right spans for the `self` part of the `&self` 0th argument
3. Remove the suggestion for adjusting a trait signature on type mismatch, bc that's gonna probably break all the other impls of the trait even if it fixes its one usage 😅
2023-07-22 19:57:35 +02:00
yukang 3ddf6f7c17 use maybe_body_owned_by for closure 2023-07-14 07:12:35 +08:00
Michael Goulet 3a3f4a2144 Don't use method span on clone suggestion 2023-07-10 20:09:28 +00:00
Michael Goulet fe870424a7 Do not set up wrong span for adjustments 2023-07-10 20:09:26 +00:00
Matthias Krüger 70c637808f
Rollup merge of #113331 - chenyukang:yukang-fix-112590-false-positive, r=estebank
Add filter with following segment while lookup typo for path

From the discussion: https://github.com/rust-lang/rust/pull/112917#discussion_r1239150173

Seems we can not get the assoc items for `Struct`, `Enum` in the resolving phase.
A obvious filter is avoid suggesting the same name with the following segment path.

Use `following_seg` can extend the function `smart_resolve_partial_mod_path_errors` for more scenarios, such as `std::sync_error::atomic::AtomicBool` in test case.

r? `@estebank`
2023-07-10 12:01:32 +02:00
Matthias Krüger 48a0d038fa
Rollup merge of #113005 - compiler-errors:dont-query-normalize, r=cjgillot
Don't call `query_normalize` when reporting similar impls

Firstly, It's sketchy to be using `query_normalize` at all during HIR typeck -- it's asking for an ICE 😅. Secondly, we're normalizing an impl trait ref that potentially has parameter types in `ty::ParamEnv::empty()`, which is kinda sketchy as well.

The only UI test change from removing this normalization is that we don't evaluate anonymous constants in impls, which end up giving us really ugly suggestions:

```
error[E0277]: the trait bound `[X; 35]: Default` is not satisfied
 --> /home/gh-compiler-errors/test.rs:4:5
  |
4 |     <[X; 35] as Default>::default();
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Default` is not implemented for `[X; 35]`
  |
  = help: the following other types implement trait `Default`:
            &[T]
            &mut [T]
            [T; 32]
            [T; core::::array::{impl#30}::{constant#0}]
            [T; core::::array::{impl#31}::{constant#0}]
            [T; core::::array::{impl#32}::{constant#0}]
            [T; core::::array::{impl#33}::{constant#0}]
            [T; core::::array::{impl#34}::{constant#0}]
          and 27 others
```

So just fold the impls with a `BottomUpFolder` that calls `ty::Const::eval`. This doesn't work totally correctly with generic-const-exprs, but it's fine for stable code, and this is error reporting after all.
2023-07-08 20:53:27 +02:00
yukang 37b40e592a adjust smart_resolve_partial_mod_path_errors 2023-07-07 10:19:30 +08:00
yukang 9763472e2b smart_resolve_partial_mod_path_errors should not suggest parent 2023-07-07 10:18:20 +08:00
bors 4dbc7e3092 Auto merge of #113309 - chenyukang:yukang-fix-89640-space, r=Nilstrieb
Detect extra space in keyword for better hint

Fixes #89640

r? `@Nilstrieb`

I met the same issue, then found out this old issue :)
2023-07-04 12:04:57 +00:00
yukang 799d2917e7 Detect extra space in keyword for better hint 2023-07-04 18:13:31 +08:00
bors e728b5b98d Auto merge of #112917 - chenyukang:yukang-fix-112590, r=estebank
Suggest importing for partial mod path matching in name resolving

Fixes #112590
2023-07-04 02:01:24 +00:00
yukang b26701ea79 add testcase for 112590 2023-07-02 15:35:18 +08:00
Matthias Krüger 9082287213
Rollup merge of #113174 - chenyukang:yukang-fix-102972-loop-next, r=compiler-errors
Better messages for next on a iterator inside for loops

Fixes #102972
2023-07-01 13:46:01 +02:00
yukang 44a8a8d0ca Better messages for next in a iterator inside for loops 2023-06-30 14:02:02 +08:00
Matthias Krüger 6c22e0419f
Rollup merge of #111403 - y21:suggest-slice-swap, r=compiler-errors
suggest `slice::swap` for `mem::swap(&mut x[0], &mut x[1])` borrowck error

Recently saw someone ask why this code (example slightly modified):
```rs
fn main() {
  let mut foo = [1, 2];
  std::mem::swap(&mut foo[0], &mut foo[1]);
}
```
triggers this error and how to fix it:
```
error[E0499]: cannot borrow `foo[_]` as mutable more than once at a time
 --> src/main.rs:4:33
  |
4 |     std::mem::swap(&mut foo[0], &mut foo[1]);
  |     -------------- -----------  ^^^^^^^^^^^ second mutable borrow occurs here
  |     |              |
  |     |              first mutable borrow occurs here
  |     first borrow later used by call
  |
  = help: consider using `.split_at_mut(position)` or similar method to obtain two mutable non-overlapping sub-slices
```
The current help message is nice and goes in the right direction, but I think we can do better for this specific instance and suggest `slice::swap`, which makes this compile
2023-06-30 08:01:12 +02:00
y21 679c5be405 add slice::swap suggestion 2023-06-29 19:19:59 +02:00
Michael Goulet 8621285e3b reword message to be less vague 2023-06-28 17:51:01 +00:00