Skip to content

Commit aa03344

Browse files
committed
Auto merge of #8797 - xFrednet:0000-expect-a-playground, r=flip1995
Replace `#[allow]` with `#[expect]` in Clippy Hey `@rust-lang/clippy,` `@Alexendoo,` `@dswij,` I'm currently working on the expect attribute as defined in [Rust RFC 2383](https://rust-lang.github.io/rfcs/2383-lint-reasons.html). With that, an `#[allow]` attribute can be replaced with a `#[expect]` attribute that suppresses the lint, but also emits a warning, if the lint isn't emitted in the expected scope. With this PR I would like to test the attribute on a project scale and Clippy obviously came to mind. This PR replaces (almost) all `#[allow]` attributes in `clippy_utils` and `clippy_lints` with the `#[expect]` attribute. I was also able to remove some allows since, the related FPs have been fixed 🎉. My question is now, are there any concerns regarding this? It's still okay to add normal `#[allow]` attributes, I see the need to nit-pick about that in new PRs, unless it's actually a FP. Also, I would not recommend using `#[expect]` in tests, as changes to a lint could the trigger the expect attribute in other files. Additionally, I've noticed that Clippy has a bunch of `#[allow(clippy::too_many_lines)]` attributes. Should we maybe allow the lint all together or increase the threshold setting? To me, it seems like we mostly just ignore it in our code. 😅 🙃 --- changelog: none r? `@flip1995` (I've requested you for now, since you're also helping with reviewing the expect implementation. You are welcome to delegate this PR, even if it should be a simple review 🙃 )
2 parents c3f3c58 + 03960eb commit aa03344

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+73
-93
lines changed

clippy_lints/src/booleans.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ impl<'a, 'tcx, 'v> Hir2Qmm<'a, 'tcx, 'v> {
137137
}
138138
for (n, expr) in self.terminals.iter().enumerate() {
139139
if eq_expr_value(self.cx, e, expr) {
140-
#[allow(clippy::cast_possible_truncation)]
140+
#[expect(clippy::cast_possible_truncation)]
141141
return Ok(Bool::Term(n as u8));
142142
}
143143

@@ -149,15 +149,15 @@ impl<'a, 'tcx, 'v> Hir2Qmm<'a, 'tcx, 'v> {
149149
if eq_expr_value(self.cx, e_lhs, expr_lhs);
150150
if eq_expr_value(self.cx, e_rhs, expr_rhs);
151151
then {
152-
#[allow(clippy::cast_possible_truncation)]
152+
#[expect(clippy::cast_possible_truncation)]
153153
return Ok(Bool::Not(Box::new(Bool::Term(n as u8))));
154154
}
155155
}
156156
}
157157
let n = self.terminals.len();
158158
self.terminals.push(e);
159159
if n < 32 {
160-
#[allow(clippy::cast_possible_truncation)]
160+
#[expect(clippy::cast_possible_truncation)]
161161
Ok(Bool::Term(n as u8))
162162
} else {
163163
Err("too many literals".to_owned())

clippy_lints/src/cognitive_complexity.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ impl CognitiveComplexity {
4848
impl_lint_pass!(CognitiveComplexity => [COGNITIVE_COMPLEXITY]);
4949

5050
impl CognitiveComplexity {
51-
#[allow(clippy::cast_possible_truncation)]
51+
#[expect(clippy::cast_possible_truncation)]
5252
fn check<'tcx>(
5353
&mut self,
5454
cx: &LateContext<'tcx>,
@@ -70,7 +70,7 @@ impl CognitiveComplexity {
7070
let ret_adjust = if is_type_diagnostic_item(cx, ret_ty, sym::Result) {
7171
returns
7272
} else {
73-
#[allow(clippy::integer_division)]
73+
#[expect(clippy::integer_division)]
7474
(returns / 2)
7575
};
7676

clippy_lints/src/default.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ impl<'tcx> LateLintPass<'tcx> for Default {
110110
}
111111
}
112112

113-
#[allow(clippy::too_many_lines)]
113+
#[expect(clippy::too_many_lines)]
114114
fn check_block(&mut self, cx: &LateContext<'tcx>, block: &Block<'tcx>) {
115115
// start from the `let mut _ = _::default();` and look at all the following
116116
// statements, see if they re-assign the fields of the binding

clippy_lints/src/default_numeric_fallback.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ impl<'a, 'tcx> NumericFallbackVisitor<'a, 'tcx> {
116116
}
117117

118118
impl<'a, 'tcx> Visitor<'tcx> for NumericFallbackVisitor<'a, 'tcx> {
119-
#[allow(clippy::too_many_lines)]
120119
fn visit_expr(&mut self, expr: &'tcx Expr<'_>) {
121120
match &expr.kind {
122121
ExprKind::Call(func, args) => {

clippy_lints/src/dereference.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ struct RefPat {
168168
}
169169

170170
impl<'tcx> LateLintPass<'tcx> for Dereferencing {
171-
#[allow(clippy::too_many_lines)]
171+
#[expect(clippy::too_many_lines)]
172172
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
173173
// Skip path expressions from deref calls. e.g. `Deref::deref(e)`
174174
if Some(expr.hir_id) == self.skip_expr.take() {
@@ -580,7 +580,7 @@ fn find_adjustments<'tcx>(
580580
}
581581
}
582582

583-
#[allow(clippy::needless_pass_by_value)]
583+
#[expect(clippy::needless_pass_by_value)]
584584
fn report(cx: &LateContext<'_>, expr: &Expr<'_>, state: State, data: StateData) {
585585
match state {
586586
State::DerefMethod {

clippy_lints/src/doc.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ declare_clippy_lint! {
198198
"presence of `fn main() {` in code examples"
199199
}
200200

201-
#[allow(clippy::module_name_repetitions)]
201+
#[expect(clippy::module_name_repetitions)]
202202
#[derive(Clone)]
203203
pub struct DocMarkdown {
204204
valid_idents: FxHashSet<String>,
@@ -373,7 +373,7 @@ fn lint_for_missing_headers<'tcx>(
373373
/// `rustc_ast::parse::lexer::comments::strip_doc_comment_decoration` because we
374374
/// need to keep track of
375375
/// the spans but this function is inspired from the later.
376-
#[allow(clippy::cast_possible_truncation)]
376+
#[expect(clippy::cast_possible_truncation)]
377377
#[must_use]
378378
pub fn strip_doc_comment_decoration(doc: &str, comment_kind: CommentKind, span: Span) -> (String, Vec<(usize, Span)>) {
379379
// one-line comments lose their prefix
@@ -428,7 +428,7 @@ fn check_attrs<'a>(cx: &LateContext<'_>, valid_idents: &FxHashSet<String>, attrs
428428
/// We don't want the parser to choke on intra doc links. Since we don't
429429
/// actually care about rendering them, just pretend that all broken links are
430430
/// point to a fake address.
431-
#[allow(clippy::unnecessary_wraps)] // we're following a type signature
431+
#[expect(clippy::unnecessary_wraps)] // we're following a type signature
432432
fn fake_broken_link_callback<'a>(_: BrokenLink<'_>) -> Option<(CowStr<'a>, CowStr<'a>)> {
433433
Some(("fake".into(), "fake".into()))
434434
}

clippy_lints/src/double_comparison.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ declare_clippy_lint! {
4040
declare_lint_pass!(DoubleComparisons => [DOUBLE_COMPARISONS]);
4141

4242
impl<'tcx> DoubleComparisons {
43-
#[allow(clippy::similar_names)]
43+
#[expect(clippy::similar_names)]
4444
fn check_binop(cx: &LateContext<'tcx>, op: BinOpKind, lhs: &'tcx Expr<'_>, rhs: &'tcx Expr<'_>, span: Span) {
4545
let (lkind, llhs, lrhs, rkind, rlhs, rrhs) = match (&lhs.kind, &rhs.kind) {
4646
(ExprKind::Binary(lb, llhs, lrhs), ExprKind::Binary(rb, rlhs, rrhs)) => {

clippy_lints/src/entry.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ declare_clippy_lint! {
6363
declare_lint_pass!(HashMapPass => [MAP_ENTRY]);
6464

6565
impl<'tcx> LateLintPass<'tcx> for HashMapPass {
66-
#[allow(clippy::too_many_lines)]
66+
#[expect(clippy::too_many_lines)]
6767
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
6868
let (cond_expr, then_expr, else_expr) = match higher::If::hir(expr) {
6969
Some(higher::If { cond, then, r#else }) => (cond, then, r#else),
@@ -319,7 +319,7 @@ struct Insertion<'tcx> {
319319
/// `or_insert_with`.
320320
/// * Determine if there's any sub-expression that can't be placed in a closure.
321321
/// * Determine if there's only a single insert statement. `or_insert` can be used in this case.
322-
#[allow(clippy::struct_excessive_bools)]
322+
#[expect(clippy::struct_excessive_bools)]
323323
struct InsertSearcher<'cx, 'tcx> {
324324
cx: &'cx LateContext<'tcx>,
325325
/// The map expression used in the contains call.

clippy_lints/src/enum_clike.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ declare_clippy_lint! {
3737
declare_lint_pass!(UnportableVariant => [ENUM_CLIKE_UNPORTABLE_VARIANT]);
3838

3939
impl<'tcx> LateLintPass<'tcx> for UnportableVariant {
40-
#[allow(clippy::cast_possible_truncation, clippy::cast_possible_wrap, clippy::cast_sign_loss)]
40+
#[expect(clippy::cast_possible_wrap)]
4141
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
4242
if cx.tcx.data_layout.pointer_size.bits() != 64 {
4343
return;

clippy_lints/src/enum_variants.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ impl LateLintPass<'_> for EnumVariantNames {
240240
assert!(last.is_some());
241241
}
242242

243-
#[allow(clippy::similar_names)]
243+
#[expect(clippy::similar_names)]
244244
fn check_item(&mut self, cx: &LateContext<'_>, item: &Item<'_>) {
245245
let item_name = item.ident.name.as_str();
246246
let item_camel = to_camel_case(item_name);

0 commit comments

Comments
 (0)