Skip to content

Improve opaque type higher-ranked region error message under NLL#92306

Merged
bors merged 1 commit intorust-lang:masterfrom
Aaron1011:opaque-type-op
Feb 9, 2022
Merged

Improve opaque type higher-ranked region error message under NLL#92306
bors merged 1 commit intorust-lang:masterfrom
Aaron1011:opaque-type-op

Conversation

@Aaron1011
Copy link
Copy Markdown
Contributor

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:

error: implementation of `MyTrait` is not general enough
  --> $DIR/opaque-hrtb.rs:12:13
   |
LL | fn foo() -> impl for<'a> MyTrait<&'a str> {
   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ implementation of `MyTrait` is not general enough
   |
   = note: `impl MyTrait<&'2 str>` must implement `MyTrait<&'1 str>`, for any lifetime `'1`...
   = note: ...but it actually implements `MyTrait<&'2 str>`, for some specific lifetime `'2`

error: aborting due to previous error

To accomplish this, several different refactoring needed to be made:

  • We now have a dedicated InstantiateOpaqueType struct which
    implements TypeOp. This is used to invoke instantiate_opaque_types
    during MIR type checking.
  • TypeOp is refactored to pass around a MirBorrowckCtxt, which is
    needed to report opaque type region errors.
  • We no longer assume that all TypeOps correspond to canonicalized
    queries. This allows us to properly handle opaque type instantiation
    (which does not occur in a query) as a TypeOp.
    A new ErrorInfo associated type is used to determine what
    additional information is used during higher-ranked region error
    handling.
  • The body of try_extract_error_from_fulfill_cx
    has 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 take
    region constraints from the pre-existing InferCtxt that we use
    throughout MIR borrow checking).

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants