Skip to content

Commit fd79533

Browse files
authored
Rollup merge of rust-lang#104156 - oli-obk:autoderef, r=estebank
Cleanups in autoderef impl Just something I noticed. Turns out the `overloaded_span` is not actually used separately from the main span, so I merged them.
2 parents 3a2ab4e + b745a29 commit fd79533

File tree

7 files changed

+8
-35
lines changed

7 files changed

+8
-35
lines changed

compiler/rustc_hir_analysis/src/check/wfcheck.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1708,8 +1708,7 @@ fn receiver_is_valid<'tcx>(
17081708
return true;
17091709
}
17101710

1711-
let mut autoderef =
1712-
Autoderef::new(infcx, wfcx.param_env, wfcx.body_id, span, receiver_ty, span);
1711+
let mut autoderef = Autoderef::new(infcx, wfcx.param_env, wfcx.body_id, span, receiver_ty);
17131712

17141713
// The `arbitrary_self_types` feature allows raw pointer receivers like `self: *const Self`.
17151714
if arbitrary_self_types_enabled {

compiler/rustc_hir_typeck/src/autoderef.rs

+2-17
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,7 @@ use std::iter;
1212

1313
impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1414
pub fn autoderef(&'a self, span: Span, base_ty: Ty<'tcx>) -> Autoderef<'a, 'tcx> {
15-
Autoderef::new(self, self.param_env, self.body_id, span, base_ty, span)
16-
}
17-
18-
/// Like `autoderef`, but provides a custom `Span` to use for calls to
19-
/// an overloaded `Deref` operator
20-
pub fn autoderef_overloaded_span(
21-
&'a self,
22-
span: Span,
23-
base_ty: Ty<'tcx>,
24-
overloaded_span: Span,
25-
) -> Autoderef<'a, 'tcx> {
26-
Autoderef::new(self, self.param_env, self.body_id, span, base_ty, overloaded_span)
15+
Autoderef::new(self, self.param_env, self.body_id, span, base_ty)
2716
}
2817

2918
pub fn try_overloaded_deref(
@@ -55,11 +44,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
5544
|InferOk { value: method, obligations: o }| {
5645
obligations.extend(o);
5746
if let ty::Ref(region, _, mutbl) = *method.sig.output().kind() {
58-
Some(OverloadedDeref {
59-
region,
60-
mutbl,
61-
span: autoderef.overloaded_span(),
62-
})
47+
Some(OverloadedDeref { region, mutbl, span: autoderef.span() })
6348
} else {
6449
None
6550
}

compiler/rustc_hir_typeck/src/method/confirm.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
151151
) -> Ty<'tcx> {
152152
// Commit the autoderefs by calling `autoderef` again, but this
153153
// time writing the results into the various typeck results.
154-
let mut autoderef =
155-
self.autoderef_overloaded_span(self.span, unadjusted_self_ty, self.call_expr.span);
154+
let mut autoderef = self.autoderef(self.call_expr.span, unadjusted_self_ty);
156155
let Some((ty, n)) = autoderef.nth(pick.autoderefs) else {
157156
return self.tcx.ty_error_with_message(
158157
rustc_span::DUMMY_SP,

compiler/rustc_hir_typeck/src/method/probe.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -475,10 +475,9 @@ fn method_autoderef_steps<'tcx>(
475475
let (ref infcx, goal, inference_vars) = tcx.infer_ctxt().build_with_canonical(DUMMY_SP, &goal);
476476
let ParamEnvAnd { param_env, value: self_ty } = goal;
477477

478-
let mut autoderef =
479-
Autoderef::new(infcx, param_env, hir::CRATE_HIR_ID, DUMMY_SP, self_ty, DUMMY_SP)
480-
.include_raw_pointers()
481-
.silence_errors();
478+
let mut autoderef = Autoderef::new(infcx, param_env, hir::CRATE_HIR_ID, DUMMY_SP, self_ty)
479+
.include_raw_pointers()
480+
.silence_errors();
482481
let mut reached_raw_pointer = false;
483482
let mut steps: Vec<_> = autoderef
484483
.by_ref()

compiler/rustc_hir_typeck/src/pat.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use rustc_span::lev_distance::find_best_match_for_name;
1919
use rustc_span::source_map::{Span, Spanned};
2020
use rustc_span::symbol::{kw, sym, Ident};
2121
use rustc_span::{BytePos, DUMMY_SP};
22-
use rustc_trait_selection::autoderef::Autoderef;
2322
use rustc_trait_selection::traits::{ObligationCause, Pattern};
2423
use ty::VariantDef;
2524

@@ -2132,7 +2131,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
21322131
&& let ty::Array(..) | ty::Slice(..) = ty.kind()
21332132
{
21342133
err.help("the semantics of slice patterns changed recently; see issue #62254");
2135-
} else if Autoderef::new(&self.infcx, self.param_env, self.body_id, span, expected_ty, span)
2134+
} else if self.autoderef(span, expected_ty)
21362135
.any(|(ty, _)| matches!(ty.kind(), ty::Slice(..) | ty::Array(..)))
21372136
&& let (Some(span), true) = (ti.span, ti.origin_expr)
21382137
&& let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(span)

compiler/rustc_trait_selection/src/autoderef.rs

-7
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ pub struct Autoderef<'a, 'tcx> {
2727
// Meta infos:
2828
infcx: &'a InferCtxt<'tcx>,
2929
span: Span,
30-
overloaded_span: Span,
3130
body_id: hir::HirId,
3231
param_env: ty::ParamEnv<'tcx>,
3332

@@ -99,12 +98,10 @@ impl<'a, 'tcx> Autoderef<'a, 'tcx> {
9998
body_id: hir::HirId,
10099
span: Span,
101100
base_ty: Ty<'tcx>,
102-
overloaded_span: Span,
103101
) -> Autoderef<'a, 'tcx> {
104102
Autoderef {
105103
infcx,
106104
span,
107-
overloaded_span,
108105
body_id,
109106
param_env,
110107
state: AutoderefSnapshot {
@@ -193,10 +190,6 @@ impl<'a, 'tcx> Autoderef<'a, 'tcx> {
193190
self.span
194191
}
195192

196-
pub fn overloaded_span(&self) -> Span {
197-
self.overloaded_span
198-
}
199-
200193
pub fn reached_recursion_limit(&self) -> bool {
201194
self.state.reached_recursion_limit
202195
}

compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

-1
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,6 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
714714
obligation.cause.body_id,
715715
span,
716716
base_ty,
717-
span,
718717
);
719718
if let Some(steps) = autoderef.find_map(|(ty, steps)| {
720719
// Re-add the `&`

0 commit comments

Comments
 (0)