]> git.lizzy.rs Git - rust.git/commitdiff
fix #105061, Fix unused_parens issue for higher ranked function pointers
authoryukang <moorekang@gmail.com>
Fri, 23 Dec 2022 18:41:06 +0000 (02:41 +0800)
committeryukang <moorekang@gmail.com>
Sat, 14 Jan 2023 09:11:04 +0000 (17:11 +0800)
compiler/rustc_lint/src/early.rs
compiler/rustc_lint/src/unused.rs
tests/ui/lint/unused/issue-105061.rs [new file with mode: 0644]
tests/ui/lint/unused/issue-105061.stderr [new file with mode: 0644]

index f9b2df49592244fa701928bfbe71eeac0357df41..3901751c79fb0853646685d88a56f04dcf947256 100644 (file)
@@ -248,6 +248,12 @@ fn visit_generics(&mut self, g: &'a ast::Generics) {
     }
 
     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);
     }
 
index ac2b32b44e6a1d42e16ab70e7f41872df229b829..94a33138107171218c9f600b9b8c6c270e379d70 100644 (file)
@@ -1002,7 +1002,6 @@ fn check_ty(&mut self, cx: &EarlyContext<'_>, ty: &ast::Ty) {
         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 (file)
index 0000000..92d636d
--- /dev/null
@@ -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 (file)
index 0000000..f07aa20
--- /dev/null
@@ -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
+