101 Commits

Author SHA1 Message Date
Esteban Küber
28e6f1f5b9 Suggest boxing or borrowing unsized fields 2020-07-14 10:50:24 -07:00
Aaron Hill
517d361a1f
Use an 'approximate' universal upper bound when reporting region errors
Fixes #67765

When reporting errors during MIR region inference, we sometimes use
`universal_upper_bound` to obtain a named universal region that we
can display to the user. However, this is not always possible - in a
case like `fn foo<'a, 'b>() { .. }`, the only upper bound for a region
containing `'a` and `'b` is `'static`. When displaying diagnostics, it's
usually better to display *some* named region (even if there are
multiple involved) rather than fall back to a generic error involving
`'static`.

This commit adds a new `approx_universal_upper_bound` method, which
uses the lowest-numbered universal region if the only alternative is to
return `'static`.
2020-06-27 14:01:59 -04:00
Esteban Küber
8f7ee34379 Tweak type parameter errors to reduce verbosity 2020-05-30 10:22:26 -07:00
Esteban Küber
f213acf4db review comments: change wording and visual output 2020-05-27 20:58:05 -07:00
Esteban Küber
2b35247d7a Modify wording 2020-05-27 16:28:20 -07:00
Esteban Küber
3811232190 review comments 2020-05-27 16:28:20 -07:00
Esteban Küber
eb0f4d51df Tweak output for mismatched impl item
Detect type parameter that might require lifetime constraint.
Do not name `ReVar`s in expected/found output.
Reword text suggesting to check the lifetimes.
2020-05-27 16:28:20 -07:00
Esteban Küber
5ba22205a4 Name RegionKind::ReVar lifetimes in diagnostics 2020-05-27 16:28:04 -07:00
Yuki Okushi
be2d5535ea
Add test for #34979 2020-05-07 02:22:08 +09:00
Esteban Küber
1f43fc0209 Tweak wording 2020-04-22 12:12:33 -07:00
Esteban Küber
13c1daeb2f Tweak 'static suggestion code
Fix #71196.
2020-04-22 12:12:33 -07:00
Eduard-Mihai Burtescu
f86f03263c outlives: ignore lifetimes shallowly found in ty::FnDefs. 2020-04-16 23:18:44 +03:00
Mark Mansi
b6518f0f66 update tests 2020-03-12 15:47:36 -05:00
Mark Mansi
9434d6b67f update some tests 2020-02-22 16:14:14 -06:00
Esteban Küber
c816430f99 Tweak binding lifetime suggestion text
We already have a structured suggestion, but the wording made it seem
like that wasn't the case.
Fix #65286. r? @varkor
2020-02-19 18:04:03 -08: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
92505df338 Account for fn() types in lifetime suggestions 2020-02-05 10:32:01 -08:00
Esteban Küber
2100b31535 review comments 2020-02-05 10:32:01 -08:00
Esteban Küber
fa4594196d Suggest 'r instead of 'lifetime 2020-02-05 10:32:01 -08:00
Esteban Küber
7e1464336a When suggesting lifetimes, propose adding the new lifetime to all arguments 2020-02-05 10:32:01 -08:00
Esteban Küber
70dbf5526d Use spans for input borrowed types unrelated to return type 2020-02-05 10:32:01 -08: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
Esteban Küber
2102723887 review comments 2020-01-19 17:31:34 -08:00
Esteban Küber
78d3ea5484 When encountering an expected named lifetime and none are present, suggest adding one 2020-01-19 17:31:33 -08:00
Esteban Küber
5b36c187dc review comments 2020-01-16 09:49:13 -08:00
Esteban Küber
e1dd8a9095 When trait bounds are missing for return values, point at them 2020-01-16 09:37:24 -08:00
Esteban Küber
5e1b366fb6 Do not ICE on lifetime error involving closures 2019-12-28 13:51:29 -08: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
83ffda5216 Specific labels when referring to "expected" and "found" types 2019-11-18 11:02:22 -08:00
Guillaume Gomez
ffc1c5a04d Update ui tests 2019-11-07 13:02:34 +01:00
Esteban Küber
6998085c03 Point at the trait item and tweak wording 2019-10-29 10:19:58 -07:00
Esteban Küber
ef2a8539aa review comments 2019-10-29 10:19:58 -07:00
Esteban Küber
c3521fe940 Custom lifetime error for impl item doesn't conform to trait 2019-10-29 10:19:58 -07:00
Mark Mansi
cba0761e5f update tests 2019-10-27 09:39:14 -05:00
Yuki Okushi
2ae5e3421d Print lifetimes with backticks 2019-10-11 16:08:53 +09:00
Mark Mansi
5b09358592 update tests 2019-09-12 18:56:09 -05:00
Niko Matsakis
af86fb1959 distinguish object-lifetime-default elision from other elision
Object-lifetime-default elision is distinct from other forms of
elision; it always refers to some enclosing lifetime *present in the
surrounding type* (e.g., `&dyn Bar` expands to `&'a (dyn Bar + 'a)`.
If there is no enclosing lifetime, then it expands to `'static`.

Therefore, in an `impl Trait<Item = dyn Bar>` setting, we don't expand
to create a lifetime parameter for the `dyn Bar + 'X` bound.  It will
just be resolved to `'static`.

Annoyingly, the responsibility for this resolution is spread across
multiple bits of code right now (`middle::resolve_lifetimes`,
`lowering`). The lowering code knows that the default is for an object
lifetime, but it doesn't know what the correct result would be.
Probably this should be fixed, but what we do now is a surgical fix:
we have it generate a different result for elided lifetimes in a
object context, and then we can ignore those results when figuring out
the lifetimes that are captured in the opaque type.
2019-08-19 13:50:42 -04:00
Matthew Jasper
da22793a35 Create fewer basic blocks in match MIR lowering 2019-06-13 21:05:21 +01:00
memoryruins
eb4580a570 Update ui test suite to use dyn 2019-05-29 00:57:31 -04:00
Matthew Jasper
ff71b80a85 Change compare mode to use -Zborrowck=mir 2019-05-12 18:46:43 +01:00
Christopher Vittal
cfdd6ba77e Update tests 2019-05-03 03:11:37 -04:00
Mazdak Farrokhzad
a4ef188ab6
Rollup merge of #60160 - xldenis:fix-overlapping-zero-width-annotation, r=estebank
Fix #58270, fix off-by-one error in error diagnostics.

This fixes #58270 by checking if two diagnostics overlap completely when we're calculating the line offset for each message.
2019-04-25 03:05:24 +02:00
Xavier Denis
4a073dda93 Fix #58270, fix off-by-one error in error diagnostics. 2019-04-22 18:14:45 -05:00
varkor
7f0f0e31ec Remove double trailing newlines 2019-04-22 16:57:01 +01:00
Matthew Jasper
8eef102270 update tests for migrate mode by default 2019-04-22 08:40:08 +01:00
Andy Russell
b6f148c8bd
hide --explain hint if error has no extended info 2019-04-18 13:29:28 -04:00
Vadim Petrochenkov
c1cfacfb13 Update NLL tests 2019-03-11 23:18:35 +03:00