1
Fork 0

Remove overloaded_span argument from new, where it is usually redundant with the main span

This commit is contained in:
Oli Scherer 2022-11-08 15:49:29 +00:00
parent a7a40ddc79
commit 1d93b35855
6 changed files with 11 additions and 22 deletions

View file

@ -1708,8 +1708,7 @@ fn receiver_is_valid<'tcx>(
return true;
}
let mut autoderef =
Autoderef::new(infcx, wfcx.param_env, wfcx.body_id, span, receiver_ty, span);
let mut autoderef = Autoderef::new(infcx, wfcx.param_env, wfcx.body_id, span, receiver_ty);
// The `arbitrary_self_types` feature allows raw pointer receivers like `self: *const Self`.
if arbitrary_self_types_enabled {

View file

@ -12,18 +12,7 @@ use std::iter;
impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
pub fn autoderef(&'a self, span: Span, base_ty: Ty<'tcx>) -> Autoderef<'a, 'tcx> {
self.autoderef_overloaded_span(span, base_ty, span)
}
/// Like `autoderef`, but provides a custom `Span` to use for calls to
/// an overloaded `Deref` operator
pub fn autoderef_overloaded_span(
&'a self,
span: Span,
base_ty: Ty<'tcx>,
overloaded_span: Span,
) -> Autoderef<'a, 'tcx> {
Autoderef::new(self, self.param_env, self.body_id, span, base_ty, overloaded_span)
Autoderef::new(self, self.param_env, self.body_id, span, base_ty)
}
pub fn try_overloaded_deref(

View file

@ -152,7 +152,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
// Commit the autoderefs by calling `autoderef` again, but this
// time writing the results into the various typeck results.
let mut autoderef =
self.autoderef_overloaded_span(self.span, unadjusted_self_ty, self.call_expr.span);
self.autoderef(self.span, unadjusted_self_ty).with_overloaded_span(self.call_expr.span);
let Some((ty, n)) = autoderef.nth(pick.autoderefs) else {
return self.tcx.ty_error_with_message(
rustc_span::DUMMY_SP,

View file

@ -475,8 +475,7 @@ fn method_autoderef_steps<'tcx>(
let (ref infcx, goal, inference_vars) = tcx.infer_ctxt().build_with_canonical(DUMMY_SP, &goal);
let ParamEnvAnd { param_env, value: self_ty } = goal;
let mut autoderef =
Autoderef::new(infcx, param_env, hir::CRATE_HIR_ID, DUMMY_SP, self_ty, DUMMY_SP)
let mut autoderef = Autoderef::new(infcx, param_env, hir::CRATE_HIR_ID, DUMMY_SP, self_ty)
.include_raw_pointers()
.silence_errors();
let mut reached_raw_pointer = false;

View file

@ -99,12 +99,11 @@ impl<'a, 'tcx> Autoderef<'a, 'tcx> {
body_id: hir::HirId,
span: Span,
base_ty: Ty<'tcx>,
overloaded_span: Span,
) -> Autoderef<'a, 'tcx> {
Autoderef {
infcx,
span,
overloaded_span,
overloaded_span: span,
body_id,
param_env,
state: AutoderefSnapshot {
@ -119,6 +118,10 @@ impl<'a, 'tcx> Autoderef<'a, 'tcx> {
}
}
pub fn with_overloaded_span(self, overloaded_span: Span) -> Self {
Self { overloaded_span, ..self }
}
fn overloaded_deref_ty(&mut self, ty: Ty<'tcx>) -> Option<Ty<'tcx>> {
debug!("overloaded_deref_ty({:?})", ty);

View file

@ -714,7 +714,6 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
obligation.cause.body_id,
span,
base_ty,
span,
);
if let Some(steps) = autoderef.find_map(|(ty, steps)| {
// Re-add the `&`