Skip to content

Commit e294f94

Browse files
authored
r? @ghost changelog: none
2 parents 94f0994 + 8a0b225 commit e294f94

Some content is hidden

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

55 files changed

+199
-125
lines changed

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ path = "src/driver.rs"
2525
[dependencies]
2626
clippy_config = { path = "clippy_config" }
2727
clippy_lints = { path = "clippy_lints" }
28+
clippy_utils = { path = "clippy_utils" }
2829
rustc_tools_util = { path = "rustc_tools_util", version = "0.4.2" }
2930
tempfile = { version = "3.3", optional = true }
3031
termize = "0.1"

clippy_dev/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#[allow(unused_extern_crates)]
1414
extern crate rustc_driver;
1515
extern crate rustc_lexer;
16+
extern crate rustc_literal_escaper;
1617

1718
pub mod dogfood;
1819
pub mod fmt;

clippy_dev/src/update_lints.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use crate::utils::{UpdateMode, clippy_project_root, exit_with_failure, replace_region_in_file};
22
use aho_corasick::AhoCorasickBuilder;
33
use itertools::Itertools;
4-
use rustc_lexer::{LiteralKind, TokenKind, tokenize, unescape};
4+
use rustc_lexer::{LiteralKind, TokenKind, tokenize};
5+
use rustc_literal_escaper::{Mode, unescape_unicode};
56
use std::collections::{HashMap, HashSet};
67
use std::ffi::OsStr;
78
use std::fmt::{self, Write};
@@ -830,7 +831,7 @@ fn remove_line_splices(s: &str) -> String {
830831
.and_then(|s| s.strip_suffix('"'))
831832
.unwrap_or_else(|| panic!("expected quoted string, found `{s}`"));
832833
let mut res = String::with_capacity(s.len());
833-
unescape::unescape_unicode(s, unescape::Mode::Str, &mut |range, ch| {
834+
unescape_unicode(s, Mode::Str, &mut |range, ch| {
834835
if ch.is_ok() {
835836
res.push_str(&s[range]);
836837
}

clippy_lints/src/assigning_clones.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ impl<'tcx> LateLintPass<'tcx> for AssigningClones {
111111
// Only suggest if `clone_from`/`clone_into` is explicitly implemented
112112
&& resolved_assoc_items.in_definition_order().any(|assoc|
113113
match which_trait {
114-
CloneTrait::Clone => assoc.name == sym::clone_from,
115-
CloneTrait::ToOwned => assoc.name.as_str() == "clone_into",
114+
CloneTrait::Clone => assoc.name() == sym::clone_from,
115+
CloneTrait::ToOwned => assoc.name().as_str() == "clone_into",
116116
}
117117
)
118118
&& !clone_source_borrows_from_dest(cx, lhs, rhs.span)

clippy_lints/src/attrs/deprecated_cfg_attr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use super::{Attribute, DEPRECATED_CFG_ATTR, DEPRECATED_CLIPPY_CFG_ATTR, unnecessary_clippy_cfg};
22
use clippy_utils::diagnostics::span_lint_and_sugg;
33
use clippy_utils::msrvs::{self, MsrvStack};
4+
use clippy_utils::sym;
45
use rustc_ast::AttrStyle;
56
use rustc_errors::Applicability;
67
use rustc_lint::EarlyContext;
7-
use rustc_span::sym;
88

99
pub(super) fn check(cx: &EarlyContext<'_>, attr: &Attribute, msrv: &MsrvStack) {
1010
// check cfg_attr
@@ -18,7 +18,7 @@ pub(super) fn check(cx: &EarlyContext<'_>, attr: &Attribute, msrv: &MsrvStack) {
1818
&& msrv.meets(msrvs::TOOL_ATTRIBUTES)
1919
// check for `rustfmt_skip` and `rustfmt::skip`
2020
&& let Some(skip_item) = &items[1].meta_item()
21-
&& (skip_item.has_name(sym!(rustfmt_skip))
21+
&& (skip_item.has_name(sym::rustfmt_skip)
2222
|| skip_item
2323
.path
2424
.segments

clippy_lints/src/attrs/useless_attribute.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ use super::USELESS_ATTRIBUTE;
22
use super::utils::{is_lint_level, is_word, namespace_and_lint};
33
use clippy_utils::diagnostics::span_lint_and_then;
44
use clippy_utils::source::{SpanRangeExt, first_line_of_span};
5+
use clippy_utils::sym;
56
use rustc_ast::{Attribute, Item, ItemKind};
67
use rustc_errors::Applicability;
78
use rustc_lint::{EarlyContext, LintContext};
8-
use rustc_span::sym;
99

1010
pub(super) fn check(cx: &EarlyContext<'_>, item: &Item, attrs: &[Attribute]) {
1111
let skip_unused_imports = attrs.iter().any(|attr| attr.has_name(sym::macro_use));
@@ -62,7 +62,7 @@ pub(super) fn check(cx: &EarlyContext<'_>, item: &Item, attrs: &[Attribute]) {
6262
if is_word(lint, sym::unused_imports) && skip_unused_imports {
6363
return;
6464
}
65-
if is_word(lint, sym!(unused_extern_crates)) {
65+
if is_word(lint, sym::unused_extern_crates) {
6666
return;
6767
}
6868
},

clippy_lints/src/bool_assert_comparison.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ fn is_impl_not_trait_with_bool_out<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -
5353
.not_trait()
5454
.filter(|trait_id| implements_trait(cx, ty, *trait_id, &[]))
5555
.and_then(|trait_id| {
56-
cx.tcx.associated_items(trait_id).find_by_name_and_kind(
56+
cx.tcx.associated_items(trait_id).find_by_ident_and_kind(
5757
cx.tcx,
5858
Ident::from_str("Output"),
59-
ty::AssocKind::Type,
59+
ty::AssocTag::Type,
6060
trait_id,
6161
)
6262
})

clippy_lints/src/booleans.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ fn check_simplify_not(cx: &LateContext<'_>, msrv: Msrv, expr: &Expr<'_>) {
199199
&& !expr.span.from_expansion()
200200
&& !inner.span.from_expansion()
201201
&& let Some(suggestion) = simplify_not(cx, msrv, inner)
202-
&& cx.tcx.lint_level_at_node(NONMINIMAL_BOOL, expr.hir_id).0 != Level::Allow
202+
&& cx.tcx.lint_level_at_node(NONMINIMAL_BOOL, expr.hir_id).level != Level::Allow
203203
{
204204
use clippy_utils::sugg::{Sugg, has_enclosing_paren};
205205
let maybe_par = if let Some(sug) = Sugg::hir_opt(cx, inner) {
@@ -609,7 +609,7 @@ impl<'tcx> NonminimalBoolVisitor<'_, 'tcx> {
609609
}
610610
}
611611
let nonminimal_bool_lint = |mut suggestions: Vec<_>| {
612-
if self.cx.tcx.lint_level_at_node(NONMINIMAL_BOOL, e.hir_id).0 != Level::Allow {
612+
if self.cx.tcx.lint_level_at_node(NONMINIMAL_BOOL, e.hir_id).level != Level::Allow {
613613
suggestions.sort();
614614
span_lint_hir_and_then(
615615
self.cx,

clippy_lints/src/disallowed_script_idents.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ impl EarlyLintPass for DisallowedScriptIdents {
6969
// Implementation is heavily inspired by the implementation of [`non_ascii_idents`] lint:
7070
// https://github.com/rust-lang/rust/blob/master/compiler/rustc_lint/src/non_ascii_idents.rs
7171

72-
let check_disallowed_script_idents = cx.builder.lint_level(DISALLOWED_SCRIPT_IDENTS).0 != Level::Allow;
72+
let check_disallowed_script_idents = cx.builder.lint_level(DISALLOWED_SCRIPT_IDENTS).level != Level::Allow;
7373
if !check_disallowed_script_idents {
7474
return;
7575
}

clippy_lints/src/doc/needless_doctest_main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub fn check(
3838
// of all `#[test]` attributes in not ignored code examples
3939
fn check_code_sample(code: String, edition: Edition, ignore: bool) -> (bool, Vec<Range<usize>>) {
4040
rustc_driver::catch_fatal_errors(|| {
41-
rustc_span::create_session_globals_then(edition, None, || {
41+
rustc_span::create_session_globals_then(edition, &[], None, || {
4242
let mut test_attr_spans = vec![];
4343
let filename = FileName::anon_source_code(&code);
4444

clippy_lints/src/duplicate_mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use clippy_utils::diagnostics::span_lint_and_help;
22
use rustc_ast::ast::{Crate, Inline, Item, ItemKind, ModKind};
33
use rustc_errors::MultiSpan;
44
use rustc_lint::{EarlyContext, EarlyLintPass, Level, LintContext};
5+
use rustc_middle::lint::LevelAndSource;
56
use rustc_session::impl_lint_pass;
67
use rustc_span::{FileName, Span};
78
use std::collections::BTreeMap;
@@ -45,11 +46,10 @@ declare_clippy_lint! {
4546
"file loaded as module multiple times"
4647
}
4748

48-
#[derive(PartialOrd, Ord, PartialEq, Eq)]
4949
struct Modules {
5050
local_path: PathBuf,
5151
spans: Vec<Span>,
52-
lint_levels: Vec<Level>,
52+
lint_levels: Vec<LevelAndSource>,
5353
}
5454

5555
#[derive(Default)]
@@ -95,11 +95,11 @@ impl EarlyLintPass for DuplicateMod {
9595
.iter()
9696
.zip(lint_levels)
9797
.filter_map(|(span, lvl)| {
98-
if let Some(id) = lvl.get_expectation_id() {
98+
if let Some(id) = lvl.lint_id {
9999
cx.fulfill_expectation(id);
100100
}
101101

102-
(!matches!(lvl, Level::Allow | Level::Expect(_))).then_some(*span)
102+
(!matches!(lvl.level, Level::Allow | Level::Expect)).then_some(*span)
103103
})
104104
.collect();
105105

clippy_lints/src/equatable_if_let.rs

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ fn unary_pattern(pat: &Pat<'_>) -> bool {
4545
pats.iter().all(unary_pattern)
4646
}
4747
match &pat.kind {
48+
PatKind::Missing => unreachable!(),
4849
PatKind::Slice(_, _, _)
4950
| PatKind::Range(_, _, _)
5051
| PatKind::Binding(..)

clippy_lints/src/format_args.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ impl<'tcx> FormatArgsExpr<'_, 'tcx> {
550550
// a `Target` that is in `self.ty_msrv_map`.
551551
if let Some(deref_trait_id) = self.cx.tcx.lang_items().deref_trait()
552552
&& implements_trait(self.cx, ty, deref_trait_id, &[])
553-
&& let Some(target_ty) = self.cx.get_associated_type(ty, deref_trait_id, "Target")
553+
&& let Some(target_ty) = self.cx.get_associated_type(ty, deref_trait_id, sym::Target)
554554
&& let Some(msrv) = self.ty_msrv_map.get(&target_ty)
555555
&& msrv.is_none_or(|msrv| self.msrv.meets(self.cx, msrv))
556556
{

clippy_lints/src/format_push_string.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use clippy_utils::diagnostics::span_lint_and_then;
22
use clippy_utils::higher;
33
use clippy_utils::ty::is_type_lang_item;
4-
use rustc_hir::{BinOpKind, Expr, ExprKind, LangItem, MatchSource};
4+
use rustc_hir::{AssignOpKind, Expr, ExprKind, LangItem, MatchSource};
55
use rustc_lint::{LateContext, LateLintPass};
66
use rustc_session::declare_lint_pass;
77
use rustc_span::sym;
@@ -77,7 +77,7 @@ impl<'tcx> LateLintPass<'tcx> for FormatPushString {
7777
return;
7878
}
7979
},
80-
ExprKind::AssignOp(op, left, arg) if op.node == BinOpKind::Add && is_string(cx, left) => arg,
80+
ExprKind::AssignOp(op, left, arg) if op.node == AssignOpKind::AddAssign && is_string(cx, left) => arg,
8181
_ => return,
8282
};
8383
if is_format(cx, arg) {

clippy_lints/src/functions/renamed_function_params.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ pub(super) fn check_impl_item(cx: &LateContext<'_>, item: &ImplItem<'_>, ignored
2222
&& let Some(did) = trait_item_def_id_of_impl(items, item.owner_id)
2323
&& !is_from_ignored_trait(trait_ref, ignored_traits)
2424
{
25-
let mut param_idents_iter = cx.tcx.hir_body_param_names(body_id);
26-
let mut default_param_idents_iter = cx.tcx.fn_arg_names(did).iter().copied();
25+
let mut param_idents_iter = cx.tcx.hir_body_param_idents(body_id);
26+
let mut default_param_idents_iter = cx.tcx.fn_arg_idents(did).iter().copied();
2727

2828
let renames = RenamedFnArgs::new(&mut default_param_idents_iter, &mut param_idents_iter);
2929
if !renames.0.is_empty() {

clippy_lints/src/implicit_saturating_add.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use clippy_utils::source::snippet_with_context;
55
use rustc_ast::ast::{LitIntType, LitKind};
66
use rustc_data_structures::packed::Pu128;
77
use rustc_errors::Applicability;
8-
use rustc_hir::{BinOpKind, Block, Expr, ExprKind, Stmt, StmtKind};
8+
use rustc_hir::{AssignOpKind, BinOpKind, Block, Expr, ExprKind, Stmt, StmtKind};
99
use rustc_lint::{LateContext, LateLintPass};
1010
use rustc_middle::ty::{IntTy, Ty, UintTy};
1111
use rustc_session::declare_lint_pass;
@@ -68,7 +68,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitSaturatingAdd {
6868
&& ex.span.ctxt() == ctxt
6969
&& expr1.span.ctxt() == ctxt
7070
&& clippy_utils::SpanlessEq::new(cx).eq_expr(l, target)
71-
&& BinOpKind::Add == op1.node
71+
&& AssignOpKind::AddAssign == op1.node
7272
&& let ExprKind::Lit(lit) = value.kind
7373
&& let LitKind::Int(Pu128(1), LitIntType::Unsuffixed) = lit.node
7474
&& block.expr.is_none()

clippy_lints/src/implicit_saturating_sub.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use clippy_utils::{
88
use rustc_ast::ast::LitKind;
99
use rustc_data_structures::packed::Pu128;
1010
use rustc_errors::Applicability;
11-
use rustc_hir::{BinOp, BinOpKind, Expr, ExprKind, QPath};
11+
use rustc_hir::{AssignOpKind, BinOp, BinOpKind, Expr, ExprKind, QPath};
1212
use rustc_lint::{LateContext, LateLintPass};
1313
use rustc_session::impl_lint_pass;
1414
use rustc_span::Span;
@@ -366,7 +366,7 @@ fn subtracts_one<'a>(cx: &LateContext<'_>, expr: &'a Expr<'a>) -> Option<&'a Exp
366366
match peel_blocks_with_stmt(expr).kind {
367367
ExprKind::AssignOp(ref op1, target, value) => {
368368
// Check if literal being subtracted is one
369-
(BinOpKind::Sub == op1.node && is_integer_literal(value, 1)).then_some(target)
369+
(AssignOpKind::SubAssign == op1.node && is_integer_literal(value, 1)).then_some(target)
370370
},
371371
ExprKind::Assign(target, value, _) => {
372372
if let ExprKind::Binary(ref op1, left1, right1) = value.kind

clippy_lints/src/implied_bounds_in_impls.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_hir::{
88
};
99
use rustc_hir_analysis::lower_ty;
1010
use rustc_lint::{LateContext, LateLintPass};
11-
use rustc_middle::ty::{self, ClauseKind, Generics, Ty, TyCtxt};
11+
use rustc_middle::ty::{self, AssocItem, ClauseKind, Generics, Ty, TyCtxt};
1212
use rustc_session::declare_lint_pass;
1313
use rustc_span::Span;
1414

@@ -315,7 +315,7 @@ fn check<'tcx>(cx: &LateContext<'tcx>, bounds: GenericBounds<'tcx>) {
315315
assocs
316316
.filter_by_name_unhygienic(constraint.ident.name)
317317
.next()
318-
.is_some_and(|assoc| assoc.kind == ty::AssocKind::Type)
318+
.is_some_and(AssocItem::is_type)
319319
})
320320
{
321321
emit_lint(cx, poly_trait, bounds, index, implied_constraints, bound);

clippy_lints/src/len_zero.rs

+6-10
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_hir::{
1313
QPath, TraitItemRef, TyKind,
1414
};
1515
use rustc_lint::{LateContext, LateLintPass};
16-
use rustc_middle::ty::{self, AssocKind, FnSig, Ty};
16+
use rustc_middle::ty::{self, FnSig, Ty};
1717
use rustc_session::declare_lint_pass;
1818
use rustc_span::source_map::Spanned;
1919
use rustc_span::symbol::sym;
@@ -300,11 +300,7 @@ fn check_trait_items(cx: &LateContext<'_>, visited_trait: &Item<'_>, ident: Iden
300300
let is_empty_method_found = current_and_super_traits
301301
.items()
302302
.flat_map(|&i| cx.tcx.associated_items(i).filter_by_name_unhygienic(is_empty))
303-
.any(|i| {
304-
i.kind == AssocKind::Fn
305-
&& i.fn_has_self_parameter
306-
&& cx.tcx.fn_sig(i.def_id).skip_binder().inputs().skip_binder().len() == 1
307-
});
303+
.any(|i| i.is_method() && cx.tcx.fn_sig(i.def_id).skip_binder().inputs().skip_binder().len() == 1);
308304

309305
if !is_empty_method_found {
310306
span_lint(
@@ -482,7 +478,7 @@ fn check_for_is_empty(
482478
.inherent_impls(impl_ty)
483479
.iter()
484480
.flat_map(|&id| cx.tcx.associated_items(id).filter_by_name_unhygienic(is_empty))
485-
.find(|item| item.kind == AssocKind::Fn);
481+
.find(|item| item.is_fn());
486482

487483
let (msg, is_empty_span, self_kind) = match is_empty {
488484
None => (
@@ -502,7 +498,7 @@ fn check_for_is_empty(
502498
None,
503499
),
504500
Some(is_empty)
505-
if !(is_empty.fn_has_self_parameter
501+
if !(is_empty.is_method()
506502
&& check_is_empty_sig(
507503
cx,
508504
cx.tcx.fn_sig(is_empty.def_id).instantiate_identity().skip_binder(),
@@ -626,7 +622,7 @@ fn is_empty_array(expr: &Expr<'_>) -> bool {
626622
fn has_is_empty(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
627623
/// Gets an `AssocItem` and return true if it matches `is_empty(self)`.
628624
fn is_is_empty(cx: &LateContext<'_>, item: &ty::AssocItem) -> bool {
629-
if item.kind == AssocKind::Fn {
625+
if item.is_fn() {
630626
let sig = cx.tcx.fn_sig(item.def_id).skip_binder();
631627
let ty = sig.skip_binder();
632628
ty.inputs().len() == 1
@@ -662,7 +658,7 @@ fn has_is_empty(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
662658
&& cx.tcx.get_diagnostic_item(sym::Deref).is_some_and(|deref_id| {
663659
implements_trait(cx, ty, deref_id, &[])
664660
&& cx
665-
.get_associated_type(ty, deref_id, "Target")
661+
.get_associated_type(ty, deref_id, sym::Target)
666662
.is_some_and(|deref_ty| ty_has_is_empty(cx, deref_ty, depth + 1))
667663
}))
668664
},

clippy_lints/src/loops/utils.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use clippy_utils::{get_parent_expr, is_integer_const, path_to_local, path_to_loc
33
use rustc_ast::ast::{LitIntType, LitKind};
44
use rustc_errors::Applicability;
55
use rustc_hir::intravisit::{Visitor, walk_expr, walk_local};
6-
use rustc_hir::{BinOpKind, BorrowKind, Expr, ExprKind, HirId, HirIdMap, LetStmt, Mutability, PatKind};
6+
use rustc_hir::{AssignOpKind, BorrowKind, Expr, ExprKind, HirId, HirIdMap, LetStmt, Mutability, PatKind};
77
use rustc_lint::LateContext;
88
use rustc_middle::hir::nested_filter;
99
use rustc_middle::ty::{self, Ty};
@@ -58,7 +58,7 @@ impl<'tcx> Visitor<'tcx> for IncrementVisitor<'_, 'tcx> {
5858
match parent.kind {
5959
ExprKind::AssignOp(op, lhs, rhs) => {
6060
if lhs.hir_id == expr.hir_id {
61-
*state = if op.node == BinOpKind::Add
61+
*state = if op.node == AssignOpKind::AddAssign
6262
&& is_integer_const(self.cx, rhs, 1)
6363
&& *state == IncrementVisitorVarState::Initial
6464
&& self.depth == 0

clippy_lints/src/macro_metavars_in_unsafe.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use rustc_hir::def_id::LocalDefId;
66
use rustc_hir::intravisit::{Visitor, walk_block, walk_expr, walk_stmt};
77
use rustc_hir::{BlockCheckMode, Expr, ExprKind, HirId, Stmt, UnsafeSource};
88
use rustc_lint::{LateContext, LateLintPass, Level, LintContext};
9+
use rustc_middle::lint::LevelAndSource;
910
use rustc_session::impl_lint_pass;
1011
use rustc_span::{Span, SyntaxContext, sym};
1112
use std::collections::BTreeMap;
@@ -250,7 +251,12 @@ impl<'tcx> LateLintPass<'tcx> for ExprMetavarsInUnsafe {
250251
.flatten()
251252
.copied()
252253
.inspect(|&unsafe_block| {
253-
if let Level::Expect(id) = cx.tcx.lint_level_at_node(MACRO_METAVARS_IN_UNSAFE, unsafe_block).0 {
254+
if let LevelAndSource {
255+
level: Level::Expect,
256+
lint_id: Some(id),
257+
..
258+
} = cx.tcx.lint_level_at_node(MACRO_METAVARS_IN_UNSAFE, unsafe_block)
259+
{
254260
// Since we're going to deduplicate expanded unsafe blocks by its enclosing macro definition soon,
255261
// which would lead to unfulfilled `#[expect()]`s in all other unsafe blocks that are filtered out
256262
// except for the one we emit the warning at, we must manually fulfill the lint

0 commit comments

Comments
 (0)