Skip to content

Commit 1ddb9f2

Browse files
Revert #152369 because of multiple regressions
The regressions are documented in the PR comments. This reverts commit 2972b5e, reversing changes made to f908263.
1 parent 624a067 commit 1ddb9f2

9 files changed

Lines changed: 69 additions & 66 deletions

clippy_lints/src/attrs/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ impl EarlyLintPass for PostExpansionEarlyAttributes {
583583
if matches!(name, sym::allow | sym::expect) && self.msrv.meets(msrvs::LINT_REASONS_STABILIZATION) {
584584
allow_attributes_without_reason::check(cx, name, items, attr);
585585
}
586-
if is_lint_level(name) {
586+
if is_lint_level(name, attr.id) {
587587
blanket_clippy_restriction_lints::check(cx, name, items);
588588
}
589589
if items.is_empty() || !attr.has_name(sym::deprecated) {

clippy_lints/src/attrs/unnecessary_clippy_cfg.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
use crate::attrs::is_lint_level;
2-
31
use super::{Attribute, UNNECESSARY_CLIPPY_CFG};
42
use clippy_utils::diagnostics::{span_lint_and_note, span_lint_and_sugg};
53
use clippy_utils::source::SpanRangeExt;
64
use itertools::Itertools;
75
use rustc_ast::AttrStyle;
86
use rustc_errors::Applicability;
9-
use rustc_lint::{EarlyContext};
7+
use rustc_lint::{EarlyContext, Level};
108
use rustc_span::sym;
119

1210
pub(super) fn check(
@@ -15,10 +13,9 @@ pub(super) fn check(
1513
behind_cfg_attr: &rustc_ast::MetaItem,
1614
attr: &Attribute,
1715
) {
18-
// FIXME use proper attr parsing here
1916
if cfg_attr.has_name(sym::clippy)
2017
&& let Some(ident) = behind_cfg_attr.ident()
21-
&& is_lint_level(ident.name)
18+
&& Level::from_symbol(ident.name, || Some(attr.id)).is_some()
2219
&& let Some(items) = behind_cfg_attr.meta_item_list()
2320
{
2421
let nb_items = items.len();

clippy_lints/src/attrs/useless_attribute.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub(super) fn check(cx: &EarlyContext<'_>, item: &Item, attrs: &[Attribute]) {
1515
return;
1616
}
1717
if let Some(lint_list) = &attr.meta_item_list()
18-
&& attr.name().is_some_and(is_lint_level)
18+
&& attr.name().is_some_and(|name| is_lint_level(name, attr.id))
1919
{
2020
for lint in lint_list {
2121
match item.kind {

clippy_lints/src/attrs/utils.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use clippy_utils::macros::{is_panic, macro_backtrace};
2-
use rustc_ast::{MetaItemInner};
2+
use rustc_ast::{AttrId, MetaItemInner};
33
use rustc_hir::{
44
Block, Expr, ExprKind, ImplItem, ImplItemKind, Item, ItemKind, StmtKind, TraitFn, TraitItem, TraitItemKind,
55
};
@@ -16,8 +16,8 @@ pub(super) fn is_word(nmi: &MetaItemInner, expected: Symbol) -> bool {
1616
}
1717
}
1818

19-
pub(super) fn is_lint_level(symbol: Symbol) -> bool {
20-
Level::from_symbol(symbol).is_some()
19+
pub(super) fn is_lint_level(symbol: Symbol, attr_id: AttrId) -> bool {
20+
Level::from_symbol(symbol, || Some(attr_id)).is_some()
2121
}
2222

2323
pub(super) fn is_relevant_item(cx: &LateContext<'_>, item: &Item<'_>) -> bool {

clippy_lints/src/collapsible_if.rs

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@ use clippy_utils::diagnostics::span_lint_hir_and_then;
33
use clippy_utils::msrvs::Msrv;
44
use clippy_utils::source::{HasSession, IntoSpan as _, SpanRangeExt, snippet, snippet_block_with_applicability};
55
use clippy_utils::{can_use_if_let_chains, span_contains_cfg, span_contains_non_whitespace, sym, tokenize_with_text};
6-
use rustc_ast::BinOpKind;
6+
use rustc_ast::{BinOpKind, MetaItemInner};
77
use rustc_errors::Applicability;
8-
use rustc_hir::attrs::{AttributeKind, LintAttributeKind};
9-
use rustc_hir::{Attribute, Block, Expr, ExprKind, StmtKind};
8+
use rustc_hir::{Block, Expr, ExprKind, StmtKind};
109
use rustc_lexer::TokenKind;
11-
use rustc_lint::{LateContext, LateLintPass};
10+
use rustc_lint::{LateContext, LateLintPass, Level};
1211
use rustc_session::impl_lint_pass;
1312
use rustc_span::{BytePos, Span, Symbol};
1413

@@ -238,24 +237,19 @@ impl CollapsibleIf {
238237
!span_contains_non_whitespace(cx, span, self.lint_commented_code)
239238
},
240239

241-
[Attribute::Parsed(AttributeKind::LintAttributes(sub_attrs))] => {
242-
sub_attrs
243-
.into_iter()
244-
.filter(|attr| attr.kind == LintAttributeKind::Expect)
245-
.flat_map(|attr| attr.lint_instances.iter().map(|group| (attr.attr_span, group)))
246-
.filter(|(_, lint_id)| {
247-
lint_id.tool_is_named(sym::clippy)
248-
&& (expected_lint_name == lint_id.lint_name()
249-
|| [expected_lint_name, sym::style, sym::all]
250-
.contains(&lint_id.original_name_without_tool()))
251-
})
252-
.any(|(attr_span, _)| {
253-
// There is an `expect` attribute -- check that there is no _other_ significant text
254-
let span_before_attr = inner_if.span.split_at(1).1.until(attr_span);
255-
let span_after_attr = attr_span.between(inner_if_expr.span);
256-
!span_contains_non_whitespace(cx, span_before_attr, self.lint_commented_code)
257-
&& !span_contains_non_whitespace(cx, span_after_attr, self.lint_commented_code)
258-
})
240+
[attr]
241+
if matches!(Level::from_attr(attr), Some((Level::Expect, _)))
242+
&& let Some(metas) = attr.meta_item_list()
243+
&& let Some(MetaItemInner::MetaItem(meta_item)) = metas.first()
244+
&& let [tool, lint_name] = meta_item.path.segments.as_slice()
245+
&& tool.ident.name == sym::clippy
246+
&& [expected_lint_name, sym::style, sym::all].contains(&lint_name.ident.name) =>
247+
{
248+
// There is an `expect` attribute -- check that there is no _other_ significant text
249+
let span_before_attr = inner_if.span.split_at(1).1.until(attr.span());
250+
let span_after_attr = attr.span().between(inner_if_expr.span);
251+
!span_contains_non_whitespace(cx, span_before_attr, self.lint_commented_code)
252+
&& !span_contains_non_whitespace(cx, span_after_attr, self.lint_commented_code)
259253
},
260254

261255
// There are other attributes, which are significant tokens -- check failed

clippy_lints/src/returns/needless_return.rs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ use clippy_utils::{
44
binary_expr_needs_parentheses, is_from_proc_macro, leaks_droppable_temporary_with_limited_lifetime,
55
span_contains_cfg, span_find_starting_semi, sym,
66
};
7+
use rustc_ast::MetaItemInner;
78
use rustc_errors::Applicability;
8-
use rustc_hir::attrs::{AttributeKind, LintAttributeKind};
99
use rustc_hir::intravisit::FnKind;
10-
use rustc_hir::{Attribute, Body, Expr, ExprKind, HirId, LangItem, MatchSource, StmtKind};
11-
use rustc_lint::{LateContext, LintContext};
10+
use rustc_hir::{Body, Expr, ExprKind, HirId, LangItem, MatchSource, StmtKind};
11+
use rustc_lint::{LateContext, Level, LintContext};
1212
use rustc_middle::ty::{self, Ty};
1313
use rustc_span::{BytePos, Pos, Span};
1414
use std::borrow::Cow;
@@ -180,18 +180,20 @@ fn check_final_expr<'tcx>(
180180
// actually fulfill the expectation (clippy::#12998)
181181
match cx.tcx.hir_attrs(expr.hir_id) {
182182
[] => {},
183-
[Attribute::Parsed(AttributeKind::LintAttributes(sub_attrs))] => {
184-
if !sub_attrs
185-
.into_iter()
186-
.filter(|attr| attr.kind == LintAttributeKind::Expect)
187-
.flat_map(|attr| &attr.lint_instances)
188-
.any(|lint| {
189-
matches!(
190-
lint.original_name_without_tool(),
191-
sym::needless_return | sym::style | sym::all | sym::warnings
192-
)
193-
})
183+
[attr] => {
184+
if matches!(Level::from_attr(attr), Some((Level::Expect, _)))
185+
&& let metas = attr.meta_item_list()
186+
&& let Some(lst) = metas
187+
&& let [MetaItemInner::MetaItem(meta_item), ..] = lst.as_slice()
188+
&& let [tool, lint_name] = meta_item.path.segments.as_slice()
189+
&& tool.ident.name == sym::clippy
190+
&& matches!(
191+
lint_name.ident.name,
192+
sym::needless_return | sym::style | sym::all | sym::warnings
193+
)
194194
{
195+
// This is an expectation of the `needless_return` lint
196+
} else {
195197
return;
196198
}
197199
},

tests/ui/expect_tool_lint_rfc_2383.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ mod rustc_warn {
3636

3737
#[expect(invalid_nan_comparisons)]
3838
//~^ ERROR: this lint expectation is unfulfilled
39+
//~| NOTE: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
40+
//~| ERROR: this lint expectation is unfulfilled
3941
let _b = x == 5;
4042
}
4143
}

tests/ui/expect_tool_lint_rfc_2383.stderr

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,36 @@ LL | #[expect(invalid_nan_comparisons)]
1414
| ^^^^^^^^^^^^^^^^^^^^^^^
1515

1616
error: this lint expectation is unfulfilled
17-
--> tests/ui/expect_tool_lint_rfc_2383.rs:108:14
17+
--> tests/ui/expect_tool_lint_rfc_2383.rs:37:18
18+
|
19+
LL | #[expect(invalid_nan_comparisons)]
20+
| ^^^^^^^^^^^^^^^^^^^^^^^
21+
|
22+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
23+
24+
error: this lint expectation is unfulfilled
25+
--> tests/ui/expect_tool_lint_rfc_2383.rs:110:14
1826
|
1927
LL | #[expect(clippy::almost_swapped)]
2028
| ^^^^^^^^^^^^^^^^^^^^^^
2129

2230
error: this lint expectation is unfulfilled
23-
--> tests/ui/expect_tool_lint_rfc_2383.rs:116:14
31+
--> tests/ui/expect_tool_lint_rfc_2383.rs:118:14
2432
|
2533
LL | #[expect(clippy::bytes_nth)]
2634
| ^^^^^^^^^^^^^^^^^
2735

2836
error: this lint expectation is unfulfilled
29-
--> tests/ui/expect_tool_lint_rfc_2383.rs:122:14
37+
--> tests/ui/expect_tool_lint_rfc_2383.rs:124:14
3038
|
3139
LL | #[expect(clippy::if_same_then_else)]
3240
| ^^^^^^^^^^^^^^^^^^^^^^^^^
3341

3442
error: this lint expectation is unfulfilled
35-
--> tests/ui/expect_tool_lint_rfc_2383.rs:128:14
43+
--> tests/ui/expect_tool_lint_rfc_2383.rs:130:14
3644
|
3745
LL | #[expect(clippy::overly_complex_bool_expr)]
3846
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3947

40-
error: aborting due to 6 previous errors
48+
error: aborting due to 7 previous errors
4149

tests/ui/unknown_clippy_lints.stderr

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,23 @@
1+
error: unknown lint: `clippy::All`
2+
--> tests/ui/unknown_clippy_lints.rs:3:10
3+
|
4+
LL | #![allow(clippy::All)]
5+
| ^^^^^^^^^^^ help: did you mean: `clippy::all`
6+
|
7+
= note: `-D unknown-lints` implied by `-D warnings`
8+
= help: to override `-D warnings` add `#[allow(unknown_lints)]`
9+
10+
error: unknown lint: `clippy::CMP_OWNED`
11+
--> tests/ui/unknown_clippy_lints.rs:5:9
12+
|
13+
LL | #![warn(clippy::CMP_OWNED)]
14+
| ^^^^^^^^^^^^^^^^^ help: did you mean: `clippy::cmp_owned`
15+
116
error: unknown lint: `clippy::if_not_els`
217
--> tests/ui/unknown_clippy_lints.rs:9:8
318
|
419
LL | #[warn(clippy::if_not_els)]
520
| ^^^^^^^^^^^^^^^^^^ help: did you mean: `clippy::if_not_else`
6-
|
7-
= note: `-D unknown-lints` implied by `-D warnings`
8-
= help: to override `-D warnings` add `#[allow(unknown_lints)]`
921

1022
error: unknown lint: `clippy::UNNecsaRy_cAst`
1123
--> tests/ui/unknown_clippy_lints.rs:11:8
@@ -55,17 +67,5 @@ LL - #[warn(clippy::missing_docs)]
5567
LL + #[warn(missing_docs)]
5668
|
5769

58-
error: unknown lint: `clippy::All`
59-
--> tests/ui/unknown_clippy_lints.rs:3:10
60-
|
61-
LL | #![allow(clippy::All)]
62-
| ^^^^^^^^^^^ help: did you mean: `clippy::all`
63-
64-
error: unknown lint: `clippy::CMP_OWNED`
65-
--> tests/ui/unknown_clippy_lints.rs:5:9
66-
|
67-
LL | #![warn(clippy::CMP_OWNED)]
68-
| ^^^^^^^^^^^^^^^^^ help: did you mean: `clippy::cmp_owned`
69-
7070
error: aborting due to 9 previous errors
7171

0 commit comments

Comments
 (0)