Crate clippy_utils

source

Re-exports§

Modules§

Macros§

Structs§

  • The context an expressions value is used in.
  • Type used to check whether two ast are the same. This is different from the operator == on ast types as this operator would compare true equality with ID and span.
  • Type used to hash an ast element. This is different from the Hash trait on ast types as this trait would consider IDs and spans.

Enums§

Statics§

Traits§

Functions§

  • Returns true if the given expr is binary expression that needs to be wrapped in parentheses.
  • Converts BinOpKind::Add to (LangItem::Add, LangItem::AddAssign), for example
  • Checks if the two Options are both None or some equal values as per eq_fn.
  • Checks if the expression can be moved into a closure as is. This will return a list of captures if so, otherwise, None.
  • Checks if the top level expression can be moved into a closure as is. Currently checks for:
  • Checks if two expressions can be mutably borrowed simultaneously and they aren’t dependent on borrowing same thing twice
  • Given an expression referencing a local, determines how it would be captured in a closure.
  • clip unused bytes
  • Checks if an Expr contains a certain name.
  • Returns true if expr contains a return expression
  • Counts how many elements of the slices are equal as per eq_fn.
  • Creates a map of disallowed items to the reason they were disallowed.
  • Resolves a def path like std::vec::Vec to its DefIds, see def_path_res.
  • Resolves a def path like std::vec::Vec.
  • Resolves a def path like vec::Vec with the base std.
  • Checks if two expressions evaluate to the same value, and don’t contain any side effects.
  • Gets the mutability of the custom deref adjustment, if any.
  • If the given expression is a local binding, find the initializer expression. If that initializer expression is another local binding, find its initializer again.
  • Gets the context an expression’s value is used in.
  • Finds the initializer expression for a local binding. Returns None if the binding is mutable.
  • Finds the crates called name, may be multiple due to multiple major versions.
  • Returns the DefId of the callee if the given expression is a function or method call.
  • Returns the DefId of the callee if the given expression is a function or method call, as well as its node args.
  • Check if it’s even possible to satisfy the where clause for the item.
  • Returns true if the lint is #[allow]ed or #[expect]ed at any of the ids, fulfilling all of the expectations in ids
  • Peels away all the compiler generated code surrounding the body of an async function,
  • Gets the enclosing block, if any.
  • Gets the loop or closure enclosing the given expression, if any.
  • Gets the node where an expression is either used, or it’s type is unified with another branch. Returns both the node and the HirId of the closest child node.
  • Gets the name of the item the expression is in, if available.
  • Gets the parent node if it’s an impl block.
  • Gets the parent expression, if any –- this is useful to constrain a lint.
  • This retrieves the parent for the given HirId if it’s an expression. This is useful for constraint lints
  • Produces a path from a local caller to the type of the called method. Suitable for user output/suggestions.
  • Produce a path from some local caller to the callee. Suitable for user output/suggestions.
  • Convenience function to get the DefId of a trait by path. It could be a trait or trait alias.
  • Returns the list of condition expressions and the list of blocks in a sequence of if/else. E.g., this returns ([a, b], [c, d, e]) for the expression if a { c } else if b { d } else { e }.
  • Checks if the given HIR node is inside an impl block with the automatically_derived attribute.
  • Checks if the item of any of its parents has #[cfg(...)] attribute applied.
  • Returns true if the given Expr has been coerced before.
  • Checks if the given function kind is an async function.
  • Returns true if the given expr is a block or resembled as a block, such as if, loop, match expressions etc.
  • Checks if a function’s body represents the identity function. Looks for bodies of the form:
  • Checks if id has a #[cfg(test)] attribute applied
  • Checks if an expression is constructing a tuple-like enum variant or struct
  • Checks if the def_id belongs to a function that is part of a trait impl.
  • Returns true if the expr is equal to Default::default() of it’s type when evaluated.
  • Returns true if the expr is equal to Default::default when evaluated.
  • Returns true if the def_id associated with the path is recognized as a “default-equivalent” constructor from the std library
  • Checks if a method is defined in an impl of a diagnostic item
  • Checks if a method is in a diagnostic item trait
  • Checks if the DefId matches the given diagnostic item or it’s constructor.
  • Returns the pre-expansion span if the span directly comes from an expansion of the macro name. The difference with is_expn_of is that in
  • Checks if the given expression is the else clause of either an if or if let expression.
  • Checks if the given expression is the else clause of a let else expression
  • Returns true if the provided def_id is an entrypoint to a program.
  • Checks if {ctor_call_id}(...) is {enum_item}::{variant_name}(...).
  • Returns the pre-expansion span if this comes from an expansion of the macro name. See also is_direct_expn_of.
  • Checks if the expression is the final expression returned from a block.
  • Checks if an expression represents the identity function Only examines closures and std::convert::identity
  • If the expression is a path, resolves it to a DefId and checks if it matches the given path.
  • This is the same as is_expr_identity_function, but does not consider closures with type annotations for its bindings (or similar) as identity functions:
  • Checks if the result of an expression is used, or it’s type is unified with another branch.
  • Checks if the item likely came from a proc-macro.
  • Checks if any parent node of HirId has #[cfg(test)] attribute applied
  • Checks if we are currently in a const context (e.g. const fn, static/const initializer).
  • Returns true if the expression is in the program’s #[panic_handler].
  • Checks if the node is in a #[test] function or has any parent node marked #[cfg(test)]
  • Checks if the function containing the given HirId is a #[test] function
  • Checks if the given method call expression calls an inherent method.
  • Returns true if the given HirId is inside an always constant context.
  • Checks if the given expression is a part of let else returns true for both the init and the else part
  • Checks whether the given expression is a constant integer of the given value. unlike is_integer_literal, this version does const folding
  • Checks whether the given expression is a constant literal of the given value.
  • Checks if the DefId matches the given LangItem or it’s constructor.
  • Returns true if the lint is allowed in the current context. This is useful for skipping long running code when it’s unnecessary
  • Check if the expression return !, a type coerced from !, or could return ! if the final expression were turned into a statement.
  • Returns true if the specified HirId is the top-level expression of a statement or the only expression in a block.
  • If maybe_path is a path node which resolves to an item, resolves it to a DefId and checks if it matches the given diagnostic item.
  • If maybe_path is a path node which resolves to an item, resolves it to a DefId and checks if it matches the given lang item.
  • Checks whether the given Expr is a range equivalent to a RangeFull.
  • Returns true if the specified expression is in a receiver position.
  • Returns true if a pattern is refutable.
  • Checks if a Res refers to a constructor of a LangItem For example, use this to check whether a function call or a pattern is Some(..).
  • Returns Option<String> where String is a textual representation of the type encapsulated in the slice iff the given expression is a slice of primitives.
  • Checks if the span actually refers to an if expression
  • Checks if the span actually refers to a match expression
  • Check if parent of a hir node is a trait implementation block. For example, f in
  • Checks if the given expression is a path referring an item on the trait that is marked with the given diagnostic item.
  • Checks if the method call given in expr belongs to the given trait.
  • Checks if a given expression is a match expression expanded from the ? operator or the try macro.
  • Checks if the given QPath belongs to a type alias.
  • Checks if given pattern is a wildcard (_)
  • Checks if the given local has an initializer or is from something other than a let statement
  • Checks if the given DefId matches any of the paths. Returns the index of matching path, if any.
  • Checks if the given DefId matches the path.
  • Matches a function call with the given path and returns the arguments.
  • Checks if the given DefId matches the libc item.
  • THIS METHOD IS DEPRECATED. Matches a Path against a slice of segment string literals.
  • THIS METHOD IS DEPRECATED. Matches a QPath against a slice of segment string literals.
  • Checks if the method call given in expr belongs to the given trait. This is a deprecated function, consider using is_trait_method.
  • Tries to produce a relative path from from to to; if such a path would contain more than max_super super items, produces an absolute path instead. Both from and to should be in the local crate.
  • Returns the method names and argument list of nested method call expressions that make up expr. method/span lists are sorted with the most recent call first.
  • Matches an Expr against a chain of methods, and return the matched Exprs.
  • Convenience function to get the nth argument type of a function.
  • Checks if two slices are equal as per eq_fn.
  • Returns whether the given let pattern and else body can be turned into a question mark
  • Returns true if the pattern is a PatWild, or is an ident prefixed with _ that is not locally used.
  • If maybe_path is a path node which resolves to an item, retrieves the item ID
  • If maybe_path is a path node, resolves it, otherwise returns Res::Err
  • If the expression is a path to a local, returns the canonical HirId of the local.
  • Returns true if the expression is a path to a local with the specified HirId. Use this function to see if an expression matches a function argument or a match binding.
  • Removes blocks around an expression, only if the block contains just one expression and no statements. Unsafe blocks are not removed.
  • Removes blocks around an expression, only if the block contains just one expression or just one expression statement with a semicolon. Unsafe blocks are not removed.
  • Peels off all references on the expression. Returns the underlying expression and the number of references removed.
  • Peels off all unary operators of an expression. Returns the underlying expression and the number of operators removed.
  • Peels of expressions while the given closure returns Some.
  • Peels off all references on the pattern. Returns the underlying pattern and the number of references removed.
  • Peels off all references on the type. Returns the underlying type and the number of references removed.
  • Peels off all references on the type. Returns the underlying type and the number of references removed.
  • Peels off up to the given number of references on the expression. Returns the underlying expression and the number of references removed.
  • Removes AddrOf operators (&) or deref operators (*), but only if a reference type is dereferenced. An overloaded deref such as Vec to slice would not be removed.
  • This method will return tuple of projection stack and root of the expression, used in can_mut_borrow_both.
  • If the pattern is an or pattern, call the function once for each sub pattern. Otherwise, call the function once on the given pattern.
  • Convenience function to get the return type of a function.
  • Returns list of all pairs (a, b) where eq(a, b) == true and a is before b in exprs for all a and b in exprs
  • Turn a constant int byte representation into an i128
  • Checks whether a given span has any comment token This checks for all types of comment: line “//”, block “/**”, doc “///” “//!”
  • Returns all the comments a given span contains
  • Tokenizes the input while keeping the text associated with each token.
  • Gets the hir::TraitRef of the trait the given method is implemented for.
  • clip unused bytes
  • Walks up the HIR tree from the given expression in an attempt to find where the value is consumed.

Type Aliases§

  • Arguments of a method: the receiver and all the additional arguments.