diff --git a/detectors/avoid-core-mem-forget/src/lib.rs b/detectors/avoid-core-mem-forget/src/lib.rs index 25fa454b..bc222d3c 100644 --- a/detectors/avoid-core-mem-forget/src/lib.rs +++ b/detectors/avoid-core-mem-forget/src/lib.rs @@ -3,11 +3,11 @@ extern crate rustc_ast; extern crate rustc_span; +use clippy_utils::diagnostics::span_lint_and_help; use if_chain::if_chain; use rustc_ast::{Expr, ExprKind, Item, NodeId}; use rustc_lint::{EarlyContext, EarlyLintPass}; use rustc_span::sym; -use clippy_utils::diagnostics::span_lint_and_help; const LINT_MESSAGE: &str = "Use the `let _ = ...` pattern or `.drop()` method to forget the value"; diff --git a/detectors/avoid-unsafe-block/src/lib.rs b/detectors/avoid-unsafe-block/src/lib.rs index 7fda4643..5540ff34 100644 --- a/detectors/avoid-unsafe-block/src/lib.rs +++ b/detectors/avoid-unsafe-block/src/lib.rs @@ -3,6 +3,7 @@ extern crate rustc_hir; extern crate rustc_span; +use clippy_utils::diagnostics::span_lint; use rustc_hir::{ def_id::LocalDefId, intravisit::{walk_expr, FnKind, Visitor}, @@ -10,7 +11,6 @@ use rustc_hir::{ }; use rustc_lint::{LateContext, LateLintPass}; use rustc_span::Span; -use clippy_utils::diagnostics::span_lint; const LINT_MESSAGE: &str = "Avoid using unsafe blocks as it may lead to undefined behavior"; diff --git a/detectors/divide-before-multiply/src/lib.rs b/detectors/divide-before-multiply/src/lib.rs index e1650491..00d293a7 100644 --- a/detectors/divide-before-multiply/src/lib.rs +++ b/detectors/divide-before-multiply/src/lib.rs @@ -7,6 +7,7 @@ extern crate rustc_span; use std::collections::HashSet; +use clippy_utils::diagnostics::span_lint_and_help; use if_chain::if_chain; use rustc_hir::{ intravisit::{walk_expr, FnKind, Visitor}, @@ -24,7 +25,6 @@ use rustc_span::{ def_id::{DefId, LocalDefId}, Span, }; -use clippy_utils::diagnostics::span_lint_and_help; const LINT_MESSAGE: &str = "Division before multiplication might result in a loss of precision"; diff --git a/detectors/incorrect-exponentiation/src/lib.rs b/detectors/incorrect-exponentiation/src/lib.rs index 7439282d..ea53024b 100644 --- a/detectors/incorrect-exponentiation/src/lib.rs +++ b/detectors/incorrect-exponentiation/src/lib.rs @@ -4,6 +4,7 @@ extern crate rustc_hir; extern crate rustc_span; +use clippy_utils::diagnostics::span_lint_and_help; use rustc_hir::def_id::LocalDefId; use rustc_hir::intravisit::Visitor; use rustc_hir::intravisit::{walk_expr, FnKind}; @@ -11,7 +12,6 @@ use rustc_hir::{Body, FnDecl}; use rustc_hir::{Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_span::Span; -use clippy_utils::diagnostics::span_lint_and_help; const LINT_MESSAGE: &str = "'^' It is not an exponential operator. It is a bitwise XOR."; const LINT_HELP: &str = "If you want to use XOR, use bitxor(). If you want to raise a number use .checked_pow() or .pow() "; diff --git a/detectors/insufficiently-random-values/src/lib.rs b/detectors/insufficiently-random-values/src/lib.rs index d606a025..60541bd7 100644 --- a/detectors/insufficiently-random-values/src/lib.rs +++ b/detectors/insufficiently-random-values/src/lib.rs @@ -3,11 +3,11 @@ extern crate rustc_hir; extern crate rustc_span; +use clippy_utils::diagnostics::span_lint_and_help; use if_chain::if_chain; use rustc_hir::{BinOpKind, Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_span::Symbol; -use clippy_utils::diagnostics::span_lint_and_help; const LINT_MESSAGE: &str = "Use env.prng() to generate random numbers, and remember that all random numbers are under the control of validators"; diff --git a/detectors/iterators-over-indexing/src/lib.rs b/detectors/iterators-over-indexing/src/lib.rs index f99e5185..c65ea9b0 100644 --- a/detectors/iterators-over-indexing/src/lib.rs +++ b/detectors/iterators-over-indexing/src/lib.rs @@ -7,6 +7,7 @@ extern crate rustc_middle; extern crate rustc_span; extern crate rustc_type_ir; +use clippy_utils::diagnostics::span_lint_and_help; use rustc_ast::{Label, LitIntType, LitKind}; use rustc_hir::{ def::Res, @@ -19,7 +20,6 @@ use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::{TyCtxt, TyKind}; use rustc_span::{symbol::Ident, Span}; use rustc_type_ir::Interner; -use clippy_utils::diagnostics::span_lint_and_help; use utils::get_node_type; const LINT_MESSAGE: &str = diff --git a/detectors/overflow-check/src/lib.rs b/detectors/overflow-check/src/lib.rs index 253ffdc7..2842b879 100644 --- a/detectors/overflow-check/src/lib.rs +++ b/detectors/overflow-check/src/lib.rs @@ -10,10 +10,10 @@ use std::{ str::from_utf8, }; +use clippy_utils::diagnostics::span_lint_and_help; use rustc_ast::Crate; use rustc_lint::{EarlyContext, EarlyLintPass, LintContext}; use rustc_span::DUMMY_SP; -use clippy_utils::diagnostics::span_lint_and_help; use toml::Value; const LINT_MESSAGE: &str = "Use `overflow-checks = true` in Cargo.toml profile"; diff --git a/detectors/set-contract-storage/src/lib.rs b/detectors/set-contract-storage/src/lib.rs index c4555362..7d11a93d 100644 --- a/detectors/set-contract-storage/src/lib.rs +++ b/detectors/set-contract-storage/src/lib.rs @@ -6,6 +6,7 @@ extern crate rustc_span; use std::collections::{HashMap, HashSet}; +use clippy_utils::diagnostics::span_lint_and_help; use if_chain::if_chain; use rustc_hir::{ intravisit::{walk_expr, FnKind, Visitor}, @@ -17,7 +18,6 @@ use rustc_span::{ def_id::{DefId, LocalDefId}, Span, Symbol, }; -use clippy_utils::diagnostics::span_lint_and_help; use utils::FunctionCallVisitor; const LINT_MESSAGE: &str = "Abitrary users should not have control over keys because it implies writing any value of left mapping, lazy variable, or the main struct of the contract located in position 0 of the storage"; diff --git a/detectors/soroban-version/src/lib.rs b/detectors/soroban-version/src/lib.rs index df01a214..253549f5 100644 --- a/detectors/soroban-version/src/lib.rs +++ b/detectors/soroban-version/src/lib.rs @@ -5,10 +5,10 @@ extern crate rustc_span; use std::{io::Error, process::Command}; +use clippy_utils::diagnostics::span_lint_and_help; use rustc_ast::Crate; use rustc_lint::{EarlyContext, EarlyLintPass, LintContext}; use rustc_span::DUMMY_SP; -use clippy_utils::diagnostics::span_lint_and_help; use semver::Version; use serde_json::Value; diff --git a/detectors/unprotected-update-current-contract-wasm/src/lib.rs b/detectors/unprotected-update-current-contract-wasm/src/lib.rs index d8f7a377..0a8959dd 100644 --- a/detectors/unprotected-update-current-contract-wasm/src/lib.rs +++ b/detectors/unprotected-update-current-contract-wasm/src/lib.rs @@ -7,6 +7,7 @@ extern crate rustc_span; use std::collections::{HashMap, HashSet}; +use clippy_utils::diagnostics::span_lint_and_help; use if_chain::if_chain; use rustc_hir::{ intravisit::{walk_expr, FnKind, Visitor}, @@ -18,7 +19,6 @@ use rustc_span::{ def_id::{DefId, LocalDefId}, Span, Symbol, }; -use clippy_utils::diagnostics::span_lint_and_help; use utils::{is_soroban_address, is_soroban_env, is_soroban_function, FunctionCallVisitor}; const LINT_MESSAGE: &str = "This update_current_contract_wasm is called without access control"; diff --git a/detectors/unused-return-enum/src/lib.rs b/detectors/unused-return-enum/src/lib.rs index 363e8f39..379e52ee 100644 --- a/detectors/unused-return-enum/src/lib.rs +++ b/detectors/unused-return-enum/src/lib.rs @@ -3,6 +3,7 @@ extern crate rustc_hir; extern crate rustc_span; +use clippy_utils::diagnostics::span_lint_and_help; use if_chain::if_chain; use rustc_hir::{ intravisit::{walk_expr, FnKind, Visitor}, @@ -10,7 +11,6 @@ use rustc_hir::{ }; use rustc_lint::{LateContext, LateLintPass}; use rustc_span::{def_id::LocalDefId, sym, Span}; -use clippy_utils::diagnostics::span_lint_and_help; const LINT_MESSAGE : &str = "If any of the variants (Ok/Err) is not used, the code could be simplified or it could imply a bug"; diff --git a/detectors/vec-could-be-mapping/src/lib.rs b/detectors/vec-could-be-mapping/src/lib.rs index 67c58e1a..983ad61b 100644 --- a/detectors/vec-could-be-mapping/src/lib.rs +++ b/detectors/vec-could-be-mapping/src/lib.rs @@ -7,6 +7,7 @@ extern crate rustc_middle; extern crate rustc_span; extern crate rustc_type_ir; +use clippy_utils::diagnostics::span_lint_and_help; use rustc_hir::{ intravisit::{walk_expr, FnKind, Visitor}, Body, Expr, FnDecl, GenericArg, HirId, QPath, Stmt, TyKind, @@ -14,7 +15,6 @@ use rustc_hir::{ use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::GenericArgKind; use rustc_span::{def_id::LocalDefId, Span}; -use clippy_utils::diagnostics::span_lint_and_help; use utils::{ definition_to_string, expr_to_method_call, expr_to_path, get_node_type, get_type_string, path_to_resolved, resolution_to_local, stmt_to_local, type_to_adt, diff --git a/test-cases/avoid-panic-error/avoid-panic-error-1/remediated-example/src/lib.rs b/test-cases/avoid-panic-error/avoid-panic-error-1/remediated-example/src/lib.rs index 871aa92d..4a50c7d8 100644 --- a/test-cases/avoid-panic-error/avoid-panic-error-1/remediated-example/src/lib.rs +++ b/test-cases/avoid-panic-error/avoid-panic-error-1/remediated-example/src/lib.rs @@ -60,7 +60,7 @@ mod tests { let client = AvoidPanicErrorClient::new(&env, &contract_id); // When - let _max_value = client.try_add(&u32::max_value()); + let _max_value = client.try_add(&u32::MAX); let overflow = client.try_add(&1); // Then diff --git a/test-cases/avoid-panic-error/avoid-panic-error-1/vulnerable-example/src/lib.rs b/test-cases/avoid-panic-error/avoid-panic-error-1/vulnerable-example/src/lib.rs index 2ead32b9..7119ed1d 100644 --- a/test-cases/avoid-panic-error/avoid-panic-error-1/vulnerable-example/src/lib.rs +++ b/test-cases/avoid-panic-error/avoid-panic-error-1/vulnerable-example/src/lib.rs @@ -54,7 +54,7 @@ mod tests { let client = AvoidPanicErrorClient::new(&env, &contract_id); // When - client.add(&u32::max_value()); + client.add(&u32::MAX); client.add(&1); // Then