Plumb through param_env to note_type_err
This commit is contained in:
parent
b8bb2968ce
commit
1920c66a8d
15 changed files with 98 additions and 39 deletions
|
@ -75,6 +75,7 @@ use crate::errors::{ObligationCauseFailureCode, TypeErrorAdditionalDiags};
|
|||
use crate::infer;
|
||||
use crate::infer::relate::{self, RelateResult, TypeRelation};
|
||||
use crate::infer::{InferCtxt, TypeTrace, ValuePairs};
|
||||
use crate::solve::deeply_normalize_for_diagnostics;
|
||||
use crate::traits::{
|
||||
IfExpressionCause, MatchExpressionArmCause, ObligationCause, ObligationCauseCode,
|
||||
};
|
||||
|
@ -145,21 +146,31 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||
pub fn report_mismatched_types(
|
||||
&self,
|
||||
cause: &ObligationCause<'tcx>,
|
||||
param_env: ty::ParamEnv<'tcx>,
|
||||
expected: Ty<'tcx>,
|
||||
actual: Ty<'tcx>,
|
||||
err: TypeError<'tcx>,
|
||||
) -> Diag<'a> {
|
||||
self.report_and_explain_type_error(TypeTrace::types(cause, true, expected, actual), err)
|
||||
self.report_and_explain_type_error(
|
||||
TypeTrace::types(cause, true, expected, actual),
|
||||
param_env,
|
||||
err,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn report_mismatched_consts(
|
||||
&self,
|
||||
cause: &ObligationCause<'tcx>,
|
||||
param_env: ty::ParamEnv<'tcx>,
|
||||
expected: ty::Const<'tcx>,
|
||||
actual: ty::Const<'tcx>,
|
||||
err: TypeError<'tcx>,
|
||||
) -> Diag<'a> {
|
||||
self.report_and_explain_type_error(TypeTrace::consts(cause, true, expected, actual), err)
|
||||
self.report_and_explain_type_error(
|
||||
TypeTrace::consts(cause, true, expected, actual),
|
||||
param_env,
|
||||
err,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn get_impl_future_output_ty(&self, ty: Ty<'tcx>) -> Option<Ty<'tcx>> {
|
||||
|
@ -1133,7 +1144,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||
diag: &mut Diag<'_>,
|
||||
cause: &ObligationCause<'tcx>,
|
||||
secondary_span: Option<(Span, Cow<'static, str>, bool)>,
|
||||
mut values: Option<ValuePairs<'tcx>>,
|
||||
mut values: Option<ty::ParamEnvAnd<'tcx, ValuePairs<'tcx>>>,
|
||||
terr: TypeError<'tcx>,
|
||||
prefer_label: bool,
|
||||
) {
|
||||
|
@ -1241,8 +1252,8 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||
}
|
||||
let (expected_found, exp_found, is_simple_error, values) = match values {
|
||||
None => (None, Mismatch::Fixed("type"), false, None),
|
||||
Some(values) => {
|
||||
let values = self.resolve_vars_if_possible(values);
|
||||
Some(ty::ParamEnvAnd { param_env: _, value: values }) => {
|
||||
let mut values = self.resolve_vars_if_possible(values);
|
||||
let (is_simple_error, exp_found) = match values {
|
||||
ValuePairs::Terms(ExpectedFound { expected, found }) => {
|
||||
match (expected.unpack(), found.unpack()) {
|
||||
|
@ -1773,6 +1784,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||
pub fn report_and_explain_type_error(
|
||||
&self,
|
||||
trace: TypeTrace<'tcx>,
|
||||
param_env: ty::ParamEnv<'tcx>,
|
||||
terr: TypeError<'tcx>,
|
||||
) -> Diag<'a> {
|
||||
debug!("report_and_explain_type_error(trace={:?}, terr={:?})", trace, terr);
|
||||
|
@ -1784,7 +1796,14 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||
self.type_error_additional_suggestions(&trace, terr),
|
||||
);
|
||||
let mut diag = self.dcx().create_err(failure_code);
|
||||
self.note_type_err(&mut diag, &trace.cause, None, Some(trace.values), terr, false);
|
||||
self.note_type_err(
|
||||
&mut diag,
|
||||
&trace.cause,
|
||||
None,
|
||||
Some(param_env.and(trace.values)),
|
||||
terr,
|
||||
false,
|
||||
);
|
||||
diag
|
||||
}
|
||||
|
||||
|
|
|
@ -295,7 +295,11 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||
let mut err = match origin {
|
||||
infer::Subtype(box trace) => {
|
||||
let terr = TypeError::RegionsDoesNotOutlive(sup, sub);
|
||||
let mut err = self.report_and_explain_type_error(trace, terr);
|
||||
let mut err = self.report_and_explain_type_error(
|
||||
trace,
|
||||
self.tcx.param_env(generic_param_scope),
|
||||
terr,
|
||||
);
|
||||
match (*sub, *sup) {
|
||||
(ty::RePlaceholder(_), ty::RePlaceholder(_)) => {}
|
||||
(ty::RePlaceholder(_), _) => {
|
||||
|
@ -646,7 +650,11 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||
}
|
||||
infer::Subtype(box trace) => {
|
||||
let terr = TypeError::RegionsPlaceholderMismatch;
|
||||
return self.report_and_explain_type_error(trace, terr);
|
||||
return self.report_and_explain_type_error(
|
||||
trace,
|
||||
self.tcx.param_env(generic_param_scope),
|
||||
terr,
|
||||
);
|
||||
}
|
||||
_ => {
|
||||
return self.report_concrete_failure(
|
||||
|
|
|
@ -1290,7 +1290,6 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||
(
|
||||
Some((
|
||||
data.projection_term,
|
||||
false,
|
||||
self.resolve_vars_if_possible(normalized_term),
|
||||
data.term,
|
||||
)),
|
||||
|
@ -1335,7 +1334,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||
derive_better_type_error(lhs, rhs)
|
||||
{
|
||||
(
|
||||
Some((lhs, true, self.resolve_vars_if_possible(expected_term), rhs)),
|
||||
Some((lhs, self.resolve_vars_if_possible(expected_term), rhs)),
|
||||
better_type_err,
|
||||
)
|
||||
} else if let Some(rhs) = rhs.to_alias_term()
|
||||
|
@ -1343,7 +1342,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||
derive_better_type_error(rhs, lhs)
|
||||
{
|
||||
(
|
||||
Some((rhs, true, self.resolve_vars_if_possible(expected_term), lhs)),
|
||||
Some((rhs, self.resolve_vars_if_possible(expected_term), lhs)),
|
||||
better_type_err,
|
||||
)
|
||||
} else {
|
||||
|
@ -1354,7 +1353,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||
};
|
||||
|
||||
let msg = values
|
||||
.and_then(|(predicate, _, normalized_term, expected_term)| {
|
||||
.and_then(|(predicate, normalized_term, expected_term)| {
|
||||
self.maybe_detailed_projection_msg(predicate, normalized_term, expected_term)
|
||||
})
|
||||
.unwrap_or_else(|| {
|
||||
|
@ -1431,8 +1430,12 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||
&mut diag,
|
||||
&obligation.cause,
|
||||
secondary_span,
|
||||
values.map(|(_, _, normalized_ty, expected_ty)| {
|
||||
infer::ValuePairs::Terms(ExpectedFound::new(true, expected_ty, normalized_ty))
|
||||
values.map(|(_, normalized_ty, expected_ty)| {
|
||||
obligation.param_env.and(infer::ValuePairs::Terms(ExpectedFound::new(
|
||||
true,
|
||||
expected_ty,
|
||||
normalized_ty,
|
||||
)))
|
||||
}),
|
||||
err,
|
||||
false,
|
||||
|
@ -2654,6 +2657,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||
};
|
||||
self.report_and_explain_type_error(
|
||||
TypeTrace::trait_refs(&cause, true, expected_trait_ref, found_trait_ref),
|
||||
obligation.param_env,
|
||||
terr,
|
||||
)
|
||||
}
|
||||
|
@ -2744,6 +2748,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||
{
|
||||
return Ok(self.report_and_explain_type_error(
|
||||
TypeTrace::trait_refs(&obligation.cause, true, expected_trait_ref, found_trait_ref),
|
||||
obligation.param_env,
|
||||
ty::error::TypeError::Mismatch,
|
||||
));
|
||||
}
|
||||
|
|
|
@ -287,6 +287,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||
FulfillmentErrorCode::Subtype(ref expected_found, ref err) => self
|
||||
.report_mismatched_types(
|
||||
&error.obligation.cause,
|
||||
error.obligation.param_env,
|
||||
expected_found.expected,
|
||||
expected_found.found,
|
||||
*err,
|
||||
|
@ -295,6 +296,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||
FulfillmentErrorCode::ConstEquate(ref expected_found, ref err) => {
|
||||
let mut diag = self.report_mismatched_consts(
|
||||
&error.obligation.cause,
|
||||
error.obligation.param_env,
|
||||
expected_found.expected,
|
||||
expected_found.found,
|
||||
*err,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue