Commit graph

67 commits

Author SHA1 Message Date
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
Matthias Krüger aa184c558f
Rollup merge of #122195 - jieyouxu:impl-return-note, r=fmease
Note that the caller chooses a type for type param

```
error[E0308]: mismatched types
  --> $DIR/return-impl-trait.rs:23:5
   |
LL | fn other_bounds<T>() -> T
   |                 -       -
   |                 |       |
   |                 |       expected `T` because of return type
   |                 |       help: consider using an impl return type: `impl Trait`
   |                 expected this type parameter
...
LL |     ()
   |     ^^ expected type parameter `T`, found `()`
   |
   = note: expected type parameter `T`
                   found unit type `()`
   = note: the caller chooses the type of T which can be different from ()
```

Tried to see if "expected this type parameter" can be replaced, but that goes all the way to `rustc_infer` so seems not worth the effort and can affect other diagnostics.

Revives #112088 and #104755.
2024-03-22 20:31:28 +01:00
Esteban Küber cc9631a371 When displaying multispans, ignore empty lines adjacent to ...
```
error[E0308]: `match` arms have incompatible types
   --> tests/ui/codemap_tests/huge_multispan_highlight.rs:98:18
    |
6   |       let _ = match true {
    |               ---------- `match` arms have incompatible types
7   |           true => (
    |  _________________-
8   | |             // last line shown in multispan header
...   |
96  | |
97  | |         ),
    | |_________- this is found to be of type `()`
98  |           false => "
    |  __________________^
...   |
119 | |
120 | |         ",
    | |_________^ expected `()`, found `&str`

error[E0308]: `match` arms have incompatible types
   --> tests/ui/codemap_tests/huge_multispan_highlight.rs:215:18
    |
122 |       let _ = match true {
    |               ---------- `match` arms have incompatible types
123 |           true => (
    |  _________________-
124 | |
125 | |         1 // last line shown in multispan header
...   |
213 | |
214 | |         ),
    | |_________- this is found to be of type `{integer}`
215 |           false => "
    |  __________________^
216 | |
217 | |
218 | |         1 last line shown in multispan
...   |
237 | |
238 | |         ",
    | |_________^ expected integer, found `&str`
```
2024-03-18 16:25:36 +00:00
许杰友 Jieyou Xu (Joe) cacdf92d37
Note that type param is chosen by caller when suggesting return impl Trait 2024-03-16 23:20:42 +00:00
bors 4cdd20584c Auto merge of #121657 - estebank:issue-119665, r=davidtwco
Detect more cases of `=` to `:` typo

When a `Local` is fully parsed, but not followed by a `;`, keep the `:` span arround and mention it. If the type could continue being parsed as an expression, suggest replacing the `:` with a `=`.

```
error: expected one of `!`, `+`, `->`, `::`, `;`, or `=`, found `.`
 --> file.rs:2:32
  |
2 |     let _: std::env::temp_dir().join("foo");
  |          -                     ^ expected one of `!`, `+`, `->`, `::`, `;`, or `=`
  |          |
  |          while parsing the type for `_`
  |          help: use `=` if you meant to assign
```

Fix #119665.
2024-03-02 05:03:46 +00:00
Esteban Küber bde2dfb127 Detect more cases of = to : typo
When a `Local` is fully parsed, but not followed by a `;`, keep the `:` span
arround and mention it. If the type could continue being parsed as an
expression, suggest replacing the `:` with a `=`.

```
error: expected one of `!`, `+`, `->`, `::`, `;`, or `=`, found `.`
 --> file.rs:2:32
  |
2 |     let _: std::env::temp_dir().join("foo");
  |          -                     ^ expected one of `!`, `+`, `->`, `::`, `;`, or `=`
  |          |
  |          while parsing the type for `_`
  |          help: use `=` if you meant to assign
```

Fix #119665.
2024-03-01 02:03:00 +00:00
Veera cc13f8278f Update item order in test 2024-02-28 19:28:34 -05:00
Veera 49961947c8 Improve error messages for generics with default parameters
Fixes #120785
2024-02-28 19:28:18 -05:00
Vadim Petrochenkov 9f8d05f29f macro_rules: Preserve all metavariable spans in a global side table 2024-02-18 11:19:24 +03:00
许杰友 Jieyou Xu (Joe) ec2cc761bc
[AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
Oli Scherer 5f6390f947 Continue compilation after check_mod_type_wf errors 2024-02-14 11:00:30 +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
Esteban Küber a9841936fe Deduplicate more sized errors on call exprs
Change the implicit `Sized` `Obligation` `Span` for call expressions to
include the whole expression. This aids the existing deduplication
machinery to reduce the number of errors caused by a single unsized
expression.
2024-01-24 02:53:15 +00:00
Esteban Küber dc30eb1967 Suggest = to == in more cases, even in the face of reference mismatch
Given `foo: &String` and `bar: str`, suggest `==` when given `if foo = bar {}`:

```
error[E0308]: mismatched types
  --> $DIR/assignment-expected-bool.rs:37:8
   |
LL |     if foo = bar {}
   |        ^^^^^^^^^ expected `bool`, found `()`
   |
help: you might have meant to compare for equality
   |
LL |     if foo == bar {}
   |             +
```
2023-12-26 23:48:55 +00:00
jyn cb6d033316 don't elide shared parts of types in diagnostics when --verbose is passed
this also changes some parts of lifetime printing, which previously were not gated behind `-Z verbose`
2023-12-24 16:47:18 -05:00
jyn b5d8361909 rename to verbose-internals 2023-12-19 13:35:37 -05:00
jyn eb53721a34 recurse into refs when comparing tys for diagnostics 2023-12-07 23:00:46 -05: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
Esteban Küber 8c04999226 On object safety error, mention new enum as alternative
When we encounter a `dyn Trait` that isn't object safe, look for its
implementors. If there's one, mention using it directly If there are
less than 9, mention the possibility of creating a new enum and using
that instead.

Account for object unsafe `impl Trait on dyn Trait {}`.  Make a
distinction between public and sealed traits.

Fix #80194.
2023-10-29 23:55:46 +00:00
Ethan Brierley 6c97f13612 Invalid ? suggestion on mismatched Ok(T) 2023-10-20 10:13:19 +01:00
bors 94bc9c737e Auto merge of #114811 - estebank:impl-ambiguity, r=wesleywiser
Show more information when multiple `impl`s apply

- When there are `impl`s without type params, show only those (to avoid showing overly generic `impl`s).
```
error[E0283]: type annotations needed
  --> $DIR/multiple-impl-apply.rs:34:9
   |
LL |     let y = x.into();
   |         ^     ---- type must be known at this point
   |
note: multiple `impl`s satisfying `_: From<Baz>` found
  --> $DIR/multiple-impl-apply.rs:14:1
   |
LL | impl From<Baz> for Bar {
   | ^^^^^^^^^^^^^^^^^^^^^^
...
LL | impl From<Baz> for Foo {
   | ^^^^^^^^^^^^^^^^^^^^^^
   = note: required for `Baz` to implement `Into<_>`
help: consider giving `y` an explicit type
   |
LL |     let y: /* Type */ = x.into();
   |          ++++++++++++
```

- Lower the importance of `T: Sized`, `T: WellFormed` and coercion errors, to prioritize more relevant errors. The pre-existing deduplication logic deals with hiding redundant errors better that way, and we show errors with more metadata that is useful to the user.

- Show `<SelfTy as Trait>::assoc_fn` suggestion in more cases.
```
error[E0790]: cannot call associated function on trait without specifying the corresponding `impl` type
  --> $DIR/cross-return-site-inference.rs:38:16
   |
LL |     return Err(From::from("foo"));
   |                ^^^^^^^^^^ cannot call associated function of trait
   |
help: use a fully-qualified path to a specific available implementation
   |
LL |     return Err(</* self type */ as From>::from("foo"));
   |                +++++++++++++++++++     +
```

Fix #88284.
2023-10-06 18:44:32 +00:00
ouz-a 3088c4b046 move subtyper change reveal_all 2023-10-05 18:56:30 +03:00
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 ac5aa8c1a4 Don't suggest nonsense suggestions for unconstrained type vars in note_source_of_type_mismatch_constraint 2023-10-02 21:13:46 +00:00
Esteban Küber ddb3b7e70a Use verbose suggestion for break without value 2023-09-25 22:10:08 +00:00
Esteban Küber 58adfd84e2 Account for more cases of nested loops for break type mismatches 2023-09-25 18:21:52 +00:00
León Orell Valerian Liehr b00e408e61
Generalize E0401 2023-09-10 23:06:14 +02:00
Martin Nordholts 6ba393c28f Rename tests/ui/issues/issue-100605.rs to ../type/option-ref-advice.rs
The test is a regression test for a bug where the compiler gave bad
advice for an `Option<&String>`. Rename the file appropriately.
2023-08-05 15:36:19 +02:00
Michael Goulet 2c33dfea76 Don't sort strings right after we just sorted by types 2023-06-27 23:31:06 +00:00
Nilstrieb 3e34be004e
Rollup merge of #111602 - tmiasko:erroneous-constant-used, r=oli-obk
Suppress "erroneous constant used" for constants tainted by errors

When constant evaluation fails because its MIR is tainted by errors,
suppress note indicating that erroneous constant was used, since those
errors have to be fixed regardless of the constant being used or not.

Fixes #110891.
2023-05-16 11:39:39 +02:00
Nilstrieb f65281534f
Rollup merge of #111428 - bvanjoi:fix-109250, r=Nilstrieb
refactor(resolve): clean up the early error return caused by non-call

closes https://github.com/rust-lang/rust/issues/109250

It seems no bad happened, r? ``@Nilstrieb``
2023-05-16 11:39:38 +02:00
Tomasz Miąsko 67f455afe1 Suppress "erroneous constant used" for constants tainted by errors
When constant evaluation fails because its MIR is tainted by errors,
suppress note indicating that erroneous constant was used, since those
errors have to be fixed regardless of the constant being used or not.
2023-05-15 00:00:00 +00:00
Michael Goulet 14bf909e71 Note base types of coercion 2023-05-12 00:10:52 +00:00
bohan 7c1bc0353b refactor(resolve): clean up the early error return caused by non-call 2023-05-10 22:35:01 +08:00
Dylan DPC 8c51701b8a
Rollup merge of #111120 - chenyukang:yukang-suggest-let, r=Nilstrieb
Suggest let for possible binding with ty

Origin from https://github.com/rust-lang/rust/pull/109128#discussion_r1179866137

r? `@Nilstrieb`
2023-05-09 12:33:46 +05:30
yukang 5e94b5faf1 code refactor and fix wrong suggestion 2023-05-08 14:56:36 +08:00
Michael Goulet a9051d861c Tweak borrow suggestion 2023-05-08 03:36:30 +00:00
yukang a7fc32ceaf fix ice in suggesting 2023-05-08 11:16:17 +08:00
yukang 0bb43c63c3 Suggest let for possible binding with ty 2023-05-08 10:56:20 +08:00
yukang 5d1796a608 soften the wording for removing type ascription 2023-05-01 16:37:00 +08:00
yukang f54489978d fix tests 2023-05-01 16:15:17 +08:00
yukang f44ebf7e54 fix test cases 2023-05-01 16:15:17 +08:00
Nilstrieb c63b6a437e Rip it out
My type ascription
Oh rip it out
Ah
If you think we live too much then
You can sacrifice diagnostics
Don't mix your garbage
Into my syntax
So many weird hacks keep diagnostics alive
Yet I don't even step outside
So many bad diagnostics keep tyasc alive
Yet tyasc doesn't even bother to survive!
2023-05-01 16:15:13 +08:00
Michael Goulet 015acc2611 Provide RHS type hint when reporting operator error 2023-04-27 01:34:03 +00:00
Michael Goulet 5cc4757421 More accurate argument blames, add some comments 2023-04-12 23:20:12 +00:00
Michael Goulet 5a71029dd3 Properly note source of arg mismatch 2023-04-12 23:20:12 +00:00
Michael Goulet 29aee6a125 Restore suggestion based off of backwards inference from bad usage to method call 2023-04-12 23:20:11 +00:00
Michael Goulet e72c45ad98 Point at which arg causes a binding to be constrained 2023-04-12 23:20:11 +00:00
Michael Goulet 42c4373ad1 Make note_source_of_type_mismatch_constraint simpler 2023-04-12 23:05:55 +00:00
yukang 65ad5f8de7 remove duplicated diagnostic for unclosed delimiter 2023-02-28 07:57:17 +00:00