Skip to content

Commit 9740050

Browse files
committed
Add self ty to pick
1 parent ad44239 commit 9740050

File tree

1 file changed

+11
-6
lines changed
  • compiler/rustc_typeck/src/check/method

1 file changed

+11
-6
lines changed

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

+11-6
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ pub struct Pick<'tcx> {
204204
/// Indicates that we want to add an autoref (and maybe also unsize it), or if the receiver is
205205
/// `*mut T`, convert it to `*const T`.
206206
pub autoref_or_ptr_adjustment: Option<AutorefOrPtrAdjustment<'tcx>>,
207+
pub self_ty: Ty<'tcx>,
207208
}
208209

209210
#[derive(Clone, Debug, PartialEq, Eq)]
@@ -1241,7 +1242,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
12411242
//
12421243
// We suppress warning if we're picking the method only because it is a
12431244
// suggestion.
1244-
self.emit_unstable_name_collision_hint(p, &unstable_candidates, self_ty);
1245+
self.emit_unstable_name_collision_hint(p, &unstable_candidates);
12451246
}
12461247
}
12471248
return Some(pick);
@@ -1285,7 +1286,9 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
12851286
debug!("applicable_candidates: {:?}", applicable_candidates);
12861287

12871288
if applicable_candidates.len() > 1 {
1288-
if let Some(pick) = self.collapse_candidates_to_trait_pick(&applicable_candidates[..]) {
1289+
if let Some(pick) =
1290+
self.collapse_candidates_to_trait_pick(self_ty, &applicable_candidates[..])
1291+
{
12891292
return Some(Ok(pick));
12901293
}
12911294
}
@@ -1309,7 +1312,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
13091312

13101313
applicable_candidates.pop().map(|(probe, status)| {
13111314
if status == ProbeResult::Match {
1312-
Ok(probe.to_unadjusted_pick())
1315+
Ok(probe.to_unadjusted_pick(self_ty))
13131316
} else {
13141317
Err(MethodError::BadReturnType)
13151318
}
@@ -1320,7 +1323,6 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
13201323
&self,
13211324
stable_pick: &Pick<'_>,
13221325
unstable_candidates: &[(&Candidate<'tcx>, Symbol)],
1323-
self_ty: Ty<'tcx>,
13241326
) {
13251327
self.tcx.struct_span_lint_hir(
13261328
lint::builtin::UNSTABLE_NAME_COLLISIONS,
@@ -1351,7 +1353,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
13511353
"use the fully qualified path to the associated const",
13521354
format!(
13531355
"<{} as {}>::{}",
1354-
self_ty,
1356+
stable_pick.self_ty,
13551357
self.tcx.def_path_str(def_id),
13561358
stable_pick.item.ident
13571359
),
@@ -1591,6 +1593,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
15911593
/// use, so it's ok to just commit to "using the method from the trait Foo".
15921594
fn collapse_candidates_to_trait_pick(
15931595
&self,
1596+
self_ty: Ty<'tcx>,
15941597
probes: &[(&Candidate<'tcx>, ProbeResult)],
15951598
) -> Option<Pick<'tcx>> {
15961599
// Do all probes correspond to the same trait?
@@ -1610,6 +1613,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
16101613
import_ids: probes[0].0.import_ids.clone(),
16111614
autoderefs: 0,
16121615
autoref_or_ptr_adjustment: None,
1616+
self_ty,
16131617
})
16141618
}
16151619

@@ -1828,7 +1832,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
18281832
}
18291833

18301834
impl<'tcx> Candidate<'tcx> {
1831-
fn to_unadjusted_pick(&self) -> Pick<'tcx> {
1835+
fn to_unadjusted_pick(&self, self_ty: Ty<'tcx>) -> Pick<'tcx> {
18321836
Pick {
18331837
item: self.item,
18341838
kind: match self.kind {
@@ -1852,6 +1856,7 @@ impl<'tcx> Candidate<'tcx> {
18521856
import_ids: self.import_ids.clone(),
18531857
autoderefs: 0,
18541858
autoref_or_ptr_adjustment: None,
1859+
self_ty,
18551860
}
18561861
}
18571862
}

0 commit comments

Comments
 (0)