Skip to content
Merged

Rustup #15704

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
9b0611f
Merge commit 'e9b70454e4c9584be3b22ddabd26b741aeb06c10' into clippy-s…
flip1995 Sep 4, 2025
b2eb28d
fix: Filter suggestion parts that match existing code
Muscraft Aug 28, 2025
27250a3
Auto merge of #146121 - Muscraft:filter-suggestion-parts, r=petrochenkov
bors Sep 5, 2025
20226db
change end to last
Qelxiros Aug 1, 2025
0df12d7
erase_regions to erase_and_anonymize_regions
BoxyUwU Aug 21, 2025
c9ed8a1
Strip frontmatter in fewer places
fmease Sep 8, 2025
a6acb29
Rollup merge of #144765 - Qelxiros:range-inclusive-last, r=jhpratt
matthiaskrgr Sep 10, 2025
5782d9e
Rollup merge of #146340 - fmease:frontmatter-containment, r=fee1-dead…
matthiaskrgr Sep 10, 2025
3272277
fixup no_{core,std} handling code
jdonszelmann Aug 24, 2025
ba107fc
Revert "Rollup merge of #122661 - estebank:assert-macro-span, r=petro…
jieyouxu Sep 11, 2025
8d5078e
Introduce trait_item_of
camsteffen Aug 15, 2025
d419d51
Rename AssocItemContainer -> AssocContainer
camsteffen Aug 13, 2025
d734981
Introduce hir::ImplItemImplKind
camsteffen Aug 5, 2025
324c214
Split AssocContainer::{InherentImpl,TraitImpl}
camsteffen Aug 13, 2025
4328c95
Rollup merge of #146389 - jdonszelmann:no-std, r=oli-obk
jdonszelmann Sep 13, 2025
968569f
Auto merge of #145186 - camsteffen:assoc-impl-kind, r=petrochenkov
bors Sep 13, 2025
4516fee
Remove Rvalue::Len.
cjgillot Sep 14, 2025
2d3efb0
Merge remote-tracking branch 'upstream/master' into rustup
flip1995 Sep 18, 2025
2c73502
Bump nightly version -> 2025-09-18
flip1995 Sep 18, 2025
6b14443
Bump Clippy version -> 0.1.92
flip1995 Sep 18, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "clippy"
version = "0.1.91"
version = "0.1.92"
description = "A bunch of helpful lints to avoid common pitfalls in Rust"
repository = "https://github.com/rust-lang/rust-clippy"
readme = "README.md"
Expand Down
2 changes: 1 addition & 1 deletion clippy_config/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "clippy_config"
version = "0.1.91"
version = "0.1.92"
edition = "2024"
publish = false

Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "clippy_lints"
version = "0.1.91"
version = "0.1.92"
description = "A bunch of helpful lints to avoid common pitfalls in Rust"
repository = "https://github.com/rust-lang/rust-clippy"
readme = "README.md"
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/dereference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ impl<'tcx> LateLintPass<'tcx> for Dereferencing<'tcx> {
// priority.
if let Some(fn_id) = typeck.type_dependent_def_id(hir_id)
&& let Some(trait_id) = cx.tcx.trait_of_assoc(fn_id)
&& let arg_ty = cx.tcx.erase_regions(adjusted_ty)
&& let arg_ty = cx.tcx.erase_and_anonymize_regions(adjusted_ty)
&& let ty::Ref(_, sub_ty, _) = *arg_ty.kind()
&& let args =
typeck.node_args_opt(hir_id).map(|args| &args[1..]).unwrap_or_default()
Expand Down
7 changes: 5 additions & 2 deletions clippy_lints/src/disallowed_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ use rustc_data_structures::fx::FxHashSet;
use rustc_hir::def::DefKind;
use rustc_hir::def_id::DefIdMap;
use rustc_hir::{
AmbigArg, Expr, ExprKind, ForeignItem, HirId, ImplItem, Item, ItemKind, OwnerId, Pat, Path, Stmt, TraitItem, Ty,
AmbigArg, Expr, ExprKind, ForeignItem, HirId, ImplItem, ImplItemImplKind, Item, ItemKind, OwnerId, Pat, Path, Stmt,
TraitItem, Ty,
};
use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::ty::TyCtxt;
Expand Down Expand Up @@ -176,7 +177,9 @@ impl LateLintPass<'_> for DisallowedMacros {

fn check_impl_item(&mut self, cx: &LateContext<'_>, item: &ImplItem<'_>) {
self.check(cx, item.span, None);
self.check(cx, item.vis_span, None);
if let ImplItemImplKind::Inherent { vis_span, .. } = item.impl_kind {
self.check(cx, vis_span, None);
}
}

fn check_trait_item(&mut self, cx: &LateContext<'_>, item: &TraitItem<'_>) {
Expand Down
16 changes: 9 additions & 7 deletions clippy_lints/src/doc/needless_doctest_main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use rustc_ast::{CoroutineKind, Fn, FnRetTy, Item, ItemKind};
use rustc_errors::emitter::HumanEmitter;
use rustc_errors::{Diag, DiagCtxt};
use rustc_lint::LateContext;
use rustc_parse::lexer::StripTokens;
use rustc_parse::new_parser_from_source_str;
use rustc_parse::parser::ForceCollect;
use rustc_session::parse::ParseSess;
Expand Down Expand Up @@ -49,13 +50,14 @@ pub fn check(
let sm = Arc::new(SourceMap::new(FilePathMapping::empty()));
let psess = ParseSess::with_dcx(dcx, sm);

let mut parser = match new_parser_from_source_str(&psess, filename, code) {
Ok(p) => p,
Err(errs) => {
errs.into_iter().for_each(Diag::cancel);
return (false, test_attr_spans);
},
};
let mut parser =
match new_parser_from_source_str(&psess, filename, code, StripTokens::ShebangAndFrontmatter) {
Ok(p) => p,
Err(errs) => {
errs.into_iter().for_each(Diag::cancel);
return (false, test_attr_spans);
},
};

let mut relevant_main_found = false;
let mut eligible = true;
Expand Down
10 changes: 2 additions & 8 deletions clippy_lints/src/functions/renamed_function_params.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use clippy_utils::diagnostics::span_lint_and_then;
use rustc_errors::{Applicability, MultiSpan};
use rustc_hir::def_id::{DefId, DefIdSet};
use rustc_hir::hir_id::OwnerId;
use rustc_hir::def_id::DefIdSet;
use rustc_hir::{Impl, ImplItem, ImplItemKind, ItemKind, Node, TraitRef};
use rustc_lint::LateContext;
use rustc_span::Span;
Expand All @@ -19,7 +18,7 @@ pub(super) fn check_impl_item(cx: &LateContext<'_>, item: &ImplItem<'_>, ignored
of_trait: Some(of_trait),
..
}) = &parent_item.kind
&& let Some(did) = trait_item_def_id_of_impl(cx, item.owner_id)
&& let Some(did) = cx.tcx.trait_item_of(item.owner_id)
&& !is_from_ignored_trait(&of_trait.trait_ref, ignored_traits)
{
let mut param_idents_iter = cx.tcx.hir_body_param_idents(body_id);
Expand Down Expand Up @@ -87,11 +86,6 @@ impl RenamedFnArgs {
}
}

/// Get the [`trait_item_def_id`](ImplItemRef::trait_item_def_id) of a relevant impl item.
fn trait_item_def_id_of_impl(cx: &LateContext<'_>, target: OwnerId) -> Option<DefId> {
cx.tcx.associated_item(target).trait_item_def_id
}

fn is_from_ignored_trait(of_trait: &TraitRef<'_>, ignored_traits: &DefIdSet) -> bool {
of_trait
.trait_def_id()
Expand Down
6 changes: 3 additions & 3 deletions clippy_lints/src/loops/explicit_iter_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,9 @@ fn is_ref_iterable<'tcx>(
return Some((AdjustKind::None, self_ty));
}

let res_ty = cx
.tcx
.erase_regions(EarlyBinder::bind(req_res_ty).instantiate(cx.tcx, typeck.node_args(call_expr.hir_id)));
let res_ty = cx.tcx.erase_and_anonymize_regions(
EarlyBinder::bind(req_res_ty).instantiate(cx.tcx, typeck.node_args(call_expr.hir_id)),
);
let mutbl = if let ty::Ref(_, _, mutbl) = *req_self_ty.kind() {
Some(mutbl)
} else {
Expand Down
12 changes: 8 additions & 4 deletions clippy_lints/src/manual_async_fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use rustc_errors::Applicability;
use rustc_hir::intravisit::FnKind;
use rustc_hir::{
Block, Body, Closure, ClosureKind, CoroutineDesugaring, CoroutineKind, CoroutineSource, Expr, ExprKind, FnDecl,
FnRetTy, GenericBound, ImplItem, Item, Node, OpaqueTy, TraitRef, Ty, TyKind,
FnRetTy, GenericBound, Node, OpaqueTy, TraitRef, Ty, TyKind,
};
use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::middle::resolve_bound_vars::ResolvedArg;
Expand Down Expand Up @@ -60,8 +60,11 @@ impl<'tcx> LateLintPass<'tcx> for ManualAsyncFn {
&& let ExprKind::Block(block, _) = body.value.kind
&& block.stmts.is_empty()
&& let Some(closure_body) = desugared_async_block(cx, block)
&& let Node::Item(Item {vis_span, ..}) | Node::ImplItem(ImplItem {vis_span, ..}) =
cx.tcx.hir_node_by_def_id(fn_def_id)
&& let Some(vis_span_opt) = match cx.tcx.hir_node_by_def_id(fn_def_id) {
Node::Item(item) => Some(Some(item.vis_span)),
Node::ImplItem(impl_item) => Some(impl_item.vis_span()),
_ => None,
}
&& !span.from_expansion()
{
let header_span = span.with_hi(ret_ty.span.hi());
Expand All @@ -72,7 +75,8 @@ impl<'tcx> LateLintPass<'tcx> for ManualAsyncFn {
header_span,
"this function can be simplified using the `async fn` syntax",
|diag| {
if let Some(vis_snip) = vis_span.get_source_text(cx)
if let Some(vis_span) = vis_span_opt
&& let Some(vis_snip) = vis_span.get_source_text(cx)
&& let Some(header_snip) = header_span.get_source_text(cx)
&& let Some(ret_pos) = position_before_rarrow(&header_snip)
&& let Some((_, ret_snip)) = suggested_ret(cx, output)
Expand Down
10 changes: 7 additions & 3 deletions clippy_lints/src/min_ident_chars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use rustc_data_structures::fx::FxHashSet;
use rustc_hir::def::{DefKind, Res};
use rustc_hir::intravisit::{Visitor, walk_item, walk_trait_item};
use rustc_hir::{
GenericParamKind, HirId, Impl, ImplItem, ImplItemKind, Item, ItemKind, ItemLocalId, Node, Pat, PatKind, TraitItem,
UsePath,
GenericParamKind, HirId, Impl, ImplItem, ImplItemImplKind, ImplItemKind, Item, ItemKind, ItemLocalId, Node, Pat,
PatKind, TraitItem, UsePath,
};
use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_session::impl_lint_pass;
Expand Down Expand Up @@ -256,7 +256,11 @@ fn is_not_in_trait_impl(cx: &LateContext<'_>, pat: &Pat<'_>, ident: Ident) -> bo
}

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

let ImplItemKind::Fn(_, body_id) = impl_item.kind else {
Expand Down
12 changes: 6 additions & 6 deletions clippy_lints/src/missing_asserts_for_indexing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use rustc_ast::{BinOpKind, LitKind, RangeLimits};
use rustc_data_structures::packed::Pu128;
use rustc_data_structures::unhash::UnindexMap;
use rustc_errors::{Applicability, Diag};
use rustc_hir::{Body, Expr, ExprKind};
use rustc_hir::{Block, Body, Expr, ExprKind, UnOp};
use rustc_lint::{LateContext, LateLintPass};
use rustc_session::declare_lint_pass;
use rustc_span::source_map::Spanned;
Expand Down Expand Up @@ -135,12 +135,12 @@ fn assert_len_expr<'hir>(
cx: &LateContext<'_>,
expr: &'hir Expr<'hir>,
) -> Option<(LengthComparison, usize, &'hir Expr<'hir>)> {
let (cmp, asserted_len, slice_len) = if let Some(
higher::IfLetOrMatch::Match(cond, [_, then], _)
) = higher::IfLetOrMatch::parse(cx, expr)
&& let ExprKind::Binary(bin_op, left, right) = &cond.kind
let (cmp, asserted_len, slice_len) = if let Some(higher::If { cond, then, .. }) = higher::If::hir(expr)
&& let ExprKind::Unary(UnOp::Not, condition) = &cond.kind
&& let ExprKind::Binary(bin_op, left, right) = &condition.kind
// check if `then` block has a never type expression
&& cx.typeck_results().expr_ty(then.body).is_never()
&& let ExprKind::Block(Block { expr: Some(then_expr), .. }, _) = then.kind
&& cx.typeck_results().expr_ty(then_expr).is_never()
{
len_comparison(bin_op.node, left, right)?
} else if let Some((macro_call, bin_op)) = first_node_macro_backtrace(cx, expr).find_map(|macro_call| {
Expand Down
18 changes: 14 additions & 4 deletions clippy_lints/src/missing_const_for_fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,23 @@ impl<'tcx> LateLintPass<'tcx> for MissingConstForFn {
let mir = cx.tcx.optimized_mir(def_id);

if let Ok(()) = is_min_const_fn(cx, mir, self.msrv)
&& let hir::Node::Item(hir::Item { vis_span, .. }) | hir::Node::ImplItem(hir::ImplItem { vis_span, .. }) =
cx.tcx.hir_node_by_def_id(def_id)
&& let node = cx.tcx.hir_node_by_def_id(def_id)
&& let Some((item_span, vis_span_opt)) = match node {
hir::Node::Item(item) => Some((item.span, Some(item.vis_span))),
hir::Node::ImplItem(impl_item) => Some((impl_item.span, impl_item.vis_span())),
_ => None,
}
{
let suggestion = if vis_span.is_empty() { "const " } else { " const" };
let (sugg_span, suggestion) = if let Some(vis_span) = vis_span_opt
&& !vis_span.is_empty()
{
(vis_span.shrink_to_hi(), " const")
} else {
(item_span.shrink_to_lo(), "const ")
};
span_lint_and_then(cx, MISSING_CONST_FOR_FN, span, "this could be a `const fn`", |diag| {
diag.span_suggestion_verbose(
vis_span.shrink_to_hi(),
sugg_span,
"make the function `const`",
suggestion,
Applicability::MachineApplicable,
Expand Down
11 changes: 5 additions & 6 deletions clippy_lints/src/missing_doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use rustc_hir::Attribute;
use rustc_hir::def::DefKind;
use rustc_hir::def_id::LocalDefId;
use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::ty::Visibility;
use rustc_middle::ty::{AssocContainer, Visibility};
use rustc_session::impl_lint_pass;
use rustc_span::def_id::CRATE_DEF_ID;
use rustc_span::symbol::kw;
Expand Down Expand Up @@ -246,12 +246,11 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {

fn check_impl_item(&mut self, cx: &LateContext<'tcx>, impl_item: &'tcx hir::ImplItem<'_>) {
// If the method is an impl for a trait, don't doc.
if let Some(cid) = cx.tcx.associated_item(impl_item.owner_id).impl_container(cx.tcx) {
if cx.tcx.impl_trait_ref(cid).is_some() {
match cx.tcx.associated_item(impl_item.owner_id).container {
AssocContainer::Trait | AssocContainer::TraitImpl(_) => {
note_prev_span_then_ret!(self.prev_span, impl_item.span);
}
} else {
note_prev_span_then_ret!(self.prev_span, impl_item.span);
},
AssocContainer::InherentImpl => {},
}

let (article, desc) = cx.tcx.article_and_description(impl_item.owner_id.to_def_id());
Expand Down
7 changes: 4 additions & 3 deletions clippy_lints/src/missing_inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use rustc_hir::attrs::AttributeKind;
use rustc_hir::def_id::DefId;
use rustc_hir::{self as hir, Attribute, find_attr};
use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::ty::AssocItemContainer;
use rustc_middle::ty::AssocContainer;
use rustc_session::declare_lint_pass;
use rustc_span::Span;

Expand Down Expand Up @@ -166,8 +166,9 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline {
let assoc_item = cx.tcx.associated_item(impl_item.owner_id);
let container_id = assoc_item.container_id(cx.tcx);
let trait_def_id = match assoc_item.container {
AssocItemContainer::Trait => Some(container_id),
AssocItemContainer::Impl => cx.tcx.impl_trait_ref(container_id).map(|t| t.skip_binder().def_id),
AssocContainer::Trait => Some(container_id),
AssocContainer::TraitImpl(_) => cx.tcx.impl_trait_ref(container_id).map(|t| t.skip_binder().def_id),
AssocContainer::InherentImpl => None,
};

if let Some(trait_def_id) = trait_def_id
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/missing_trait_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingTraitMethods {
.tcx
.associated_items(item.owner_id)
.in_definition_order()
.filter_map(|assoc_item| assoc_item.trait_item_def_id)
.filter_map(|assoc_item| assoc_item.expect_trait_impl().ok())
.collect();

for assoc in cx
Expand Down
6 changes: 4 additions & 2 deletions clippy_lints/src/only_used_in_recursion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,11 +248,13 @@ impl<'tcx> LateLintPass<'tcx> for OnlyUsedInRecursion {
.tcx
.impl_trait_ref(item.owner_id)
.map(EarlyBinder::instantiate_identity)
&& let Some(trait_item_id) = cx.tcx.associated_item(owner_id).trait_item_def_id
&& let Some(trait_item_id) = cx.tcx.trait_item_of(owner_id)
{
(
trait_item_id,
FnKind::ImplTraitFn(std::ptr::from_ref(cx.tcx.erase_regions(trait_ref.args)) as usize),
FnKind::ImplTraitFn(
std::ptr::from_ref(cx.tcx.erase_and_anonymize_regions(trait_ref.args)) as usize
),
usize::from(sig.decl.implicit_self.has_implicit_self()),
)
} else {
Expand Down
4 changes: 3 additions & 1 deletion clippy_lints/src/transmute/transmute_ref_to_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ pub(super) fn check<'tcx>(
Applicability::MaybeIncorrect,
);
triggered = true;
} else if (cx.tcx.erase_regions(from_ty) != cx.tcx.erase_regions(to_ty)) && !const_context {
} else if (cx.tcx.erase_and_anonymize_regions(from_ty) != cx.tcx.erase_and_anonymize_regions(to_ty))
&& !const_context
{
span_lint_and_then(
cx,
TRANSMUTE_PTR_TO_PTR,
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/transmute/transmute_undefined_repr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ pub(super) fn check<'tcx>(
from_ty_orig: Ty<'tcx>,
to_ty_orig: Ty<'tcx>,
) -> bool {
let mut from_ty = cx.tcx.erase_regions(from_ty_orig);
let mut to_ty = cx.tcx.erase_regions(to_ty_orig);
let mut from_ty = cx.tcx.erase_and_anonymize_regions(from_ty_orig);
let mut to_ty = cx.tcx.erase_and_anonymize_regions(to_ty_orig);

while from_ty != to_ty {
let reduced_tys = reduce_refs(cx, from_ty, to_ty);
Expand Down
3 changes: 1 addition & 2 deletions clippy_lints/src/use_self.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,7 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf {
// trait, not in the impl of the trait.
let trait_method = cx
.tcx
.associated_item(impl_item.owner_id)
.trait_item_def_id
.trait_item_of(impl_item.owner_id)
.expect("impl method matches a trait method");
let trait_method_sig = cx.tcx.fn_sig(trait_method).instantiate_identity();
let trait_method_sig = cx.tcx.instantiate_bound_regions_with_erased(trait_method_sig);
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/useless_conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ fn into_iter_bound<'tcx>(
if tr.def_id() == into_iter_did {
into_iter_span = Some(*span);
} else {
let tr = cx.tcx.erase_regions(tr);
let tr = cx.tcx.erase_and_anonymize_regions(tr);
if tr.has_escaping_bound_vars() {
return None;
}
Expand Down
2 changes: 1 addition & 1 deletion clippy_utils/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "clippy_utils"
version = "0.1.91"
version = "0.1.92"
edition = "2024"
description = "Helpful tools for writing lints, provided as they are used in Clippy"
repository = "https://github.com/rust-lang/rust-clippy"
Expand Down
2 changes: 1 addition & 1 deletion clippy_utils/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ This crate is only guaranteed to build with this `nightly` toolchain:

<!-- begin autogenerated nightly -->
```
nightly-2025-09-04
nightly-2025-09-18
```
<!-- end autogenerated nightly -->

Expand Down
Loading