fix issues in unused lint
This commit is contained in:
parent
7d99866bfc
commit
c67903ef21
@ -248,13 +248,9 @@ impl<'a, T: EarlyLintPass> ast_visit::Visitor<'a> for EarlyContextAndPass<'a, T>
|
||||
}
|
||||
|
||||
fn visit_where_predicate(&mut self, p: &'a ast::WherePredicate) {
|
||||
use rustc_ast::{WhereBoundPredicate, WherePredicate};
|
||||
if let WherePredicate::BoundPredicate(WhereBoundPredicate { bounded_ty, .. }) = p &&
|
||||
let ast::TyKind::BareFn(b) = &bounded_ty.kind &&
|
||||
b.generic_params.len() > 0 {
|
||||
return;
|
||||
}
|
||||
lint_callback!(self, enter_where_predicate, p);
|
||||
ast_visit::walk_where_predicate(self, p);
|
||||
lint_callback!(self, exit_where_predicate, p);
|
||||
}
|
||||
|
||||
fn visit_poly_trait_ref(&mut self, t: &'a ast::PolyTraitRef) {
|
||||
|
@ -145,7 +145,7 @@ early_lint_methods!(
|
||||
[
|
||||
pub BuiltinCombinedEarlyLintPass,
|
||||
[
|
||||
UnusedParens: UnusedParens,
|
||||
UnusedParens: UnusedParens::new(),
|
||||
UnusedBraces: UnusedBraces,
|
||||
UnusedImportBraces: UnusedImportBraces,
|
||||
UnsafeCode: UnsafeCode,
|
||||
|
@ -171,6 +171,9 @@ macro_rules! early_lint_methods {
|
||||
|
||||
/// Counterpart to `enter_lint_attrs`.
|
||||
fn exit_lint_attrs(a: &[ast::Attribute]);
|
||||
|
||||
fn enter_where_predicate(a: &ast::WherePredicate);
|
||||
fn exit_where_predicate(a: &ast::WherePredicate);
|
||||
]);
|
||||
)
|
||||
}
|
||||
|
@ -824,7 +824,17 @@ declare_lint! {
|
||||
"`if`, `match`, `while` and `return` do not need parentheses"
|
||||
}
|
||||
|
||||
declare_lint_pass!(UnusedParens => [UNUSED_PARENS]);
|
||||
pub struct UnusedParens {
|
||||
with_self_ty_parens: bool,
|
||||
}
|
||||
|
||||
impl UnusedParens {
|
||||
pub fn new() -> Self {
|
||||
Self { with_self_ty_parens: false }
|
||||
}
|
||||
}
|
||||
|
||||
impl_lint_pass!(UnusedParens => [UNUSED_PARENS]);
|
||||
|
||||
impl UnusedDelimLint for UnusedParens {
|
||||
const DELIM_STR: &'static str = "parentheses";
|
||||
@ -999,20 +1009,22 @@ 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 => {}
|
||||
ast::TyKind::Array(_, len) => {
|
||||
self.check_unused_delims_expr(
|
||||
cx,
|
||||
&len.value,
|
||||
UnusedDelimsCtx::ArrayLenExpr,
|
||||
false,
|
||||
None,
|
||||
None,
|
||||
);
|
||||
}
|
||||
_ => {
|
||||
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())))
|
||||
@ -1028,6 +1040,23 @@ impl EarlyLintPass for UnusedParens {
|
||||
fn check_item(&mut self, cx: &EarlyContext<'_>, item: &ast::Item) {
|
||||
<Self as UnusedDelimLint>::check_item(self, cx, item)
|
||||
}
|
||||
|
||||
fn enter_where_predicate(&mut self, _: &EarlyContext<'_>, pred: &ast::WherePredicate) {
|
||||
use rustc_ast::{WhereBoundPredicate, WherePredicate};
|
||||
if let WherePredicate::BoundPredicate(WhereBoundPredicate {
|
||||
bounded_ty,
|
||||
bound_generic_params,
|
||||
..
|
||||
}) = pred &&
|
||||
let ast::TyKind::Paren(_) = &bounded_ty.kind &&
|
||||
bound_generic_params.is_empty() {
|
||||
self.with_self_ty_parens = true;
|
||||
}
|
||||
}
|
||||
|
||||
fn exit_where_predicate(&mut self, _: &EarlyContext<'_>, _: &ast::WherePredicate) {
|
||||
self.with_self_ty_parens = false;
|
||||
}
|
||||
}
|
||||
|
||||
declare_lint! {
|
||||
|
@ -374,10 +374,10 @@ static_assert!((TAG_MASK + 1).is_power_of_two());
|
||||
static_assert!(align_of::<SimpleMessage>() >= TAG_MASK + 1);
|
||||
static_assert!(align_of::<Custom>() >= TAG_MASK + 1);
|
||||
|
||||
static_assert!(@usize_eq: (TAG_MASK & TAG_SIMPLE_MESSAGE), TAG_SIMPLE_MESSAGE);
|
||||
static_assert!(@usize_eq: (TAG_MASK & TAG_CUSTOM), TAG_CUSTOM);
|
||||
static_assert!(@usize_eq: (TAG_MASK & TAG_OS), TAG_OS);
|
||||
static_assert!(@usize_eq: (TAG_MASK & TAG_SIMPLE), TAG_SIMPLE);
|
||||
static_assert!(@usize_eq: TAG_MASK & TAG_SIMPLE_MESSAGE, TAG_SIMPLE_MESSAGE);
|
||||
static_assert!(@usize_eq: TAG_MASK & TAG_CUSTOM, TAG_CUSTOM);
|
||||
static_assert!(@usize_eq: TAG_MASK & TAG_OS, TAG_OS);
|
||||
static_assert!(@usize_eq: TAG_MASK & TAG_SIMPLE, TAG_SIMPLE);
|
||||
|
||||
// This is obviously true (`TAG_CUSTOM` is `0b01`), but in `Repr::new_custom` we
|
||||
// offset a pointer by this value, and expect it to both be within the same
|
||||
|
Loading…
x
Reference in New Issue
Block a user