Skip to content

Commit 4b76fac

Browse files
committed
Document some builtin impls in the next solver
1 parent 09bc67b commit 4b76fac

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

compiler/rustc_target/src/abi/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ impl<'a> Layout<'a> {
121121
///
122122
/// Currently, that means that the type is pointer-sized, pointer-aligned,
123123
/// and has a initialized (non-union), scalar ABI.
124+
// Please also update compiler/rustc_trait_selection/src/solve/trait_goals.rs if the criteria changes
124125
pub fn is_pointer_like(self, data_layout: &TargetDataLayout) -> bool {
125126
self.size() == data_layout.pointer_size
126127
&& self.align().abi == data_layout.pointer_align.abi

compiler/rustc_trait_selection/src/solve/trait_goals.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,16 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
188188
})
189189
}
190190

191+
/// ```rust,ignore (not valid rust syntax)
192+
/// impl Sized for u*, i*, bool, f*, FnPtr, FnDef, *(const/mut) T, char, &mut? T, [T; N], dyn* Trait, !
193+
///
194+
/// impl Sized for (T1, T2, .., Tn) where T1: Sized, T2: Sized, .. Tn: Sized
195+
///
196+
/// impl Sized for Adt where T: Sized forall T in field types
197+
/// ```
198+
///
199+
/// note that `[T; N]` is unconditionally sized since `T: Sized` is required for the array type to be
200+
/// well-formed.
191201
fn consider_builtin_sized_candidate(
192202
ecx: &mut EvalCtxt<'_, 'tcx>,
193203
goal: Goal<'tcx, Self>,
@@ -202,6 +212,20 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
202212
)
203213
}
204214

215+
/// ```rust,ignore (not valid rust syntax)
216+
/// impl Copy/Clone for FnDef, FnPtr
217+
///
218+
/// impl Copy/Clone for (T1, T2, .., Tn) where T1: Copy/Clone, T2: Copy/Clone, .. Tn: Copy/Clone
219+
///
220+
/// impl Copy/Clone for Closure where T: Copy/Clone forall T in upvars
221+
///
222+
/// // only when `coroutine_clone` is enabled and the coroutine is movable
223+
/// impl Copy/Clone for Coroutine where T: Copy/Clone forall T in (upvars, witnesses)
224+
///
225+
/// impl Copy/Clone for CoroutineWitness where T: Copy/Clone forall T in coroutine_hidden_types
226+
/// ```
227+
///
228+
/// Some built-in types don't have built-in impls because they can be implemented within the standard library.
205229
fn consider_builtin_copy_clone_candidate(
206230
ecx: &mut EvalCtxt<'_, 'tcx>,
207231
goal: Goal<'tcx, Self>,
@@ -216,6 +240,9 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
216240
)
217241
}
218242

243+
/// Implements `PointerLike` for types that are pointer-sized, pointer-aligned,
244+
/// and have a initialized (non-union), scalar ABI.
245+
// Please also update compiler/rustc_target/src/abi/mod.rs if the criteria changes
219246
fn consider_builtin_pointer_like_candidate(
220247
ecx: &mut EvalCtxt<'_, 'tcx>,
221248
goal: Goal<'tcx, Self>,
@@ -245,6 +272,12 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
245272
}
246273
}
247274

275+
/// ```rust,ignore (not valid rust syntax)
276+
/// impl FnPtr for FnPtr {}
277+
/// impl !FnPtr for T where T != FnPtr && T is rigid {}
278+
/// ```
279+
///
280+
/// Note: see [`Ty::is_known_rigid`] for what it means for the type to be rigid.
248281
fn consider_builtin_fn_ptr_trait_candidate(
249282
ecx: &mut EvalCtxt<'_, 'tcx>,
250283
goal: Goal<'tcx, Self>,
@@ -375,6 +408,12 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
375408
}
376409
}
377410

411+
/// ```rust, ignore (not valid rust syntax)
412+
/// impl Tuple for () {}
413+
/// impl Tuple for (T1,) {}
414+
/// impl Tuple for (T1, T2) {}
415+
/// impl Tuple for (T1, .., Tn) {}
416+
/// ```
378417
fn consider_builtin_tuple_candidate(
379418
ecx: &mut EvalCtxt<'_, 'tcx>,
380419
goal: Goal<'tcx, Self>,

0 commit comments

Comments
 (0)