rust/src/librustc_errors
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
..
json Move JSON emitter to rustc_errors 2019-11-15 08:45:49 -05:00
annotate_snippet_emitter_writer.rs Remove SourceMapper trait 2019-11-15 08:45:43 -05:00
Cargo.toml Introduce term-size dependency and consider term width when trimming 2019-08-21 11:56:20 -07:00
diagnostic.rs Auto merge of #58281 - mark-i-m:synthesis, r=estebank 2019-11-18 22:08:31 +00:00
diagnostic_builder.rs RFC 2027: "first draft" of implementation 2019-10-22 15:24:33 -04:00
emitter.rs Remove SourceMapper trait 2019-11-15 08:45:43 -05:00
json.rs Move JSON emitter to rustc_errors 2019-11-15 08:45:49 -05:00
lib.rs Auto merge of #58281 - mark-i-m:synthesis, r=estebank 2019-11-18 22:08:31 +00:00
lock.rs Make use of ptr::null(_mut) instead of casting zero 2019-06-17 10:52:46 +00:00
registry.rs Remove licenses 2018-12-25 21:08:33 -07:00
snippet.rs librustc_errors: Remove unused annotation style OldSchoolNoteText 2019-05-23 08:01:38 +02:00
styled_buffer.rs Correctly estimate required space for string 2019-10-05 03:08:05 +03:00