Delay several is_from_proc_macro
checks
This commit is contained in:
parent
184845fb0c
commit
f3f2f17478
@ -48,11 +48,10 @@
|
||||
|
||||
impl<'tcx> LateLintPass<'tcx> for AsConversions {
|
||||
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &Expr<'tcx>) {
|
||||
if in_external_macro(cx.sess(), expr.span) || is_from_proc_macro(cx, expr) {
|
||||
return;
|
||||
}
|
||||
|
||||
if let ExprKind::Cast(_, _) = expr.kind {
|
||||
if let ExprKind::Cast(_, _) = expr.kind
|
||||
&& !in_external_macro(cx.sess(), expr.span)
|
||||
&& !is_from_proc_macro(cx, expr)
|
||||
{
|
||||
span_lint_and_help(
|
||||
cx,
|
||||
AS_CONVERSIONS,
|
||||
|
@ -57,7 +57,6 @@ fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &rustc_hir::Expr<'tcx>) {
|
||||
&& !matches!(deref_target.kind, ExprKind::Unary(UnOp::Deref, ..))
|
||||
&& let ref_ty = cx.typeck_results().expr_ty(deref_target)
|
||||
&& let ty::Ref(_, inner_ty, Mutability::Not) = ref_ty.kind()
|
||||
&& !is_from_proc_macro(cx, e)
|
||||
{
|
||||
if let Some(parent_expr) = get_parent_expr(cx, e) {
|
||||
if matches!(parent_expr.kind, ExprKind::Unary(UnOp::Deref, ..))
|
||||
@ -75,6 +74,9 @@ fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &rustc_hir::Expr<'tcx>) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if is_from_proc_macro(cx, e) {
|
||||
return;
|
||||
}
|
||||
|
||||
span_lint_and_then(
|
||||
cx,
|
||||
|
@ -105,7 +105,6 @@ fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) {
|
||||
// case somebody does that for some reason
|
||||
&& (is_infinity(const_1) && is_neg_infinity(const_2)
|
||||
|| is_neg_infinity(const_1) && is_infinity(const_2))
|
||||
&& !is_from_proc_macro(cx, expr)
|
||||
&& let Some(local_snippet) = snippet_opt(cx, first.span)
|
||||
{
|
||||
let variant = match (kind.node, lhs_kind.node, rhs_kind.node) {
|
||||
@ -113,6 +112,9 @@ fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) {
|
||||
(BinOpKind::And, BinOpKind::Ne, BinOpKind::Ne) => Variant::ManualIsFinite,
|
||||
_ => return,
|
||||
};
|
||||
if is_from_proc_macro(cx, expr) {
|
||||
return;
|
||||
}
|
||||
|
||||
span_lint_and_then(cx, variant.lint(), expr.span, variant.msg(), |diag| {
|
||||
match variant {
|
||||
|
@ -19,10 +19,6 @@ pub(super) fn check<'tcx>(
|
||||
arg: &'tcx hir::Expr<'_>,
|
||||
simplify_using: &str,
|
||||
) {
|
||||
if is_from_proc_macro(cx, expr) {
|
||||
return;
|
||||
}
|
||||
|
||||
let is_option = is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(recv), sym::Option);
|
||||
let is_result = is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(recv), sym::Result);
|
||||
let is_bool = cx.typeck_results().expr_ty(recv).is_bool();
|
||||
@ -32,7 +28,7 @@ pub(super) fn check<'tcx>(
|
||||
let body = cx.tcx.hir().body(body);
|
||||
let body_expr = &body.value;
|
||||
|
||||
if usage::BindingUsageFinder::are_params_used(cx, body) {
|
||||
if usage::BindingUsageFinder::are_params_used(cx, body) || is_from_proc_macro(cx, expr) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -44,7 +44,6 @@ fn check_stmt<'tcx>(&mut self, cx: &LateContext<'tcx>, stmt: &Stmt<'tcx>) {
|
||||
&& block.stmts.is_empty()
|
||||
&& block.expr.is_none()
|
||||
&& !in_external_macro(cx.sess(), expr.span)
|
||||
&& !is_from_proc_macro(cx, expr)
|
||||
&& let Some(then_snippet) = snippet_opt(cx, then.span)
|
||||
// Ignore
|
||||
// - empty macro expansions
|
||||
@ -53,6 +52,7 @@ fn check_stmt<'tcx>(&mut self, cx: &LateContext<'tcx>, stmt: &Stmt<'tcx>) {
|
||||
// - #[cfg]'d out code
|
||||
&& then_snippet.chars().all(|ch| matches!(ch, '{' | '}') || ch.is_ascii_whitespace())
|
||||
&& let Some(cond_snippet) = snippet_opt(cx, cond.span)
|
||||
&& !is_from_proc_macro(cx, expr)
|
||||
{
|
||||
span_lint_and_sugg(
|
||||
cx,
|
||||
|
@ -132,7 +132,11 @@ fn is_integral(ty: Ty<'_>) -> bool {
|
||||
}
|
||||
|
||||
// Common entry-point to avoid code duplication.
|
||||
fn issue_lint(&mut self, cx: &LateContext<'_>, expr: &hir::Expr<'_>) {
|
||||
fn issue_lint<'tcx>(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) {
|
||||
if is_from_proc_macro(cx, expr) {
|
||||
return;
|
||||
}
|
||||
|
||||
let msg = "arithmetic operation that can potentially result in unexpected side-effects";
|
||||
span_lint(cx, ARITHMETIC_SIDE_EFFECTS, expr.span, msg);
|
||||
self.expr_span = Some(expr.span);
|
||||
@ -160,10 +164,10 @@ fn literal_integer(cx: &LateContext<'_>, expr: &hir::Expr<'_>) -> Option<u128> {
|
||||
fn manage_bin_ops<'tcx>(
|
||||
&mut self,
|
||||
cx: &LateContext<'tcx>,
|
||||
expr: &hir::Expr<'tcx>,
|
||||
expr: &'tcx hir::Expr<'_>,
|
||||
op: &Spanned<hir::BinOpKind>,
|
||||
lhs: &hir::Expr<'tcx>,
|
||||
rhs: &hir::Expr<'tcx>,
|
||||
lhs: &'tcx hir::Expr<'_>,
|
||||
rhs: &'tcx hir::Expr<'_>,
|
||||
) {
|
||||
if constant_simple(cx, cx.typeck_results(), expr).is_some() {
|
||||
return;
|
||||
@ -236,10 +240,10 @@ fn manage_bin_ops<'tcx>(
|
||||
/// provided input.
|
||||
fn manage_method_call<'tcx>(
|
||||
&mut self,
|
||||
args: &[hir::Expr<'tcx>],
|
||||
args: &'tcx [hir::Expr<'_>],
|
||||
cx: &LateContext<'tcx>,
|
||||
ps: &hir::PathSegment<'tcx>,
|
||||
receiver: &hir::Expr<'tcx>,
|
||||
ps: &'tcx hir::PathSegment<'_>,
|
||||
receiver: &'tcx hir::Expr<'_>,
|
||||
) {
|
||||
let Some(arg) = args.first() else {
|
||||
return;
|
||||
@ -264,8 +268,8 @@ fn manage_method_call<'tcx>(
|
||||
fn manage_unary_ops<'tcx>(
|
||||
&mut self,
|
||||
cx: &LateContext<'tcx>,
|
||||
expr: &hir::Expr<'tcx>,
|
||||
un_expr: &hir::Expr<'tcx>,
|
||||
expr: &'tcx hir::Expr<'_>,
|
||||
un_expr: &'tcx hir::Expr<'_>,
|
||||
un_op: hir::UnOp,
|
||||
) {
|
||||
let hir::UnOp::Neg = un_op else {
|
||||
@ -287,14 +291,13 @@ fn manage_unary_ops<'tcx>(
|
||||
|
||||
fn should_skip_expr<'tcx>(&mut self, cx: &LateContext<'tcx>, expr: &hir::Expr<'tcx>) -> bool {
|
||||
is_lint_allowed(cx, ARITHMETIC_SIDE_EFFECTS, expr.hir_id)
|
||||
|| is_from_proc_macro(cx, expr)
|
||||
|| self.expr_span.is_some()
|
||||
|| self.const_span.map_or(false, |sp| sp.contains(expr.span))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> LateLintPass<'tcx> for ArithmeticSideEffects {
|
||||
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &hir::Expr<'tcx>) {
|
||||
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'tcx>) {
|
||||
if self.should_skip_expr(cx, expr) {
|
||||
return;
|
||||
}
|
||||
|
@ -72,8 +72,8 @@ fn check_fn(
|
||||
) {
|
||||
if self.avoid_breaking_exported_api && cx.effective_visibilities.is_exported(def_id)
|
||||
|| in_external_macro(cx.sess(), span)
|
||||
|| is_from_proc_macro(cx, &(&kind, body, cx.tcx.local_def_id_to_hir_id(def_id), span))
|
||||
|| is_in_test_function(cx.tcx, body.value.hir_id)
|
||||
|| is_from_proc_macro(cx, &(&kind, body, cx.tcx.local_def_id_to_hir_id(def_id), span))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user