Commit Graph

112 Commits

Author SHA1 Message Date
Esteban Küber 5d0697b1be reworded message 2021-03-03 12:15:26 -08:00
Esteban Küber 5824917dbb Account for macros when suggesting adding lifetime
Fix #70152.
2021-03-02 18:24:13 -08:00
Matthew Jasper 9337d4fde8 Print closure signatures when reporting placeholder errors 2021-02-09 23:00:33 +00:00
Matthew Jasper 94c11dfe78 Report "nice" placeholder errors more often
If we have a cause containing `ValuePairs::PolyTraitRefs` but neither
TraitRef has any escaping bound regions then we report the same error as
for `ValuePairs::TraitRefs`.
2021-02-09 22:59:32 +00:00
Dan Aloni eaefe4a230 path trimming: ignore type aliases 2021-02-06 12:03:48 +02:00
Jesus Rubio c57889bbf9 Update ui tests (nll) 2021-02-02 18:57:34 +01:00
bors d03fe84169 Auto merge of #79328 - c410-f3r:hir-if, r=matthewjasper
Reintroduce hir::ExprKind::If

Basically copied and paste #59288/https://github.com/rust-lang/rust-clippy/pull/4080 with some modifications.

The vast majority of tests were fixed and now there are only a few remaining. Since I am still unable to figure out the missing pieces, any help with the following list is welcome.

- [ ] **Unnecessary `typeck` exception**: [Cheated on this one to make CI green.](https://github.com/rust-lang/rust/pull/79328/files#diff-3faee9ba23fc54a12b7c43364ba81f8c5660045c7e1d7989a02a0cee1c5b2051)
- [x] **Incorrect span**: [Span should reference `then` and `else` separately.](https://github.com/rust-lang/rust/pull/79328/files#diff-cf2c46e82222ee4b1037a68fff8a1af3c4f1de7a6b3fd798aacbf3c0475abe3d)
- [x] **New note regarding `assert!`**: [Modified but not "wrong". Maybe can be a good thing?](https://github.com/rust-lang/rust/pull/79328/files#diff-9e0d7c89ed0224e2b62060c957177c27db43c30dfe3c2974cb6b5091cda9cfb5)
- [x] **Inverted report location**: [Modified but not "wrong". Locations were inverted.](https://github.com/rust-lang/rust/pull/79328/files#diff-f637ce7c1f68d523a165aa9651765df05e36c4d7d279194b1a6b28b48a323691)
- [x] **`src/test/ui/point-to-type-err-cause-on-impl-trait-return.rs` has weird errors**: [Not sure why this is happening.](https://github.com/rust-lang/rust/pull/79328/files#diff-c823c09660f5b112f95e97e8ff71f1797b6c7f37dbb3d16f8e98bbaea8072e95)
- [x] **Missing diagnostic**: [???](https://github.com/rust-lang/rust/pull/79328/files#diff-6b8ab09360d725ba4513933827f9796b42ff9522b0690f80b76de067143af2fc)
2021-01-14 14:41:58 +00:00
Esteban Küber a8a974245e Provide more information for HRTB lifetime errors involving closures 2021-01-12 13:53:13 -08:00
Caio f85fc264fe Reintroduce hir::ExprKind::If 2021-01-07 18:54:12 -03:00
Matthew Jasper 5b279c8016 Check opaque types satisfy their bounds 2020-10-06 11:19:30 +01: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 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::FnDef`s. 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