Skip to content

Commit 919500f

Browse files
committed
Consider obligations when checking for self methods
1 parent 12e3222 commit 919500f

File tree

3 files changed

+16
-41
lines changed

3 files changed

+16
-41
lines changed

compiler/rustc_hir_typeck/src/method/probe.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -651,8 +651,8 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
651651
}
652652
}
653653

654+
#[instrument(level = "debug", skip(self))]
654655
fn assemble_probe(&mut self, self_ty: &Canonical<'tcx, QueryResponse<'tcx, Ty<'tcx>>>) {
655-
debug!("assemble_probe: self_ty={:?}", self_ty);
656656
let raw_self_ty = self_ty.value.value;
657657
match *raw_self_ty.kind() {
658658
ty::Dynamic(data, ..) if let Some(p) = data.principal() => {
@@ -730,13 +730,12 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
730730
}
731731
}
732732

733+
#[instrument(level = "debug", skip(self))]
733734
fn assemble_inherent_impl_probe(&mut self, impl_def_id: DefId) {
734735
if !self.impl_dups.insert(impl_def_id) {
735736
return; // already visited
736737
}
737738

738-
debug!("assemble_inherent_impl_probe {:?}", impl_def_id);
739-
740739
for item in self.impl_or_trait_item(impl_def_id) {
741740
if !self.has_applicable_self(&item) {
742741
// No receiver declared. Not a candidate.
@@ -786,9 +785,8 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
786785
}
787786
}
788787

788+
#[instrument(level = "debug", skip(self))]
789789
fn assemble_inherent_candidates_from_object(&mut self, self_ty: Ty<'tcx>) {
790-
debug!("assemble_inherent_candidates_from_object(self_ty={:?})", self_ty);
791-
792790
let principal = match self_ty.kind() {
793791
ty::Dynamic(ref data, ..) => Some(data),
794792
_ => None,
@@ -835,9 +833,9 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
835833
});
836834
}
837835

836+
#[instrument(level = "debug", skip(self))]
838837
fn assemble_inherent_candidates_from_param(&mut self, param_ty: ty::ParamTy) {
839838
// FIXME: do we want to commit to this behavior for param bounds?
840-
debug!("assemble_inherent_candidates_from_param(param_ty={:?})", param_ty);
841839

842840
let bounds = self.param_env.caller_bounds().iter().filter_map(|predicate| {
843841
let bound_predicate = predicate.kind();
@@ -904,6 +902,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
904902
}
905903
}
906904

905+
#[instrument(level = "debug", skip(self))]
907906
fn assemble_extension_candidates_for_traits_in_scope(&mut self) {
908907
let mut duplicates = FxHashSet::default();
909908
let opt_applicable_traits = self.tcx.in_scope_traits(self.scope_expr_id);
@@ -920,6 +919,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
920919
}
921920
}
922921

922+
#[instrument(level = "debug", skip(self))]
923923
fn assemble_extension_candidates_for_all_traits(&mut self) {
924924
let mut duplicates = FxHashSet::default();
925925
for trait_info in suggest::all_traits(self.tcx) {
@@ -956,12 +956,12 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
956956
}
957957
}
958958

959+
#[instrument(level = "debug", skip(self))]
959960
fn assemble_extension_candidates_for_trait(
960961
&mut self,
961962
import_ids: &SmallVec<[LocalDefId; 1]>,
962963
trait_def_id: DefId,
963964
) {
964-
debug!("assemble_extension_candidates_for_trait(trait_def_id={:?})", trait_def_id);
965965
let trait_args = self.fresh_args_for_item(self.span, trait_def_id);
966966
let trait_ref = ty::TraitRef::new(self.tcx, trait_def_id, trait_args);
967967

@@ -1066,6 +1066,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
10661066
///////////////////////////////////////////////////////////////////////////
10671067
// THE ACTUAL SEARCH
10681068

1069+
#[instrument(level = "debug", skip(self))]
10691070
fn pick(mut self) -> PickResult<'tcx> {
10701071
assert!(self.method_name.is_some());
10711072

@@ -1492,12 +1493,10 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
14921493
// Thus we need to prevent them from trying to match the `&_` autoref
14931494
// candidates that get created for `&self` trait methods.
14941495
ty::Alias(ty::Opaque, alias_ty)
1495-
if self.infcx.can_define_opaque_ty(alias_ty.def_id) =>
1496+
if self.infcx.can_define_opaque_ty(alias_ty.def_id)
1497+
&& !probe.xform_self_ty.is_ty_var() =>
14961498
{
1497-
if !probe.xform_self_ty.is_ty_var() {
1498-
return ProbeResult::NoMatch;
1499-
}
1500-
vec![]
1499+
return ProbeResult::NoMatch;
15011500
}
15021501
_ => match self.at(&ObligationCause::dummy(), self.param_env).sup(
15031502
DefineOpaqueTypes::Yes,
@@ -1767,6 +1766,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
17671766
/// Similarly to `probe_for_return_type`, this method attempts to find the best matching
17681767
/// candidate method where the method name may have been misspelled. Similarly to other
17691768
/// edit distance based suggestions, we provide at most one such suggestion.
1769+
#[instrument(level = "debug", skip(self))]
17701770
pub(crate) fn probe_for_similar_candidate(
17711771
&mut self,
17721772
) -> Result<Option<ty::AssocItem>, MethodError<'tcx>> {

tests/ui/impl-trait/recursive-parent-trait-method-call.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1+
//! This test checks that we can resolve the `boxed` method call to `FutureExt`,
2+
//! because we know that the anonymous future does not implement `StreamExt`.
3+
14
//@ edition: 2021
5+
//@ check-pass
26

37
use std::future::Future;
48
use std::pin::Pin;
@@ -22,7 +26,6 @@ fn go(i: usize) -> impl Future<Output = ()> + Send + 'static {
2226
if i != 0 {
2327
spawn(async move {
2428
let fut = go(i - 1).boxed();
25-
//~^ ERROR: multiple applicable items in scope
2629
fut.await;
2730
})
2831
.await;

tests/ui/impl-trait/recursive-parent-trait-method-call.stderr

-28
This file was deleted.

0 commit comments

Comments
 (0)