Commit Graph

95 Commits

Author SHA1 Message Date
David Tolnay
b0059500f6
Reduce diagram mess in 'match arms have incompatible types' error 2020-10-22 16:16:02 -07:00
David Tolnay
f82adf5bdb
Add test of incompatible match arm types with multiline arm 2020-10-22 16:11:57 -07:00
Oliver Scherer
ce6c25da58 References to ZSTs may be at arbitrary aligned addresses 2020-09-30 10:40:49 +02:00
varkor
94c789b275 char not char 2020-09-26 13:34:49 +01:00
Oliver Scherer
177d0cef48 Deduplicate errors in const to pat conversion 2020-09-23 17:03:31 +02:00
Oliver Scherer
adf98ab2dc Use precise errors during const to pat conversion instead of a catch-all on the main constant 2020-09-20 18:42:15 +02:00
Oliver Scherer
b2532a8730 Implement destructuring for all aggregates and for references 2020-09-20 13:28:18 +02:00
Wonwoo Choi
c4fb3f297b Provide better spans for the match arm without tail expression 2020-08-18 15:28:56 +09:00
Ayaz Hafiz
3c63fba03d
Correctly mark the ending span of a match arm
Closes #74050

r? @matthewjasper
2020-07-08 07:28:07 -07:00
Bastian Kauschke
29508ce3ad normalize adt fields during structural match check 2020-06-02 00:23:47 +02:00
Yuki Okushi
9a164ff4c5
Skip tests on emscripten 2020-05-08 00:39:02 +09:00
Yuki Okushi
e69748ba4f
Move tests from test/run-fail to UI 2020-05-06 14:02:55 +09:00
Bastian Kauschke
2f5c0f59a9 emit err when using trait objects in pat 2020-04-29 19:33:50 +02:00
Mazdak Farrokhzad
c858593ed0 non-exhastive diagnostic: add note re. scrutinee type 2020-03-27 06:49:07 +01:00
Mark Mansi
b6518f0f66 update tests 2020-03-12 15:47:36 -05:00
Esteban Küber
125159f30a When encountering an Item in a pat context, point at the item def 2020-03-06 15:29:26 -08:00
Mazdak Farrokhzad
e9f6bb7f79 check_pat_path: use pattern_cause 2020-02-25 05:41:03 +01:00
Mazdak Farrokhzad
5da3a2f354 enhance check_pat_lit with TopInfo 2020-02-25 04:10:58 +01: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
varkor
24a2929ed1 Normalise notes with the/is 2020-01-24 16:24:50 +00:00
Mazdak Farrokhzad
e3c2f8fc57 slice_patterns: organize some tests 2020-01-18 19:33:47 +01:00
Mazdak Farrokhzad
a1eadca88f slice_patterns: remove gates in tests 2020-01-18 19:33:47 +01:00
Vadim Petrochenkov
642669c74d Update tests 2020-01-09 21:23:12 +03:00
varkor
0c2cf07d6e Add backticks to various diagnostics 2020-01-05 00:17:46 +00:00
Mazdak Farrokhzad
ab050d6a83 MatchExpressionArmPattern: Use more generic wording.
The existing wording was inappropriate for e.g.
`if let Ok(_) = expr { .. }`. The diagnostic would
leak the fact that we desugar to a `match`.
2019-12-30 13:50:20 +01:00
Mazdak Farrokhzad
c4b6de2d6a note other end-point when typeck range pats 2019-12-30 02:48:35 +01:00
bors
53712f8637 Auto merge of #66389 - estebank:type-err-labels, r=petrochenkov
Specific labels when referring to "expected" and "found" types
2019-11-21 17:53:19 +00:00
bors
0ccee30773 Auto merge of #58281 - mark-i-m:synthesis, r=estebank
Add outlives suggestions for some lifetime errors

This PR implements suggestion diagnostics for some lifetime mismatch errors. When the borrow checker finds that some lifetime 'a doesn't outlive some other lifetime 'b that it should outlive, then in addition to the current lifetime error, we also emit a suggestion for how to fix the problem by adding a bound:

- If a and b are normal named regions, suggest to add the bound `'a: 'b`
- If b is static, suggest to replace a with static
- If b also needs to outlive a, they must be the same, so suggest unifying  them

We start with a simpler implementation that avoids diagnostic regression or implementation complexity:
- We only makes suggestions for lifetimes the user can already name (eg not closure regions or elided regions)
- For now, we only emit a help note, not an actually suggestion because it is significantly easier.

Finally, there is one hack: it seems that implicit regions in async fn are given the name '_ incorrectly. To avoid suggesting '_: 'x, we simply filter out such lifetimes by name.

For more info, see this internals thread:

https://internals.rust-lang.org/t/mechanical-suggestions-for-some-borrow-checker-errors/9049/3

TL;DR Make suggestions to add a `where 'a: 'b` constraint for some lifetime errors. Details are in the paper linked from the internals thread above.

r? @estebank

TODO
- [x] Clean up code
- [x] Only make idiomatic suggestions
     - [x] don't suggest naming `&'a self`
     - [x] rather than `'a: 'static`, suggest replacing `'a` with `'static`
     - [x] rather than `'a: 'b, 'b: 'a`, suggest replacing `'a` with `'b` or vice versa
- [x] Performance (maybe need a perf run when this is closer to the finish line?)
     - perf run was clean...
     - EDIT: perf run seems to only check non-error performance... How do we check that error performance didn't regress?
- [x] Needs ui tests
- [x] Integrate the `help` message into the main lifetime `error`
2019-11-18 22:08:31 +00: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
83ffda5216 Specific labels when referring to "expected" and "found" types 2019-11-18 11:02:22 -08:00
Yuki Okushi
302cf6db74 Tweak non-char/numeric in range pattern diagnostic 2019-11-13 08:27:53 +09:00
Patryk Wychowaniec
273ee611f0
Improve the "try using a variant of the expected type" hint. 2019-10-28 18:43:51 +01:00
bors
8d78bf6b27 Auto merge of #65421 - estebank:variants, r=petrochenkov
Point at local similarly named element and tweak references to variants

Partially address #65386.
2019-10-28 13:41:13 +00:00
Nadrieril
09f9947ebc Gather together usefulness tests
I took most tests that were testing only for match exhaustiveness,
pattern refutability or match arm reachability, and put them in
the same test folder.
2019-10-27 21:20:26 +00:00
Esteban Küber
b26ddb8af3 Point at local similarly named element and tweak references to variants
Point at the span for the definition of ADTs internal to the current
crate.

Look at the leading char of the ident to determine whether we're
expecting a likely fn or any of a fn, a tuple struct or a tuple variant.

Turn fn `add_typo_suggestion` into a `Resolver` method.
2019-10-27 11:50:43 -07:00
Mark Mansi
cba0761e5f update tests 2019-10-27 09:39:14 -05:00
Esteban Küber
73d6efc43e Only emit overlapping patterns lint if the overlap is partial 2019-10-16 11:57:35 -07:00
Esteban Küber
89b19ccfdc Continue to emit unreachable pattern on cases caught by overlapping patterns 2019-10-16 11:57:19 -07:00
Esteban Küber
220b9b29c2 Move overlapping patterns to its own lint 2019-10-16 11:57:19 -07:00
Esteban Küber
91a3db95a1 Add check for overlapping ranges to unreachable patterns lint 2019-10-16 11:57:02 -07:00
Mazdak Farrokhzad
c2ae4ded4d
Rollup merge of #65292 - JohnTitor:add-backticks, r=varkor,Centril
Print lifetimes with backticks

Fixes #65287

r? @varkor
2019-10-14 07:36:54 +02:00
Yuki Okushi
2ae5e3421d Print lifetimes with backticks 2019-10-11 16:08:53 +09:00
Esteban Küber
4bb1592402 Suggest if let on let refutable binding 2019-10-09 12:25:48 -07:00
Esteban Küber
ea70fb7567 Do not trigger unreachable lint in async body and Use span labels 2019-09-21 13:04:04 -07:00
Aaron Hill
822393d690
Point at original span when emitting unreachable lint
Fixes #64590

When we emit an 'unreachable' lint, we now add a note pointing at the
expression that actually causes the code to be unreachable (e.g.
`return`, `break`, `panic`).

This is especially useful when macros are involved, since a diverging
expression might be hidden inside of a macro invocation.
2019-09-18 18:35:10 -04:00
bors
f0b58fcf03 Auto merge of #64271 - Centril:non-exhaustive-peel-refs, r=estebank
check_match: refactor + improve non-exhaustive diagnostics for default binding modes

Refactor `check_match` a bit with more code-reuse and improve the diagnostics for a non-exhaustive pattern match by peeling off any references from the scrutinee type so that the "defined here" label is added in more cases. For example:

```rust
error[E0004]: non-exhaustive patterns: `&mut &B` not covered
 --> foo.rs:4:11
  |
1 | enum E { A, B }
  | ---------------
  | |           |
  | |           not covered
  | `E` defined here
...
4 |     match x {
  |           ^ pattern `&mut &B` not covered
  |
  = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
```

Moreover, wrt. "defined here", we give irrefutable pattern matching (i.e. in `let`, `for`, and `fn` parameters) a more consistent treatment in line with `match`.

r? @estebank
2019-09-11 18:46:18 +00:00
Mazdak Farrokhzad
7d4665b097 check_match: unify check_irrefutable & check_exhaustive more. 2019-09-09 16:44:23 +02:00