]> git.lizzy.rs Git - rust.git/commit
move leak-check to during coherence, candidate eval
authorNiko Matsakis <niko@alum.mit.edu>
Wed, 20 May 2020 10:19:36 +0000 (10:19 +0000)
committerNiko Matsakis <niko@alum.mit.edu>
Mon, 22 Jun 2020 15:33:05 +0000 (15:33 +0000)
commit5a7a850753b60abfd2a806bf6bba4259d3535e7b
tree9748a6a3e7991503d0d3660206c14837b7d7fcfd
parentf2cf9944831f15b1940da85c8fb1b419dec9f074
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
60 files changed:
src/librustc_infer/infer/higher_ranked/mod.rs
src/librustc_infer/infer/region_constraints/leak_check.rs
src/librustc_trait_selection/traits/coherence.rs
src/librustc_trait_selection/traits/project.rs
src/librustc_trait_selection/traits/select/mod.rs
src/test/ui/associated-types/associated-types-eq-hr.stderr
src/test/ui/associated-types/cache/project-fn-ret-invariant.krisskross.stderr
src/test/ui/associated-types/cache/project-fn-ret-invariant.ok.stderr
src/test/ui/associated-types/cache/project-fn-ret-invariant.oneuse.stderr
src/test/ui/associated-types/cache/project-fn-ret-invariant.rs
src/test/ui/associated-types/cache/project-fn-ret-invariant.transmute.stderr
src/test/ui/closure-expected-type/expect-fn-supply-fn.rs
src/test/ui/closure-expected-type/expect-fn-supply-fn.stderr
src/test/ui/closures/issue-41366.rs
src/test/ui/closures/issue-41366.stderr
src/test/ui/generator/resume-arg-late-bound.rs
src/test/ui/generator/resume-arg-late-bound.stderr
src/test/ui/hr-subtype/hr-subtype.bound_a_b_ret_a_vs_bound_a_ret_a.stderr
src/test/ui/hr-subtype/hr-subtype.bound_a_b_vs_bound_a.stderr
src/test/ui/hr-subtype/hr-subtype.bound_a_vs_bound_a.stderr
src/test/ui/hr-subtype/hr-subtype.bound_a_vs_bound_b.stderr
src/test/ui/hr-subtype/hr-subtype.bound_a_vs_free_x.stderr
src/test/ui/hr-subtype/hr-subtype.bound_co_a_b_vs_bound_co_a.stderr
src/test/ui/hr-subtype/hr-subtype.bound_co_a_co_b_ret_contra_a.stderr
src/test/ui/hr-subtype/hr-subtype.bound_co_a_vs_bound_co_b.stderr
src/test/ui/hr-subtype/hr-subtype.bound_contra_a_contra_b_ret_co_a.stderr
src/test/ui/hr-subtype/hr-subtype.bound_inv_a_b_vs_bound_inv_a.stderr
src/test/ui/hr-subtype/hr-subtype.bound_inv_a_vs_bound_inv_b.stderr
src/test/ui/hr-subtype/hr-subtype.free_x_vs_free_x.stderr
src/test/ui/hr-subtype/hr-subtype.rs
src/test/ui/hrtb/hrtb-exists-forall-fn.stderr
src/test/ui/hrtb/issue-30786.migrate.stderr
src/test/ui/hrtb/issue-30786.nll.stderr
src/test/ui/hrtb/issue-30786.rs
src/test/ui/issues/issue-40000.stderr
src/test/ui/issues/issue-43623.rs
src/test/ui/issues/issue-43623.stderr
src/test/ui/issues/issue-60283.rs
src/test/ui/issues/issue-60283.stderr
src/test/ui/lub-glb/old-lub-glb-hr.rs
src/test/ui/lub-glb/old-lub-glb-hr.stderr
src/test/ui/lub-glb/old-lub-glb-object.stderr
src/test/ui/mismatched_types/closure-arg-type-mismatch.rs
src/test/ui/mismatched_types/closure-arg-type-mismatch.stderr
src/test/ui/mismatched_types/closure-mismatch.rs
src/test/ui/mismatched_types/closure-mismatch.stderr
src/test/ui/regions-fn-subtyping-return-static-fail.stderr
src/test/ui/regions/region-lifetime-bounds-on-fns-where-clause.stderr
src/test/ui/regions/region-multiple-lifetime-bounds-on-fns-where-clause.stderr
src/test/ui/regions/regions-lifetime-bounds-on-fns.stderr
src/test/ui/rfc1623.rs
src/test/ui/rfc1623.stderr
src/test/ui/type-alias-impl-trait/issue-57611-trait-alias.rs
src/test/ui/type-alias-impl-trait/issue-57611-trait-alias.stderr
src/test/ui/unboxed-closures/unboxed-closures-unsafe-extern-fn.rs
src/test/ui/unboxed-closures/unboxed-closures-unsafe-extern-fn.stderr
src/test/ui/unboxed-closures/unboxed-closures-wrong-abi.rs
src/test/ui/unboxed-closures/unboxed-closures-wrong-abi.stderr
src/test/ui/unboxed-closures/unboxed-closures-wrong-arg-type-extern-fn.rs
src/test/ui/unboxed-closures/unboxed-closures-wrong-arg-type-extern-fn.stderr