Commit graph

32 commits

Author SHA1 Message Date
surechen 2a6a42329f Change E0369 diagnostic give note information for foreign items.
Make it easy for developers to understand why the binop cannot be applied.

fixes #125631
2024-06-25 10:00:30 +08:00
Alex Macleod d0112c6849 Spell out other trait diagnostic 2024-06-12 12:34:47 +00:00
Michael Goulet a02aba7c54 Only suppress binop error in favor of semicolon suggestion if we're in an assignment statement 2024-05-23 19:22:55 -04:00
Esteban Küber d68f2a6b71 Mention when type parameter could be Clone
```
error[E0382]: use of moved value: `t`
  --> $DIR/use_of_moved_value_copy_suggestions.rs:7:9
   |
LL | fn duplicate_t<T>(t: T) -> (T, T) {
   |                   - move occurs because `t` has type `T`, which does not implement the `Copy` trait
...
LL |     (t, t)
   |      -  ^ value used here after move
   |      |
   |      value moved here
   |
help: if `T` implemented `Clone`, you could clone the value
  --> $DIR/use_of_moved_value_copy_suggestions.rs:4:16
   |
LL | fn duplicate_t<T>(t: T) -> (T, T) {
   |                ^ consider constraining this type parameter with `Clone`
...
LL |     (t, t)
   |      - you could clone this value
help: consider restricting type parameter `T`
   |
LL | fn duplicate_t<T: Copy>(t: T) -> (T, T) {
   |                 ++++++
```

The `help` is new. On ADTs, we also extend the output with span labels:

```
error[E0507]: cannot move out of static item `FOO`
  --> $DIR/issue-17718-static-move.rs:6:14
   |
LL |     let _a = FOO;
   |              ^^^ move occurs because `FOO` has type `Foo`, which does not implement the `Copy` trait
   |
note: if `Foo` implemented `Clone`, you could clone the value
  --> $DIR/issue-17718-static-move.rs:1:1
   |
LL | struct Foo;
   | ^^^^^^^^^^ consider implementing `Clone` for this type
...
LL |     let _a = FOO;
   |              --- you could clone this value
help: consider borrowing here
   |
LL |     let _a = &FOO;
   |              +
```
2024-04-24 22:21:15 +00:00
bors ab71ee7a92 Auto merge of #123736 - compiler-errors:multiply-on-rhs, r=estebank
Don't delay a bug if we suggest adding a semicolon to the RHS of an assign operator

It only makes sense to delay a bug based on the assumption that "[we] defer to the later error produced by `check_lhs_assignable`" *if* the expression we're erroring actually is an LHS; otherwise, we should still report the error since it's both useful and required.

Fixes #123722
2024-04-12 08:41:20 +00:00
Esteban Küber e17388b809 Handle more cases of value suggestions 2024-04-10 20:36:14 +00:00
Michael Goulet 889ca7e216 Don't delay a bug if we suggest adding a semicolon to the RHS of an assign operator 2024-04-10 15:07:13 -04:00
Esteban Küber a983dd8563 Tweak value suggestions in borrowck and hir_analysis
Unify the output of `suggest_assign_value` and `ty_kind_suggestion`.

Ideally we'd make these a single function, but doing so would likely require modify the crate dependency tree.
2024-04-09 23:37:13 +00:00
Trevor Gross d7d5fc9734 Add basic trait impls for f16 and f128
Split off part of <https://github.com/rust-lang/rust/pull/122470> so the
compiler doesn't ICE because it expects primitives to have some minimal
traits.

Fixes <https://github.com/rust-lang/rust/issues/123074>
2024-03-28 15:02:51 -04:00
Oli Scherer ae24fef028 Use TraitRef::to_string sorting in favor of TraitRef::ord, as the latter compares DefIds which we need to avoid 2024-03-27 14:02:15 +00:00
Oli Scherer 96d24f2dd1 Revert "Auto merge of #122140 - oli-obk:track_errors13, r=davidtwco"
This reverts commit 65cd843ae0, reversing
changes made to d255c6a57c.
2024-03-11 21:28:16 +00:00
Oli Scherer 55ea94402b Run a single huge par_body_owners instead of many small ones after each other.
This improves parallel rustc parallelism by avoiding the bottleneck after each individual `par_body_owners` (because it needs to wait for queries to finish, so if there is one long running one, a lot of cores will be idle while waiting for the single query).
2024-03-11 08:48:03 +00:00
许杰友 Jieyou Xu (Joe) ec2cc761bc
[AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
Caio 69a5264a52 Move some tests 2024-02-09 15:43:08 -03:00
Oli Scherer eab2adb660 Continue to borrowck even if there were previous errors 2024-02-08 08:10:43 +00:00
Esteban Küber 6efddac288 Provide more context on derived obligation error primary label
Expand the primary span of E0277 when the immediate unmet bound is not what the user wrote:

```
error[E0277]: the trait bound `i32: Bar` is not satisfied
 --> f100.rs:6:6
  |
6 |     <i32 as Foo>::foo();
  |      ^^^ the trait `Bar` is not implemented for `i32`, which is required by `i32: Foo`
  |
help: this trait has no implementations, consider adding one
 --> f100.rs:2:1
  |
2 | trait Bar {}
  | ^^^^^^^^^
note: required for `i32` to implement `Foo`
 --> f100.rs:3:14
  |
3 | impl<T: Bar> Foo for T {}
  |         ---  ^^^     ^
  |         |
  |         unsatisfied trait bound introduced here
```

Fix #40120.
2024-01-30 21:28:18 +00:00
sjwang05 c36b5d5353
Fix ICE when suggesting dereferencing binop operands 2024-01-12 17:49:37 -08:00
Esteban Küber 7f795a5221 Make derive(Trait) suggestion more accurate
Only suggest `derive(PartialEq)` when both LHS and RHS types
are the same, otherwise the suggestion is not useful.
2024-01-03 23:49:56 +00:00
sjwang05 2618e0f805
Provide better suggestions for T == &T and &T == T 2023-12-16 19:56:50 -08:00
Nilstrieb 41e8d152dc Show number in error message even for one error
Co-authored-by: Adrian <adrian.iosdev@gmail.com>
2023-11-24 19:15:52 +01:00
sjwang05 614ddc9695
Suggest lhs deref for binops 2023-11-13 16:25:16 -08:00
Esteban Küber 4b7aacaa4f Silence redundant error on typo resulting on binop 2023-11-06 17:38:06 +00:00
Esteban Küber 231f93524d Detect misparsed binop caused by missing semi
When encountering

```rust
foo()
*bar = baz;
```

We currently emit potentially two errors, one for the return type of
`foo` not being multiplyiable by the type of `bar`, and another for
`foo() * bar` not being assignable.

We now check for this case and suggest adding a semicolon in the right
place.

Fix #80446.
2023-10-27 17:19:32 +00:00
Urgau ad0729e9d2 Improve diagnostic for wrong borrow on binary operations 2023-08-01 10:08:17 +02:00
Michael Goulet fe870424a7 Do not set up wrong span for adjustments 2023-07-10 20:09:26 +00:00
Michael Goulet 2c33dfea76 Don't sort strings right after we just sorted by types 2023-06-27 23:31:06 +00:00
Michael Goulet 015acc2611 Provide RHS type hint when reporting operator error 2023-04-27 01:34:03 +00:00
Esteban Küber 5b40aa5eb4 Tweak output for 'add line' suggestion 2023-04-12 22:50:10 +00:00
Matthias Kaak 8d7b092a11
Improved wording of error messages of missing remainder implementations 2023-01-30 19:54:33 +00:00
Matthias Kaak e02517d753
Fixed confusement between mod and remainder 2023-01-27 21:01:07 +00:00
Esteban Küber 656db98bd9 Tweak E0597
CC #99430
2023-01-15 19:46:20 +00:00
Albert Larsan cf2dff2b1e
Move /src/test to /tests 2023-01-11 09:32:08 +00:00