From 97d95d48e2ef72d9ededeb5821f0bfcbd8fcf7c6 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Wed, 23 Nov 2022 17:57:11 -0700 Subject: [PATCH] lint: do not warn unused parens around higher-ranked function pointers Fixes #104397 --- compiler/rustc_lint/src/unused.rs | 1 + src/test/ui/lint/unused/issue-104397.rs | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 src/test/ui/lint/unused/issue-104397.rs diff --git a/compiler/rustc_lint/src/unused.rs b/compiler/rustc_lint/src/unused.rs index 0471890230aa6..21a060a36d24b 100644 --- a/compiler/rustc_lint/src/unused.rs +++ b/compiler/rustc_lint/src/unused.rs @@ -1002,6 +1002,7 @@ impl EarlyLintPass for UnusedParens { if let ast::TyKind::Paren(r) = &ty.kind { match &r.kind { ast::TyKind::TraitObject(..) => {} + ast::TyKind::BareFn(b) if b.generic_params.len() > 0 => {} ast::TyKind::ImplTrait(_, bounds) if bounds.len() > 1 => {} ast::TyKind::Array(_, len) => { self.check_unused_delims_expr( diff --git a/src/test/ui/lint/unused/issue-104397.rs b/src/test/ui/lint/unused/issue-104397.rs new file mode 100644 index 0000000000000..94e15cd96bc37 --- /dev/null +++ b/src/test/ui/lint/unused/issue-104397.rs @@ -0,0 +1,18 @@ +// check-pass + +#![warn(unused)] +#![deny(warnings)] + +struct Inv<'a>(&'a mut &'a ()); + +trait Trait {} +impl Trait for for<'a> fn(Inv<'a>) {} + +fn with_bound() +where + (for<'a> fn(Inv<'a>)): Trait, +{} + +fn main() { + with_bound(); +}