Skip to content

Commit 3f700d2

Browse files
committed
Document pub items in clippy_utils::visitors
- module - `Descend::{Yes, No}` - `find_all_ret_expressions()` - `for_each_unconsumed_temporary()` - this one was mostly just reformatting the non-doc comment that was already there - `any_temporaries_need_ordered_drop()` - `contains_break_or_continue()`
1 parent 9230419 commit 3f700d2

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

clippy_utils/src/visitors.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Utilities for analyzing the contents of expressions and other [visitable](Visitable) items.
2+
13
use crate::get_enclosing_block;
24
use crate::msrvs::Msrv;
35
use crate::qualify_min_const_fn::is_stable_const_fn;
@@ -36,7 +38,9 @@ impl Continue for () {
3638
/// descending into child nodes.
3739
#[derive(Clone, Copy)]
3840
pub enum Descend {
41+
/// Controlled [`Visitor`] should descend into child nodes.
3942
Yes,
43+
/// Controlled [`Visitor`] should not descend into child nodes.
4044
No,
4145
}
4246
impl From<bool> for Descend {
@@ -204,6 +208,9 @@ fn contains_try(expr: &Expr<'_>) -> bool {
204208
.is_some()
205209
}
206210

211+
/// Calls a given function of the form `|return_expr: &Expr| -> bool` for all `return` expressions
212+
/// in the given [expression](Expr), and returns whether that callback returned true for all found
213+
/// `return`s.
207214
pub fn find_all_ret_expressions<'hir, F>(_cx: &LateContext<'_>, expr: &'hir Expr<'hir>, callback: F) -> bool
208215
where
209216
F: FnMut(&'hir Expr<'hir>) -> bool,
@@ -589,9 +596,11 @@ pub fn for_each_local_use_after_expr<'tcx, B>(
589596
}
590597
}
591598

592-
// Calls the given function for every unconsumed temporary created by the expression. Note the
593-
// function is only guaranteed to be called for types which need to be dropped, but it may be called
594-
// for other types.
599+
/// Calls a given function of the form `|temporary_type: Ty| -> ControlFlow<B>` for every unconsumed
600+
/// temporary created by the given [expression](Expr), and returns the result of that function.
601+
///
602+
/// Note the function is only guaranteed to be called for types which need to be dropped, but it may
603+
/// be called for other types.
595604
#[expect(clippy::too_many_lines)]
596605
pub fn for_each_unconsumed_temporary<'tcx, B>(
597606
cx: &LateContext<'tcx>,
@@ -708,6 +717,8 @@ pub fn for_each_unconsumed_temporary<'tcx, B>(
708717
helper(cx.typeck_results(), true, e, &mut f)
709718
}
710719

720+
/// Checks whether the drop order matters for any unconsumed temporary created by the given
721+
/// [expression](Expr).
711722
pub fn any_temporaries_need_ordered_drop<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'tcx>) -> bool {
712723
for_each_unconsumed_temporary(cx, e, |ty| {
713724
if needs_ordered_drop(cx, ty) {
@@ -765,6 +776,8 @@ pub fn for_each_local_assignment<'tcx, B>(
765776
}
766777
}
767778

779+
/// Checks whether the given [expression](Expr) contains any `break` or `continue` expressions. This
780+
/// does not enter any bodies or nested items.
768781
pub fn contains_break_or_continue(expr: &Expr<'_>) -> bool {
769782
for_each_expr_without_closures(expr, |e| {
770783
if matches!(e.kind, ExprKind::Break(..) | ExprKind::Continue(..)) {

0 commit comments

Comments
 (0)