diff options
| -rw-r--r-- | compiler/rustc_lint/src/unused.rs | 52 | ||||
| -rw-r--r-- | tests/ui/lint/unused/issue-105061-should-lint.rs | 8 | ||||
| -rw-r--r-- | tests/ui/lint/unused/issue-105061-should-lint.stderr | 16 |
3 files changed, 49 insertions, 27 deletions
diff --git a/compiler/rustc_lint/src/unused.rs b/compiler/rustc_lint/src/unused.rs index 65f2644a858..e40530a6dd6 100644 --- a/compiler/rustc_lint/src/unused.rs +++ b/compiler/rustc_lint/src/unused.rs @@ -1009,31 +1009,35 @@ impl EarlyLintPass for UnusedParens { } fn check_ty(&mut self, cx: &EarlyContext<'_>, ty: &ast::Ty) { - if let ast::TyKind::Array(_, len) = &ty.kind { - self.check_unused_delims_expr( - cx, - &len.value, - UnusedDelimsCtx::ArrayLenExpr, - false, - None, - None, - ); - } - if let ast::TyKind::Paren(r) = &ty.kind { - match &r.kind { - ast::TyKind::TraitObject(..) => {} - ast::TyKind::BareFn(b) - if self.with_self_ty_parens && b.generic_params.len() > 0 => {} - ast::TyKind::ImplTrait(_, bounds) if bounds.len() > 1 => {} - _ => { - let spans = if let Some(r) = r.span.find_ancestor_inside(ty.span) { - Some((ty.span.with_hi(r.lo()), ty.span.with_lo(r.hi()))) - } else { - None - }; - self.emit_unused_delims(cx, ty.span, spans, "type", (false, false)); + match &ty.kind { + ast::TyKind::Array(_, len) => { + self.check_unused_delims_expr( + cx, + &len.value, + UnusedDelimsCtx::ArrayLenExpr, + false, + None, + None, + ); + } + ast::TyKind::Paren(r) => { + match &r.kind { + ast::TyKind::TraitObject(..) => {} + ast::TyKind::BareFn(b) + if self.with_self_ty_parens && b.generic_params.len() > 0 => {} + ast::TyKind::ImplTrait(_, bounds) if bounds.len() > 1 => {} + _ => { + let spans = if let Some(r) = r.span.find_ancestor_inside(ty.span) { + Some((ty.span.with_hi(r.lo()), ty.span.with_lo(r.hi()))) + } else { + None + }; + self.emit_unused_delims(cx, ty.span, spans, "type", (false, false)); + } } + self.with_self_ty_parens = false; } + _ => {} } } @@ -1055,7 +1059,7 @@ impl EarlyLintPass for UnusedParens { } fn exit_where_predicate(&mut self, _: &EarlyContext<'_>, _: &ast::WherePredicate) { - self.with_self_ty_parens = false; + assert!(!self.with_self_ty_parens); } } diff --git a/tests/ui/lint/unused/issue-105061-should-lint.rs b/tests/ui/lint/unused/issue-105061-should-lint.rs index ff47e1734f7..7e4e0947349 100644 --- a/tests/ui/lint/unused/issue-105061-should-lint.rs +++ b/tests/ui/lint/unused/issue-105061-should-lint.rs @@ -6,12 +6,18 @@ struct Inv<'a>(&'a mut &'a ()); trait Trait<'a> {} impl<'b> Trait<'b> for for<'a> fn(Inv<'a>) {} - fn with_bound() where for<'b> (for<'a> fn(Inv<'a>)): Trait<'b>, //~ ERROR unnecessary parentheses around type {} +trait Hello<T> {} +fn with_dyn_bound<T>() +where + (dyn Hello<(for<'b> fn(&'b ()))>): Hello<T> //~ ERROR unnecessary parentheses around type +{} + fn main() { with_bound(); + with_dyn_bound(); } diff --git a/tests/ui/lint/unused/issue-105061-should-lint.stderr b/tests/ui/lint/unused/issue-105061-should-lint.stderr index 60b1af71e0e..e591f1ffb6b 100644 --- a/tests/ui/lint/unused/issue-105061-should-lint.stderr +++ b/tests/ui/lint/unused/issue-105061-should-lint.stderr @@ -1,5 +1,5 @@ error: unnecessary parentheses around type - --> $DIR/issue-105061-should-lint.rs:12:13 + --> $DIR/issue-105061-should-lint.rs:11:13 | LL | for<'b> (for<'a> fn(Inv<'a>)): Trait<'b>, | ^ ^ @@ -16,5 +16,17 @@ LL - for<'b> (for<'a> fn(Inv<'a>)): Trait<'b>, LL + for<'b> for<'a> fn(Inv<'a>): Trait<'b>, | -error: aborting due to previous error +error: unnecessary parentheses around type + --> $DIR/issue-105061-should-lint.rs:17:16 + | +LL | (dyn Hello<(for<'b> fn(&'b ()))>): Hello<T> + | ^ ^ + | +help: remove these parentheses + | +LL - (dyn Hello<(for<'b> fn(&'b ()))>): Hello<T> +LL + (dyn Hello<for<'b> fn(&'b ())>): Hello<T> + | + +error: aborting due to 2 previous errors |
