Update doc comments to avoid lazy continuations
This commit is contained in:
parent
f3dd31e214
commit
afedaf6a26
@ -255,8 +255,10 @@ fn expr_add_sign(cx: &LateContext<'_>, expr: &Expr<'_>) -> Sign {
|
||||
|
||||
/// Peels binary operators such as [`BinOpKind::Mul`], [`BinOpKind::Div`] or [`BinOpKind::Rem`],
|
||||
/// where the result depends on:
|
||||
///
|
||||
/// - the number of negative values in the entire expression, or
|
||||
/// - the number of negative values on the left hand side of the expression.
|
||||
///
|
||||
/// Ignores overflow.
|
||||
///
|
||||
///
|
||||
@ -303,8 +305,10 @@ fn exprs_with_muldiv_binop_peeled<'e>(expr: &'e Expr<'_>) -> Vec<&'e Expr<'e>> {
|
||||
}
|
||||
|
||||
/// Peels binary operators such as [`BinOpKind::Add`], where the result depends on:
|
||||
///
|
||||
/// - all the expressions being positive, or
|
||||
/// - all the expressions being negative.
|
||||
///
|
||||
/// Ignores overflow.
|
||||
///
|
||||
/// Expressions using other operators are preserved, so we can try to evaluate them later.
|
||||
|
@ -611,15 +611,22 @@ impl<'tcx> BinaryOp<'tcx> {
|
||||
|
||||
/// The clamp meta pattern is a pattern shared between many (but not all) patterns.
|
||||
/// In summary, this pattern consists of two if statements that meet many criteria,
|
||||
///
|
||||
/// - binary operators that are one of [`>`, `<`, `>=`, `<=`].
|
||||
///
|
||||
/// - Both binary statements must have a shared argument
|
||||
///
|
||||
/// - Which can appear on the left or right side of either statement
|
||||
///
|
||||
/// - The binary operators must define a finite range for the shared argument. To put this in
|
||||
/// the terms of Rust `std` library, the following ranges are acceptable
|
||||
///
|
||||
/// - `Range`
|
||||
/// - `RangeInclusive`
|
||||
///
|
||||
/// And all other range types are not accepted. For the purposes of `clamp` it's irrelevant
|
||||
/// whether the range is inclusive or not, the output is the same.
|
||||
///
|
||||
/// - The result of each if statement must be equal to the argument unique to that if statement. The
|
||||
/// result can not be the shared argument in either case.
|
||||
fn is_clamp_meta_pattern<'tcx>(
|
||||
|
@ -126,15 +126,15 @@ enum FilterType {
|
||||
///
|
||||
/// How this is done:
|
||||
/// 1. we know that this is invoked in a method call with `filter` as the method name via `mod.rs`
|
||||
/// 2. we check that we are in a trait method. Therefore we are in an
|
||||
/// `(x as Iterator).filter({filter_arg})` method call.
|
||||
/// 2. we check that we are in a trait method. Therefore we are in an `(x as
|
||||
/// Iterator).filter({filter_arg})` method call.
|
||||
/// 3. we check that the parent expression is not a map. This is because we don't want to lint
|
||||
/// twice, and we already have a specialized lint for that.
|
||||
/// 4. we check that the span of the filter does not contain a comment.
|
||||
/// 5. we get the type of the `Item` in the `Iterator`, and compare against the type of Option and
|
||||
/// Result.
|
||||
/// Result.
|
||||
/// 6. we finally check the contents of the filter argument to see if it is a call to `is_some` or
|
||||
/// `is_ok`.
|
||||
/// `is_ok`.
|
||||
/// 7. if all of the above are true, then we return the `FilterType`
|
||||
fn expression_type(
|
||||
cx: &LateContext<'_>,
|
||||
|
@ -12,8 +12,10 @@ use rustc_middle::ty;
|
||||
use rustc_span::{sym, Span};
|
||||
|
||||
/// lint use of:
|
||||
///
|
||||
/// - `hashmap.iter().map(|(_, v)| v)`
|
||||
/// - `hashmap.into_iter().map(|(_, v)| v)`
|
||||
///
|
||||
/// on `HashMaps` and `BTreeMaps` in std
|
||||
|
||||
pub(super) fn check<'tcx>(
|
||||
|
@ -120,6 +120,7 @@ fn pat_bindings(pat: &Pat<'_>) -> Vec<HirId> {
|
||||
/// operations performed on `binding_hir_ids` are:
|
||||
/// * to take non-mutable references to them
|
||||
/// * to use them as non-mutable `&self` in method calls
|
||||
///
|
||||
/// If any of `binding_hir_ids` is used in any other way, then `clone_or_copy_needed` will be true
|
||||
/// when `CloneOrCopyVisitor` is done visiting.
|
||||
struct CloneOrCopyVisitor<'cx, 'tcx> {
|
||||
|
@ -178,8 +178,7 @@ impl EarlyLintPass for NeedlessContinue {
|
||||
/// Given an expression, returns true if either of the following is true
|
||||
///
|
||||
/// - The expression is a `continue` node.
|
||||
/// - The expression node is a block with the first statement being a
|
||||
/// `continue`.
|
||||
/// - The expression node is a block with the first statement being a `continue`.
|
||||
fn needless_continue_in_else(else_expr: &ast::Expr, label: Option<&ast::Label>) -> bool {
|
||||
match else_expr.kind {
|
||||
ast::ExprKind::Block(ref else_block, _) => is_first_block_stmt_continue(else_block, label),
|
||||
|
@ -1513,15 +1513,18 @@ pub fn is_else_clause_in_let_else(tcx: TyCtxt<'_>, expr: &Expr<'_>) -> bool {
|
||||
}
|
||||
|
||||
/// Checks whether the given `Expr` is a range equivalent to a `RangeFull`.
|
||||
///
|
||||
/// For the lower bound, this means that:
|
||||
/// - either there is none
|
||||
/// - or it is the smallest value that can be represented by the range's integer type
|
||||
///
|
||||
/// For the upper bound, this means that:
|
||||
/// - either there is none
|
||||
/// - or it is the largest value that can be represented by the range's integer type and is
|
||||
/// inclusive
|
||||
/// - or it is a call to some container's `len` method and is exclusive, and the range is passed to
|
||||
/// a method call on that same container (e.g. `v.drain(..v.len())`)
|
||||
///
|
||||
/// If the given `Expr` is not some kind of range, the function returns `false`.
|
||||
pub fn is_range_full(cx: &LateContext<'_>, expr: &Expr<'_>, container_path: Option<&Path<'_>>) -> bool {
|
||||
let ty = cx.typeck_results().expr_ty(expr);
|
||||
|
@ -250,7 +250,7 @@ pub fn snippet<'a, T: LintContext>(cx: &T, span: Span, default: &'a str) -> Cow<
|
||||
/// - Applicability level `Unspecified` will never be changed.
|
||||
/// - If the span is inside a macro, change the applicability level to `MaybeIncorrect`.
|
||||
/// - If the default value is used and the applicability level is `MachineApplicable`, change it to
|
||||
/// `HasPlaceholders`
|
||||
/// `HasPlaceholders`
|
||||
pub fn snippet_with_applicability<'a, T: LintContext>(
|
||||
cx: &T,
|
||||
span: Span,
|
||||
|
@ -68,8 +68,7 @@ impl<'a> Sugg<'a> {
|
||||
/// - Applicability level `Unspecified` will never be changed.
|
||||
/// - If the span is inside a macro, change the applicability level to `MaybeIncorrect`.
|
||||
/// - If the default value is used and the applicability level is `MachineApplicable`, change it
|
||||
/// to
|
||||
/// `HasPlaceholders`
|
||||
/// to `HasPlaceholders`
|
||||
pub fn hir_with_applicability(
|
||||
cx: &LateContext<'_>,
|
||||
expr: &hir::Expr<'_>,
|
||||
|
Loading…
x
Reference in New Issue
Block a user