Skip to content

Commit 7d99866

Browse files
committed
fix #105061, Fix unused_parens issue for higher ranked function pointers
1 parent 44a500c commit 7d99866

File tree

4 files changed

+43
-1
lines changed

4 files changed

+43
-1
lines changed

compiler/rustc_lint/src/early.rs

+6
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,12 @@ impl<'a, T: EarlyLintPass> ast_visit::Visitor<'a> for EarlyContextAndPass<'a, T>
248248
}
249249

250250
fn visit_where_predicate(&mut self, p: &'a ast::WherePredicate) {
251+
use rustc_ast::{WhereBoundPredicate, WherePredicate};
252+
if let WherePredicate::BoundPredicate(WhereBoundPredicate { bounded_ty, .. }) = p &&
253+
let ast::TyKind::BareFn(b) = &bounded_ty.kind &&
254+
b.generic_params.len() > 0 {
255+
return;
256+
}
251257
ast_visit::walk_where_predicate(self, p);
252258
}
253259

compiler/rustc_lint/src/unused.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1002,7 +1002,6 @@ impl EarlyLintPass for UnusedParens {
10021002
if let ast::TyKind::Paren(r) = &ty.kind {
10031003
match &r.kind {
10041004
ast::TyKind::TraitObject(..) => {}
1005-
ast::TyKind::BareFn(b) if b.generic_params.len() > 0 => {}
10061005
ast::TyKind::ImplTrait(_, bounds) if bounds.len() > 1 => {}
10071006
ast::TyKind::Array(_, len) => {
10081007
self.check_unused_delims_expr(

tests/ui/lint/unused/issue-105061.rs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#![warn(unused)]
2+
#![deny(warnings)]
3+
4+
struct Inv<'a>(&'a mut &'a ());
5+
6+
trait Trait {}
7+
impl Trait for (for<'a> fn(Inv<'a>),) {}
8+
9+
10+
fn with_bound()
11+
where
12+
((for<'a> fn(Inv<'a>)),): Trait, //~ ERROR unnecessary parentheses around type
13+
{}
14+
15+
fn main() {
16+
with_bound();
17+
}
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error: unnecessary parentheses around type
2+
--> $DIR/issue-105061.rs:12:6
3+
|
4+
LL | ((for<'a> fn(Inv<'a>)),): Trait,
5+
| ^ ^
6+
|
7+
note: the lint level is defined here
8+
--> $DIR/issue-105061.rs:2:9
9+
|
10+
LL | #![deny(warnings)]
11+
| ^^^^^^^^
12+
= note: `#[deny(unused_parens)]` implied by `#[deny(warnings)]`
13+
help: remove these parentheses
14+
|
15+
LL - ((for<'a> fn(Inv<'a>)),): Trait,
16+
LL + (for<'a> fn(Inv<'a>),): Trait,
17+
|
18+
19+
error: aborting due to previous error
20+

0 commit comments

Comments
 (0)