Commit Graph

43 Commits

Author SHA1 Message Date
Reese Williams d8540ae5a9 Fix suggestion span and move suggestions into new subwindow. 2021-02-20 15:33:08 -05:00
Reese Williams 7879099ad3 Clarify error message and remove pretty printing in help suggestions. 2021-02-14 13:15:37 -05:00
Dan Aloni 07e7823c01 pretty: trim paths of unique symbols
If a symbol name can only be imported from one place for a type, and
as long as it was not glob-imported anywhere in the current crate, we
can trim its printed path and print only the name.

This has wide implications on error messages with types, for example,
shortening `std::vec::Vec` to just `Vec`, as long as there is no other
`Vec` importable anywhere.

This adds a new '-Z trim-diagnostic-paths=false' option to control this
feature.

On the good path, with no diagnosis printed, we should try to avoid
issuing this query, so we need to prevent trimmed_def_paths query on
several cases.

This change also relies on a previous commit that differentiates
between `Debug` and `Display` on various rustc types, where the latter
is trimmed and presented to the user and the former is not.
2020-09-02 22:26:37 +03:00
Esteban Küber 07112ca62d Suggest `if let x = y` when encountering `if x = y`
Detect potential cases where `if let` was meant but `let` was left out.

Fix #44990.
2020-08-30 15:01:06 -07:00
Esteban Küber 5daedea3db Detect tuple struct incorrectly used as struct pat 2020-07-12 10:34:48 -07:00
Esteban Küber 75f066dc68 Handle binop on unbound type param
When encountering a binary operation involving a type parameter that has
no bindings, suggest adding the appropriate bound.
2020-05-04 09:52:40 -07:00
Esteban Küber bd7ea5441e Use `PredicateObligation`s instead of `Predicate`s
Keep more information about trait binding failures.
2020-04-08 14:40:45 -07:00
Esteban Küber 0cd4c89366 "cannot resolve" → "cannot satisfy" 2020-04-05 10:14:04 -07:00
Eduard-Mihai Burtescu 4c7eb59e81 rustc_macros: don't limit the -Zmacro-backtrace suggestion to extern macros. 2020-02-06 21:46:38 +02:00
Eduard-Mihai Burtescu f6fc80206e rustc: rename -Zexternal-macro-backtrace to -Zmacro-backtrace. 2020-02-06 21:32:07 +02:00
Esteban Küber 6870f79e9c Use more accurate failed predicate spans 2020-02-02 11:53:09 -08:00
Esteban Küber fca5c64abd Point at arguments or output when fn obligations come from them, or ident when they don't 2020-02-02 11:52:33 -08:00
varkor 0c2cf07d6e Add backticks to various diagnostics 2020-01-05 00:17:46 +00:00
varkor 35979a92bf Add span information to `ExprKind::Assign` 2019-12-23 11:20:13 +00:00
varkor b7bfdbe681 Improve invalid assignment error 2019-12-23 11:16:51 +00:00
Mazdak Farrokhzad eac5fb8b0a
Rollup merge of #67189 - LeSeulArtichaut:binop-wording, r=estebank
Unify binop wording

Closes #60497
r? @estebank
2019-12-19 10:29:51 +01:00
bors 8843b28e64 Auto merge of #65951 - estebank:type-inference-error, r=nikomatsakis
Point at method call when type annotations are needed

- Point at method call instead of whole expression when type annotations are needed.
- Suggest use of turbofish on function and methods.

Fix #49391, fix #46333, fix #48089. CC #58517, #63502, #63082.

Fixes https://github.com/rust-lang/rust/issues/40015

r? @nikomatsakis
2019-12-13 22:56:27 +00:00
Mazdak Farrokhzad f97c37f8ae coerce_inner: use initial expected_ty 2019-12-13 15:52:51 +01:00
LeSeulArtichaut eac6fac10b Update tests 2019-12-12 20:56:14 +01:00
LeSeulArtichaut 3bd46f1aec Update UI test expectations 2019-12-12 20:56:14 +01:00
Esteban Küber da023c0c6f Add more context for type parameters 2019-12-11 17:18:43 -08:00
Esteban Küber 252773af8b Deduplicate logic 2019-12-10 12:02:18 -08:00
Esteban Küber 34f03c01f6 Point at type in `let` assignment on type errors 2019-11-21 19:24:31 -08:00
Esteban Küber 6f8f70624b Surround types with backticks in type errors 2019-11-18 11:03:04 -08:00
Esteban Küber 94c6425464 Remove E0308 note when primary label has all info 2019-11-18 11:03:03 -08:00
Esteban Küber b2e6aef073 review comments: tweak prefix strings 2019-11-18 11:02:44 -08:00
Esteban Küber d9ab4ff9a3 Remove blanket silencing of "type annotation needed" errors
Remove blanket check for existence of other errors before emitting
"type annotation needed" errors, and add some eager checks to avoid
adding obligations when they refer to types that reference
`[type error]` in order to reduce unneded errors.
2019-09-24 11:31:14 -07:00
Esteban Küber 444bc3ca66 Use span label instead of note for cause in E0631 2019-08-31 00:14:23 -07:00
Esteban Küber e420f4410b Account for cases where we can find the type arg name, but the local name is `_` 2019-06-01 15:33:31 -07:00
Esteban Küber 9616b333b2 review comment: tweak wording 2019-06-01 14:47:15 -07:00
Esteban Küber ebbe725dd0 Tweak wording 2019-05-31 20:48:09 -07:00
Esteban Küber 74fb3bbee4 On type inference errors use the type argument name when possible
```
error[E0282]: type annotations needed in `std::result::Result<i32, E>`
 --> file7.rs:3:13
  |
3 |     let b = Ok(4);
  |         -   ^^ cannot infer type for `E` in `std::result::Result<i32, E>`
  |         |
  |         consider giving `b` a type`
```
2019-05-31 18:33:59 -07:00
Esteban Küber 65c2a7b18b Alternative wording for inference failure 2019-05-31 18:33:59 -07:00
Esteban Küber 8bb094dac5 Add more detail to type inference error
When encountering code where type inference fails, add more actionable
information:

```
fn main() {
    let foo = Vec::new();
}
```

```
error[E0282]: type annotations needed for `std::vec::Vec<_>`
  --> $DIR/vector-no-ann.rs:2:16
   |
LL |     let foo = Vec::new();
   |         ---   ^^^^^^^^ cannot infer type for `T`
   |         |
   |         consider giving `foo` the type `std::vec::Vec<_>` with the type parameter `T` specified
```

We still need to modify type printing to optionally accept a
`TypeVariableTable` in order to properly print `std::vec::Vec<T>`.

CC #25633.
2019-05-31 18:33:59 -07:00
Andy Russell b6f148c8bd
hide `--explain` hint if error has no extended info 2019-04-18 13:29:28 -04:00
Mazdak Farrokhzad fda206633d
Rollup merge of #59467 - hgallagher1993:local_branch, r=estebank
Better diagnostic for binary operation on BoxedValues

Fixes #59458
2019-03-29 12:32:26 +01:00
hgallagher1993 4d648ce1b9 Better diagnostic for binary operation on BoxedValues 2019-03-27 13:13:09 -04:00
Mazdak Farrokhzad ce1c5e0a61 add negative test case in assignment-expected-bool 2019-03-27 10:19:47 +01:00
Mazdak Farrokhzad 0b9c589beb adjust assignment-in-if test accordingly. 2019-03-27 10:19:47 +01:00
Mazdak Farrokhzad 05d59feb64 add test for assignment x = y where type bool is expected. 2019-03-27 10:19:47 +01:00
Vadim Petrochenkov fa72a81bea Update tests 2019-03-11 23:10:26 +03:00
Mark Rousskov 2a663555dd Remove licenses 2018-12-25 21:08:33 -07:00
David Wood 3fc7ab2373
Merged migrated compile-fail tests and ui tests. Fixes #46841. 2018-08-14 11:12:09 +02:00