Improve opaque type higher-ranked region error message under NLL#92306
Merged
bors merged 1 commit intorust-lang:masterfrom Feb 9, 2022
Merged
Improve opaque type higher-ranked region error message under NLL#92306bors merged 1 commit intorust-lang:masterfrom
bors merged 1 commit intorust-lang:masterfrom
Conversation
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Currently, any higher-ranked region errors involving opaque types
fall back to a generic "higher-ranked subtype error" message when
run under NLL. This PR adds better error message handling for this
case, giving us the same kinds of error messages that we currently
get without NLL:
To accomplish this, several different refactoring needed to be made:
InstantiateOpaqueTypestruct whichimplements
TypeOp. This is used to invokeinstantiate_opaque_typesduring MIR type checking.
TypeOpis refactored to pass around aMirBorrowckCtxt, which isneeded to report opaque type region errors.
TypeOps correspond to canonicalizedqueries. This allows us to properly handle opaque type instantiation
(which does not occur in a query) as a
TypeOp.A new
ErrorInfoassociated type is used to determine whatadditional information is used during higher-ranked region error
handling.
try_extract_error_from_fulfill_cxhas been moved out to a new function
try_extract_error_from_region_constraints.This allows us to re-use the same error reporting code between
canonicalized queries (which can extract region constraints directly
from a fresh
InferCtxt) and opaque type handling (which needs to takeregion constraints from the pre-existing
InferCtxtthat we usethroughout MIR borrow checking).