about summary refs log tree commit diff
diff options
context:
space:
mode:
authoryukang <moorekang@gmail.com>2022-12-24 02:41:06 +0800
committeryukang <moorekang@gmail.com>2023-01-14 17:11:04 +0800
commit7d99866bfc43f34dbdd84f4bf982c48a51b70a99 (patch)
treec01620bc933dd4f3fc811e87738cdcee2e32e9f1
parent44a500c8c187b245638684748f54bd6ec67e0b25 (diff)
downloadrust-7d99866bfc43f34dbdd84f4bf982c48a51b70a99.tar.gz
rust-7d99866bfc43f34dbdd84f4bf982c48a51b70a99.zip
fix #105061, Fix unused_parens issue for higher ranked function pointers
-rw-r--r--compiler/rustc_lint/src/early.rs6
-rw-r--r--compiler/rustc_lint/src/unused.rs1
-rw-r--r--tests/ui/lint/unused/issue-105061.rs17
-rw-r--r--tests/ui/lint/unused/issue-105061.stderr20
4 files changed, 43 insertions, 1 deletions
diff --git a/compiler/rustc_lint/src/early.rs b/compiler/rustc_lint/src/early.rs
index f9b2df49592..3901751c79f 100644
--- a/compiler/rustc_lint/src/early.rs
+++ b/compiler/rustc_lint/src/early.rs
@@ -248,6 +248,12 @@ impl<'a, T: EarlyLintPass> ast_visit::Visitor<'a> for EarlyContextAndPass<'a, T>
     }
 
     fn visit_where_predicate(&mut self, p: &'a ast::WherePredicate) {
+        use rustc_ast::{WhereBoundPredicate, WherePredicate};
+        if let WherePredicate::BoundPredicate(WhereBoundPredicate { bounded_ty, .. }) = p &&
+            let ast::TyKind::BareFn(b) = &bounded_ty.kind &&
+            b.generic_params.len() > 0 {
+                return;
+        }
         ast_visit::walk_where_predicate(self, p);
     }
 
diff --git a/compiler/rustc_lint/src/unused.rs b/compiler/rustc_lint/src/unused.rs
index ac2b32b44e6..94a33138107 100644
--- a/compiler/rustc_lint/src/unused.rs
+++ b/compiler/rustc_lint/src/unused.rs
@@ -1002,7 +1002,6 @@ 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/tests/ui/lint/unused/issue-105061.rs b/tests/ui/lint/unused/issue-105061.rs
new file mode 100644
index 00000000000..92d636d0ac6
--- /dev/null
+++ b/tests/ui/lint/unused/issue-105061.rs
@@ -0,0 +1,17 @@
+#![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, //~ ERROR unnecessary parentheses around type
+{}
+
+fn main() {
+    with_bound();
+}
diff --git a/tests/ui/lint/unused/issue-105061.stderr b/tests/ui/lint/unused/issue-105061.stderr
new file mode 100644
index 00000000000..f07aa2012df
--- /dev/null
+++ b/tests/ui/lint/unused/issue-105061.stderr
@@ -0,0 +1,20 @@
+error: unnecessary parentheses around type
+  --> $DIR/issue-105061.rs:12:6
+   |
+LL |     ((for<'a> fn(Inv<'a>)),): Trait,
+   |      ^                   ^
+   |
+note: the lint level is defined here
+  --> $DIR/issue-105061.rs:2:9
+   |
+LL | #![deny(warnings)]
+   |         ^^^^^^^^
+   = note: `#[deny(unused_parens)]` implied by `#[deny(warnings)]`
+help: remove these parentheses
+   |
+LL -     ((for<'a> fn(Inv<'a>)),): Trait,
+LL +     (for<'a> fn(Inv<'a>),): Trait,
+   |
+
+error: aborting due to previous error
+