Skip to content

Commit 4122a22

Browse files
committed
Do not look for disallowed methods inside desugared code
1 parent 4180830 commit 4122a22

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

clippy_lints/src/disallowed_methods.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ impl_lint_pass!(DisallowedMethods => [DISALLOWED_METHODS]);
8888

8989
impl<'tcx> LateLintPass<'tcx> for DisallowedMethods {
9090
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
91+
if expr.span.desugaring_kind().is_some() {
92+
return;
93+
}
9194
let (id, span) = match &expr.kind {
9295
ExprKind::Path(path) if let Res::Def(_, id) = cx.qpath_res(path, expr.hir_id) => (id, expr.span),
9396
ExprKind::MethodCall(name, ..) if let Some(id) = cx.typeck_results().type_dependent_def_id(expr.hir_id) => {

tests/ui-toml/toml_disallowed_methods/clippy.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,6 @@ disallowed-methods = [
1717
# re-exports
1818
"conf_disallowed_methods::identity",
1919
"conf_disallowed_methods::renamed",
20+
# also used in desugaring
21+
"std::future::Future::poll",
2022
]

tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,19 @@ fn main() {
8080
renamed(1);
8181
//~^ disallowed_methods
8282
}
83+
84+
mod issue16185 {
85+
use std::pin::Pin;
86+
use std::task::Context;
87+
88+
async fn test(f: impl Future<Output = ()>) {
89+
// Should not lint even though desugaring uses
90+
// disallowed method `std::future::Future::poll()`.
91+
f.await
92+
}
93+
94+
fn explicit<F: Future<Output = ()>>(f: Pin<&mut F>, cx: &mut Context<'_>) {
95+
f.poll(cx);
96+
//~^ disallowed_methods
97+
}
98+
}

tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.stderr

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,5 +99,11 @@ error: use of a disallowed method `conf_disallowed_methods::renamed`
9999
LL | renamed(1);
100100
| ^^^^^^^
101101

102-
error: aborting due to 16 previous errors
102+
error: use of a disallowed method `std::future::Future::poll`
103+
--> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:95:11
104+
|
105+
LL | f.poll(cx);
106+
| ^^^^
107+
108+
error: aborting due to 17 previous errors
103109

0 commit comments

Comments
 (0)