Module clippy_lints::utils [] [src]

Modules

author

A group of attributes that can be attached to Rust code in order to generate a clippy lint detecting said code automatically.

comparisons

Utility functions about comparison operators.

conf

Read configurations files.

constants

This module contains some useful constants.

higher

This module contains functions for retrieve the original AST from lowered hir.

inspector

checks for attributes

internal_lints
paths

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

ptr
sugg

Contains utility functions to generate suggestions.

Structs

DiagnosticWrapper
LimitStack
SpanlessEq

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.

SpanlessHash

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.

Functions

camel_case_from

Return index of the last camel-case component of s.

camel_case_until

Return the index of the character after the first camel-case component of s.

clip

clip unused bytes

contains_name

check if an Expr contains a certain name

differing_macro_contexts

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

expr_block

Like snippet_block, but add braces if the expr is not an ExprBlock. Also takes an Option<String> which can be put inside the braces.

get_arg_name
get_enclosing_block
get_item_name

Get the name of the item the expression is in, if available.

get_parent_expr

Get a parent expressions if any – this is useful to constrain a lint.

get_pat_name

Get the name of a Pat, if any

get_trait_def_id

Convenience function to get the DefId of a trait by path.

has_drop

Check whether this type implements Drop.

implements_trait

Check whether a type implements a trait. See also get_trait_def_id.

in_constant
in_external_macro

Returns true if the macro that expanded the crate was outside of the current crate or was a compiler plugin.

in_macro

Returns true if this expn_info was expanded by any macro.

int_bits
is_adjusted
is_allowed

Returns true if the lint is allowed in the current context

is_automatically_derived

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

is_copy
is_direct_expn_of

Return the pre-expansion span if is this directly comes from an expansion of the macro name. The difference with is_expn_of is that in

is_expn_of

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

is_integer_literal

Check whether the given expression is a constant literal of the given value.

is_range_expression

Returns true if expn_info was expanded by range expressions.

is_refutable

Return whether a pattern is refutable.

is_self
is_self_ty
is_try

Check if a given expression is a match expression expanded from ? operator or try macro.

iter_input_pats
last_line_of_span

Returns a new Span that covers the full last line of the given Span

last_path_segment
match_def_path

Check if a DefId's path matches the given absolute type path usage.

match_impl_method

Check if the method call given in expr belongs to given type.

match_path
match_path_ast

Match a Path against a slice of segment string literals, e.g.

match_qpath

Match a Path against a slice of segment string literals.

match_trait_method

Check if the method call given in expr belongs to given trait.

match_type

Check if type is struct, enum or union type with given def path.

match_var

Check if an expression references a variable of the given name.

method_chain_args

Match an Expr against a chain of methods, and return the matched Exprs.

multispan_sugg

Create a suggestion made from several span → replacement.

opt_def_id
path_to_def

Get the definition associated to a path.

remove_blocks

Remove blocks around an expression.

resolve_node

Resolve the definition of a node from its HirId.

return_ty

Convenience function to get the return type of a function

same_tys

Check if two types are the same.

sext

Turn a constant int byte representation into an i128

single_segment_path
snippet

Convert a span to a code snippet if available, otherwise use default.

snippet_block

Convert a span (from a block) to a code snippet if available, otherwise use default. This trims the code of indentation, except for the first line. Use it for blocks or block-like things which need to be printed as such.

snippet_opt

Convert a span to a code snippet. Returns None if not available.

span_help_and_lint
span_lint
span_lint_and_sugg

Add a span lint with a suggestion on how to fix it.

span_lint_and_then
span_note_and_lint
trim_multiline

Trim indentation from a multiline string with possibility of ignoring the first line.

type_is_unsafe_function

Return whether the given type is an unsafe function.

unsext

clip unused bytes

walk_ptrs_hir_ty

Return the base type for HIR references and pointers.

walk_ptrs_ty

Return the base type for references and raw pointers.

walk_ptrs_ty_depth

Return the base type for references and raw pointers, and count reference depth.

without_block_comments

Remove block comments from the given Vec of lines

Type Definitions

MethodArgs