Skip to content

Commit dc8bdbc

Browse files
Fix dogfood lints
1 parent 1f70be9 commit dc8bdbc

File tree

5 files changed

+42
-26
lines changed

5 files changed

+42
-26
lines changed

clippy_lints/src/doc/too_long_first_doc_paragraph.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ pub(super) fn check(
5858
}
5959
}
6060

61-
let &[first_span, .., last_span] = spans.as_slice() else { return };
61+
let &[first_span, .., last_span] = spans.as_slice() else {
62+
return;
63+
};
6264

6365
if should_suggest_empty_doc
6466
&& let Some(second_span) = spans.get(1)

clippy_utils/src/lib.rs

+13-8
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ macro_rules! extract_msrv_attr {
150150

151151
/// If the given expression is a local binding, find the initializer expression.
152152
/// If that initializer expression is another local binding, find its initializer again.
153+
///
153154
/// This process repeats as long as possible (but usually no more than once). Initializer
154155
/// expressions with adjustments are ignored. If this is not desired, use [`find_binding_init`]
155156
/// instead.
@@ -180,6 +181,7 @@ pub fn expr_or_init<'a, 'b, 'tcx: 'b>(cx: &LateContext<'tcx>, mut expr: &'a Expr
180181
}
181182

182183
/// Finds the initializer expression for a local binding. Returns `None` if the binding is mutable.
184+
///
183185
/// By only considering immutable bindings, we guarantee that the returned expression represents the
184186
/// value of the binding wherever it is referenced.
185187
///
@@ -428,12 +430,12 @@ pub fn qpath_generic_tys<'tcx>(qpath: &QPath<'tcx>) -> impl Iterator<Item = &'tc
428430
})
429431
}
430432

431-
/// THIS METHOD IS DEPRECATED and will eventually be removed since it does not match against the
433+
/// THIS METHOD IS DEPRECATED. Matches a `QPath` against a slice of segment string literals.
434+
///
435+
/// This method is deprecated and will eventually be removed since it does not match against the
432436
/// entire path or resolved `DefId`. Prefer using `match_def_path`. Consider getting a `DefId` from
433437
/// `QPath::Resolved.1.res.opt_def_id()`.
434438
///
435-
/// Matches a `QPath` against a slice of segment string literals.
436-
///
437439
/// There is also `match_path` if you are dealing with a `rustc_hir::Path` instead of a
438440
/// `rustc_hir::QPath`.
439441
///
@@ -482,12 +484,12 @@ pub fn is_path_diagnostic_item<'tcx>(
482484
path_def_id(cx, maybe_path).map_or(false, |id| cx.tcx.is_diagnostic_item(diag_item, id))
483485
}
484486

485-
/// THIS METHOD IS DEPRECATED and will eventually be removed since it does not match against the
487+
/// THIS METHOD IS DEPRECATED. Matches a `Path` against a slice of segment string literals.
488+
///
489+
/// This method is deprecated and will eventually be removed since it does not match against the
486490
/// entire path or resolved `DefId`. Prefer using `match_def_path`. Consider getting a `DefId` from
487491
/// `QPath::Resolved.1.res.opt_def_id()`.
488492
///
489-
/// Matches a `Path` against a slice of segment string literals.
490-
///
491493
/// There is also `match_qpath` if you are dealing with a `rustc_hir::QPath` instead of a
492494
/// `rustc_hir::Path`.
493495
///
@@ -903,6 +905,7 @@ pub fn is_default_equivalent_call(cx: &LateContext<'_>, repl_func: &Expr<'_>) ->
903905
}
904906

905907
/// Returns true if the expr is equal to `Default::default()` of it's type when evaluated.
908+
///
906909
/// It doesn't cover all cases, for example indirect function calls (some of std
907910
/// functions are supported) but it is the best we have.
908911
pub fn is_default_equivalent(cx: &LateContext<'_>, e: &Expr<'_>) -> bool {
@@ -1057,6 +1060,7 @@ impl std::ops::BitOrAssign for CaptureKind {
10571060
}
10581061

10591062
/// Given an expression referencing a local, determines how it would be captured in a closure.
1063+
///
10601064
/// Note as this will walk up to parent expressions until the capture can be determined it should
10611065
/// only be used while making a closure somewhere a value is consumed. e.g. a block, match arm, or
10621066
/// function argument (other than a receiver).
@@ -2359,8 +2363,9 @@ pub fn fn_def_id_with_node_args<'tcx>(
23592363
}
23602364

23612365
/// Returns `Option<String>` where String is a textual representation of the type encapsulated in
2362-
/// the slice iff the given expression is a slice of primitives (as defined in the
2363-
/// `is_recursively_primitive_type` function) and `None` otherwise.
2366+
/// the slice iff the given expression is a slice of primitives.
2367+
///
2368+
/// (As defined in the `is_recursively_primitive_type` function.) Returns `None` otherwise.
23642369
pub fn is_slice_of_primitives(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option<String> {
23652370
let expr_type = cx.typeck_results().expr_ty_adjusted(expr);
23662371
let expr_kind = expr_type.kind();

clippy_utils/src/macros.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,11 @@ pub fn first_node_macro_backtrace(cx: &LateContext<'_>, node: &impl HirNode) ->
150150
}
151151

152152
/// If `node` is the "first node" in a macro expansion, returns `Some` with the `ExpnId` of the
153-
/// macro call site (i.e. the parent of the macro expansion). This generally means that `node`
154-
/// is the outermost node of an entire macro expansion, but there are some caveats noted below.
155-
/// This is useful for finding macro calls while visiting the HIR without processing the macro call
156-
/// at every node within its expansion.
153+
/// macro call site (i.e. the parent of the macro expansion).
154+
///
155+
/// This generally means that `node` is the outermost node of an entire macro expansion, but there
156+
/// are some caveats noted below. This is useful for finding macro calls while visiting the HIR
157+
/// without processing the macro call at every node within its expansion.
157158
///
158159
/// If you already have immediate access to the parent node, it is simpler to
159160
/// just check the context of that span directly (e.g. `parent.span.from_expansion()`).

clippy_utils/src/source.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -527,9 +527,10 @@ pub fn snippet_block_with_context<'a>(
527527
(reindent_multiline(snip, true, indent), from_macro)
528528
}
529529

530-
/// Same as `snippet_with_applicability`, but first walks the span up to the given context. This
531-
/// will result in the macro call, rather than the expansion, if the span is from a child context.
532-
/// If the span is not from a child context, it will be used directly instead.
530+
/// Same as `snippet_with_applicability`, but first walks the span up to the given context.
531+
///
532+
/// This will result in the macro call, rather than the expansion, if the span is from a child
533+
/// context. If the span is not from a child context, it will be used directly instead.
533534
///
534535
/// e.g. Given the expression `&vec![]`, getting a snippet from the span for `vec![]` as a HIR node
535536
/// would result in `box []`. If given the context of the address of expression, this function will
@@ -572,9 +573,10 @@ fn snippet_with_context_sess<'a>(
572573
}
573574

574575
/// Walks the span up to the target context, thereby returning the macro call site if the span is
575-
/// inside a macro expansion, or the original span if it is not. Note this will return `None` in the
576-
/// case of the span being in a macro expansion, but the target context is from expanding a macro
577-
/// argument.
576+
/// inside a macro expansion, or the original span if it is not.
577+
///
578+
/// Note this will return `None` in the case of the span being in a macro expansion, but the target
579+
/// context is from expanding a macro argument.
578580
///
579581
/// Given the following
580582
///

clippy_utils/src/ty.rs

+13-7
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,10 @@ pub fn get_type_diagnostic_name(cx: &LateContext<'_>, ty: Ty<'_>) -> Option<Symb
160160
}
161161

162162
/// Returns true if `ty` is a type on which calling `Clone` through a function instead of
163-
/// as a method, such as `Arc::clone()` is considered idiomatic. Lints should avoid suggesting to
164-
/// replace instances of `ty::Clone()` by `.clone()` for objects of those types.
163+
/// as a method, such as `Arc::clone()` is considered idiomatic.
164+
///
165+
/// Lints should avoid suggesting to replace instances of `ty::Clone()` by `.clone()` for objects
166+
/// of those types.
165167
pub fn should_call_clone_as_function(cx: &LateContext<'_>, ty: Ty<'_>) -> bool {
166168
matches!(
167169
get_type_diagnostic_name(cx, ty),
@@ -398,8 +400,10 @@ fn is_normalizable_helper<'tcx>(
398400
}
399401

400402
/// Returns `true` if the given type is a non aggregate primitive (a `bool` or `char`, any
401-
/// integer or floating-point number type). For checking aggregation of primitive types (e.g.
402-
/// tuples and slices of primitive type) see `is_recursively_primitive_type`
403+
/// integer or floating-point number type).
404+
///
405+
/// For checking aggregation of primitive types (e.g. tuples and slices of primitive type) see
406+
/// `is_recursively_primitive_type`
403407
pub fn is_non_aggregate_primitive_type(ty: Ty<'_>) -> bool {
404408
matches!(ty.kind(), ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_) | ty::Float(_))
405409
}
@@ -476,9 +480,10 @@ pub fn match_type(cx: &LateContext<'_>, ty: Ty<'_>, path: &[&str]) -> bool {
476480
}
477481
}
478482

479-
/// Checks if the drop order for a type matters. Some std types implement drop solely to
480-
/// deallocate memory. For these types, and composites containing them, changing the drop order
481-
/// won't result in any observable side effects.
483+
/// Checks if the drop order for a type matters.
484+
///
485+
/// Some std types implement drop solely to deallocate memory. For these types, and composites
486+
/// containing them, changing the drop order won't result in any observable side effects.
482487
pub fn needs_ordered_drop<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool {
483488
fn needs_ordered_drop_inner<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>, seen: &mut FxHashSet<Ty<'tcx>>) -> bool {
484489
if !seen.insert(ty) {
@@ -1324,6 +1329,7 @@ pub fn deref_chain<'cx, 'tcx>(cx: &'cx LateContext<'tcx>, ty: Ty<'tcx>) -> impl
13241329
}
13251330

13261331
/// Checks if a Ty<'_> has some inherent method Symbol.
1332+
///
13271333
/// This does not look for impls in the type's `Deref::Target` type.
13281334
/// If you need this, you should wrap this call in `clippy_utils::ty::deref_chain().any(...)`.
13291335
pub fn get_adt_inherent_method<'a>(cx: &'a LateContext<'_>, ty: Ty<'_>, method_name: Symbol) -> Option<&'a AssocItem> {

0 commit comments

Comments
 (0)