Skip to content

Commit f7ab40d

Browse files
Remove unsize step from AutorefOrPtrAdjustment in method selection
1 parent b2c1897 commit f7ab40d

File tree

3 files changed

+8
-67
lines changed

3 files changed

+8
-67
lines changed

compiler/rustc_middle/src/traits/query.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,6 @@ pub struct CandidateStep<'tcx> {
188188
/// `fn by_raw_ptr(self: *const Self)` and `fn by_ref(&self)`, then
189189
/// `foo.by_raw_ptr()` will work and `foo.by_ref()` won't.
190190
pub from_unsafe_deref: bool,
191-
pub unsize: bool,
192191
}
193192

194193
#[derive(Clone, Debug, HashStable)]

compiler/rustc_typeck/src/check/method/confirm.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
166166
self.structurally_resolved_type(autoderef.span(), autoderef.final_ty(false));
167167

168168
match &pick.autoref_or_ptr_adjustment {
169-
Some(probe::AutorefOrPtrAdjustment::Autoref { mutbl, unsize }) => {
169+
Some(probe::AutorefOrPtrAdjustment::Autoref { mutbl }) => {
170170
let region = self.next_region_var(infer::Autoref(self.span));
171171
target = self.tcx.mk_ref(region, ty::TypeAndMut { mutbl: *mutbl, ty: target });
172172
let mutbl = match mutbl {
@@ -181,14 +181,6 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
181181
kind: Adjust::Borrow(AutoBorrow::Ref(region, mutbl)),
182182
target,
183183
});
184-
185-
if let Some(unsize_target) = unsize {
186-
target = self
187-
.tcx
188-
.mk_ref(region, ty::TypeAndMut { mutbl: mutbl.into(), ty: unsize_target });
189-
adjustments
190-
.push(Adjustment { kind: Adjust::Pointer(PointerCast::Unsize), target });
191-
}
192184
}
193185
Some(probe::AutorefOrPtrAdjustment::ToConstPtr) => {
194186
target = match target.kind() {

compiler/rustc_typeck/src/check/method/probe.rs

Lines changed: 7 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -168,29 +168,13 @@ enum ProbeResult {
168168
/// (at most) one of these. Either the receiver has type `T` and we convert it to `&T` (or with
169169
/// `mut`), or it has type `*mut T` and we convert it to `*const T`.
170170
#[derive(Debug, PartialEq, Clone)]
171-
pub enum AutorefOrPtrAdjustment<'tcx> {
172-
/// Receiver has type `T`, add `&` or `&mut` (it `T` is `mut`), and maybe also "unsize" it.
173-
/// Unsizing is used to convert a `[T; N]` to `[T]`, which only makes sense when autorefing.
174-
Autoref {
175-
mutbl: hir::Mutability,
176-
177-
/// Indicates that the source expression should be "unsized" to a target type. This should
178-
/// probably eventually go away in favor of just coercing method receivers.
179-
unsize: Option<Ty<'tcx>>,
180-
},
171+
pub enum AutorefOrPtrAdjustment {
172+
/// Receiver has type `T`, add `&` or `&mut` (it `T` is `mut`)
173+
Autoref { mutbl: hir::Mutability },
181174
/// Receiver has type `*mut T`, convert to `*const T`
182175
ToConstPtr,
183176
}
184177

185-
impl<'tcx> AutorefOrPtrAdjustment<'tcx> {
186-
fn get_unsize(&self) -> Option<Ty<'tcx>> {
187-
match self {
188-
AutorefOrPtrAdjustment::Autoref { mutbl: _, unsize } => *unsize,
189-
AutorefOrPtrAdjustment::ToConstPtr => None,
190-
}
191-
}
192-
}
193-
194178
#[derive(Debug, PartialEq, Clone)]
195179
pub struct Pick<'tcx> {
196180
pub item: ty::AssocItem,
@@ -204,7 +188,7 @@ pub struct Pick<'tcx> {
204188

205189
/// Indicates that we want to add an autoref (and maybe also unsize it), or if the receiver is
206190
/// `*mut T`, convert it to `*const T`.
207-
pub autoref_or_ptr_adjustment: Option<AutorefOrPtrAdjustment<'tcx>>,
191+
pub autoref_or_ptr_adjustment: Option<AutorefOrPtrAdjustment>,
208192
pub self_ty: Ty<'tcx>,
209193
}
210194

@@ -371,7 +355,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
371355
),
372356
autoderefs: 0,
373357
from_unsafe_deref: false,
374-
unsize: false,
375358
}]),
376359
opt_bad_ty: None,
377360
reached_recursion_limit: false,
@@ -483,7 +466,7 @@ fn method_autoderef_steps<'tcx>(
483466
.include_raw_pointers()
484467
.silence_errors();
485468
let mut reached_raw_pointer = false;
486-
let mut steps: Vec<_> = autoderef
469+
let steps: Vec<_> = autoderef
487470
.by_ref()
488471
.map(|(ty, d)| {
489472
let step = CandidateStep {
@@ -493,7 +476,6 @@ fn method_autoderef_steps<'tcx>(
493476
),
494477
autoderefs: d,
495478
from_unsafe_deref: reached_raw_pointer,
496-
unsize: false,
497479
};
498480
if let ty::RawPtr(_) = ty.kind() {
499481
// all the subsequent steps will be from_unsafe_deref
@@ -510,23 +492,6 @@ fn method_autoderef_steps<'tcx>(
510492
ty: infcx
511493
.make_query_response_ignoring_pending_obligations(inference_vars, final_ty),
512494
}),
513-
ty::Array(elem_ty, _) => {
514-
let dereferences = steps.len() - 1;
515-
516-
steps.push(CandidateStep {
517-
self_ty: infcx.make_query_response_ignoring_pending_obligations(
518-
inference_vars,
519-
infcx.tcx.mk_slice(elem_ty),
520-
),
521-
autoderefs: dereferences,
522-
// this could be from an unsafe deref if we had
523-
// a *mut/const [T; N]
524-
from_unsafe_deref: reached_raw_pointer,
525-
unsize: true,
526-
});
527-
528-
None
529-
}
530495
_ => None,
531496
};
532497

@@ -1189,21 +1154,14 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
11891154
self_ty: Ty<'tcx>,
11901155
unstable_candidates: Option<&mut Vec<(Candidate<'tcx>, Symbol)>>,
11911156
) -> Option<PickResult<'tcx>> {
1192-
if step.unsize {
1193-
return None;
1194-
}
1195-
11961157
self.pick_method(self_ty, unstable_candidates).map(|r| {
11971158
r.map(|mut pick| {
11981159
pick.autoderefs = step.autoderefs;
11991160

12001161
// Insert a `&*` or `&mut *` if this is a reference type:
12011162
if let ty::Ref(_, _, mutbl) = *step.self_ty.value.value.kind() {
12021163
pick.autoderefs += 1;
1203-
pick.autoref_or_ptr_adjustment = Some(AutorefOrPtrAdjustment::Autoref {
1204-
mutbl,
1205-
unsize: pick.autoref_or_ptr_adjustment.and_then(|a| a.get_unsize()),
1206-
})
1164+
pick.autoref_or_ptr_adjustment = Some(AutorefOrPtrAdjustment::Autoref { mutbl })
12071165
}
12081166

12091167
pick
@@ -1227,10 +1185,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
12271185
self.pick_method(autoref_ty, unstable_candidates).map(|r| {
12281186
r.map(|mut pick| {
12291187
pick.autoderefs = step.autoderefs;
1230-
pick.autoref_or_ptr_adjustment = Some(AutorefOrPtrAdjustment::Autoref {
1231-
mutbl,
1232-
unsize: step.unsize.then_some(self_ty),
1233-
});
1188+
pick.autoref_or_ptr_adjustment = Some(AutorefOrPtrAdjustment::Autoref { mutbl });
12341189
pick
12351190
})
12361191
})
@@ -1245,11 +1200,6 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
12451200
self_ty: Ty<'tcx>,
12461201
unstable_candidates: Option<&mut Vec<(Candidate<'tcx>, Symbol)>>,
12471202
) -> Option<PickResult<'tcx>> {
1248-
// Don't convert an unsized reference to ptr
1249-
if step.unsize {
1250-
return None;
1251-
}
1252-
12531203
let ty = match self_ty.kind() {
12541204
ty::RawPtr(ty::TypeAndMut { ty, mutbl: hir::Mutability::Mut }) => ty,
12551205
_ => return None,

0 commit comments

Comments
 (0)