Skip to content

Commit 9ef9f73

Browse files
Extend documentation for Ty::to_opt_closure_kind method
1 parent 81b757c commit 9ef9f73

File tree

1 file changed

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

1 file changed

+14
-0
lines changed

Diff for: compiler/rustc_middle/src/ty/sty.rs

+14
Original file line numberDiff line numberDiff line change
@@ -2362,6 +2362,20 @@ impl<'tcx> Ty<'tcx> {
23622362
/// to represent the closure kind, because it has not yet been
23632363
/// inferred. Once upvar inference (in `rustc_hir_analysis/src/check/upvar.rs`)
23642364
/// is complete, that type variable will be unified.
2365+
///
2366+
/// To be noted that you can use [`ClosureArgs::kind()`] or [`CoroutineClosureArgs::kind()`]
2367+
/// to get the same information, which you can get by calling [`GenericArgs::as_closure()`]
2368+
/// or [`GenericArgs::as_coroutine_closure()`], depending on the type of the closure.
2369+
///
2370+
/// Otherwise, this method can be used as follows:
2371+
///
2372+
/// ```rust,ignore (snippet of compiler code)
2373+
/// let TyKind::Closure(def_id, [closure_fn_kind_ty, ..]) = closure_ty.kind()
2374+
/// && let Some(closure_kind) = closure_fn_kind_ty.expect_ty().to_opt_closure_kind()
2375+
/// {
2376+
/// // your code
2377+
/// }
2378+
/// ```
23652379
pub fn to_opt_closure_kind(self) -> Option<ty::ClosureKind> {
23662380
match self.kind() {
23672381
Int(int_ty) => match int_ty {

0 commit comments

Comments
 (0)