if no suggestion, dont add suggestion
This commit is contained in:
parent
f7d1ef90a0
commit
61c20c148e
1 changed files with 10 additions and 11 deletions
|
@ -56,14 +56,13 @@ impl<'a, 'tcx> lint::LateLintPass<'a, 'tcx> for Pass {
|
||||||
None => return,
|
None => return,
|
||||||
};
|
};
|
||||||
|
|
||||||
utils::span_lint_and_sugg(
|
let msg = "use of `offset` with a `usize` casted to an `isize`";
|
||||||
cx,
|
if let Some(sugg) = build_suggestion(cx, receiver_expr, cast_lhs_expr) {
|
||||||
PTR_OFFSET_WITH_CAST,
|
utils::span_lint_and_sugg(cx, PTR_OFFSET_WITH_CAST, expr.span, msg, "try", sugg);
|
||||||
expr.span,
|
} else {
|
||||||
"use of `offset` with a `usize` casted to an `isize`",
|
utils::span_lint(cx, PTR_OFFSET_WITH_CAST, expr.span, msg);
|
||||||
"try",
|
}
|
||||||
build_suggestion(cx, receiver_expr, cast_lhs_expr),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,12 +113,12 @@ fn build_suggestion<'a, 'tcx>(
|
||||||
cx: &lint::LateContext<'a, 'tcx>,
|
cx: &lint::LateContext<'a, 'tcx>,
|
||||||
receiver_expr: &hir::Expr,
|
receiver_expr: &hir::Expr,
|
||||||
cast_lhs_expr: &hir::Expr,
|
cast_lhs_expr: &hir::Expr,
|
||||||
) -> String {
|
) -> Option<String> {
|
||||||
match (
|
match (
|
||||||
utils::snippet_opt(cx, receiver_expr.span),
|
utils::snippet_opt(cx, receiver_expr.span),
|
||||||
utils::snippet_opt(cx, cast_lhs_expr.span)
|
utils::snippet_opt(cx, cast_lhs_expr.span)
|
||||||
) {
|
) {
|
||||||
(Some(receiver), Some(cast_lhs)) => format!("{}.add({})", receiver, cast_lhs),
|
(Some(receiver), Some(cast_lhs)) => Some(format!("{}.add({})", receiver, cast_lhs)),
|
||||||
_ => String::new(),
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue