Skip to content

Commit

Permalink
Auto merge of #6914 - camsteffen:source-utils, r=Manishearth
Browse files Browse the repository at this point in the history
Move some utils to `clippy_utils::source`

changelog: none

Continues #6907
  • Loading branch information
bors committed Mar 16, 2021
2 parents 0929a24 + 6fc52a6 commit d7a2311
Show file tree
Hide file tree
Showing 152 changed files with 753 additions and 649 deletions.
3 changes: 2 additions & 1 deletion clippy_lints/src/assertions_on_constants.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::consts::{constant, Constant};
use crate::utils::{is_direct_expn_of, is_expn_of, match_panic_call, snippet_opt, span_lint_and_help};
use crate::utils::{is_direct_expn_of, is_expn_of, match_panic_call, span_lint_and_help};
use clippy_utils::source::snippet_opt;
use if_chain::if_chain;
use rustc_hir::{Expr, ExprKind, UnOp};
use rustc_lint::{LateContext, LateLintPass};
Expand Down
3 changes: 2 additions & 1 deletion clippy_lints/src/assign_ops.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::utils::{eq_expr_value, get_trait_def_id, snippet_opt, span_lint_and_then, trait_ref_of_method};
use crate::utils::{eq_expr_value, get_trait_def_id, span_lint_and_then, trait_ref_of_method};
use crate::utils::{higher, sugg};
use clippy_utils::source::snippet_opt;
use clippy_utils::ty::implements_trait;
use if_chain::if_chain;
use rustc_errors::Applicability;
Expand Down
3 changes: 2 additions & 1 deletion clippy_lints/src/async_yields_async.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::utils::{snippet, span_lint_and_then};
use crate::utils::span_lint_and_then;
use clippy_utils::source::snippet;
use clippy_utils::ty::implements_trait;
use rustc_errors::Applicability;
use rustc_hir::{AsyncGeneratorKind, Body, BodyId, ExprKind, GeneratorKind, QPath};
Expand Down
6 changes: 2 additions & 4 deletions clippy_lints/src/attrs.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
//! checks for attributes
use crate::utils::{
first_line_of_span, is_present_in_source, match_panic_def_id, snippet_opt, span_lint, span_lint_and_help,
span_lint_and_sugg, span_lint_and_then, without_block_comments,
};
use crate::utils::{match_panic_def_id, span_lint, span_lint_and_help, span_lint_and_sugg, span_lint_and_then};
use clippy_utils::source::{first_line_of_span, is_present_in_source, snippet_opt, without_block_comments};
use if_chain::if_chain;
use rustc_ast::{AttrKind, AttrStyle, Attribute, Lit, LitKind, MetaItemKind, NestedMetaItem};
use rustc_errors::Applicability;
Expand Down
5 changes: 2 additions & 3 deletions clippy_lints/src/blocks_in_if_conditions.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::utils::{
differing_macro_contexts, get_parent_expr, snippet_block_with_applicability, span_lint, span_lint_and_sugg,
};
use crate::utils::{differing_macro_contexts, get_parent_expr, span_lint, span_lint_and_sugg};
use clippy_utils::source::snippet_block_with_applicability;
use clippy_utils::ty::implements_trait;
use if_chain::if_chain;
use rustc_errors::Applicability;
Expand Down
5 changes: 2 additions & 3 deletions clippy_lints/src/booleans.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::utils::{
eq_expr_value, get_trait_def_id, in_macro, paths, snippet_opt, span_lint_and_sugg, span_lint_and_then,
};
use crate::utils::{eq_expr_value, get_trait_def_id, in_macro, paths, span_lint_and_sugg, span_lint_and_then};
use clippy_utils::source::snippet_opt;
use clippy_utils::ty::{implements_trait, is_type_diagnostic_item};
use if_chain::if_chain;
use rustc_ast::ast::LitKind;
Expand Down
5 changes: 2 additions & 3 deletions clippy_lints/src/bytecount.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::utils::{
contains_name, get_pat_name, paths, single_segment_path, snippet_with_applicability, span_lint_and_sugg,
};
use crate::utils::{contains_name, get_pat_name, paths, single_segment_path, span_lint_and_sugg};
use clippy_utils::source::snippet_with_applicability;
use clippy_utils::ty::match_type;
use if_chain::if_chain;
use rustc_errors::Applicability;
Expand Down
3 changes: 2 additions & 1 deletion clippy_lints/src/casts/cast_lossless.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use clippy_utils::source::snippet_opt;
use clippy_utils::ty::is_isize_or_usize;
use rustc_errors::Applicability;
use rustc_hir::{Expr, ExprKind};
use rustc_lint::LateContext;
use rustc_middle::ty::{self, FloatTy, Ty};

use crate::utils::{in_constant, snippet_opt, span_lint_and_sugg};
use crate::utils::{in_constant, span_lint_and_sugg};

use super::{utils, CAST_LOSSLESS};

Expand Down
6 changes: 3 additions & 3 deletions clippy_lints/src/casts/char_lit_as_u8.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use clippy_utils::source::snippet_with_applicability;
use if_chain::if_chain;
use rustc_ast::LitKind;
use rustc_errors::Applicability;
use rustc_hir::{Expr, ExprKind};
use rustc_lint::LateContext;
use rustc_middle::ty::{self, UintTy};

use if_chain::if_chain;

use crate::utils::{snippet_with_applicability, span_lint_and_then};
use crate::utils::span_lint_and_then;

use super::CHAR_LIT_AS_U8;

Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/casts/fn_to_numeric_cast.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::utils::span_lint_and_sugg;
use clippy_utils::source::snippet_with_applicability;
use rustc_errors::Applicability;
use rustc_hir::Expr;
use rustc_lint::LateContext;
use rustc_middle::ty::{self, Ty, UintTy};

use crate::utils::{snippet_with_applicability, span_lint_and_sugg};

use super::{utils, FN_TO_NUMERIC_CAST};

pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_expr: &Expr<'_>, cast_from: Ty<'_>, cast_to: Ty<'_>) {
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/casts/fn_to_numeric_cast_with_truncation.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::utils::span_lint_and_sugg;
use clippy_utils::source::snippet_with_applicability;
use rustc_errors::Applicability;
use rustc_hir::Expr;
use rustc_lint::LateContext;
use rustc_middle::ty::{self, Ty};

use crate::utils::{snippet_with_applicability, span_lint_and_sugg};

use super::{utils, FN_TO_NUMERIC_CAST_WITH_TRUNCATION};

pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_expr: &Expr<'_>, cast_from: Ty<'_>, cast_to: Ty<'_>) {
Expand Down
6 changes: 3 additions & 3 deletions clippy_lints/src/casts/unnecessary_cast.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use clippy_utils::source::snippet_opt;
use if_chain::if_chain;
use rustc_ast::{LitFloatType, LitIntType, LitKind};
use rustc_errors::Applicability;
use rustc_hir::{Expr, ExprKind, Lit, UnOp};
use rustc_lint::{LateContext, LintContext};
use rustc_middle::lint::in_external_macro;
use rustc_middle::ty::{self, FloatTy, InferTy, Ty};

use if_chain::if_chain;

use crate::utils::{numeric_literal::NumericLiteral, snippet_opt, span_lint_and_sugg};
use crate::utils::{numeric_literal::NumericLiteral, span_lint_and_sugg};

use super::UNNECESSARY_CAST;

Expand Down
3 changes: 2 additions & 1 deletion clippy_lints/src/checked_conversions.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! lint on manually implemented checked conversions that could be transformed into `try_from`
use clippy_utils::source::snippet_with_applicability;
use if_chain::if_chain;
use rustc_ast::ast::LitKind;
use rustc_errors::Applicability;
Expand All @@ -9,7 +10,7 @@ use rustc_middle::lint::in_external_macro;
use rustc_semver::RustcVersion;
use rustc_session::{declare_tool_lint, impl_lint_pass};

use crate::utils::{meets_msrv, snippet_with_applicability, span_lint_and_sugg, SpanlessEq};
use crate::utils::{meets_msrv, span_lint_and_sugg, SpanlessEq};

const CHECKED_CONVERSIONS_MSRV: RustcVersion = RustcVersion::new(1, 34, 0);

Expand Down
3 changes: 2 additions & 1 deletion clippy_lints/src/cognitive_complexity.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! calculate cognitive complexity and warn about overly complex functions
use clippy_utils::source::snippet_opt;
use clippy_utils::ty::is_type_diagnostic_item;
use rustc_ast::ast::Attribute;
use rustc_hir::intravisit::{walk_expr, FnKind, NestedVisitorMap, Visitor};
Expand All @@ -10,7 +11,7 @@ use rustc_session::{declare_tool_lint, impl_lint_pass};
use rustc_span::source_map::Span;
use rustc_span::{sym, BytePos};

use crate::utils::{snippet_opt, span_lint_and_help, LimitStack};
use crate::utils::{span_lint_and_help, LimitStack};

declare_clippy_lint! {
/// **What it does:** Checks for methods with high cognitive complexity.
Expand Down
5 changes: 3 additions & 2 deletions clippy_lints/src/collapsible_if.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@
//!
//! This lint is **warn** by default
use clippy_utils::source::{snippet_block, snippet_block_with_applicability};
use if_chain::if_chain;
use rustc_ast::ast;
use rustc_errors::Applicability;
use rustc_lint::{EarlyContext, EarlyLintPass};
use rustc_session::{declare_lint_pass, declare_tool_lint};

use crate::utils::sugg::Sugg;
use crate::utils::{snippet_block, snippet_block_with_applicability, span_lint_and_sugg, span_lint_and_then};
use rustc_errors::Applicability;
use crate::utils::{span_lint_and_sugg, span_lint_and_then};

declare_clippy_lint! {
/// **What it does:** Checks for nested `if` statements which can be collapsed
Expand Down
3 changes: 2 additions & 1 deletion clippy_lints/src/create_dir.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::utils::{match_def_path, paths, snippet, span_lint_and_sugg};
use crate::utils::{match_def_path, paths, span_lint_and_sugg};
use clippy_utils::source::snippet;
use if_chain::if_chain;
use rustc_errors::Applicability;
use rustc_hir::{Expr, ExprKind};
Expand Down
3 changes: 2 additions & 1 deletion clippy_lints/src/dbg_macro.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::utils::{snippet_opt, span_lint_and_help, span_lint_and_sugg};
use crate::utils::{span_lint_and_help, span_lint_and_sugg};
use clippy_utils::source::snippet_opt;
use rustc_ast::ast;
use rustc_ast::tokenstream::TokenStream;
use rustc_errors::Applicability;
Expand Down
5 changes: 2 additions & 3 deletions clippy_lints/src/default.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::utils::{
any_parent_is_automatically_derived, contains_name, match_def_path, paths, snippet_with_macro_callsite,
};
use crate::utils::{any_parent_is_automatically_derived, contains_name, match_def_path, paths};
use crate::utils::{span_lint_and_note, span_lint_and_sugg};
use clippy_utils::source::snippet_with_macro_callsite;
use if_chain::if_chain;
use rustc_data_structures::fx::FxHashSet;
use rustc_errors::Applicability;
Expand Down
6 changes: 3 additions & 3 deletions clippy_lints/src/default_numeric_fallback.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use clippy_utils::source::snippet;
use if_chain::if_chain;
use rustc_ast::ast::{LitFloatType, LitIntType, LitKind};
use rustc_errors::Applicability;
use rustc_hir::{
Expand All @@ -11,9 +13,7 @@ use rustc_middle::{
};
use rustc_session::{declare_lint_pass, declare_tool_lint};

use if_chain::if_chain;

use crate::utils::{snippet, span_lint_and_sugg};
use crate::utils::span_lint_and_sugg;

declare_clippy_lint! {
/// **What it does:** Checks for usage of unconstrained numeric literals which may cause default numeric fallback in type
Expand Down
3 changes: 2 additions & 1 deletion clippy_lints/src/dereference.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::utils::{get_parent_node, in_macro, is_allowed, snippet_with_context, span_lint_and_sugg};
use crate::utils::{get_parent_node, in_macro, is_allowed, span_lint_and_sugg};
use clippy_utils::source::snippet_with_context;
use clippy_utils::ty::peel_mid_ty_refs;
use rustc_ast::util::parser::PREC_PREFIX;
use rustc_errors::Applicability;
Expand Down
3 changes: 2 additions & 1 deletion clippy_lints/src/double_comparison.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
//! Lint on unnecessary double comparisons. Some examples:
use clippy_utils::source::snippet_with_applicability;
use rustc_errors::Applicability;
use rustc_hir::{BinOpKind, Expr, ExprKind};
use rustc_lint::{LateContext, LateLintPass};
use rustc_session::{declare_lint_pass, declare_tool_lint};
use rustc_span::source_map::Span;

use crate::utils::{eq_expr_value, snippet_with_applicability, span_lint_and_sugg};
use crate::utils::{eq_expr_value, span_lint_and_sugg};

declare_clippy_lint! {
/// **What it does:** Checks for double comparisons that could be simplified to a single expression.
Expand Down
3 changes: 2 additions & 1 deletion clippy_lints/src/duration_subsec.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use clippy_utils::source::snippet_with_applicability;
use clippy_utils::ty::match_type;
use if_chain::if_chain;
use rustc_errors::Applicability;
Expand All @@ -8,7 +9,7 @@ use rustc_span::source_map::Spanned;

use crate::consts::{constant, Constant};
use crate::utils::paths;
use crate::utils::{snippet_with_applicability, span_lint_and_sugg};
use crate::utils::span_lint_and_sugg;

declare_clippy_lint! {
/// **What it does:** Checks for calculation of subsecond microseconds or milliseconds
Expand Down
5 changes: 3 additions & 2 deletions clippy_lints/src/entry.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::utils::span_lint_and_then;
use crate::utils::SpanlessEq;
use crate::utils::{get_item_name, paths, snippet, snippet_opt};
use crate::utils::{snippet_with_applicability, span_lint_and_then};
use crate::utils::{get_item_name, paths};
use clippy_utils::source::{snippet, snippet_opt, snippet_with_applicability};
use clippy_utils::ty::{is_type_diagnostic_item, match_type};
use if_chain::if_chain;
use rustc_errors::Applicability;
Expand Down
3 changes: 2 additions & 1 deletion clippy_lints/src/enum_variants.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
//! lint on enum variants that are prefixed or suffixed by the same characters
use crate::utils::{camel_case, is_present_in_source};
use crate::utils::camel_case;
use crate::utils::{span_lint, span_lint_and_help};
use clippy_utils::source::is_present_in_source;
use rustc_ast::ast::{EnumDef, Item, ItemKind, VisibilityKind};
use rustc_lint::{EarlyContext, EarlyLintPass, Lint};
use rustc_session::{declare_tool_lint, impl_lint_pass};
Expand Down
5 changes: 3 additions & 2 deletions clippy_lints/src/eq_op.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use crate::utils::{
ast_utils::is_useless_with_eq_exprs, eq_expr_value, higher, in_macro, is_expn_of, multispan_sugg, snippet,
span_lint, span_lint_and_then,
ast_utils::is_useless_with_eq_exprs, eq_expr_value, higher, in_macro, is_expn_of, multispan_sugg, span_lint,
span_lint_and_then,
};
use clippy_utils::source::snippet;
use clippy_utils::ty::{implements_trait, is_copy};
use if_chain::if_chain;
use rustc_errors::Applicability;
Expand Down
3 changes: 2 additions & 1 deletion clippy_lints/src/eta_reduction.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use clippy_utils::higher;
use clippy_utils::higher::VecArgs;
use clippy_utils::source::snippet_opt;
use clippy_utils::ty::{implements_trait, type_is_unsafe_function};
use if_chain::if_chain;
use rustc_errors::Applicability;
Expand All @@ -9,7 +10,7 @@ use rustc_middle::lint::in_external_macro;
use rustc_middle::ty::{self, Ty};
use rustc_session::{declare_lint_pass, declare_tool_lint};

use crate::utils::{is_adjusted, iter_input_pats, snippet_opt, span_lint_and_sugg, span_lint_and_then};
use crate::utils::{is_adjusted, iter_input_pats, span_lint_and_sugg, span_lint_and_then};

declare_clippy_lint! {
/// **What it does:** Checks for closures which just call another function where
Expand Down
5 changes: 4 additions & 1 deletion clippy_lints/src/exhaustive_items.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
use crate::utils::{indent_of, span_lint_and_then};
use clippy_utils::source::indent_of;
use if_chain::if_chain;

use rustc_errors::Applicability;
use rustc_hir::{Item, ItemKind};
use rustc_lint::{LateContext, LateLintPass};
use rustc_session::{declare_lint_pass, declare_tool_lint};
use rustc_span::sym;

use crate::utils::span_lint_and_then;

declare_clippy_lint! {
/// **What it does:** Warns on any exported `enum`s that are not tagged `#[non_exhaustive]`
///
Expand Down
5 changes: 2 additions & 3 deletions clippy_lints/src/format.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::utils::paths;
use crate::utils::{
is_expn_of, last_path_segment, match_def_path, match_function_call, snippet, snippet_opt, span_lint_and_then,
};
use crate::utils::{is_expn_of, last_path_segment, match_def_path, match_function_call, span_lint_and_then};
use clippy_utils::source::{snippet, snippet_opt};
use clippy_utils::ty::is_type_diagnostic_item;
use if_chain::if_chain;
use rustc_ast::ast::LitKind;
Expand Down
3 changes: 2 additions & 1 deletion clippy_lints/src/formatting.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::utils::{differing_macro_contexts, snippet_opt, span_lint_and_help, span_lint_and_note};
use crate::utils::{differing_macro_contexts, span_lint_and_help, span_lint_and_note};
use clippy_utils::source::snippet_opt;
use if_chain::if_chain;
use rustc_ast::ast::{BinOpKind, Block, Expr, ExprKind, StmtKind, UnOp};
use rustc_lint::{EarlyContext, EarlyLintPass};
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/functions.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::utils::{
attr_by_name, attrs::is_proc_macro, is_trait_impl_item, iter_input_pats, match_def_path, must_use_attr,
path_to_local, return_ty, snippet, snippet_opt, span_lint, span_lint_and_help, span_lint_and_then,
trait_ref_of_method,
path_to_local, return_ty, span_lint, span_lint_and_help, span_lint_and_then, trait_ref_of_method,
};
use clippy_utils::source::{snippet, snippet_opt};
use clippy_utils::ty::{is_must_use_ty, is_type_diagnostic_item, type_is_unsafe_function};
use if_chain::if_chain;
use rustc_ast::ast::Attribute;
Expand Down
3 changes: 2 additions & 1 deletion clippy_lints/src/get_last_with_len.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! lint on using `x.get(x.len() - 1)` instead of `x.last()`
use crate::utils::{snippet_with_applicability, span_lint_and_sugg, SpanlessEq};
use crate::utils::{span_lint_and_sugg, SpanlessEq};
use clippy_utils::source::snippet_with_applicability;
use clippy_utils::ty::is_type_diagnostic_item;
use if_chain::if_chain;
use rustc_ast::ast::LitKind;
Expand Down
3 changes: 2 additions & 1 deletion clippy_lints/src/identity_op.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use clippy_utils::source::snippet;
use if_chain::if_chain;
use rustc_hir::{BinOp, BinOpKind, Expr, ExprKind};
use rustc_lint::{LateContext, LateLintPass};
Expand All @@ -6,7 +7,7 @@ use rustc_session::{declare_lint_pass, declare_tool_lint};
use rustc_span::source_map::Span;

use crate::consts::{constant_simple, Constant};
use crate::utils::{clip, snippet, span_lint, unsext};
use crate::utils::{clip, span_lint, unsext};

declare_clippy_lint! {
/// **What it does:** Checks for identity operations, e.g., `x + 0`.
Expand Down
3 changes: 2 additions & 1 deletion clippy_lints/src/if_let_some_result.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::utils::{method_chain_args, snippet_with_applicability, span_lint_and_sugg};
use crate::utils::{method_chain_args, span_lint_and_sugg};
use clippy_utils::source::snippet_with_applicability;
use clippy_utils::ty::is_type_diagnostic_item;
use if_chain::if_chain;
use rustc_errors::Applicability;
Expand Down
Loading

0 comments on commit d7a2311

Please sign in to comment.