Commit Graph

534 Commits

Author SHA1 Message Date
bors
5371ddf8c6 Auto merge of #68080 - varkor:declared-here, r=petrochenkov
Address inconsistency in using "is" with "declared here"

"is" was generally used for NLL diagnostics, but not other diagnostics. Using "is" makes the diagnostics sound more natural and readable, so it seems sensible to commit to them throughout.

r? @Centril
2020-01-31 15:13:51 +00:00
Esteban Küber
3fb1810476 Use better bound names in -Zverbose mode 2020-01-25 13:25:19 -08:00
varkor
24a2929ed1 Normalise notes with the/is 2020-01-24 16:24:50 +00:00
varkor
f4f96e2943 Normalise diagnostics with respect to "the X is declared/defined here" 2020-01-24 16:24:49 +00:00
Tomasz Miąsko
5c73d21eaa Use check-pass mode for nll tests 2020-01-23 00:00:00 +00:00
varkor
0810210bcb Diagnostics should start lowercase 2020-01-12 15:36:40 +00:00
Lzu Tao
dd8f072233 Use drop instead of the toilet closure |_| () 2020-01-02 08:56:12 +00:00
Remy Rakic
1314ba323b add subset relations test using polonius
It's a relatively simple smoke-test for subset errors, executed outside
of the polonius compare-mode.
2019-12-06 11:50:02 +01:00
Remy Rakic
720716f9d0 bless polonius output due to lacking the 'static special-casing 2019-12-06 11:50:02 +01:00
Remy Rakic
695640816a bless polonius output of test ui/nll/outlives-suggestion-simple.rs
The polonius output has one more error which should be displayed
in the regular case, but error reporting in the regular case stopped
at the first error.

Admittedly it would be nice to combine suggestions for the same source
lifetime so that `'a: 'b` and `'a: 'c` are not bothsuggested, but instead
a single `'a: 'b + 'c` is.
2019-12-06 11:50:02 +01:00
bors
234c9f21d9 Auto merge of #66911 - eddyb:nicer-rustc_regions, r=matthewjasper
rustc_mir: use nicer path printing for #[rustc_regions] NLL tests.

Similar to #66850, spotted while working on #66907.

r? @matthewjasper
2019-12-06 00:22:54 +00:00
Aaron Hill
168e35d569
Include a span in more expected...found notes
In most places, we use a span when emitting `expected...found` errors.
However, there were a couple of places where we didn't use any span,
resulting in hard-to-interpret error messages.

This commit attaches the relevant span to these notes, and additionally
switches over to using `note_expected_found` instead of manually
formatting the message
2019-12-03 23:13:10 -05:00
Eduard-Mihai Burtescu
84bad09420 rustc_mir: use nicer path printing for #[rustc_regions] NLL tests. 2019-11-30 18:47:21 +02:00
Eduard-Mihai Burtescu
9034efe3f7 rustc: don't just show raw DefIndex's in BrNamed's fmt::Debug impl. 2019-11-30 17:29:56 +02:00
Esteban Küber
9c97d73a2d Tweak move error due to non-Copy 2019-11-25 13:30:52 -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
Mazdak Farrokhzad
40deec82bc
Rollup merge of #66155 - GuillaumeGomez:long-err-explanation-E0594, r=Dylan-DPC
Add long error explanation for E0594

Part of #61137.

r? @Dylan-DPC
2019-11-19 13:10:12 +01: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
cd13335ae2 Update ui tests 2019-11-18 19:00:10 +01:00
Matthew Jasper
4bf0685cca Evaluate borrow and struct expressions in into
This fixes some ordering problems around assignment expressions.
2019-11-11 22:06:54 +00:00
Mazdak Farrokhzad
a96811ee9c
Rollup merge of #66087 - tmiasko:ui-mode, r=Centril
Update some build-pass ui tests to use check-pass where applicable

Helps with issue https://github.com/rust-lang/rust/issues/62277.
2019-11-07 14:27:24 +01:00
Eduard-Mihai Burtescu
25953321c0 rustc: remove "GlobalMetaData" dead code from hir::map::definitions. 2019-11-05 21:00:38 +02:00
Tomasz Miąsko
0501d8ab0d Use check-pass in ui tests where appropriate 2019-11-04 16:03:46 +01:00
Mark Mansi
cba0761e5f update tests 2019-10-27 09:39:14 -05:00
Mark Mansi
89a184a399 add test for complex suggestions 2019-10-27 08:47:22 -05:00
Mark Mansi
3a1847b07d implement outlive suggestions 2019-10-27 08:47:22 -05:00
Mazdak Farrokhzad
0aa7c6f96b
Rollup merge of #65773 - estebank:sugg-whitespace, r=Centril
Increase spacing for suggestions in diagnostics

Make the spacing between the code snippet and verbose structured
suggestions consistent with note and help messages.

r? @Centril
2019-10-26 14:17:45 +02:00
Matthew Jasper
d724174346 Fix more ReEmpty ICEs 2019-10-24 21:15:08 +01:00
Esteban Küber
0baf61bfdb Increase spacing for suggestions in diagnostics
Make the spacing between the code snippet and verbose structured
suggestions consistent with note and help messages.
2019-10-24 12:26:01 -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
bors
3da6836cc9 Auto merge of #65099 - pnkfelix:issue-63154-needed-more-normalize, r=nagisa
MIR typeck needed more normalize

Add some missing normalization calls (@nagisa [was right](https://github.com/rust-lang/rust/issues/63154#issuecomment-517305589)).

Fix #63154
2019-10-13 03:37:25 +00:00
Yuki Okushi
2ae5e3421d Print lifetimes with backticks 2019-10-11 16:08:53 +09:00
Guillaume Gomez
96efaad342 update ui tests 2019-10-07 17:12:54 +02:00
Felix S Klock II
00bf29bded
Update src/test/ui/nll/issue-63154-normalize.rs
review feedback

Co-Authored-By: Mazdak Farrokhzad <twingoow@gmail.com>
2019-10-07 10:19:38 +02:00
Felix S. Klock II
6dd86b411f Regression test for #63154. 2019-10-04 14:21:12 +02:00
Mazdak Farrokhzad
314fbf48cf
Rollup merge of #64749 - matthewjasper:liveness-opt, r=nikomatsakis
Fix most remaining Polonius test differences

This fixes most of the Polonius test differences and also avoids overflow in issue-38591.rs.

r? @nikomatsakis
2019-10-04 07:24:33 +02:00
Matthew Jasper
2180c24321 Make lifetimes in constants live at the point of use 2019-10-02 20:39:01 +01:00
Matthew Jasper
08a60ac6ed Calculate liveness for the same locals with and without -Zpolonius
This fixes some test differences and also avoids overflow in
issue-38591.rs.
2019-10-02 20:39:01 +01:00
Aaron Hill
1245467322
Improve HRTB error span when -Zno-leak-check is used
As described in #57374, NLL currently produces unhelpful higher-ranked
trait bound (HRTB) errors when '-Zno-leak-check' is enabled.

This PR tackles one half of this issue - making the error message point
at the proper span. The error message itself is still the very generic
"higher-ranked subtype error", but this can be improved in a follow-up
PR.

The root cause of the bad spans lies in how NLL attempts to compute the
'blamed' region, for which it will retrieve a span for.
Consider the following code, which (correctly) does not compile:

```rust
let my_val: u8 = 25;
let a: &u8 = &my_val;
let b = a;
let c = b;
let d: &'static u8 = c;
```

This will cause NLL to generate the following subtype constraints:

d :< c
c :< b
b <: a

Since normal Rust lifetimes are covariant, this results in the following
region constraints (I'm using 'd to denote the lifetime of 'd',
'c to denote the lifetime of 'c, etc.):

'c: 'd
'b: 'c
'a: 'b

From this, we can derive that 'a: 'd holds, which implies that 'a: 'static
must hold. However, this is not the case, since 'a refers to 'my_val',
which does not outlive the current function.

When NLL attempts to infer regions for this code, it will see that the
region 'a has grown 'too large' - it will be inferred to outlive
'static, despite the fact that is not declared as outliving 'static
We can find the region responsible, 'd, by starting at the *end* of
the 'constraint chain' we generated above. This works because for normal
(non-higher-ranked) lifetimes, we generally build up a 'chain' of
lifetime constraints *away* from the original variable/lifetime.
That is, our original lifetime 'a is required to outlive progressively
more regions. If it ends up living for too long, we can look at the
'end' of this chain to determine the 'most recent' usage that caused
the lifetime to grow too large.

However, this logic does not work correctly when higher-ranked trait
bounds (HRTBs) come into play. This is because HRTBs have
*contravariance* with respect to their bound regions. For example,
this code snippet compiles:

```rust
let a: for<'a> fn(&'a ()) = |_| {};
let b: fn(&'static ()) = a;
```

Here, we require that 'a' is a subtype of 'b'. Because of
contravariance, we end up with the region constraint 'static: 'a,
*not* 'a: 'static

This means that our 'constraint chains' grow in the opposite direction
of 'normal lifetime' constraint chains. As we introduce subtypes, our
lifetime ends up being outlived by other lifetimes, rather than
outliving other lifetimes. Therefore, starting at the end of the
'constraint chain' will cause us to 'blame' a lifetime close to the original
definition of a variable, instead of close to where the bad lifetime
constraint is introduced.

This PR improves how we select the region to blame for 'too large'
universal lifetimes, when bound lifetimes are involved. If the region
we're checking is a 'placeholder' region (e.g. the region 'a' in
for<'a>, or the implicit region in fn(&())), we start traversing the
constraint chain from the beginning, rather than the end.

There are two (maybe more) different ways we generate region constraints for NLL:
requirements generated from trait queries, and requirements generated
from MIR subtype constraints. While the former always use explicit
placeholder regions, the latter is more tricky. In order to implement
contravariance for HRTBs, TypeRelating replaces placeholder regions with
existential regions. This requires us to keep track of whether or not an
existential region was originally a placeholder region. When we look for
a region to blame, we check if our starting region is either a
placeholder region or is an existential region created from a
placeholder region. If so, we start iterating from the beginning of the
constraint chain, rather than the end.
2019-10-01 19:47:28 -04:00
Mazdak Farrokhzad
2b80ed99db remove feature(nll) in more cases. 2019-09-26 06:44:57 +02:00
Mazdak Farrokhzad
b638aa1f5b remove feature(nll) from #27868 test. 2019-09-26 06:44:57 +02:00
Mazdak Farrokhzad
1256613ac7 remove feature(nll) from #31567 test. 2019-09-26 06:44:57 +02:00
Mazdak Farrokhzad
6ec9b3a0b6 Adjust & --bless tests due to no longer downgrading NLL errors on 2015. 2019-09-26 06:44:57 +02:00
Mazdak Farrokhzad
0204f36441
Rollup merge of #64428 - GuillaumeGomez:error-explanation-E0524, r=Centril
Error explanation e0524

Part of https://github.com/rust-lang/rust/issues/61137
2019-09-25 03:48:24 +02:00
Guillaume Gomez
d2b873b067 update ui tests 2019-09-21 17:43:56 +02:00
Guillaume Gomez
cf6a1feda6 update ui tests 2019-09-12 13:25:42 +02:00
bors
45859b7ca7 Auto merge of #63118 - Centril:stabilize-bind-by-move, r=matthewjasper
Stabilize `bind_by_move_pattern_guards` in Rust 1.39.0

Closes https://github.com/rust-lang/rust/issues/15287.

After stabilizing `#![feature(bind_by_move_pattern_guards)]`, you can now use bind-by-move bindings in patterns and take references to those bindings in `if` guards of `match` expressions. For example, the following now becomes legal:

```rust
fn main() {
    let array: Box<[u8; 4]> = Box::new([1, 2, 3, 4]);

    match array {
        nums
//      ---- `nums` is bound by move.
            if nums.iter().sum::<u8>() == 10
//                 ^------ `.iter()` implicitly takes a reference to `nums`.
        => {
            drop(nums);
//          --------- Legal as `nums` was bound by move and so we have ownership.
        }
        _ => unreachable!(),
    }
}
```

r? @matthewjasper
2019-09-09 12:46:59 +00:00
Mark Rousskov
6fdbece55f Update test stderr with results of enabling unused lints 2019-09-08 11:32:28 -04:00
Mazdak Farrokhzad
642993e6dc Update tests wrt. bind_by_by_move_pattern_guards stabilization. 2019-09-08 01:39:24 +02:00