Skip to content

Commit f7ed4f2

Browse files
trait_goals: Handle auto trait bounds in objects
1 parent 3cd8baa commit f7ed4f2

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

compiler/rustc_trait_selection/src/solve/trait_goals.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use std::iter;
44

55
use super::assembly::{self, AssemblyCtxt};
6-
use super::{CanonicalGoal, EvalCtxt, Goal, QueryResult};
6+
use super::{CanonicalGoal, Certainty, EvalCtxt, Goal, QueryResult};
77
use rustc_hir::def_id::DefId;
88
use rustc_infer::infer::{InferOk, LateBoundRegionConversionTime};
99
use rustc_infer::traits::query::NoSolution;
@@ -39,6 +39,9 @@ pub(super) enum CandidateSource {
3939
AliasBound(usize),
4040
/// Implementation of `Trait` or its supertraits for a `dyn Trait + Send + Sync`.
4141
ObjectBound(usize),
42+
/// Implementation of `Send` or other explicitly listed *auto* traits for
43+
/// a `dyn Trait + Send + Sync`
44+
ObjectAutoBound(usize),
4245
/// A builtin implementation for some specific traits, used in cases
4346
/// where we cannot rely an ordinary library implementations.
4447
///
@@ -161,6 +164,14 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
161164
);
162165
}
163166
}
167+
168+
for (idx, predicate) in object_bounds.iter().enumerate() {
169+
let ty::ExistentialPredicate::AutoTrait(def_id) = predicate.skip_binder() else { continue };
170+
if def_id != goal.predicate.def_id() {
171+
continue;
172+
}
173+
acx.try_insert_candidate(CandidateSource::ObjectAutoBound(idx), Certainty::Yes);
174+
}
164175
}
165176
}
166177

@@ -254,6 +265,7 @@ impl<'tcx> EvalCtxt<'tcx> {
254265
| (CandidateSource::ParamEnv(_), _)
255266
| (CandidateSource::AliasBound(_), _)
256267
| (CandidateSource::ObjectBound(_), _)
268+
| (CandidateSource::ObjectAutoBound(_), _)
257269
| (CandidateSource::Builtin, _)
258270
| (CandidateSource::AutoImpl, _) => unimplemented!(),
259271
}

0 commit comments

Comments
 (0)