use crate::consts::{constant_simple, Constant};
use crate::utils::{match_def_path, opt_def_id, paths, span_lint};
use rustc::hir::*;
-use rustc::lint::*;
+use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
+use rustc::{declare_tool_lint, lint_array};
use std::cmp::Ordering;
/// **What it does:** Checks for expressions where `std::cmp::min` and `max` are
"`min(_, max(_, _))` (or vice versa) with bounds clamping the result to a constant"
}
-#[allow(missing_copy_implementations)]
pub struct MinMaxPass;
impl LintPass for MinMaxPass {
fn get_lints(&self) -> LintArray {
lint_array!(MIN_MAX)
}
+
+ fn name(&self) -> &'static str {
+ "MinMax"
+ }
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MinMaxPass {
}
match (
outer_max,
- Constant::partial_cmp(cx.tcx, &cx.tables.expr_ty(ie).sty, &outer_c, &inner_c),
+ Constant::partial_cmp(cx.tcx, cx.tables.expr_ty(ie), &outer_c, &inner_c),
) {
(_, None) | (MinMax::Max, Some(Ordering::Less)) | (MinMax::Min, Some(Ordering::Greater)) => (),
_ => {
Max,
}
-fn min_max<'a>(cx: &LateContext, expr: &'a Expr) -> Option<(MinMax, Constant, &'a Expr)> {
+fn min_max<'a>(cx: &LateContext<'_, '_>, expr: &'a Expr) -> Option<(MinMax, Constant, &'a Expr)> {
if let ExprKind::Call(ref path, ref args) = expr.node {
if let ExprKind::Path(ref qpath) = path.node {
opt_def_id(cx.tables.qpath_def(qpath, path.hir_id)).and_then(|def_id| {
}
}
-fn fetch_const<'a>(cx: &LateContext, args: &'a [Expr], m: MinMax) -> Option<(MinMax, Constant, &'a Expr)> {
+fn fetch_const<'a>(cx: &LateContext<'_, '_>, args: &'a [Expr], m: MinMax) -> Option<(MinMax, Constant, &'a Expr)> {
if args.len() != 2 {
return None;
}