Auto merge of #10775 - lochetti:fix_10723, r=xFrednet

Ignoring `let_underscore_untyped` warnings in code from proc macros

Don't linting let_underscore_untyped if code was generated by procedural macro.

This PR fixes https://github.com/rust-lang/rust-clippy/issues/10723

---

closes: https://github.com/rust-lang/rust-clippy/issues/10723

changelog: Fix: [`let_underscore_untyped`]: No longer lints inside proc macros
[#10775](https://github.com/rust-lang/rust-clippy/pull/10775)
<!-- changelog_checked -->
This commit is contained in:
bors 2023-05-18 01:59:38 +00:00
commit f3f6fd8920
3 changed files with 30 additions and 11 deletions

View file

@ -1,4 +1,5 @@
use clippy_utils::diagnostics::span_lint_and_help;
use clippy_utils::is_from_proc_macro;
use clippy_utils::ty::{implements_trait, is_must_use_ty, match_type};
use clippy_utils::{is_must_use_func_call, paths};
use rustc_hir::{ExprKind, Local, PatKind};
@ -138,7 +139,7 @@ const SYNC_GUARD_PATHS: [&[&str]; 3] = [
];
impl<'tcx> LateLintPass<'tcx> for LetUnderscore {
fn check_local(&mut self, cx: &LateContext<'_>, local: &Local<'_>) {
fn check_local(&mut self, cx: &LateContext<'tcx>, local: &Local<'tcx>) {
if !in_external_macro(cx.tcx.sess, local.span)
&& let PatKind::Wild = local.pat.kind
&& let Some(init) = local.init
@ -200,6 +201,10 @@ impl<'tcx> LateLintPass<'tcx> for LetUnderscore {
}
}
// Ignore if it is from a procedural macro...
if is_from_proc_macro(cx, init) {
return;
}
span_lint_and_help(
cx,

View file

@ -1,6 +1,12 @@
//@aux-build: proc_macros.rs
#![allow(unused)]
#![warn(clippy::let_underscore_untyped)]
extern crate proc_macros;
use proc_macros::with_span;
use clippy_utils::is_from_proc_macro;
use std::future::Future;
use std::{boxed::Box, fmt::Display};
@ -32,6 +38,14 @@ fn g() -> impl Fn() {
|| {}
}
with_span!(
span
fn dont_lint_proc_macro() {
let _ = a();
}
);
fn main() {
let _ = a();
let _ = b(1);

View file

@ -1,60 +1,60 @@
error: non-binding `let` without a type annotation
--> $DIR/let_underscore_untyped.rs:36:5
--> $DIR/let_underscore_untyped.rs:50:5
|
LL | let _ = a();
| ^^^^^^^^^^^^
|
help: consider adding a type annotation
--> $DIR/let_underscore_untyped.rs:36:10
--> $DIR/let_underscore_untyped.rs:50:10
|
LL | let _ = a();
| ^
= note: `-D clippy::let-underscore-untyped` implied by `-D warnings`
error: non-binding `let` without a type annotation
--> $DIR/let_underscore_untyped.rs:37:5
--> $DIR/let_underscore_untyped.rs:51:5
|
LL | let _ = b(1);
| ^^^^^^^^^^^^^
|
help: consider adding a type annotation
--> $DIR/let_underscore_untyped.rs:37:10
--> $DIR/let_underscore_untyped.rs:51:10
|
LL | let _ = b(1);
| ^
error: non-binding `let` without a type annotation
--> $DIR/let_underscore_untyped.rs:39:5
--> $DIR/let_underscore_untyped.rs:53:5
|
LL | let _ = d(&1);
| ^^^^^^^^^^^^^^
|
help: consider adding a type annotation
--> $DIR/let_underscore_untyped.rs:39:10
--> $DIR/let_underscore_untyped.rs:53:10
|
LL | let _ = d(&1);
| ^
error: non-binding `let` without a type annotation
--> $DIR/let_underscore_untyped.rs:40:5
--> $DIR/let_underscore_untyped.rs:54:5
|
LL | let _ = e();
| ^^^^^^^^^^^^
|
help: consider adding a type annotation
--> $DIR/let_underscore_untyped.rs:40:10
--> $DIR/let_underscore_untyped.rs:54:10
|
LL | let _ = e();
| ^
error: non-binding `let` without a type annotation
--> $DIR/let_underscore_untyped.rs:41:5
--> $DIR/let_underscore_untyped.rs:55:5
|
LL | let _ = f();
| ^^^^^^^^^^^^
|
help: consider adding a type annotation
--> $DIR/let_underscore_untyped.rs:41:10
--> $DIR/let_underscore_untyped.rs:55:10
|
LL | let _ = f();
| ^