Merge commit 'b7f3f7f608
' into clippyup
This commit is contained in:
parent
87bb18e7c2
commit
5cf4984872
147 changed files with 4288 additions and 2969 deletions
|
@ -26,6 +26,9 @@ declare_clippy_lint! {
|
|||
|
||||
declare_lint_pass!(OverflowCheckConditional => [OVERFLOW_CHECK_CONDITIONAL]);
|
||||
|
||||
const OVERFLOW_MSG: &str = "you are trying to use classic C overflow conditions that will fail in Rust";
|
||||
const UNDERFLOW_MSG: &str = "you are trying to use classic C underflow conditions that will fail in Rust";
|
||||
|
||||
impl<'tcx> LateLintPass<'tcx> for OverflowCheckConditional {
|
||||
// a + b < a, a > a + b, a < a - b, a - b > a
|
||||
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
|
||||
|
@ -40,17 +43,11 @@ impl<'tcx> LateLintPass<'tcx> for OverflowCheckConditional {
|
|||
if cx.typeck_results().expr_ty(ident1).is_integral();
|
||||
if cx.typeck_results().expr_ty(ident2).is_integral();
|
||||
then {
|
||||
if let BinOpKind::Lt = op.node {
|
||||
if let BinOpKind::Add = op2.node {
|
||||
span_lint(cx, OVERFLOW_CHECK_CONDITIONAL, expr.span,
|
||||
"you are trying to use classic C overflow conditions that will fail in Rust");
|
||||
}
|
||||
if op.node == BinOpKind::Lt && op2.node == BinOpKind::Add {
|
||||
span_lint(cx, OVERFLOW_CHECK_CONDITIONAL, expr.span, OVERFLOW_MSG);
|
||||
}
|
||||
if let BinOpKind::Gt = op.node {
|
||||
if let BinOpKind::Sub = op2.node {
|
||||
span_lint(cx, OVERFLOW_CHECK_CONDITIONAL, expr.span,
|
||||
"you are trying to use classic C underflow conditions that will fail in Rust");
|
||||
}
|
||||
if op.node == BinOpKind::Gt && op2.node == BinOpKind::Sub {
|
||||
span_lint(cx, OVERFLOW_CHECK_CONDITIONAL, expr.span, UNDERFLOW_MSG);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -65,17 +62,11 @@ impl<'tcx> LateLintPass<'tcx> for OverflowCheckConditional {
|
|||
if cx.typeck_results().expr_ty(ident1).is_integral();
|
||||
if cx.typeck_results().expr_ty(ident2).is_integral();
|
||||
then {
|
||||
if let BinOpKind::Gt = op.node {
|
||||
if let BinOpKind::Add = op2.node {
|
||||
span_lint(cx, OVERFLOW_CHECK_CONDITIONAL, expr.span,
|
||||
"you are trying to use classic C overflow conditions that will fail in Rust");
|
||||
}
|
||||
if op.node == BinOpKind::Gt && op2.node == BinOpKind::Add {
|
||||
span_lint(cx, OVERFLOW_CHECK_CONDITIONAL, expr.span, OVERFLOW_MSG);
|
||||
}
|
||||
if let BinOpKind::Lt = op.node {
|
||||
if let BinOpKind::Sub = op2.node {
|
||||
span_lint(cx, OVERFLOW_CHECK_CONDITIONAL, expr.span,
|
||||
"you are trying to use classic C underflow conditions that will fail in Rust");
|
||||
}
|
||||
if op.node == BinOpKind::Lt && op2.node == BinOpKind::Sub {
|
||||
span_lint(cx, OVERFLOW_CHECK_CONDITIONAL, expr.span, UNDERFLOW_MSG);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue