1
Fork 0

review comment: change span argument

This commit is contained in:
Esteban Küber 2024-10-27 19:23:21 +00:00
parent d2a781a2ec
commit d116767113
6 changed files with 15 additions and 10 deletions

View file

@ -642,7 +642,6 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
); );
let hir = tcx.hir(); let hir = tcx.hir();
infcx.err_ctxt().note_type_err( infcx.err_ctxt().note_type_err(
cause.span,
&mut diag, &mut diag,
&cause, &cause,
hir.get_if_local(impl_m.def_id) hir.get_if_local(impl_m.def_id)
@ -654,6 +653,7 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
}))), }))),
terr, terr,
false, false,
None,
); );
return Err(diag.emit()); return Err(diag.emit());
} }
@ -1062,7 +1062,6 @@ fn report_trait_method_mismatch<'tcx>(
cause.span = impl_err_span; cause.span = impl_err_span;
infcx.err_ctxt().note_type_err( infcx.err_ctxt().note_type_err(
cause.span,
&mut diag, &mut diag,
&cause, &cause,
trait_err_span.map(|sp| (sp, Cow::from("type in trait"), false)), trait_err_span.map(|sp| (sp, Cow::from("type in trait"), false)),
@ -1072,6 +1071,7 @@ fn report_trait_method_mismatch<'tcx>(
}))), }))),
terr, terr,
false, false,
None,
); );
diag.emit() diag.emit()
@ -1855,7 +1855,6 @@ fn compare_const_predicate_entailment<'tcx>(
}); });
infcx.err_ctxt().note_type_err( infcx.err_ctxt().note_type_err(
cause.span,
&mut diag, &mut diag,
&cause, &cause,
trait_c_span.map(|span| (span, Cow::from("type in trait"), false)), trait_c_span.map(|span| (span, Cow::from("type in trait"), false)),
@ -1865,6 +1864,7 @@ fn compare_const_predicate_entailment<'tcx>(
}))), }))),
terr, terr,
false, false,
None,
); );
return Err(diag.emit()); return Err(diag.emit());
}; };

View file

@ -640,7 +640,6 @@ pub fn check_function_signature<'tcx>(
let failure_code = cause.as_failure_code_diag(err, cause.span, vec![]); let failure_code = cause.as_failure_code_diag(err, cause.span, vec![]);
let mut diag = tcx.dcx().create_err(failure_code); let mut diag = tcx.dcx().create_err(failure_code);
err_ctxt.note_type_err( err_ctxt.note_type_err(
cause.span,
&mut diag, &mut diag,
&cause, &cause,
None, None,
@ -650,6 +649,7 @@ pub fn check_function_signature<'tcx>(
}))), }))),
err, err,
false, false,
None,
); );
return Err(diag.emit()); return Err(diag.emit());
} }

View file

@ -1141,13 +1141,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let trace = mk_trace(provided_span, (formal_ty, expected_ty), provided_ty); let trace = mk_trace(provided_span, (formal_ty, expected_ty), provided_ty);
if let Some(e) = error { if let Some(e) = error {
self.err_ctxt().note_type_err( self.err_ctxt().note_type_err(
trace.cause.span,
&mut err, &mut err,
&trace.cause, &trace.cause,
None, None,
Some(self.param_env.and(trace.values)), Some(self.param_env.and(trace.values)),
e, e,
true, true,
None,
); );
} }
} }

View file

@ -2462,7 +2462,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
} }
infcx.err_ctxt().note_type_err( infcx.err_ctxt().note_type_err(
cause.span,
&mut diag, &mut diag,
&cause, &cause,
None, None,
@ -2472,6 +2471,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
}))), }))),
terr, terr,
false, false,
None,
); );
diag.emit(); diag.emit();
self.abort.set(true); self.abort.set(true);

View file

@ -1386,14 +1386,19 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
#[instrument(level = "debug", skip(self, diag, secondary_span, prefer_label))] #[instrument(level = "debug", skip(self, diag, secondary_span, prefer_label))]
pub fn note_type_err( pub fn note_type_err(
&self, &self,
span: Span,
diag: &mut Diag<'_>, diag: &mut Diag<'_>,
cause: &ObligationCause<'tcx>, cause: &ObligationCause<'tcx>,
secondary_span: Option<(Span, Cow<'static, str>, bool)>, secondary_span: Option<(Span, Cow<'static, str>, bool)>,
mut values: Option<ty::ParamEnvAnd<'tcx, ValuePairs<'tcx>>>, mut values: Option<ty::ParamEnvAnd<'tcx, ValuePairs<'tcx>>>,
terr: TypeError<'tcx>, terr: TypeError<'tcx>,
prefer_label: bool, prefer_label: bool,
override_span: Option<Span>,
) { ) {
// We use `override_span` when we want the error to point at a `Span` other than
// `cause.span`. This is used in E0271, when a closure is passed in where the return type
// isn't what was expected. We want to point at the closure's return type (or expression),
// instead of the expression where the closure is passed as call argument.
let span = override_span.unwrap_or(cause.span);
// For some types of errors, expected-found does not make // For some types of errors, expected-found does not make
// sense, so just ignore the values we were given. // sense, so just ignore the values we were given.
if let TypeError::CyclicTy(_) = terr { if let TypeError::CyclicTy(_) = terr {
@ -2052,13 +2057,13 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
); );
let mut diag = self.dcx().create_err(failure_code); let mut diag = self.dcx().create_err(failure_code);
self.note_type_err( self.note_type_err(
span,
&mut diag, &mut diag,
&trace.cause, &trace.cause,
None, None,
Some(param_env.and(trace.values)), Some(param_env.and(trace.values)),
terr, terr,
false, false,
None,
); );
diag diag
} }

View file

@ -702,13 +702,13 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
); );
self.note_type_err( self.note_type_err(
span,
&mut diag, &mut diag,
&obligation.cause, &obligation.cause,
None, None,
None, None,
TypeError::Sorts(ty::error::ExpectedFound::new(expected_ty, ct_ty)), TypeError::Sorts(ty::error::ExpectedFound::new(expected_ty, ct_ty)),
false, false,
None,
); );
diag diag
} }
@ -1488,7 +1488,6 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
})(); })();
self.note_type_err( self.note_type_err(
span,
&mut diag, &mut diag,
&obligation.cause, &obligation.cause,
secondary_span, secondary_span,
@ -1500,6 +1499,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
}), }),
err, err,
false, false,
Some(span),
); );
self.note_obligation_cause(&mut diag, obligation); self.note_obligation_cause(&mut diag, obligation);
diag.emit() diag.emit()