Skip to content

Commit 3d87a8e

Browse files
Assemble object bound candidates
1 parent f99b273 commit 3d87a8e

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

compiler/rustc_trait_selection/src/solve/assembly.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use super::infcx_ext::InferCtxtExt;
44
use super::{CanonicalResponse, EvalCtxt, Goal, QueryResult};
55
use rustc_hir::def_id::DefId;
66
use rustc_infer::traits::query::NoSolution;
7+
use rustc_infer::traits::util::elaborate_predicates;
78
use rustc_middle::ty::TypeFoldable;
89
use rustc_middle::ty::{self, Ty, TyCtxt};
910
use std::fmt::Debug;
@@ -119,6 +120,8 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
119120

120121
self.assemble_alias_bound_candidates(goal, &mut candidates);
121122

123+
self.assemble_object_bound_candidates(goal, &mut candidates);
124+
122125
candidates
123126
}
124127

@@ -272,4 +275,53 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
272275
}
273276
}
274277
}
278+
279+
fn assemble_object_bound_candidates<G: GoalKind<'tcx>>(
280+
&mut self,
281+
goal: Goal<'tcx, G>,
282+
candidates: &mut Vec<Candidate<'tcx>>,
283+
) {
284+
let self_ty = goal.predicate.self_ty();
285+
let bounds = match *self_ty.kind() {
286+
ty::Bool
287+
| ty::Char
288+
| ty::Int(_)
289+
| ty::Uint(_)
290+
| ty::Float(_)
291+
| ty::Adt(_, _)
292+
| ty::Foreign(_)
293+
| ty::Str
294+
| ty::Array(_, _)
295+
| ty::Slice(_)
296+
| ty::RawPtr(_)
297+
| ty::Ref(_, _, _)
298+
| ty::FnDef(_, _)
299+
| ty::FnPtr(_)
300+
| ty::Alias(..)
301+
| ty::Closure(..)
302+
| ty::Generator(..)
303+
| ty::GeneratorWitness(_)
304+
| ty::Never
305+
| ty::Tuple(_)
306+
| ty::Param(_)
307+
| ty::Placeholder(..)
308+
| ty::Infer(_)
309+
| ty::Error(_) => return,
310+
ty::Bound(..) => bug!("unexpected bound type: {goal:?}"),
311+
ty::Dynamic(bounds, ..) => bounds,
312+
};
313+
314+
let tcx = self.tcx();
315+
for assumption in
316+
elaborate_predicates(tcx, bounds.iter().map(|bound| bound.with_self_ty(tcx, self_ty)))
317+
{
318+
match G::consider_assumption(self, goal, assumption.predicate)
319+
{
320+
Ok(result) => {
321+
candidates.push(Candidate { source: CandidateSource::BuiltinImpl, result })
322+
}
323+
Err(NoSolution) => (),
324+
}
325+
}
326+
}
275327
}

0 commit comments

Comments
 (0)