Skip to content

Commit 9d74bb8

Browse files
committed
comments feedback
1 parent 644ee8d commit 9d74bb8

File tree

3 files changed

+49
-27
lines changed

3 files changed

+49
-27
lines changed

compiler/rustc_lint/src/unused.rs

+28-24
Original file line numberDiff line numberDiff line change
@@ -1009,31 +1009,35 @@ impl EarlyLintPass for UnusedParens {
10091009
}
10101010

10111011
fn check_ty(&mut self, cx: &EarlyContext<'_>, ty: &ast::Ty) {
1012-
if let ast::TyKind::Array(_, len) = &ty.kind {
1013-
self.check_unused_delims_expr(
1014-
cx,
1015-
&len.value,
1016-
UnusedDelimsCtx::ArrayLenExpr,
1017-
false,
1018-
None,
1019-
None,
1020-
);
1021-
}
1022-
if let ast::TyKind::Paren(r) = &ty.kind {
1023-
match &r.kind {
1024-
ast::TyKind::TraitObject(..) => {}
1025-
ast::TyKind::BareFn(b)
1026-
if self.with_self_ty_parens && b.generic_params.len() > 0 => {}
1027-
ast::TyKind::ImplTrait(_, bounds) if bounds.len() > 1 => {}
1028-
_ => {
1029-
let spans = if let Some(r) = r.span.find_ancestor_inside(ty.span) {
1030-
Some((ty.span.with_hi(r.lo()), ty.span.with_lo(r.hi())))
1031-
} else {
1032-
None
1033-
};
1034-
self.emit_unused_delims(cx, ty.span, spans, "type", (false, false));
1012+
match &ty.kind {
1013+
ast::TyKind::Array(_, len) => {
1014+
self.check_unused_delims_expr(
1015+
cx,
1016+
&len.value,
1017+
UnusedDelimsCtx::ArrayLenExpr,
1018+
false,
1019+
None,
1020+
None,
1021+
);
1022+
}
1023+
ast::TyKind::Paren(r) => {
1024+
match &r.kind {
1025+
ast::TyKind::TraitObject(..) => {}
1026+
ast::TyKind::BareFn(b)
1027+
if self.with_self_ty_parens && b.generic_params.len() > 0 => {}
1028+
ast::TyKind::ImplTrait(_, bounds) if bounds.len() > 1 => {}
1029+
_ => {
1030+
let spans = if let Some(r) = r.span.find_ancestor_inside(ty.span) {
1031+
Some((ty.span.with_hi(r.lo()), ty.span.with_lo(r.hi())))
1032+
} else {
1033+
None
1034+
};
1035+
self.emit_unused_delims(cx, ty.span, spans, "type", (false, false));
1036+
}
10351037
}
1038+
self.with_self_ty_parens = false;
10361039
}
1040+
_ => {}
10371041
}
10381042
}
10391043

@@ -1055,7 +1059,7 @@ impl EarlyLintPass for UnusedParens {
10551059
}
10561060

10571061
fn exit_where_predicate(&mut self, _: &EarlyContext<'_>, _: &ast::WherePredicate) {
1058-
self.with_self_ty_parens = false;
1062+
assert!(!self.with_self_ty_parens);
10591063
}
10601064
}
10611065

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

+7-1
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,18 @@ struct Inv<'a>(&'a mut &'a ());
66
trait Trait<'a> {}
77
impl<'b> Trait<'b> for for<'a> fn(Inv<'a>) {}
88

9-
109
fn with_bound()
1110
where
1211
for<'b> (for<'a> fn(Inv<'a>)): Trait<'b>, //~ ERROR unnecessary parentheses around type
1312
{}
1413

14+
trait Hello<T> {}
15+
fn with_dyn_bound<T>()
16+
where
17+
(dyn Hello<(for<'b> fn(&'b ()))>): Hello<T> //~ ERROR unnecessary parentheses around type
18+
{}
19+
1520
fn main() {
1621
with_bound();
22+
with_dyn_bound();
1723
}

tests/ui/lint/unused/issue-105061-should-lint.stderr

+14-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: unnecessary parentheses around type
2-
--> $DIR/issue-105061-should-lint.rs:12:13
2+
--> $DIR/issue-105061-should-lint.rs:11:13
33
|
44
LL | for<'b> (for<'a> fn(Inv<'a>)): Trait<'b>,
55
| ^ ^
@@ -16,5 +16,17 @@ LL - for<'b> (for<'a> fn(Inv<'a>)): Trait<'b>,
1616
LL + for<'b> for<'a> fn(Inv<'a>): Trait<'b>,
1717
|
1818

19-
error: aborting due to previous error
19+
error: unnecessary parentheses around type
20+
--> $DIR/issue-105061-should-lint.rs:17:16
21+
|
22+
LL | (dyn Hello<(for<'b> fn(&'b ()))>): Hello<T>
23+
| ^ ^
24+
|
25+
help: remove these parentheses
26+
|
27+
LL - (dyn Hello<(for<'b> fn(&'b ()))>): Hello<T>
28+
LL + (dyn Hello<for<'b> fn(&'b ())>): Hello<T>
29+
|
30+
31+
error: aborting due to 2 previous errors
2032

0 commit comments

Comments
 (0)