rust/src/test/ui/closures
Niko Matsakis 5a7a850753 move leak-check to during coherence, candidate eval
In particular, it no longer occurs during the subtyping check. This is
important for enabling lazy normalization, because the subtyping check
will be producing sub-obligations that could affect its results.

Consider an example like

    for<'a> fn(<&'a as Mirror>::Item) =
      fn(&'b u8)

where `<T as Mirror>::Item = T` for all `T`. We will wish to produce a
new subobligation like

    <'!1 as Mirror>::Item = &'b u8

This will, after being solved, ultimately yield a constraint that `'!1
= 'b` which will fail. But with the leak-check being performed on
subtyping, there is no opportunity to normalize `<'!1 as
Mirror>::Item` (unless we invoke that normalization directly from
within subtyping, and I would prefer that subtyping and unification
are distinct operations rather than part of the trait solving stack).

The reason to keep the leak check during coherence and trait
evaluation is partly for backwards compatibility. The coherence change
permits impls for `fn(T)` and `fn(&T)` to co-exist, and the trait
evaluation change means that we can distinguish those two cases
without ambiguity errors. It also avoids recreating #57639, where we
were incorrectly choosing a where clause that would have failed the
leak check over the impl which succeeds.

The other reason to keep the leak check in those places is that I
think it is actually close to the model we want. To the point, I think
the trait solver ought to have the job of "breaking down"
higher-ranked region obligation like ``!1: '2` into into region
obligations that operate on things in the root universe, at which
point they should be handed off to polonius. The leak check isn't
*really* doing that -- these obligations are still handed to the
region solver to process -- but if/when we do adopt that model, the
decision to pass/fail would be happening in roughly this part of the
code.

This change had somewhat more side-effects than I anticipated. It
seems like there are cases where the leak-check was not being enforced
during method proving and trait selection. I haven't quite tracked
this down but I think it ought to be documented, so that we know what
precisely we are committing to.

One surprising test was `issue-30786.rs`. The behavior there seems a
bit "fishy" to me, but the problem is not related to the leak check
change as far as I can tell, but more to do with the closure signature
inference code and perhaps the associated type projection, which
together seem to be conspiring to produce an unexpected
signature. Nonetheless, it is an example of where changing the
leak-check can have some unexpected consequences: we're now failing to
resolve a method earlier than we were, which suggests we might change
some method resolutions that would have been ambiguous to be
successful.

TODO:

* figure out remainig test failures
* add new coherence tests for the patterns we ARE disallowing
2020-06-22 15:33:05 +00:00
..
closure-expected-type Update tests 2020-05-22 18:03:08 +01:00
closure-array-break-length.rs ty: convert ErrorHandled::Reported to ConstKind::Error. 2020-04-16 19:00:30 +03:00
closure-array-break-length.stderr ty: convert ErrorHandled::Reported to ConstKind::Error. 2020-04-16 19:00:30 +03:00
closure-bounds-cant-promote-superkind-in-struct.rs Remove licenses 2018-12-25 21:08:33 -07:00
closure-bounds-cant-promote-superkind-in-struct.stderr Small tweaks to required bound span 2020-04-08 14:40:51 -07:00
closure-bounds-static-cant-capture-borrowed.nll.stderr Change compare mode to use -Zborrowck=mir 2019-05-12 18:46:43 +01:00
closure-bounds-static-cant-capture-borrowed.rs Remove licenses 2018-12-25 21:08:33 -07:00
closure-bounds-static-cant-capture-borrowed.stderr Remove licenses 2018-12-25 21:08:33 -07:00
closure-bounds-subtype.rs Remove licenses 2018-12-25 21:08:33 -07:00
closure-bounds-subtype.stderr Small tweaks to required bound span 2020-04-08 14:40:51 -07:00
closure-immutable-outer-variable.fixed liveness: Warn about unused captured variables 2020-05-29 17:46:38 +02:00
closure-immutable-outer-variable.rs liveness: Warn about unused captured variables 2020-05-29 17:46:38 +02:00
closure-immutable-outer-variable.rs.fixed remove remaining copyright headers 2018-12-28 21:50:33 +01:00
closure-immutable-outer-variable.stderr liveness: Warn about unused captured variables 2020-05-29 17:46:38 +02:00
closure-move-sync.rs tests: remove ignore directives from tests that mention core/alloc/std spans. 2020-04-02 11:48:34 +03:00
closure-move-sync.stderr tests: remove ignore directives from tests that mention core/alloc/std spans. 2020-04-02 11:48:34 +03:00
closure-no-fn-1.rs Remove licenses 2018-12-25 21:08:33 -07:00
closure-no-fn-1.stderr Point at type in let assignment on type errors 2019-11-21 19:24:31 -08:00
closure-no-fn-2.rs Remove licenses 2018-12-25 21:08:33 -07:00
closure-no-fn-2.stderr Point at type in let assignment on type errors 2019-11-21 19:24:31 -08:00
closure-no-fn-3.rs Remove licenses 2018-12-25 21:08:33 -07:00
closure-no-fn-3.stderr Tweak "non-primitive cast" error 2020-06-15 08:57:20 -07:00
closure-referencing-itself-issue-25954.rs Remove licenses 2018-12-25 21:08:33 -07:00
closure-referencing-itself-issue-25954.stderr Update tests 2019-03-11 23:10:26 +03:00
closure-reform-bad.rs Remove licenses 2018-12-25 21:08:33 -07:00
closure-reform-bad.stderr review comments 2020-01-08 09:29:47 -08:00
closure-wrong-kind.rs Remove licenses 2018-12-25 21:08:33 -07:00
closure-wrong-kind.stderr Update tests 2019-03-11 23:10:26 +03:00
closure_cap_coerce_many_fail.rs Test for coercion between (FnDef | Closure) and (FnDef | Closure) 2020-05-09 11:02:31 +08:00
closure_cap_coerce_many_fail.stderr Test for coercion between (FnDef | Closure) and (FnDef | Closure) 2020-05-09 11:02:31 +08:00
closure_no_cap_coerce_many_check_pass.rs Test for coercion between (FnDef | Closure) and (FnDef | Closure) 2020-05-09 11:02:31 +08:00
closure_no_cap_coerce_many_run_pass.rs Test for coercion between (FnDef | Closure) and (FnDef | Closure) 2020-05-09 11:02:31 +08:00
closure_no_cap_coerce_many_unsafe_0.rs Test for coercion between (FnDef | Closure) and (FnDef | Closure) 2020-05-09 11:02:31 +08:00
closure_no_cap_coerce_many_unsafe_0.stderr Test for coercion between (FnDef | Closure) and (FnDef | Closure) 2020-05-09 11:02:31 +08:00
closure_no_cap_coerce_many_unsafe_1.rs Test for coercion between (FnDef | Closure) and (FnDef | Closure) 2020-05-09 11:02:31 +08:00
deeply-nested_closures.rs Avoid exponential behaviour when relating types 2020-02-02 12:10:08 +00:00
diverging-closure.rs Skip tests on emscripten 2020-05-08 00:39:02 +09:00
issue-41366.rs move leak-check to during coherence, candidate eval 2020-06-22 15:33:05 +00:00
issue-41366.stderr move leak-check to during coherence, candidate eval 2020-06-22 15:33:05 +00:00
issue-46742.rs Test for coercion between (FnDef | Closure) and (FnDef | Closure) 2020-05-09 11:02:31 +08:00
issue-48109.rs Test for coercion between (FnDef | Closure) and (FnDef | Closure) 2020-05-09 11:02:31 +08:00
issue-52437.rs Evaluate repeat expression lengths as late as possible 2020-03-23 13:14:36 +01:00
issue-52437.stderr Evaluate repeat expression lengths as late as possible 2020-03-23 13:14:36 +01:00
issue-67123.rs Do not ICE on closure 2019-12-09 18:55:38 +09:00
issue-67123.stderr Tweak suggest_constraining_type_param 2020-03-29 13:13:17 -07:00
issue-68025.rs Fix ICE #68025 2020-01-20 07:06:27 +09:00