Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document some builtin impls in the next solver #122238

Merged
merged 2 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions compiler/rustc_target/src/abi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ impl<'a> Layout<'a> {
///
/// Currently, that means that the type is pointer-sized, pointer-aligned,
/// and has a initialized (non-union), scalar ABI.
// Please also update compiler/rustc_trait_selection/src/solve/trait_goals.rs if the criteria changes
pub fn is_pointer_like(self, data_layout: &TargetDataLayout) -> bool {
self.size() == data_layout.pointer_size
&& self.align().abi == data_layout.pointer_align.abi
Expand Down
39 changes: 39 additions & 0 deletions compiler/rustc_trait_selection/src/solve/trait_goals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,16 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
})
}

/// ```rust,ignore (not valid rust syntax)
/// impl Sized for u*, i*, bool, f*, FnPtr, FnDef, *(const/mut) T, char, &mut? T, [T; N], dyn* Trait, !
///
/// impl Sized for (T1, T2, .., Tn) where T1: Sized, T2: Sized, .. Tn: Sized
///
/// impl Sized for Adt where T: Sized forall T in field types
/// ```
///
/// note that `[T; N]` is unconditionally sized since `T: Sized` is required for the array type to be
/// well-formed.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My initial reaction was that I would prefer moving the comment for each builtin impl to the most specific place possible, having only a single impl per comment. This would mostly correspond to commenting the match arms on the self_ty matches in most cases.

I worry that these comments here can easily get out of date. E.g. When changing instantiate_constituent_tys_for_sized_trait we likely won't remember updating this function 🤔 E.g. this function currently diverges from the old solver by checking that all tuple fields are sized, not only the last one

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, that would work. I will move these.

fn consider_builtin_sized_candidate(
ecx: &mut EvalCtxt<'_, 'tcx>,
goal: Goal<'tcx, Self>,
Expand All @@ -202,6 +212,20 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
)
}

/// ```rust,ignore (not valid rust syntax)
/// impl Copy/Clone for FnDef, FnPtr
///
/// impl Copy/Clone for (T1, T2, .., Tn) where T1: Copy/Clone, T2: Copy/Clone, .. Tn: Copy/Clone
///
/// impl Copy/Clone for Closure where T: Copy/Clone forall T in upvars
///
/// // only when `coroutine_clone` is enabled and the coroutine is movable
/// impl Copy/Clone for Coroutine where T: Copy/Clone forall T in (upvars, witnesses)
///
/// impl Copy/Clone for CoroutineWitness where T: Copy/Clone forall T in coroutine_hidden_types
/// ```
///
/// Some built-in types don't have built-in impls because they can be implemented within the standard library.
fn consider_builtin_copy_clone_candidate(
ecx: &mut EvalCtxt<'_, 'tcx>,
goal: Goal<'tcx, Self>,
Expand All @@ -216,6 +240,9 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
)
}

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

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

/// ```rust, ignore (not valid rust syntax)
/// impl Tuple for () {}
/// impl Tuple for (T1,) {}
/// impl Tuple for (T1, T2) {}
/// impl Tuple for (T1, .., Tn) {}
/// ```
fn consider_builtin_tuple_candidate(
ecx: &mut EvalCtxt<'_, 'tcx>,
goal: Goal<'tcx, Self>,
Expand Down
Loading