Skip to content

Commit c2ae07d

Browse files
Rollup merge of #121083 - GuillaumeGomez:doc-to_opt_closure_kind, r=compiler-errors
Extend documentation for `Ty::to_opt_closure_kind` method This API was... surprising to use. With a little extra documentation, the weirdness can be reduced quite a lot. :) r? `@compiler-errors`
2 parents 18c935d + 9ef9f73 commit c2ae07d

File tree

1 file changed

+14
-0
lines changed
  • compiler/rustc_middle/src/ty

1 file changed

+14
-0
lines changed

compiler/rustc_middle/src/ty/sty.rs

+14
Original file line numberDiff line numberDiff line change
@@ -2373,6 +2373,20 @@ impl<'tcx> Ty<'tcx> {
23732373
/// to represent the closure kind, because it has not yet been
23742374
/// inferred. Once upvar inference (in `rustc_hir_analysis/src/check/upvar.rs`)
23752375
/// is complete, that type variable will be unified.
2376+
///
2377+
/// To be noted that you can use [`ClosureArgs::kind()`] or [`CoroutineClosureArgs::kind()`]
2378+
/// to get the same information, which you can get by calling [`GenericArgs::as_closure()`]
2379+
/// or [`GenericArgs::as_coroutine_closure()`], depending on the type of the closure.
2380+
///
2381+
/// Otherwise, this method can be used as follows:
2382+
///
2383+
/// ```rust,ignore (snippet of compiler code)
2384+
/// let TyKind::Closure(def_id, [closure_fn_kind_ty, ..]) = closure_ty.kind()
2385+
/// && let Some(closure_kind) = closure_fn_kind_ty.expect_ty().to_opt_closure_kind()
2386+
/// {
2387+
/// // your code
2388+
/// }
2389+
/// ```
23762390
pub fn to_opt_closure_kind(self) -> Option<ty::ClosureKind> {
23772391
match self.kind() {
23782392
Int(int_ty) => match int_ty {

0 commit comments

Comments
 (0)