Improve cause information for NLL higher-ranked errors

This PR has several interconnected pieces:

1. In some of the NLL region error code, we now pass
   around an `ObligationCause`, instead of just a plain `Span`.
   This gets forwarded into `fulfill_cx.register_predicate_obligation`
   during error reporting.
2. The general InferCtxt error reporting code is extended to
   handle `ObligationCauseCode::BindingObligation`
3. A new enum variant `ConstraintCategory::Predicate` is added.
   We try to avoid using this as the 'best blame constraint' - instead,
   we use it to enhance the `ObligationCause` of the `BlameConstraint`
   that we do end up choosing.

As a result, several NLL error messages now contain the same
"the lifetime requirement is introduced here" message as non-NLL
errors.

Having an `ObligationCause` available will likely prove useful
for future improvements to NLL error messages.
This commit is contained in:
Aaron Hill
2021-08-28 18:45:37 -05:00
parent 3e8f32e1c5
commit 93ab12eeab
16 changed files with 194 additions and 82 deletions

View File

@@ -19,7 +19,7 @@ mod normalize_erasing_regions;
mod normalize_projection_ty;
mod type_op;
pub use type_op::{type_op_ascribe_user_type_with_span, type_op_prove_predicate_with_span};
pub use type_op::{type_op_ascribe_user_type_with_span, type_op_prove_predicate_with_cause};
use rustc_middle::ty::query::Providers;