Skip to content

Commit 69d781a

Browse files
committed
move impl documentation to their actual locations
1 parent 4b76fac commit 69d781a

File tree

3 files changed

+12
-34
lines changed

3 files changed

+12
-34
lines changed

compiler/rustc_target/src/abi/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ 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
125124
pub fn is_pointer_like(self, data_layout: &TargetDataLayout) -> bool {
126125
self.size() == data_layout.pointer_size
127126
&& self.align().abi == data_layout.pointer_align.abi

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

+2-33
Original file line numberDiff line numberDiff line change
@@ -188,16 +188,6 @@ 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.
201191
fn consider_builtin_sized_candidate(
202192
ecx: &mut EvalCtxt<'_, 'tcx>,
203193
goal: Goal<'tcx, Self>,
@@ -212,20 +202,6 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
212202
)
213203
}
214204

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.
229205
fn consider_builtin_copy_clone_candidate(
230206
ecx: &mut EvalCtxt<'_, 'tcx>,
231207
goal: Goal<'tcx, Self>,
@@ -240,9 +216,6 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
240216
)
241217
}
242218

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
246219
fn consider_builtin_pointer_like_candidate(
247220
ecx: &mut EvalCtxt<'_, 'tcx>,
248221
goal: Goal<'tcx, Self>,
@@ -272,25 +245,21 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
272245
}
273246
}
274247

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.
281248
fn consider_builtin_fn_ptr_trait_candidate(
282249
ecx: &mut EvalCtxt<'_, 'tcx>,
283250
goal: Goal<'tcx, Self>,
284251
) -> QueryResult<'tcx> {
285252
let self_ty = goal.predicate.self_ty();
286253
match goal.predicate.polarity {
254+
// impl FnPtr for FnPtr {}
287255
ty::ImplPolarity::Positive => {
288256
if self_ty.is_fn_ptr() {
289257
ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
290258
} else {
291259
Err(NoSolution)
292260
}
293261
}
262+
// impl !FnPtr for T where T != FnPtr && T is rigid {}
294263
ty::ImplPolarity::Negative => {
295264
// If a type is rigid and not a fn ptr, then we know for certain
296265
// that it does *not* implement `FnPtr`.

0 commit comments

Comments
 (0)