Commit Graph

17 Commits

Author SHA1 Message Date
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
Takayuki Maeda
9e84f6d86a
Rollup merge of #117110 - estebank:deref-field-suggestion, r=b-naber
Suggest field typo through derefs

Take into account implicit dereferences when suggesting fields.

```
error[E0609]: no field `longname` on type `Arc<S>`
  --> $DIR/suggest-field-through-deref.rs:10:15
   |
LL |     let _ = x.longname;
   |               ^^^^^^^^ help: a field with a similar name exists: `long_name`
```

CC https://github.com/rust-lang/rust/issues/78374#issuecomment-719564114
2023-11-19 04:14:41 +09:00
Esteban Küber
289ce572b3 tweak logic of "unknown field" label 2023-11-18 00:40:11 +00:00
Esteban Küber
4f7dddd4a1 recover primary span label 2023-11-16 17:00:23 +00:00
Esteban Küber
8bd8f3b090 Suggest unwrap() on field not found for Result/Option
When encountering a `Result<T, _>` or `Option<T>` where `T` has a field
that's being accessed, suggest calling `.unwrap()` to get to the field.
2023-11-16 17:00:23 +00:00
Esteban Küber
d8456855f5 Suggest replacing Self with the right type on type error
When encountering a type error caused by the use of `Self`, suggest
using the actual type name instead.

```
error[E0308]: mismatched types
  --> $DIR/struct-path-self-type-mismatch.rs:13:9
   |
LL |   impl<T> Foo<T> {
   |        -  ------ this is the type of the `Self` literal
   |        |
   |        found type parameter
LL |       fn new<U>(u: U) -> Foo<U> {
   |              -           ------ expected `Foo<U>` because of return type
   |              |
   |              expected type parameter
LL | /         Self {
LL | |
LL | |             inner: u
LL | |
LL | |         }
   | |_________^ expected `Foo<U>`, found `Foo<T>`
   |
   = note: expected struct `Foo<U>`
              found struct `Foo<T>`
   = note: a type parameter was expected, but a different one was found; you might be missing a type parameter or trait bound
   = note: for more information, visit https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters
help: use the type name directly
   |
LL |         Foo::<U> {
   |         ~~~~~~~~
```

Fix #76086.
2023-11-16 16:19:19 +00:00
Esteban Küber
a7e035ab89 Point at impl self ty on type error involving Self
When encountering a type error involving a `Self` literal, point at the
self type of the enclosing `impl`.

CC #76086.
2023-11-16 16:19:19 +00:00
Swapna Iyer
56a109d15b Recurse over the method chain and maintain a stack to peek at previous receiver to align spans 2023-11-10 13:00:27 -08:00
Esteban Küber
890e92feed Unify suggestion wording 2023-10-17 17:33:55 +00:00
Esteban Küber
7dffd24da5 Tweak privacy errors to account for reachable items
Suggest publicly accessible paths for items in private mod:

  When encountering a path in non-import situations that are not reachable
  due to privacy constraints, search for any public re-exports that the
  user could use instead.

Track whether an import suggestion is offering a re-export.

When encountering a path with private segments, mention if the item at
the final path segment is not publicly accessible at all.

Add item visibility metadata to privacy errors from imports:

  On unreachable imports, record the item that was being imported in order
  to suggest publicly available re-exports or to be explicit that the item
  is not available publicly from any path.

  In order to allow this, we add a mode to `resolve_path` that will not
  add new privacy errors, nor return early if it encounters one. This way
  we can get the `Res` corresponding to the final item in the import,
  which is used in the privacy error machinery.
2023-06-22 16:50:31 +00:00
Michael Goulet
140c011ca6 Don't mention already set fields 2023-06-05 21:00:08 +00:00
Esteban Küber
5b40aa5eb4 Tweak output for 'add line' suggestion 2023-04-12 22:50:10 +00:00
Maciej Wasilewski
3b38dd9112 better diagnostics for pattern matching tuple structs
Better diagnostic message when trying to pattern match a tuple struct with a struct pattern.
2023-03-30 10:38:04 +02:00
Michael Howell
a5b639dc01 diagnostics: remove inconsistent English article "this" from E0107
Consider `tests/ui/const-generics/generic_const_exprs/issue-102768.stderr`,
the error message where it gives additional notes about where the associated
type is defined, and how the dead code lint doesn't have an article,
like in `tests/ui/lint/dead-code/issue-85255.stderr`. They don't have
articles, so it seems unnecessary to have one here.
2023-02-23 10:27:06 -07:00
Esteban Küber
62ba3e70a1 Modify primary span label for E0308
The previous output was unintuitive to users.
2023-01-30 20:12:19 +00:00
Esteban Küber
12ddf77811 When suggesting writing a fully qualified path probe for appropriate types
Fix #46585.
2023-01-11 21:30:10 +00:00
Albert Larsan
cf2dff2b1e
Move /src/test to /tests 2023-01-11 09:32:08 +00:00