Skip to content

Commit adda088

Browse files
authored
Unrolled build for rust-lang#122238
Rollup merge of rust-lang#122238 - fee1-dead-contrib:builtin-impl-next-solver-dox, r=lcnr Document some builtin impls in the next solver This does not cover all builtin impls, but ones that I were able to go over within a cycle. r? `@lcnr` Let me know if the place isn't correct for these, or if you'd like me to change how the impls are presented ^^
2 parents fe61575 + 69d781a commit adda088

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

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

+10
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ pub(in crate::solve) fn instantiate_constituent_tys_for_sized_trait<'tcx>(
120120
ty: Ty<'tcx>,
121121
) -> Result<Vec<ty::Binder<'tcx, Ty<'tcx>>>, NoSolution> {
122122
match *ty.kind() {
123+
// impl Sized for u*, i*, bool, f*, FnDef, FnPtr, *(const/mut) T, char, &mut? T, [T; N], dyn* Trait, !
124+
// impl Sized for Coroutine, CoroutineWitness, Closure, CoroutineClosure
123125
ty::Infer(ty::IntVar(_) | ty::FloatVar(_))
124126
| ty::Uint(_)
125127
| ty::Int(_)
@@ -152,8 +154,10 @@ pub(in crate::solve) fn instantiate_constituent_tys_for_sized_trait<'tcx>(
152154
bug!("unexpected type `{ty}`")
153155
}
154156

157+
// impl Sized for (T1, T2, .., Tn) where T1: Sized, T2: Sized, .. Tn: Sized
155158
ty::Tuple(tys) => Ok(tys.iter().map(ty::Binder::dummy).collect()),
156159

160+
// impl Sized for Adt where T: Sized forall T in field types
157161
ty::Adt(def, args) => {
158162
let sized_crit = def.sized_constraint(ecx.tcx());
159163
Ok(sized_crit.iter_instantiated(ecx.tcx(), args).map(ty::Binder::dummy).collect())
@@ -167,6 +171,7 @@ pub(in crate::solve) fn instantiate_constituent_tys_for_copy_clone_trait<'tcx>(
167171
ty: Ty<'tcx>,
168172
) -> Result<Vec<ty::Binder<'tcx, Ty<'tcx>>>, NoSolution> {
169173
match *ty.kind() {
174+
// impl Copy/Clone for FnDef, FnPtr
170175
ty::FnDef(..) | ty::FnPtr(_) | ty::Error(_) => Ok(vec![]),
171176

172177
// Implementations are provided in core
@@ -196,12 +201,16 @@ pub(in crate::solve) fn instantiate_constituent_tys_for_copy_clone_trait<'tcx>(
196201
bug!("unexpected type `{ty}`")
197202
}
198203

204+
// impl Copy/Clone for (T1, T2, .., Tn) where T1: Copy/Clone, T2: Copy/Clone, .. Tn: Copy/Clone
199205
ty::Tuple(tys) => Ok(tys.iter().map(ty::Binder::dummy).collect()),
200206

207+
// impl Copy/Clone for Closure where Self::TupledUpvars: Copy/Clone
201208
ty::Closure(_, args) => Ok(vec![ty::Binder::dummy(args.as_closure().tupled_upvars_ty())]),
202209

203210
ty::CoroutineClosure(..) => Err(NoSolution),
204211

212+
// only when `coroutine_clone` is enabled and the coroutine is movable
213+
// impl Copy/Clone for Coroutine where T: Copy/Clone forall T in (upvars, witnesses)
205214
ty::Coroutine(def_id, args) => match ecx.tcx().coroutine_movability(def_id) {
206215
Movability::Static => Err(NoSolution),
207216
Movability::Movable => {
@@ -217,6 +226,7 @@ pub(in crate::solve) fn instantiate_constituent_tys_for_copy_clone_trait<'tcx>(
217226
}
218227
},
219228

229+
// impl Copy/Clone for CoroutineWitness where T: Copy/Clone forall T in coroutine_hidden_types
220230
ty::CoroutineWitness(def_id, args) => Ok(ecx
221231
.tcx()
222232
.coroutine_hidden_types(def_id)

compiler/rustc_trait_selection/src/solve/trait_goals.rs

+8
Original file line numberDiff line numberDiff line change
@@ -250,13 +250,15 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
250250
) -> QueryResult<'tcx> {
251251
let self_ty = goal.predicate.self_ty();
252252
match goal.predicate.polarity {
253+
// impl FnPtr for FnPtr {}
253254
ty::ImplPolarity::Positive => {
254255
if self_ty.is_fn_ptr() {
255256
ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
256257
} else {
257258
Err(NoSolution)
258259
}
259260
}
261+
// impl !FnPtr for T where T != FnPtr && T is rigid {}
260262
ty::ImplPolarity::Negative => {
261263
// If a type is rigid and not a fn ptr, then we know for certain
262264
// that it does *not* implement `FnPtr`.
@@ -374,6 +376,12 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
374376
}
375377
}
376378

379+
/// ```rust, ignore (not valid rust syntax)
380+
/// impl Tuple for () {}
381+
/// impl Tuple for (T1,) {}
382+
/// impl Tuple for (T1, T2) {}
383+
/// impl Tuple for (T1, .., Tn) {}
384+
/// ```
377385
fn consider_builtin_tuple_candidate(
378386
ecx: &mut EvalCtxt<'_, 'tcx>,
379387
goal: Goal<'tcx, Self>,

0 commit comments

Comments
 (0)