use crate::errors::LifetimesOrBoundsMismatchOnTrait;
use rustc_data_structures::stable_set::FxHashSet;
-use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticId, ErrorReported};
+use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticId, ErrorGuaranteed};
use rustc_hir as hir;
use rustc_hir::def::{DefKind, Res};
use rustc_hir::intravisit;
/// - `impl_m_span`: span to use for reporting errors
/// - `trait_m`: the method in the trait
/// - `impl_trait_ref`: the TraitRef corresponding to the trait implementation
-
crate fn compare_impl_method<'tcx>(
tcx: TyCtxt<'tcx>,
impl_m: &ty::AssocItem,
let impl_m_span = tcx.sess.source_map().guess_head_span(impl_m_span);
- if let Err(ErrorReported) = compare_self_type(tcx, impl_m, impl_m_span, trait_m, impl_trait_ref)
- {
+ if let Err(_) = compare_self_type(tcx, impl_m, impl_m_span, trait_m, impl_trait_ref) {
return;
}
- if let Err(ErrorReported) =
- compare_number_of_generics(tcx, impl_m, impl_m_span, trait_m, trait_item_span)
- {
+ if let Err(_) = compare_number_of_generics(tcx, impl_m, impl_m_span, trait_m, trait_item_span) {
return;
}
- if let Err(ErrorReported) =
+ if let Err(_) =
compare_number_of_method_arguments(tcx, impl_m, impl_m_span, trait_m, trait_item_span)
{
return;
}
- if let Err(ErrorReported) = compare_synthetic_generics(tcx, impl_m, trait_m) {
+ if let Err(_) = compare_synthetic_generics(tcx, impl_m, trait_m) {
return;
}
- if let Err(ErrorReported) =
- compare_predicate_entailment(tcx, impl_m, impl_m_span, trait_m, impl_trait_ref)
+ if let Err(_) = compare_predicate_entailment(tcx, impl_m, impl_m_span, trait_m, impl_trait_ref)
{
return;
}
- if let Err(ErrorReported) = compare_const_param_types(tcx, impl_m, trait_m, trait_item_span) {
+ if let Err(_) = compare_const_param_types(tcx, impl_m, trait_m, trait_item_span) {
return;
}
}
impl_m_span: Span,
trait_m: &ty::AssocItem,
impl_trait_ref: ty::TraitRef<'tcx>,
-) -> Result<(), ErrorReported> {
+) -> Result<(), ErrorGuaranteed> {
let trait_to_impl_substs = impl_trait_ref.substs;
// This node-id should be used for the `body_id` field on each
impl_m_span,
impl_m_hir_id,
ObligationCauseCode::CompareImplMethodObligation {
- impl_item_def_id: impl_m.def_id,
+ impl_item_def_id: impl_m.def_id.expect_local(),
trait_item_def_id: trait_m.def_id,
},
);
traits::normalize(&mut selcx, param_env, normalize_cause, predicate);
inh.register_predicates(obligations);
- let mut cause = cause.clone();
- cause.span = span;
+ let cause = ObligationCause::new(
+ span,
+ impl_m_hir_id,
+ ObligationCauseCode::CompareImplMethodObligation {
+ impl_item_def_id: impl_m.def_id.expect_local(),
+ trait_item_def_id: trait_m.def_id,
+ },
+ );
inh.register_predicate(traits::Obligation::new(cause, param_env, predicate));
}
&terr,
false,
);
- diag.emit();
- return Err(ErrorReported);
+
+ return Err(diag.emit());
}
// Check that all obligations are satisfied by the implementation's
// version.
let errors = inh.fulfillment_cx.borrow_mut().select_all_or_error(&infcx);
if !errors.is_empty() {
- infcx.report_fulfillment_errors(&errors, None, false);
- return Err(ErrorReported);
+ let reported = infcx.report_fulfillment_errors(&errors, None, false);
+ return Err(reported);
}
// Finally, resolve all regions. This catches wily misuses of
trait_m: &ty::AssocItem,
trait_generics: &ty::Generics,
impl_generics: &ty::Generics,
-) -> Result<(), ErrorReported> {
+) -> Result<(), ErrorGuaranteed> {
let trait_params = trait_generics.own_counts().lifetimes;
let impl_params = impl_generics.own_counts().lifetimes;
.map_or(def_sp, |g| g.span)
});
- tcx.sess.emit_err(LifetimesOrBoundsMismatchOnTrait {
+ let reported = tcx.sess.emit_err(LifetimesOrBoundsMismatchOnTrait {
span,
item_kind,
ident: impl_m.ident(tcx),
generics_span,
});
- return Err(ErrorReported);
+ return Err(reported);
}
Ok(())
impl_m_span: Span,
trait_m: &ty::AssocItem,
impl_trait_ref: ty::TraitRef<'tcx>,
-) -> Result<(), ErrorReported> {
+) -> Result<(), ErrorGuaranteed> {
// Try to give more informative error messages about self typing
// mismatches. Note that any mismatch will also be detected
// below, where we construct a canonical function type that
} else {
err.note_trait_signature(trait_m.name.to_string(), trait_m.signature(tcx));
}
- err.emit();
- return Err(ErrorReported);
+ let reported = err.emit();
+ return Err(reported);
}
(true, false) => {
} else {
err.note_trait_signature(trait_m.name.to_string(), trait_m.signature(tcx));
}
- err.emit();
- return Err(ErrorReported);
+ let reported = err.emit();
+ return Err(reported);
}
}
_impl_span: Span,
trait_: &ty::AssocItem,
trait_span: Option<Span>,
-) -> Result<(), ErrorReported> {
+) -> Result<(), ErrorGuaranteed> {
let trait_own_counts = tcx.generics_of(trait_.def_id).own_counts();
let impl_own_counts = tcx.generics_of(impl_.def_id).own_counts();
let item_kind = assoc_item_kind_str(impl_);
- let mut err_occurred = false;
+ let mut err_occurred = None;
for (kind, trait_count, impl_count) in matchings {
if impl_count != trait_count {
- err_occurred = true;
-
let (trait_spans, impl_trait_spans) = if let Some(def_id) = trait_.def_id.as_local() {
let trait_item = tcx.hir().expect_trait_item(def_id);
if trait_item.generics.params.is_empty() {
err.span_label(*span, "`impl Trait` introduces an implicit type parameter");
}
- err.emit();
+ let reported = err.emit();
+ err_occurred = Some(reported);
}
}
- if err_occurred { Err(ErrorReported) } else { Ok(()) }
+ if let Some(reported) = err_occurred { Err(reported) } else { Ok(()) }
}
fn compare_number_of_method_arguments<'tcx>(
impl_m_span: Span,
trait_m: &ty::AssocItem,
trait_item_span: Option<Span>,
-) -> Result<(), ErrorReported> {
+) -> Result<(), ErrorGuaranteed> {
let impl_m_fty = tcx.fn_sig(impl_m.def_id);
let trait_m_fty = tcx.fn_sig(trait_m.def_id);
let trait_number_args = trait_m_fty.inputs().skip_binder().len();
impl_number_args
),
);
- err.emit();
- return Err(ErrorReported);
+ let reported = err.emit();
+ return Err(reported);
}
Ok(())
tcx: TyCtxt<'tcx>,
impl_m: &ty::AssocItem,
trait_m: &ty::AssocItem,
-) -> Result<(), ErrorReported> {
+) -> Result<(), ErrorGuaranteed> {
// FIXME(chrisvittal) Clean up this function, list of FIXME items:
// 1. Better messages for the span labels
// 2. Explanation as to what is going on
// If we get here, we already have the same number of generics, so the zip will
// be okay.
- let mut error_found = false;
+ let mut error_found = None;
let impl_m_generics = tcx.generics_of(impl_m.def_id);
let trait_m_generics = tcx.generics_of(trait_m.def_id);
let impl_m_type_params = impl_m_generics.params.iter().filter_map(|param| match param.kind {
}
_ => unreachable!(),
}
- err.emit();
- error_found = true;
+ let reported = err.emit();
+ error_found = Some(reported);
}
}
- if error_found { Err(ErrorReported) } else { Ok(()) }
+ if let Some(reported) = error_found { Err(reported) } else { Ok(()) }
}
fn compare_const_param_types<'tcx>(
impl_m: &ty::AssocItem,
trait_m: &ty::AssocItem,
trait_item_span: Option<Span>,
-) -> Result<(), ErrorReported> {
+) -> Result<(), ErrorGuaranteed> {
let const_params_of = |def_id| {
tcx.generics_of(def_id).params.iter().filter_map(|param| match param.kind {
GenericParamDefKind::Const { .. } => Some(param.def_id),
trait_ty
),
);
- err.emit();
- return Err(ErrorReported);
+ let reported = err.emit();
+ return Err(reported);
}
}
) {
debug!("compare_impl_type(impl_trait_ref={:?})", impl_trait_ref);
- let _: Result<(), ErrorReported> = (|| {
+ let _: Result<(), ErrorGuaranteed> = (|| {
compare_number_of_generics(tcx, impl_ty, impl_ty_span, trait_ty, trait_item_span)?;
let sp = tcx.def_span(impl_ty.def_id);
impl_ty_span: Span,
trait_ty: &ty::AssocItem,
impl_trait_ref: ty::TraitRef<'tcx>,
-) -> Result<(), ErrorReported> {
+) -> Result<(), ErrorGuaranteed> {
let impl_substs = InternalSubsts::identity_for_item(tcx, impl_ty.def_id);
let trait_to_impl_substs =
impl_substs.rebase_onto(tcx, impl_ty.container.id(), impl_trait_ref.substs);
impl_ty_span,
impl_ty_hir_id,
ObligationCauseCode::CompareImplTypeObligation {
- impl_item_def_id: impl_ty.def_id,
+ impl_item_def_id: impl_ty.def_id.expect_local(),
trait_item_def_id: trait_ty.def_id,
},
);
// version.
let errors = inh.fulfillment_cx.borrow_mut().select_all_or_error(&infcx);
if !errors.is_empty() {
- infcx.report_fulfillment_errors(&errors, None, false);
- return Err(ErrorReported);
+ let reported = infcx.report_fulfillment_errors(&errors, None, false);
+ return Err(reported);
}
// Finally, resolve all regions. This catches wily misuses of
impl_ty: &ty::AssocItem,
impl_ty_span: Span,
impl_trait_ref: ty::TraitRef<'tcx>,
-) -> Result<(), ErrorReported> {
+) -> Result<(), ErrorGuaranteed> {
// Given
//
// impl<A, B> Foo<u32> for (A, B) {
impl_ty_span,
impl_ty_hir_id,
ObligationCauseCode::CheckAssociatedTypeBounds {
- impl_item_def_id: impl_ty.def_id,
+ impl_item_def_id: impl_ty.def_id.expect_local(),
trait_item_def_id: trait_ty.def_id,
},
);
// version.
let errors = inh.fulfillment_cx.borrow_mut().select_all_or_error(&infcx);
if !errors.is_empty() {
- infcx.report_fulfillment_errors(&errors, None, false);
- return Err(ErrorReported);
+ let reported = infcx.report_fulfillment_errors(&errors, None, false);
+ return Err(reported);
}
// Finally, resolve all regions. This catches wily misuses of