Skip to content

Commit 0a95878

Browse files
drive-by: style nits
1 parent 94e047b commit 0a95878

File tree

1 file changed

+19
-25
lines changed

1 file changed

+19
-25
lines changed

compiler/rustc_hir_analysis/src/check/compare_method.rs

+19-25
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@ use rustc_infer::traits::util;
1414
use rustc_middle::ty::error::{ExpectedFound, TypeError};
1515
use rustc_middle::ty::util::ExplicitSelf;
1616
use rustc_middle::ty::{
17-
self, AssocItem, DefIdTree, TraitRef, Ty, TypeFoldable, TypeFolder, TypeSuperFoldable,
18-
TypeVisitable,
17+
self, DefIdTree, InternalSubsts, Ty, TypeFoldable, TypeFolder, TypeSuperFoldable, TypeVisitable,
1918
};
20-
use rustc_middle::ty::{FnSig, InternalSubsts};
2119
use rustc_middle::ty::{GenericParamDefKind, ToPredicate, TyCtxt};
2220
use rustc_span::Span;
2321
use rustc_trait_selection::traits::error_reporting::TypeErrCtxtExt;
@@ -144,9 +142,9 @@ pub(crate) fn compare_impl_method<'tcx>(
144142
#[instrument(level = "debug", skip(tcx, impl_m_span, impl_trait_ref))]
145143
fn compare_predicate_entailment<'tcx>(
146144
tcx: TyCtxt<'tcx>,
147-
impl_m: &AssocItem,
145+
impl_m: &ty::AssocItem,
148146
impl_m_span: Span,
149-
trait_m: &AssocItem,
147+
trait_m: &ty::AssocItem,
150148
impl_trait_ref: ty::TraitRef<'tcx>,
151149
) -> Result<(), ErrorGuaranteed> {
152150
let trait_to_impl_substs = impl_trait_ref.substs;
@@ -157,8 +155,7 @@ fn compare_predicate_entailment<'tcx>(
157155
// FIXME(@lcnr): remove that after removing `cause.body_id` from
158156
// obligations.
159157
let impl_m_hir_id = tcx.hir().local_def_id_to_hir_id(impl_m.def_id.expect_local());
160-
// We sometimes modify the span further down.
161-
let mut cause = ObligationCause::new(
158+
let cause = ObligationCause::new(
162159
impl_m_span,
163160
impl_m_hir_id,
164161
ObligationCauseCode::CompareImplItemObligation {
@@ -307,14 +304,13 @@ fn compare_predicate_entailment<'tcx>(
307304
debug!(?terr, "sub_types failed: impl ty {:?}, trait ty {:?}", impl_fty, trait_fty);
308305

309306
let emitted = report_trait_method_mismatch(
310-
tcx,
311-
&mut cause,
312307
&infcx,
308+
cause,
313309
terr,
314310
(trait_m, trait_fty),
315311
(impl_m, impl_fty),
316-
&trait_sig,
317-
&impl_trait_ref,
312+
trait_sig,
313+
impl_trait_ref,
318314
);
319315
return Err(emitted);
320316
}
@@ -360,7 +356,7 @@ pub fn collect_trait_impl_trait_tys<'tcx>(
360356

361357
let impl_m_hir_id = tcx.hir().local_def_id_to_hir_id(impl_m.def_id.expect_local());
362358
let return_span = tcx.hir().fn_decl_by_hir_id(impl_m_hir_id).unwrap().output.span();
363-
let mut cause = ObligationCause::new(
359+
let cause = ObligationCause::new(
364360
return_span,
365361
impl_m_hir_id,
366362
ObligationCauseCode::CompareImplItemObligation {
@@ -457,14 +453,13 @@ pub fn collect_trait_impl_trait_tys<'tcx>(
457453
// emit an error now because `compare_predicate_entailment` will not report the error
458454
// when normalization fails.
459455
let emitted = report_trait_method_mismatch(
460-
tcx,
461-
&mut cause,
462456
infcx,
457+
cause,
463458
terr,
464459
(trait_m, trait_fty),
465460
(impl_m, impl_fty),
466-
&trait_sig,
467-
&impl_trait_ref,
461+
trait_sig,
462+
impl_trait_ref,
468463
);
469464
return Err(emitted);
470465
}
@@ -634,23 +629,21 @@ impl<'tcx> TypeFolder<'tcx> for ImplTraitInTraitCollector<'_, 'tcx> {
634629
}
635630

636631
fn report_trait_method_mismatch<'tcx>(
637-
tcx: TyCtxt<'tcx>,
638-
cause: &mut ObligationCause<'tcx>,
639632
infcx: &InferCtxt<'tcx>,
633+
mut cause: ObligationCause<'tcx>,
640634
terr: TypeError<'tcx>,
641-
(trait_m, trait_fty): (&AssocItem, Ty<'tcx>),
642-
(impl_m, impl_fty): (&AssocItem, Ty<'tcx>),
643-
trait_sig: &FnSig<'tcx>,
644-
impl_trait_ref: &TraitRef<'tcx>,
635+
(trait_m, trait_fty): (&ty::AssocItem, Ty<'tcx>),
636+
(impl_m, impl_fty): (&ty::AssocItem, Ty<'tcx>),
637+
trait_sig: ty::FnSig<'tcx>,
638+
impl_trait_ref: ty::TraitRef<'tcx>,
645639
) -> ErrorGuaranteed {
640+
let tcx = infcx.tcx;
646641
let (impl_err_span, trait_err_span) =
647642
extract_spans_for_error_reporting(&infcx, terr, &cause, impl_m, trait_m);
648643

649-
cause.span = impl_err_span;
650-
651644
let mut diag = struct_span_err!(
652645
tcx.sess,
653-
cause.span(),
646+
impl_err_span,
654647
E0053,
655648
"method `{}` has an incompatible type for trait",
656649
trait_m.name
@@ -721,6 +714,7 @@ fn report_trait_method_mismatch<'tcx>(
721714
_ => {}
722715
}
723716

717+
cause.span = impl_err_span;
724718
infcx.err_ctxt().note_type_err(
725719
&mut diag,
726720
&cause,

0 commit comments

Comments
 (0)