diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2024-02-14 15:41:29 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-02-14 15:41:29 +0100 |
| commit | c2ae07d20df5854409efdf765a3df662c696cd32 (patch) | |
| tree | 34a69fbf360eb10a6f35cc36dc2a649d1da96ce5 /compiler | |
| parent | 18c935d000352fbad2e3c5e91e020945357bd9a8 (diff) | |
| parent | 9ef9f737ca80db042ae42ad944ee88465914b05c (diff) | |
| download | rust-c2ae07d20df5854409efdf765a3df662c696cd32.tar.gz rust-c2ae07d20df5854409efdf765a3df662c696cd32.zip | |
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`
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_middle/src/ty/sty.rs | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/compiler/rustc_middle/src/ty/sty.rs b/compiler/rustc_middle/src/ty/sty.rs index ae6544b9dbe..66086ac87f1 100644 --- a/compiler/rustc_middle/src/ty/sty.rs +++ b/compiler/rustc_middle/src/ty/sty.rs @@ -2373,6 +2373,20 @@ impl<'tcx> Ty<'tcx> { /// to represent the closure kind, because it has not yet been /// inferred. Once upvar inference (in `rustc_hir_analysis/src/check/upvar.rs`) /// is complete, that type variable will be unified. + /// + /// To be noted that you can use [`ClosureArgs::kind()`] or [`CoroutineClosureArgs::kind()`] + /// to get the same information, which you can get by calling [`GenericArgs::as_closure()`] + /// or [`GenericArgs::as_coroutine_closure()`], depending on the type of the closure. + /// + /// Otherwise, this method can be used as follows: + /// + /// ```rust,ignore (snippet of compiler code) + /// let TyKind::Closure(def_id, [closure_fn_kind_ty, ..]) = closure_ty.kind() + /// && let Some(closure_kind) = closure_fn_kind_ty.expect_ty().to_opt_closure_kind() + /// { + /// // your code + /// } + /// ``` pub fn to_opt_closure_kind(self) -> Option<ty::ClosureKind> { match self.kind() { Int(int_ty) => match int_ty { |
