Skip to content

Commit 920b0a7

Browse files
Use a proper probe for shadowing impl
1 parent 14081a2 commit 920b0a7

File tree

5 files changed

+17
-13
lines changed

5 files changed

+17
-13
lines changed

compiler/rustc_middle/src/traits/solve/inspect.rs

+2
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ pub enum ProbeKind<'tcx> {
153153
/// do a probe to find out what projection type(s) may be used to prove that
154154
/// the source type upholds all of the target type's object bounds.
155155
UpcastProjectionCompatibility,
156+
/// Looking for param-env candidates that satisfy the trait ref for a projection.
157+
ShadowedEnvProbing,
156158
/// Try to unify an opaque type with an existing key in the storage.
157159
OpaqueTypeStorageLookup { result: QueryResult<'tcx> },
158160
}

compiler/rustc_middle/src/traits/solve/inspect/format.rs

+3
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ impl<'a, 'b> ProofTreeFormatter<'a, 'b> {
118118
ProbeKind::TraitCandidate { source, result } => {
119119
write!(self.f, "CANDIDATE {source:?}: {result:?}")
120120
}
121+
ProbeKind::ShadowedEnvProbing => {
122+
write!(self.f, "PROBING FOR IMPLS SHADOWED BY PARAM-ENV CANDIDATE:")
123+
}
121124
}?;
122125

123126
self.nested(|this| {

compiler/rustc_trait_selection/src/solve/assembly/mod.rs

+8-11
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Code shared by trait and projection goals for candidate assembly.
22
33
use crate::solve::GoalSource;
4-
use crate::solve::{inspect, EvalCtxt, SolverMode};
4+
use crate::solve::{EvalCtxt, SolverMode};
55
use rustc_hir::def_id::DefId;
66
use rustc_infer::traits::query::NoSolution;
77
use rustc_middle::traits::solve::inspect::ProbeKind;
@@ -15,7 +15,6 @@ use rustc_middle::ty::{fast_reject, TypeFoldable};
1515
use rustc_middle::ty::{ToPredicate, TypeVisitableExt};
1616
use rustc_span::{ErrorGuaranteed, DUMMY_SP};
1717
use std::fmt::Debug;
18-
use std::mem;
1918

2019
pub(super) mod structural_traits;
2120

@@ -791,17 +790,16 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
791790
goal: Goal<'tcx, G>,
792791
candidates: &mut Vec<Candidate<'tcx>>,
793792
) {
794-
// HACK: We temporarily remove the `ProofTreeBuilder` to
795-
// avoid adding `Trait` candidates to the candidates used
796-
// to prove the current goal.
797-
let inspect = mem::replace(&mut self.inspect, inspect::ProofTreeBuilder::new_noop());
798-
799793
let tcx = self.tcx();
800794
let trait_goal: Goal<'tcx, ty::TraitPredicate<'tcx>> =
801795
goal.with(tcx, goal.predicate.trait_ref(tcx));
802-
let mut trait_candidates_from_env = Vec::new();
803-
self.assemble_param_env_candidates(trait_goal, &mut trait_candidates_from_env);
804-
self.assemble_alias_bound_candidates(trait_goal, &mut trait_candidates_from_env);
796+
797+
let mut trait_candidates_from_env = vec![];
798+
self.probe(|_| ProbeKind::ShadowedEnvProbing).enter(|ecx| {
799+
ecx.assemble_param_env_candidates(trait_goal, &mut trait_candidates_from_env);
800+
ecx.assemble_alias_bound_candidates(trait_goal, &mut trait_candidates_from_env);
801+
});
802+
805803
if !trait_candidates_from_env.is_empty() {
806804
let trait_env_result = self.merge_candidates(trait_candidates_from_env);
807805
match trait_env_result.unwrap().value.certainty {
@@ -830,7 +828,6 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
830828
}
831829
}
832830
}
833-
self.inspect = inspect;
834831
}
835832

836833
/// If there are multiple ways to prove a trait or projection goal, we have

compiler/rustc_trait_selection/src/solve/eval_ctxt/select.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,8 @@ fn to_selection<'tcx>(
175175
| ProbeKind::UnsizeAssembly
176176
| ProbeKind::UpcastProjectionCompatibility
177177
| ProbeKind::OpaqueTypeStorageLookup { result: _ }
178-
| ProbeKind::Root { result: _ } => {
178+
| ProbeKind::Root { result: _ }
179+
| ProbeKind::ShadowedEnvProbing => {
179180
span_bug!(span, "didn't expect to assemble trait candidate from {:#?}", cand.kind())
180181
}
181182
})

compiler/rustc_trait_selection/src/solve/inspect/analyse.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,8 @@ impl<'a, 'tcx> InspectGoal<'a, 'tcx> {
297297
match probe.kind {
298298
inspect::ProbeKind::NormalizedSelfTyAssembly
299299
| inspect::ProbeKind::UnsizeAssembly
300-
| inspect::ProbeKind::UpcastProjectionCompatibility => (),
300+
| inspect::ProbeKind::UpcastProjectionCompatibility
301+
| inspect::ProbeKind::ShadowedEnvProbing => (),
301302

302303
// We add a candidate even for the root evaluation if there
303304
// is only one way to prove a given goal, e.g. for `WellFormed`.

0 commit comments

Comments
 (0)