Skip to content

Commit c67903e

Browse files
committed
fix issues in unused lint
1 parent 7d99866 commit c67903e

File tree

5 files changed

+50
-22
lines changed

5 files changed

+50
-22
lines changed

compiler/rustc_lint/src/early.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -248,13 +248,9 @@ impl<'a, T: EarlyLintPass> ast_visit::Visitor<'a> for EarlyContextAndPass<'a, T>
248248
}
249249

250250
fn visit_where_predicate(&mut self, p: &'a ast::WherePredicate) {
251-
use rustc_ast::{WhereBoundPredicate, WherePredicate};
252-
if let WherePredicate::BoundPredicate(WhereBoundPredicate { bounded_ty, .. }) = p &&
253-
let ast::TyKind::BareFn(b) = &bounded_ty.kind &&
254-
b.generic_params.len() > 0 {
255-
return;
256-
}
251+
lint_callback!(self, enter_where_predicate, p);
257252
ast_visit::walk_where_predicate(self, p);
253+
lint_callback!(self, exit_where_predicate, p);
258254
}
259255

260256
fn visit_poly_trait_ref(&mut self, t: &'a ast::PolyTraitRef) {

compiler/rustc_lint/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ early_lint_methods!(
145145
[
146146
pub BuiltinCombinedEarlyLintPass,
147147
[
148-
UnusedParens: UnusedParens,
148+
UnusedParens: UnusedParens::new(),
149149
UnusedBraces: UnusedBraces,
150150
UnusedImportBraces: UnusedImportBraces,
151151
UnsafeCode: UnsafeCode,

compiler/rustc_lint/src/passes.rs

+3
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,9 @@ macro_rules! early_lint_methods {
171171

172172
/// Counterpart to `enter_lint_attrs`.
173173
fn exit_lint_attrs(a: &[ast::Attribute]);
174+
175+
fn enter_where_predicate(a: &ast::WherePredicate);
176+
fn exit_where_predicate(a: &ast::WherePredicate);
174177
]);
175178
)
176179
}

compiler/rustc_lint/src/unused.rs

+40-11
Original file line numberDiff line numberDiff line change
@@ -824,7 +824,17 @@ declare_lint! {
824824
"`if`, `match`, `while` and `return` do not need parentheses"
825825
}
826826

827-
declare_lint_pass!(UnusedParens => [UNUSED_PARENS]);
827+
pub struct UnusedParens {
828+
with_self_ty_parens: bool,
829+
}
830+
831+
impl UnusedParens {
832+
pub fn new() -> Self {
833+
Self { with_self_ty_parens: false }
834+
}
835+
}
836+
837+
impl_lint_pass!(UnusedParens => [UNUSED_PARENS]);
828838

829839
impl UnusedDelimLint for UnusedParens {
830840
const DELIM_STR: &'static str = "parentheses";
@@ -999,20 +1009,22 @@ impl EarlyLintPass for UnusedParens {
9991009
}
10001010

10011011
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+
}
10021022
if let ast::TyKind::Paren(r) = &ty.kind {
10031023
match &r.kind {
10041024
ast::TyKind::TraitObject(..) => {}
1025+
ast::TyKind::BareFn(b)
1026+
if self.with_self_ty_parens && b.generic_params.len() > 0 => {}
10051027
ast::TyKind::ImplTrait(_, bounds) if bounds.len() > 1 => {}
1006-
ast::TyKind::Array(_, len) => {
1007-
self.check_unused_delims_expr(
1008-
cx,
1009-
&len.value,
1010-
UnusedDelimsCtx::ArrayLenExpr,
1011-
false,
1012-
None,
1013-
None,
1014-
);
1015-
}
10161028
_ => {
10171029
let spans = if let Some(r) = r.span.find_ancestor_inside(ty.span) {
10181030
Some((ty.span.with_hi(r.lo()), ty.span.with_lo(r.hi())))
@@ -1028,6 +1040,23 @@ impl EarlyLintPass for UnusedParens {
10281040
fn check_item(&mut self, cx: &EarlyContext<'_>, item: &ast::Item) {
10291041
<Self as UnusedDelimLint>::check_item(self, cx, item)
10301042
}
1043+
1044+
fn enter_where_predicate(&mut self, _: &EarlyContext<'_>, pred: &ast::WherePredicate) {
1045+
use rustc_ast::{WhereBoundPredicate, WherePredicate};
1046+
if let WherePredicate::BoundPredicate(WhereBoundPredicate {
1047+
bounded_ty,
1048+
bound_generic_params,
1049+
..
1050+
}) = pred &&
1051+
let ast::TyKind::Paren(_) = &bounded_ty.kind &&
1052+
bound_generic_params.is_empty() {
1053+
self.with_self_ty_parens = true;
1054+
}
1055+
}
1056+
1057+
fn exit_where_predicate(&mut self, _: &EarlyContext<'_>, _: &ast::WherePredicate) {
1058+
self.with_self_ty_parens = false;
1059+
}
10311060
}
10321061

10331062
declare_lint! {

library/std/src/io/error/repr_bitpacked.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -374,10 +374,10 @@ static_assert!((TAG_MASK + 1).is_power_of_two());
374374
static_assert!(align_of::<SimpleMessage>() >= TAG_MASK + 1);
375375
static_assert!(align_of::<Custom>() >= TAG_MASK + 1);
376376

377-
static_assert!(@usize_eq: (TAG_MASK & TAG_SIMPLE_MESSAGE), TAG_SIMPLE_MESSAGE);
378-
static_assert!(@usize_eq: (TAG_MASK & TAG_CUSTOM), TAG_CUSTOM);
379-
static_assert!(@usize_eq: (TAG_MASK & TAG_OS), TAG_OS);
380-
static_assert!(@usize_eq: (TAG_MASK & TAG_SIMPLE), TAG_SIMPLE);
377+
static_assert!(@usize_eq: TAG_MASK & TAG_SIMPLE_MESSAGE, TAG_SIMPLE_MESSAGE);
378+
static_assert!(@usize_eq: TAG_MASK & TAG_CUSTOM, TAG_CUSTOM);
379+
static_assert!(@usize_eq: TAG_MASK & TAG_OS, TAG_OS);
380+
static_assert!(@usize_eq: TAG_MASK & TAG_SIMPLE, TAG_SIMPLE);
381381

382382
// This is obviously true (`TAG_CUSTOM` is `0b01`), but in `Repr::new_custom` we
383383
// offset a pointer by this value, and expect it to both be within the same

0 commit comments

Comments
 (0)