mirror of
https://github.com/rust-lang/rust.git
synced 2024-10-31 22:41:50 +00:00
comments feedback
This commit is contained in:
parent
644ee8d250
commit
9d74bb832f
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user