Description
The MIR type-checker does not currently check that the predicates associated with values are met. For example, when you have a MIR rvalue that references a fn item, we should be checked that the where-clauses on that function are satisfied; similarly, we should check that when a struct rvalue is instantiated, its predicates are satisfied.
(More generally, to cope with NLL, I think we may need to ensure that the type of each variable is WF also when it is used, so that we enforce constraints at the right locations? But let's start with the basics.)
Before addressing this, we should fix #45889, which will introduce the check_rvalue
method and build up a bit more infrastructure. The instructions in #45889 check that each field has a suitable type, but they don't check that the where-clauses declared on the struct are met. I'll leave some instructions here shortly once #45889 proceeds a bit further.
(Hint: a good first step is that we have to write-up a test case or 3!)
Activity
SimonSapin commentedon Nov 17, 2017
Has this been implemented? In b3f3390 the test case wrote (and expected to fail) passes. Or is my test not testing the right thing?
(I don’t know why the same error is reported twice in the struct case, but that’s even further from the expected zero.)
nikomatsakis commentedon Nov 20, 2017
Some example tests that ought not to pass. Try running them with
-Znll -Zborrowck-mir
. I'll update with more as I go.The problem here is that the where-clauses on
foo
are not being enforced by the MIR type-checker.Another example, with structs.
In
check_rvalue
, when checking aggregate values, we need to also enforce the predicates from the aggregate.To get those, we will want to write a helper like
aggregate_field_ty
. This will usepredicates_of
to get the predicates for the various kinds of things and then apply the appropriate substitutes. Example for ADTs:Auto merge of #46054 - nikomatsakis:nll-master-to-rust-master-1, r=ar…
nikomatsakis commentedon Dec 5, 2017
Done (in nll-master)