Commit Graph

40 Commits

Author SHA1 Message Date
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
Eduard-Mihai Burtescu
25953321c0 rustc: remove "GlobalMetaData" dead code from hir::map::definitions. 2019-11-05 21:00:38 +02:00
Mark Mansi
cba0761e5f update tests 2019-10-27 09:39:14 -05:00
Mark Mansi
3a1847b07d implement outlive suggestions 2019-10-27 08:47:22 -05:00
Vadim Petrochenkov
ee6d315200 cleanup: Remove DefIndexAddressSpace 2019-05-09 00:46:38 +03:00
Andy Russell
b6f148c8bd
hide --explain hint if error has no extended info 2019-04-18 13:29:28 -04:00
David Tolnay
cfd31fb4df
Include trailing comma in multiline Debug representation
This commit changes the behavior of Formatter::debug_struct,
debug_tuple, debug_list, debug_set, and debug_map to render trailing
commas in {:#?} mode, which is the dominant style in modern Rust code.

Before:

    Language {
        name: "Rust",
        trailing_commas: false
    }

After:

    Language {
        name: "Rust",
        trailing_commas: true,
    }
2019-04-05 06:45:40 -07: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
Niv Kaminer
3773ae26a0 FIXME(45827) remove comment since errors are reported 2018-12-19 10:51:47 +02:00
Niko Matsakis
64b5599352 stop reporting "unsatisfied lifetime bounds" errors after the first
In particular, after the first for a given region variable. This
suppresses a lot of duplicate errors.
2018-10-22 11:41:46 -04:00
Matthew Jasper
275432c115 Give an error number for "borrowed data escapes outside of closure" 2018-10-20 23:11:30 +01:00
Matthew Jasper
825810734b Improve closure region bound errors
Now use the category and span that are associated to the most
interesting bound that led to the closure bound.
2018-10-06 10:00:26 +01:00
Matthew Jasper
bd0895d7d0 Update ui tests 2018-09-19 20:50:09 +01:00
Niko Matsakis
bb8c4c0db9 print less info to stabilize tests 2018-09-07 17:24:46 -04:00
Niko Matsakis
db169e53e5 move annotate onto a method of UniversalRegions
This allows it to print out the "late-bound regions" from the closure
context more easily. Besides, all the state that is being printed it
is private to the `UniversalRegions`.
2018-09-07 17:08:21 -04:00
Wesley Wiser
b1211e8703 Fix tests 2018-09-06 22:57:05 -04:00
Basile Desloges
b01550a718 Update tests 2018-09-01 12:58:18 +02:00
Felix S. Klock II
6787e25c29 Blindly update the #[rustc_region] tests which got touched by the NLL diagnostic change. 2018-07-31 14:35:43 +02:00
Mikhail Modin
bb66d70b89 fix issues #51351 and #52133 2018-07-29 11:42:50 +01:00
David Wood
b377e7bbfb
Change label from closure to function where appropriate. 2018-07-27 12:48:47 +02:00
David Wood
c64db0078a
Fallback to general error handling in ICE cases. 2018-07-22 12:53:55 +01:00
Niko Matsakis
727f01700b write code to extract region names and emit new style message 2018-07-04 05:09:33 -04:00
David Wood
c0c4741ef7
Updated affected tests after rebase. 2018-07-01 16:14:26 +01:00
David Wood
a11245f80e
Ensure that changed errors are lower case. 2018-07-01 16:14:25 +01:00
David Wood
59e64e9085
Updated affected tests. 2018-07-01 16:14:25 +01:00
Vytautas Astrauskas
03ecd982bf Fix the error of selecting obligation by not running the borrow checker. 2018-06-27 18:14:00 +02:00
bors
fc19590297 Auto merge of #51248 - fabric-and-ink:newtype_index_debrujin, r=nikomatsakis
Declare DebruijnIndex via newtype_index macro

Part of #49887

Declare `DebruijnIndex` via the `newtype_index` macro.
2018-06-18 23:14:50 +00:00
Fabian Drinck
a06870eb78 Fix typo DebrujinIndex -> DebruijnIndex 2018-06-14 18:44:37 +02:00
Fabian Drinck
54b2228778 Add DEBUG_FORMAT for DebruijnIndex 2018-06-14 18:44:37 +02:00
Fabian Drinck
0ad3600700 Declare DebruijnIndex via newtype_index macro 2018-06-14 18:44:36 +02:00
Niko Matsakis
a40e629a33 update some tests affected by some of the prior tweaks 2018-06-09 11:02:14 -04:00
Niko Matsakis
783fe4f880 change to 0-based indices
Co-authored-by: csmoe <35686186+csmoe@users.noreply.github.com>
2018-05-28 19:47:05 -04:00
Niko Matsakis
45d281d7fa remove -Znll -- borrowck=mir implies nll now 2018-04-15 07:13:42 -04:00
Vadim Petrochenkov
7ba5fd168a Update UI tests 2018-02-26 20:24:42 +03:00
Vadim Petrochenkov
fa2d9fc4b9 Update UI tests 2018-02-26 20:24:02 +03:00
Niko Matsakis
6b39781df6 connect NLL machinery to the NiceRegionError code 2017-12-20 14:38:12 -05:00
Niko Matsakis
a30e2259da fix closure tests now that MIR typeck works properly
These tests had FIXMEs for errors that were not previously being
reported.
2017-12-13 12:20:27 -05:00
Tommy Ip
2ad5bf056c Update ui tests' line numbers. 2017-12-10 21:14:57 +00:00
Niko Matsakis
ca60826110 test approximations of the "shorter side" that resort to 'static
This includes the additional case suggested by arielb1.
2017-12-07 05:28:03 -05:00