Skip to content

Commit 20ce69b

Browse files
authored
r? @ghost changelog: none
2 parents 4b109ed + 6b14443 commit 20ce69b

33 files changed

+117
-111
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "clippy"
3-
version = "0.1.91"
3+
version = "0.1.92"
44
description = "A bunch of helpful lints to avoid common pitfalls in Rust"
55
repository = "https://github.com/rust-lang/rust-clippy"
66
readme = "README.md"

clippy_config/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "clippy_config"
3-
version = "0.1.91"
3+
version = "0.1.92"
44
edition = "2024"
55
publish = false
66

clippy_lints/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "clippy_lints"
3-
version = "0.1.91"
3+
version = "0.1.92"
44
description = "A bunch of helpful lints to avoid common pitfalls in Rust"
55
repository = "https://github.com/rust-lang/rust-clippy"
66
readme = "README.md"

clippy_lints/src/dereference.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ impl<'tcx> LateLintPass<'tcx> for Dereferencing<'tcx> {
363363
// priority.
364364
if let Some(fn_id) = typeck.type_dependent_def_id(hir_id)
365365
&& let Some(trait_id) = cx.tcx.trait_of_assoc(fn_id)
366-
&& let arg_ty = cx.tcx.erase_regions(adjusted_ty)
366+
&& let arg_ty = cx.tcx.erase_and_anonymize_regions(adjusted_ty)
367367
&& let ty::Ref(_, sub_ty, _) = *arg_ty.kind()
368368
&& let args =
369369
typeck.node_args_opt(hir_id).map(|args| &args[1..]).unwrap_or_default()

clippy_lints/src/disallowed_macros.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ use rustc_data_structures::fx::FxHashSet;
77
use rustc_hir::def::DefKind;
88
use rustc_hir::def_id::DefIdMap;
99
use rustc_hir::{
10-
AmbigArg, Expr, ExprKind, ForeignItem, HirId, ImplItem, Item, ItemKind, OwnerId, Pat, Path, Stmt, TraitItem, Ty,
10+
AmbigArg, Expr, ExprKind, ForeignItem, HirId, ImplItem, ImplItemImplKind, Item, ItemKind, OwnerId, Pat, Path, Stmt,
11+
TraitItem, Ty,
1112
};
1213
use rustc_lint::{LateContext, LateLintPass};
1314
use rustc_middle::ty::TyCtxt;
@@ -176,7 +177,9 @@ impl LateLintPass<'_> for DisallowedMacros {
176177

177178
fn check_impl_item(&mut self, cx: &LateContext<'_>, item: &ImplItem<'_>) {
178179
self.check(cx, item.span, None);
179-
self.check(cx, item.vis_span, None);
180+
if let ImplItemImplKind::Inherent { vis_span, .. } = item.impl_kind {
181+
self.check(cx, vis_span, None);
182+
}
180183
}
181184

182185
fn check_trait_item(&mut self, cx: &LateContext<'_>, item: &TraitItem<'_>) {

clippy_lints/src/doc/needless_doctest_main.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use rustc_ast::{CoroutineKind, Fn, FnRetTy, Item, ItemKind};
88
use rustc_errors::emitter::HumanEmitter;
99
use rustc_errors::{Diag, DiagCtxt};
1010
use rustc_lint::LateContext;
11+
use rustc_parse::lexer::StripTokens;
1112
use rustc_parse::new_parser_from_source_str;
1213
use rustc_parse::parser::ForceCollect;
1314
use rustc_session::parse::ParseSess;
@@ -49,13 +50,14 @@ pub fn check(
4950
let sm = Arc::new(SourceMap::new(FilePathMapping::empty()));
5051
let psess = ParseSess::with_dcx(dcx, sm);
5152

52-
let mut parser = match new_parser_from_source_str(&psess, filename, code) {
53-
Ok(p) => p,
54-
Err(errs) => {
55-
errs.into_iter().for_each(Diag::cancel);
56-
return (false, test_attr_spans);
57-
},
58-
};
53+
let mut parser =
54+
match new_parser_from_source_str(&psess, filename, code, StripTokens::ShebangAndFrontmatter) {
55+
Ok(p) => p,
56+
Err(errs) => {
57+
errs.into_iter().for_each(Diag::cancel);
58+
return (false, test_attr_spans);
59+
},
60+
};
5961

6062
let mut relevant_main_found = false;
6163
let mut eligible = true;

clippy_lints/src/functions/renamed_function_params.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use clippy_utils::diagnostics::span_lint_and_then;
22
use rustc_errors::{Applicability, MultiSpan};
3-
use rustc_hir::def_id::{DefId, DefIdSet};
4-
use rustc_hir::hir_id::OwnerId;
3+
use rustc_hir::def_id::DefIdSet;
54
use rustc_hir::{Impl, ImplItem, ImplItemKind, ItemKind, Node, TraitRef};
65
use rustc_lint::LateContext;
76
use rustc_span::Span;
@@ -19,7 +18,7 @@ pub(super) fn check_impl_item(cx: &LateContext<'_>, item: &ImplItem<'_>, ignored
1918
of_trait: Some(of_trait),
2019
..
2120
}) = &parent_item.kind
22-
&& let Some(did) = trait_item_def_id_of_impl(cx, item.owner_id)
21+
&& let Some(did) = cx.tcx.trait_item_of(item.owner_id)
2322
&& !is_from_ignored_trait(&of_trait.trait_ref, ignored_traits)
2423
{
2524
let mut param_idents_iter = cx.tcx.hir_body_param_idents(body_id);
@@ -87,11 +86,6 @@ impl RenamedFnArgs {
8786
}
8887
}
8988

90-
/// Get the [`trait_item_def_id`](ImplItemRef::trait_item_def_id) of a relevant impl item.
91-
fn trait_item_def_id_of_impl(cx: &LateContext<'_>, target: OwnerId) -> Option<DefId> {
92-
cx.tcx.associated_item(target).trait_item_def_id
93-
}
94-
9589
fn is_from_ignored_trait(of_trait: &TraitRef<'_>, ignored_traits: &DefIdSet) -> bool {
9690
of_trait
9791
.trait_def_id()

clippy_lints/src/loops/explicit_iter_loop.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,9 @@ fn is_ref_iterable<'tcx>(
138138
return Some((AdjustKind::None, self_ty));
139139
}
140140

141-
let res_ty = cx
142-
.tcx
143-
.erase_regions(EarlyBinder::bind(req_res_ty).instantiate(cx.tcx, typeck.node_args(call_expr.hir_id)));
141+
let res_ty = cx.tcx.erase_and_anonymize_regions(
142+
EarlyBinder::bind(req_res_ty).instantiate(cx.tcx, typeck.node_args(call_expr.hir_id)),
143+
);
144144
let mutbl = if let ty::Ref(_, _, mutbl) = *req_self_ty.kind() {
145145
Some(mutbl)
146146
} else {

clippy_lints/src/manual_async_fn.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use rustc_errors::Applicability;
44
use rustc_hir::intravisit::FnKind;
55
use rustc_hir::{
66
Block, Body, Closure, ClosureKind, CoroutineDesugaring, CoroutineKind, CoroutineSource, Expr, ExprKind, FnDecl,
7-
FnRetTy, GenericBound, ImplItem, Item, Node, OpaqueTy, TraitRef, Ty, TyKind,
7+
FnRetTy, GenericBound, Node, OpaqueTy, TraitRef, Ty, TyKind,
88
};
99
use rustc_lint::{LateContext, LateLintPass};
1010
use rustc_middle::middle::resolve_bound_vars::ResolvedArg;
@@ -60,8 +60,11 @@ impl<'tcx> LateLintPass<'tcx> for ManualAsyncFn {
6060
&& let ExprKind::Block(block, _) = body.value.kind
6161
&& block.stmts.is_empty()
6262
&& let Some(closure_body) = desugared_async_block(cx, block)
63-
&& let Node::Item(Item {vis_span, ..}) | Node::ImplItem(ImplItem {vis_span, ..}) =
64-
cx.tcx.hir_node_by_def_id(fn_def_id)
63+
&& let Some(vis_span_opt) = match cx.tcx.hir_node_by_def_id(fn_def_id) {
64+
Node::Item(item) => Some(Some(item.vis_span)),
65+
Node::ImplItem(impl_item) => Some(impl_item.vis_span()),
66+
_ => None,
67+
}
6568
&& !span.from_expansion()
6669
{
6770
let header_span = span.with_hi(ret_ty.span.hi());
@@ -72,7 +75,8 @@ impl<'tcx> LateLintPass<'tcx> for ManualAsyncFn {
7275
header_span,
7376
"this function can be simplified using the `async fn` syntax",
7477
|diag| {
75-
if let Some(vis_snip) = vis_span.get_source_text(cx)
78+
if let Some(vis_span) = vis_span_opt
79+
&& let Some(vis_snip) = vis_span.get_source_text(cx)
7680
&& let Some(header_snip) = header_span.get_source_text(cx)
7781
&& let Some(ret_pos) = position_before_rarrow(&header_snip)
7882
&& let Some((_, ret_snip)) = suggested_ret(cx, output)

clippy_lints/src/min_ident_chars.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use rustc_data_structures::fx::FxHashSet;
55
use rustc_hir::def::{DefKind, Res};
66
use rustc_hir::intravisit::{Visitor, walk_item, walk_trait_item};
77
use rustc_hir::{
8-
GenericParamKind, HirId, Impl, ImplItem, ImplItemKind, Item, ItemKind, ItemLocalId, Node, Pat, PatKind, TraitItem,
9-
UsePath,
8+
GenericParamKind, HirId, Impl, ImplItem, ImplItemImplKind, ImplItemKind, Item, ItemKind, ItemLocalId, Node, Pat,
9+
PatKind, TraitItem, UsePath,
1010
};
1111
use rustc_lint::{LateContext, LateLintPass, LintContext};
1212
use rustc_session::impl_lint_pass;
@@ -256,7 +256,11 @@ fn is_not_in_trait_impl(cx: &LateContext<'_>, pat: &Pat<'_>, ident: Ident) -> bo
256256
}
257257

258258
fn get_param_name(impl_item: &ImplItem<'_>, cx: &LateContext<'_>, ident: Ident) -> Option<Symbol> {
259-
if let Some(trait_item_def_id) = impl_item.trait_item_def_id {
259+
if let ImplItemImplKind::Trait {
260+
trait_item_def_id: Ok(trait_item_def_id),
261+
..
262+
} = impl_item.impl_kind
263+
{
260264
let trait_param_names = cx.tcx.fn_arg_idents(trait_item_def_id);
261265

262266
let ImplItemKind::Fn(_, body_id) = impl_item.kind else {

0 commit comments

Comments
 (0)