comments feedback
This commit is contained in:
parent
644ee8d250
commit
9d74bb832f
3 changed files with 50 additions and 28 deletions
|
@ -1009,31 +1009,35 @@ impl EarlyLintPass for UnusedParens {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_ty(&mut self, cx: &EarlyContext<'_>, ty: &ast::Ty) {
|
fn check_ty(&mut self, cx: &EarlyContext<'_>, ty: &ast::Ty) {
|
||||||
if let ast::TyKind::Array(_, len) = &ty.kind {
|
match &ty.kind {
|
||||||
self.check_unused_delims_expr(
|
ast::TyKind::Array(_, len) => {
|
||||||
cx,
|
self.check_unused_delims_expr(
|
||||||
&len.value,
|
cx,
|
||||||
UnusedDelimsCtx::ArrayLenExpr,
|
&len.value,
|
||||||
false,
|
UnusedDelimsCtx::ArrayLenExpr,
|
||||||
None,
|
false,
|
||||||
None,
|
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));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
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) {
|
fn exit_where_predicate(&mut self, _: &EarlyContext<'_>, _: &ast::WherePredicate) {
|
||||||
self.with_self_ty_parens = false;
|
assert!(!self.with_self_ty_parens);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,12 +6,18 @@ struct Inv<'a>(&'a mut &'a ());
|
||||||
trait Trait<'a> {}
|
trait Trait<'a> {}
|
||||||
impl<'b> Trait<'b> for for<'a> fn(Inv<'a>) {}
|
impl<'b> Trait<'b> for for<'a> fn(Inv<'a>) {}
|
||||||
|
|
||||||
|
|
||||||
fn with_bound()
|
fn with_bound()
|
||||||
where
|
where
|
||||||
for<'b> (for<'a> fn(Inv<'a>)): Trait<'b>, //~ ERROR unnecessary parentheses around type
|
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() {
|
fn main() {
|
||||||
with_bound();
|
with_bound();
|
||||||
|
with_dyn_bound();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
error: unnecessary parentheses around type
|
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>,
|
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>,
|
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
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue