-use super::{potentially_plural_count, Inherited};
+use super::potentially_plural_count;
use crate::check::regionck::OutlivesEnvironmentExt;
use crate::check::wfcheck;
use crate::errors::LifetimesOrBoundsMismatchOnTrait;
use rustc_hir::intravisit;
use rustc_hir::{GenericParamKind, ImplItemKind, TraitItemKind};
use rustc_infer::infer::outlives::env::OutlivesEnvironment;
-use rustc_infer::infer::{self, InferOk, TyCtxtInferExt};
+use rustc_infer::infer::{self, TyCtxtInferExt};
use rustc_infer::traits::util;
use rustc_middle::ty::error::{ExpectedFound, TypeError};
use rustc_middle::ty::subst::{InternalSubsts, Subst};
use rustc_middle::ty::{GenericParamDefKind, ToPredicate, TyCtxt};
use rustc_span::Span;
use rustc_trait_selection::traits::error_reporting::InferCtxtExt;
-use rustc_trait_selection::traits::{self, ObligationCause, ObligationCauseCode, Reveal};
+use rustc_trait_selection::traits::{
+ self, ObligationCause, ObligationCauseCode, ObligationCtxt, Reveal,
+};
use std::iter;
/// Checks that a method from an impl conforms to the signature of
);
let param_env = traits::normalize_param_env_or_error(tcx, param_env, normalize_cause);
- tcx.infer_ctxt().enter(|infcx| {
- let inh = Inherited::new(infcx, impl_m.def_id.expect_local());
- let infcx = &inh.infcx;
+ tcx.infer_ctxt().enter(|ref infcx| {
+ let ocx = ObligationCtxt::new(infcx);
debug!("compare_impl_method: caller_bounds={:?}", param_env.caller_bounds());
let mut selcx = traits::SelectionContext::new(&infcx);
-
let impl_m_own_bounds = impl_m_predicates.instantiate_own(tcx, impl_to_placeholder_substs);
for (predicate, span) in iter::zip(impl_m_own_bounds.predicates, impl_m_own_bounds.spans) {
let normalize_cause = traits::ObligationCause::misc(span, impl_m_hir_id);
let traits::Normalized { value: predicate, obligations } =
traits::normalize(&mut selcx, param_env, normalize_cause, predicate);
- inh.register_predicates(obligations);
+ ocx.register_obligations(obligations);
let cause = ObligationCause::new(
span,
impl_m_hir_id,
trait_item_def_id: trait_m.def_id,
},
);
- inh.register_predicate(traits::Obligation::new(cause, param_env, predicate));
+ ocx.register_obligation(traits::Obligation::new(cause, param_env, predicate));
}
// We now need to check that the signature of the impl method is
infer::HigherRankedType,
tcx.fn_sig(impl_m.def_id),
);
- let impl_sig =
- inh.normalize_associated_types_in(impl_m_span, impl_m_hir_id, param_env, impl_sig);
+
+ let norm_cause = ObligationCause::misc(impl_m_span, impl_m_hir_id);
+ let impl_sig = ocx.normalize(norm_cause.clone(), param_env, impl_sig);
let impl_fty = tcx.mk_fn_ptr(ty::Binder::dummy(impl_sig));
debug!("compare_impl_method: impl_fty={:?}", impl_fty);
let trait_sig = tcx.bound_fn_sig(trait_m.def_id).subst(tcx, trait_to_placeholder_substs);
let trait_sig = tcx.liberate_late_bound_regions(impl_m.def_id, trait_sig);
- let trait_sig =
- inh.normalize_associated_types_in(impl_m_span, impl_m_hir_id, param_env, trait_sig);
+ let trait_sig = ocx.normalize(norm_cause, param_env, trait_sig);
// Add the resulting inputs and output as well-formed.
wf_tys.extend(trait_sig.inputs_and_output.iter());
let trait_fty = tcx.mk_fn_ptr(ty::Binder::dummy(trait_sig));
debug!("compare_impl_method: trait_fty={:?}", trait_fty);
- let sub_result = infcx.at(&cause, param_env).sup(trait_fty, impl_fty).map(
- |InferOk { obligations, .. }| {
- // FIXME: We'd want to keep more accurate spans than "the method signature" when
- // processing the comparison between the trait and impl fn, but we sadly lose them
- // and point at the whole signature when a trait bound or specific input or output
- // type would be more appropriate. In other places we have a `Vec<Span>`
- // corresponding to their `Vec<Predicate>`, but we don't have that here.
- // Fixing this would improve the output of test `issue-83765.rs`.
- inh.register_predicates(obligations);
- },
- );
+ // FIXME: We'd want to keep more accurate spans than "the method signature" when
+ // processing the comparison between the trait and impl fn, but we sadly lose them
+ // and point at the whole signature when a trait bound or specific input or output
+ // type would be more appropriate. In other places we have a `Vec<Span>`
+ // corresponding to their `Vec<Predicate>`, but we don't have that here.
+ // Fixing this would improve the output of test `issue-83765.rs`.
+ let sub_result = infcx
+ .at(&cause, param_env)
+ .sup(trait_fty, impl_fty)
+ .map(|infer_ok| ocx.register_infer_ok_obligations(infer_ok));
if let Err(terr) = sub_result {
debug!("sub_types failed: impl ty {:?}, trait ty {:?}", impl_fty, trait_fty);
// Check that all obligations are satisfied by the implementation's
// version.
- let errors = inh.fulfillment_cx.borrow_mut().select_all_or_error(&infcx);
+ let errors = ocx.select_all_or_error();
if !errors.is_empty() {
let reported = infcx.report_fulfillment_errors(&errors, None, false);
return Err(reported);
// lifetime parameters.
let mut outlives_environment = OutlivesEnvironment::new(param_env);
outlives_environment.add_implied_bounds(infcx, wf_tys, impl_m_hir_id);
- infcx.check_region_obligations_and_report_errors(&outlives_environment);
+ infcx.check_region_obligations_and_report_errors(
+ impl_m.def_id.expect_local(),
+ &outlives_environment,
+ );
Ok(())
})
if let Some(span) = tcx.hir().span_if_local(trait_m.def_id) {
err.span_label(span, format!("trait method declared without `{self_descr}`"));
} else {
- err.note_trait_signature(trait_m.name.to_string(), trait_m.signature(tcx));
+ err.note_trait_signature(trait_m.name, trait_m.signature(tcx));
}
let reported = err.emit();
return Err(reported);
if let Some(span) = tcx.hir().span_if_local(trait_m.def_id) {
err.span_label(span, format!("`{self_descr}` used in trait"));
} else {
- err.note_trait_signature(trait_m.name.to_string(), trait_m.signature(tcx));
+ err.note_trait_signature(trait_m.name, trait_m.signature(tcx));
}
let reported = err.emit();
return Err(reported);
),
);
} else {
- err.note_trait_signature(trait_m.name.to_string(), trait_m.signature(tcx));
+ err.note_trait_signature(trait_m.name, trait_m.signature(tcx));
}
err.span_label(
impl_span,
tcx.infer_ctxt().enter(|infcx| {
let param_env = tcx.param_env(impl_c.def_id);
- let inh = Inherited::new(infcx, impl_c.def_id.expect_local());
- let infcx = &inh.infcx;
+ let ocx = ObligationCtxt::new(&infcx);
// The below is for the most part highly similar to the procedure
// for methods above. It is simpler in many respects, especially
);
// There is no "body" here, so just pass dummy id.
- let impl_ty =
- inh.normalize_associated_types_in(impl_c_span, impl_c_hir_id, param_env, impl_ty);
+ let impl_ty = ocx.normalize(cause.clone(), param_env, impl_ty);
debug!("compare_const_impl: impl_ty={:?}", impl_ty);
- let trait_ty =
- inh.normalize_associated_types_in(impl_c_span, impl_c_hir_id, param_env, trait_ty);
+ let trait_ty = ocx.normalize(cause.clone(), param_env, trait_ty);
debug!("compare_const_impl: trait_ty={:?}", trait_ty);
let err = infcx
.at(&cause, param_env)
.sup(trait_ty, impl_ty)
- .map(|ok| inh.register_infer_ok_obligations(ok));
+ .map(|ok| ocx.register_infer_ok_obligations(ok));
if let Err(terr) = err {
debug!(
// Check that all obligations are satisfied by the implementation's
// version.
- let errors = inh.fulfillment_cx.borrow_mut().select_all_or_error(&infcx);
+ let errors = ocx.select_all_or_error();
if !errors.is_empty() {
infcx.report_fulfillment_errors(&errors, None, false);
return;
}
let outlives_environment = OutlivesEnvironment::new(param_env);
- infcx.resolve_regions_and_report_errors(&outlives_environment);
+ infcx
+ .resolve_regions_and_report_errors(impl_c.def_id.expect_local(), &outlives_environment);
});
}
);
let param_env = traits::normalize_param_env_or_error(tcx, param_env, normalize_cause.clone());
tcx.infer_ctxt().enter(|infcx| {
- let inh = Inherited::new(infcx, impl_ty.def_id.expect_local());
- let infcx = &inh.infcx;
+ let ocx = ObligationCtxt::new(&infcx);
debug!("compare_type_predicate_entailment: caller_bounds={:?}", param_env.caller_bounds());
let traits::Normalized { value: predicate, obligations } =
traits::normalize(&mut selcx, param_env, normalize_cause.clone(), predicate);
- inh.register_predicates(obligations);
- inh.register_predicate(traits::Obligation::new(cause.clone(), param_env, predicate));
+ ocx.register_obligations(obligations);
+ ocx.register_obligation(traits::Obligation::new(cause.clone(), param_env, predicate));
}
// Check that all obligations are satisfied by the implementation's
// version.
- let errors = inh.fulfillment_cx.borrow_mut().select_all_or_error(&infcx);
+ let errors = ocx.select_all_or_error();
if !errors.is_empty() {
let reported = infcx.report_fulfillment_errors(&errors, None, false);
return Err(reported);
// Finally, resolve all regions. This catches wily misuses of
// lifetime parameters.
let outlives_environment = OutlivesEnvironment::new(param_env);
- infcx.check_region_obligations_and_report_errors(&outlives_environment);
+ infcx.check_region_obligations_and_report_errors(
+ impl_ty.def_id.expect_local(),
+ &outlives_environment,
+ );
Ok(())
})
impl_ty_substs.rebase_onto(tcx, impl_ty.container.id(), impl_trait_ref.substs);
tcx.infer_ctxt().enter(move |infcx| {
- let inh = Inherited::new(infcx, impl_ty.def_id.expect_local());
- let infcx = &inh.infcx;
- let mut selcx = traits::SelectionContext::new(&infcx);
+ let ocx = ObligationCtxt::new(&infcx);
+ let mut selcx = traits::SelectionContext::new(&infcx);
let impl_ty_hir_id = tcx.hir().local_def_id_to_hir_id(impl_ty.def_id.expect_local());
let normalize_cause = ObligationCause::new(
impl_ty_span,
debug!("compare_projection_bounds: normalized predicate = {:?}", normalized_predicate);
obligation.predicate = normalized_predicate;
- inh.register_predicates(obligations);
- inh.register_predicate(obligation);
+ ocx.register_obligations(obligations);
+ ocx.register_obligation(obligation);
}
// Check that all obligations are satisfied by the implementation's
// version.
- let errors = inh.fulfillment_cx.borrow_mut().select_all_or_error(&infcx);
+ let errors = ocx.select_all_or_error();
if !errors.is_empty() {
let reported = infcx.report_fulfillment_errors(&errors, None, false);
return Err(reported);
}
};
let mut outlives_environment = OutlivesEnvironment::new(param_env);
- outlives_environment.add_implied_bounds(infcx, implied_bounds, impl_ty_hir_id);
- infcx.check_region_obligations_and_report_errors(&outlives_environment);
+ outlives_environment.add_implied_bounds(&infcx, implied_bounds, impl_ty_hir_id);
+ infcx.check_region_obligations_and_report_errors(
+ impl_ty.def_id.expect_local(),
+ &outlives_environment,
+ );
+
+ let constraints = infcx.inner.borrow_mut().opaque_type_storage.take_opaque_types();
+ for (key, value) in constraints {
+ infcx
+ .report_mismatched_types(
+ &ObligationCause::misc(
+ value.hidden_type.span,
+ tcx.hir().local_def_id_to_hir_id(impl_ty.def_id.expect_local()),
+ ),
+ tcx.mk_opaque(key.def_id, key.substs),
+ value.hidden_type.ty,
+ TypeError::Mismatch,
+ )
+ .emit();
+ }
Ok(())
})