Crate clippy_utils[−][src]

Re-exports

pub use self::attrs::*;

Modules

The Rust abstract syntax tree module.

Utilities for manipulating and extracting information from rustc_ast::ast.

Utility functions about comparison operators.

Clippy wrappers around rustc’s diagnostic functions.

Utilities for evaluating whether eagerly evaluated expressions can be made lazy and vice versa.

This module contains functions that retrieve specific elements.

HIR walker for walking the contents of nodes.

This module contains all the defined keyword Symbols.

This module contains paths to types and functions Clippy needs to know about.

Defines how the compiler represents types internally.

Utils for extracting, inspecting or transforming source code

Contains utility functions to generate suggestions.

This module contains all the defined non-keyword Symbols.

Util methods for rustc_middle::ty

Macros

Macro for writing nested if let expressions.

Convenience wrapper around rustc’s Symbol::intern

Structs

Represents coercing a value to a different type of value.

Represents a single arm of a match expression, e.g. <pat> (if <guard>) => <body>.

Metadata associated with an item.

A block of statements { .. }, which may have a label (in this case the targeted_by_break field will be true) and may be unsafe by means of the rules being anything but DefaultBlock.

The body of a function, closure, or constant value. In the case of a function, the body contains not only the function body itself (which is an expression), but also the argument patterns, since those are something that the caller doesn’t really care about.

A DefId identifies a particular definition, by combining a crate index and a def index.

An erased version of Map<'hir>, using dynamic dispatch. NOTE: This type is effectively only usable with NestedVisitorMap::None.

An expression.

Represents the header (not the body) of a function declaration.

Uniquely identifies a node in the HIR of the current crate. It is composed of the owner, which is the LocalDefId of the directly enclosing hir::Item, hir::TraitItem, or hir::ImplItem (i.e., the closest “item-like”), and the local_id which is unique within the given owner.

Represents anything within an impl block.

An item

Context for lint checking after type checking.

Specification of a single lint.

Represents a let statement (i.e., let <pat>:<ty> = <expr>;).

Represents a parameter in a function header.

A Path is essentially Rust’s notion of a name; for instance, std::cmp::PartialEq. It’s represented as a sequence of identifiers, along with a bunch of supporting information.

A segment of a path: an identifier, an optional lifetime, and a set of types.

Represents the data associated with a compilation session for a single crate.

A compressed span.

A statement.

An interned string.

Represents an item declaration within a trait declaration, possibly including a default implementation. A trait item is either required (meaning it doesn’t have an implementation, just a signature) or provided (meaning it has a default implementation).

References to traits in impls.

The central data structure of the compiler. It stores references to the various arenas and also houses the results of the various compiler queries that have been performed. See the rustc dev guide for more details.

Used to create a default BuildHasher instance for types that implement Hasher and Default.

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

Explicit binding annotations given in the HIR for a binding. Note that this is not the final binding mode that we infer after type inference.

How a local is captured by a closure

What kind of definition something is; e.g., mod vs struct.

Expansion kind.

Represents various kinds of content within an impl.

Integers, also used for enum discriminants.

A representation of all the valid language items in Rust.

Setting for how to handle a lint.

Literal kind.

The kind of macro invocation or definition.

Hints at the original code for a match _ { .. }.

Specifies what nested things a visitor wants to visit. The most common choice is OnlyBodies, which will cause the visitor to visit fn bodies for fns that it encounters, but skip over nested item-like things.

Not represented directly in the AST; referred to by name through a ty_path.

Represents an optionally Self-qualified value/type path or associated extension.

The resolution of a path or export.

A view into a single entry in a map, which may either be vacant or occupied.

RustcVersion represents a version of the Rust Compiler.

The contents of a statement.

Represents a trait method or associated constant or type

The various kinds of types recognized by the compiler.

Information describing the capture of an upvar. This is computed during typeck, specifically by regionck.

Constants

Dummy span, both position and length are zero, syntax context is zero as well.

Statics

Binary operation traits like LangItem::Add

Operator-Assign traits like LangItem::AddAssign

Traits

The “item-like visitor” defines only the top-level methods that can be invoked by Crate::visit_all_item_likes(). Whether this trait is the right one to implement will depend on the overall pattern you need. Here are the three available patterns, in roughly the order of desirability:

This trait is implemented for every type that can be folded. Basically, every type that has a corresponding method in TypeFolder.

Each method of the Visitor trait is a hook to be potentially overridden. Each method’s default implementation recursively visits the substructure of the input via the corresponding walk method; e.g., the visit_mod method by default calls intravisit::walk_mod.

Functions

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. Note as this will walk up to parent expressions until the capture can be determined it should only be used while making a closure somewhere a value is consumed. e.g. a block, match arm, or function argument (other than a receiver).

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.

Returns true if the two spans come from differing expansions (i.e., one is from a macro and one isn’t).

Checks if two expressions evaluate to the same value, and don’t contain any side effects.

If the given expression is a local binding, find the initializer expression. If that initializer expression is another local binding, find its initializer again. This process repeats as long as possible (but usually no more than once). Initializer expressions with adjustments are ignored. If this is not desired, use find_binding_init instead.

If the expression is a path, resolve it. Otherwise, return Res::Err.

Finds the initializer expression for a local binding. Returns None if the binding is mutable. By only considering immutable bindings, we guarantee that the returned expression represents the value of the binding wherever it is referenced.

Finds calls of the specified macros in a function body.

Returns the DefId of the callee if the given expression is a function or method call.

Check if it’s even possible to satisfy the where clause for the item.

Peels away all the compiler generated code surrounding the body of an async function,

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.

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

Gets the parent node, if any.

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 }.

Returns true if the given NodeId is inside a constant context

Returns true if this span was expanded by any macro.

Returns true if the given Expr has been coerced before.

Checks if the given function kind is an async function.

Checks for the #[automatically_derived] attribute all #[derive]d implementations have.

Checks if an expression is constructing a tuple-like enum variant or struct

Returns true if the expr is equal to Default::default() of it’s type when evaluated. It doesn’t cover all cases, for example indirect function calls (some of std functions are supported) but it is the best we have.

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

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.

Returns true if the provided def_id is an entrypoint to a program.

Returns the pre-expansion span if is this comes from an expansion of the macro name. See also is_direct_expn_of.

If the expression is a path, resolves it to a DefId and checks if it matches the given diagnostic item.

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.

Checks if the result of an expression is used, or it’s type is unified with another branch.

Returns true if the expression is in the program’s #[panic_handler].

Checks if the function containing the given HirId is a #[test] function

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 a QPath resolves to a constructor of a LangItem. For example, use this to check whether a function call or a pattern is Some(..).

Returns true if the lint is allowed in the current context

Resolves the path to a DefId and checks if it matches the given path.

Returns true if a pattern is refutable.

Returns Option where String is a textual representation of the type encapsulated in the slice iff the given expression is a slice of primitives (as defined in the is_recursively_primitive_type function) and None otherwise.

Checks whether item either has test attribute applied, or is a module with test in its name.

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 first type parameter is a diagnostic item.

Checks if the first type parameter is a lang item.

Checks if given pattern is a wildcard (_)

Extends the span to the beginning of the spans line, incl. whitespaces.

Checks if the given DefId matches any of the paths. Returns the index of matching path, if any.

Checks if the given DefId matches any of provided diagnostic items. 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.

THIS METHOD IS DEPRECATED and will eventually be removed since it does not match against the entire path or resolved DefId. Prefer using match_def_path. Consider getting a DefId from QPath::Resolved.1.res.opt_def_id().

THIS METHOD IS DEPRECATED and will eventually be removed since it does not match against the entire path or resolved DefId. Prefer using match_def_path. Consider getting a DefId from QPath::Resolved.1.res.opt_def_id().

Checks if the method call given in expr belongs to the given trait. This is a deprecated function, consider using is_trait_method.

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.

Returns the span itself if it doesn’t come from a macro expansion, otherwise return the call site span up to the enclosing_sp by following the expn_data chain.

Checks if two slices are equal as per eq_fn.

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.

Gets the definition associated to a path.

Peels off all references on the expression. Returns the underlying expression and the number of references 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 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.

Remove blocks around an expression.

Convenience function to get the return type of a function.

returns list of all pairs (a, b) from exprs such that eq(a, b) hash must be comformed with eq

Turn a constant int byte representation into an i128

Gets the hir::TraitRef of the trait the given method is implemented for.

clip unused bytes

Type Definitions