commit
20ce69b9a6
33 changed files with 117 additions and 111 deletions
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "clippy_config"
|
||||
version = "0.1.91"
|
||||
version = "0.1.92"
|
||||
edition = "2024"
|
||||
publish = false
|
||||
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
@ -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<'_>) {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
@ -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);
|
||||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
@ -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());
|
||||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
@ -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| {
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
@ -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());
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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 -->
|
||||
|
||||
|
|
|
|||
|
|
@ -22,8 +22,9 @@ use rustc_ast::token::CommentKind;
|
|||
use rustc_hir::intravisit::FnKind;
|
||||
use rustc_hir::{
|
||||
Block, BlockCheckMode, Body, Closure, Destination, Expr, ExprKind, FieldDef, FnHeader, FnRetTy, HirId, Impl,
|
||||
ImplItem, ImplItemKind, IsAuto, Item, ItemKind, Lit, LoopSource, MatchSource, MutTy, Node, Path, QPath, Safety,
|
||||
TraitImplHeader, TraitItem, TraitItemKind, Ty, TyKind, UnOp, UnsafeSource, Variant, VariantData, YieldSource,
|
||||
ImplItem, ImplItemImplKind, ImplItemKind, IsAuto, Item, ItemKind, Lit, LoopSource, MatchSource, MutTy, Node, Path,
|
||||
QPath, Safety, TraitImplHeader, TraitItem, TraitItemKind, Ty, TyKind, UnOp, UnsafeSource, Variant, VariantData,
|
||||
YieldSource,
|
||||
};
|
||||
use rustc_lint::{EarlyContext, LateContext, LintContext};
|
||||
use rustc_middle::ty::TyCtxt;
|
||||
|
|
@ -283,16 +284,17 @@ fn trait_item_search_pat(item: &TraitItem<'_>) -> (Pat, Pat) {
|
|||
}
|
||||
|
||||
fn impl_item_search_pat(item: &ImplItem<'_>) -> (Pat, Pat) {
|
||||
let (start_pat, end_pat) = match &item.kind {
|
||||
let (mut start_pat, end_pat) = match &item.kind {
|
||||
ImplItemKind::Const(..) => (Pat::Str("const"), Pat::Str(";")),
|
||||
ImplItemKind::Type(..) => (Pat::Str("type"), Pat::Str(";")),
|
||||
ImplItemKind::Fn(sig, ..) => (fn_header_search_pat(sig.header), Pat::Str("")),
|
||||
};
|
||||
if item.vis_span.is_empty() {
|
||||
(start_pat, end_pat)
|
||||
} else {
|
||||
(Pat::Str("pub"), end_pat)
|
||||
if let ImplItemImplKind::Inherent { vis_span, .. } = item.impl_kind
|
||||
&& !vis_span.is_empty()
|
||||
{
|
||||
start_pat = Pat::Str("pub");
|
||||
}
|
||||
(start_pat, end_pat)
|
||||
}
|
||||
|
||||
fn field_def_search_pat(def: &FieldDef<'_>) -> (Pat, Pat) {
|
||||
|
|
@ -316,22 +318,24 @@ fn variant_search_pat(v: &Variant<'_>) -> (Pat, Pat) {
|
|||
}
|
||||
|
||||
fn fn_kind_pat(tcx: TyCtxt<'_>, kind: &FnKind<'_>, body: &Body<'_>, hir_id: HirId) -> (Pat, Pat) {
|
||||
let (start_pat, end_pat) = match kind {
|
||||
let (mut start_pat, end_pat) = match kind {
|
||||
FnKind::ItemFn(.., header) => (fn_header_search_pat(*header), Pat::Str("")),
|
||||
FnKind::Method(.., sig) => (fn_header_search_pat(sig.header), Pat::Str("")),
|
||||
FnKind::Closure => return (Pat::Str(""), expr_search_pat(tcx, body.value).1),
|
||||
};
|
||||
let start_pat = match tcx.hir_node(hir_id) {
|
||||
Node::Item(Item { vis_span, .. }) | Node::ImplItem(ImplItem { vis_span, .. }) => {
|
||||
if vis_span.is_empty() {
|
||||
start_pat
|
||||
} else {
|
||||
Pat::Str("pub")
|
||||
match tcx.hir_node(hir_id) {
|
||||
Node::Item(Item { vis_span, .. })
|
||||
| Node::ImplItem(ImplItem {
|
||||
impl_kind: ImplItemImplKind::Inherent { vis_span, .. },
|
||||
..
|
||||
}) => {
|
||||
if !vis_span.is_empty() {
|
||||
start_pat = Pat::Str("pub");
|
||||
}
|
||||
},
|
||||
Node::TraitItem(_) => start_pat,
|
||||
_ => Pat::Str(""),
|
||||
};
|
||||
Node::ImplItem(_) | Node::TraitItem(_) => {},
|
||||
_ => start_pat = Pat::Str(""),
|
||||
}
|
||||
(start_pat, end_pat)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2137,17 +2137,11 @@ pub fn std_or_core(cx: &LateContext<'_>) -> Option<&'static str> {
|
|||
}
|
||||
|
||||
pub fn is_no_std_crate(cx: &LateContext<'_>) -> bool {
|
||||
cx.tcx
|
||||
.hir_attrs(hir::CRATE_HIR_ID)
|
||||
.iter()
|
||||
.any(|attr| attr.has_name(sym::no_std))
|
||||
find_attr!(cx.tcx.hir_attrs(hir::CRATE_HIR_ID), AttributeKind::NoStd(..))
|
||||
}
|
||||
|
||||
pub fn is_no_core_crate(cx: &LateContext<'_>) -> bool {
|
||||
cx.tcx
|
||||
.hir_attrs(hir::CRATE_HIR_ID)
|
||||
.iter()
|
||||
.any(|attr| attr.has_name(sym::no_core))
|
||||
find_attr!(cx.tcx.hir_attrs(hir::CRATE_HIR_ID), AttributeKind::NoCore(..))
|
||||
}
|
||||
|
||||
/// Check if parent of a hir node is a trait implementation block.
|
||||
|
|
@ -3251,8 +3245,8 @@ pub fn get_path_from_caller_to_method_type<'tcx>(
|
|||
let assoc_item = tcx.associated_item(method);
|
||||
let def_id = assoc_item.container_id(tcx);
|
||||
match assoc_item.container {
|
||||
rustc_ty::AssocItemContainer::Trait => get_path_to_callee(tcx, from, def_id),
|
||||
rustc_ty::AssocItemContainer::Impl => {
|
||||
rustc_ty::AssocContainer::Trait => get_path_to_callee(tcx, from, def_id),
|
||||
rustc_ty::AssocContainer::InherentImpl | rustc_ty::AssocContainer::TraitImpl(_) => {
|
||||
let ty = tcx.type_of(def_id).instantiate_identity();
|
||||
get_path_to_ty(tcx, from, ty, args)
|
||||
},
|
||||
|
|
|
|||
|
|
@ -126,7 +126,7 @@ fn check_rvalue<'tcx>(
|
|||
) -> McfResult {
|
||||
match rvalue {
|
||||
Rvalue::ThreadLocalRef(_) => Err((span, "cannot access thread local storage in const fn".into())),
|
||||
Rvalue::Len(place) | Rvalue::Discriminant(place) | Rvalue::Ref(_, _, place) | Rvalue::RawPtr(_, place) => {
|
||||
Rvalue::Discriminant(place) | Rvalue::Ref(_, _, place) | Rvalue::RawPtr(_, place) => {
|
||||
check_place(cx, *place, span, body, msrv)
|
||||
},
|
||||
Rvalue::CopyForDeref(place) => check_place(cx, *place, span, body, msrv),
|
||||
|
|
|
|||
|
|
@ -195,7 +195,6 @@ generate! {
|
|||
itertools,
|
||||
join,
|
||||
kw,
|
||||
last,
|
||||
lazy_static,
|
||||
lint_vec,
|
||||
ln,
|
||||
|
|
|
|||
|
|
@ -280,7 +280,7 @@ pub fn implements_trait_with_env_from_iter<'tcx>(
|
|||
let _ = tcx.hir_body_owner_kind(callee_id);
|
||||
}
|
||||
|
||||
let ty = tcx.erase_regions(ty);
|
||||
let ty = tcx.erase_and_anonymize_regions(ty);
|
||||
if ty.has_escaping_bound_vars() {
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "declare_clippy_lint"
|
||||
version = "0.1.91"
|
||||
version = "0.1.92"
|
||||
edition = "2024"
|
||||
repository = "https://github.com/rust-lang/rust-clippy"
|
||||
license = "MIT OR Apache-2.0"
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
[toolchain]
|
||||
# begin autogenerated nightly
|
||||
channel = "nightly-2025-09-04"
|
||||
channel = "nightly-2025-09-18"
|
||||
# end autogenerated nightly
|
||||
components = ["cargo", "llvm-tools", "rust-src", "rust-std", "rustc", "rustc-dev", "rustfmt"]
|
||||
profile = "minimal"
|
||||
|
|
|
|||
|
|
@ -272,10 +272,8 @@ LL | assert_eq!(a!(), true);
|
|||
|
|
||||
help: replace it with `assert!(..)`
|
||||
|
|
||||
LL | true
|
||||
...
|
||||
LL |
|
||||
LL ~ assert!(a!());
|
||||
LL - assert_eq!(a!(), true);
|
||||
LL + assert!(a!());
|
||||
|
|
||||
|
||||
error: used `assert_eq!` with a literal bool
|
||||
|
|
@ -286,10 +284,8 @@ LL | assert_eq!(true, b!());
|
|||
|
|
||||
help: replace it with `assert!(..)`
|
||||
|
|
||||
LL | true
|
||||
...
|
||||
LL |
|
||||
LL ~ assert!(b!());
|
||||
LL - assert_eq!(true, b!());
|
||||
LL + assert!(b!());
|
||||
|
|
||||
|
||||
error: used `debug_assert_eq!` with a literal bool
|
||||
|
|
|
|||
|
|
@ -196,7 +196,6 @@ fn issue_13106() {
|
|||
|
||||
const {
|
||||
assert!(EMPTY_STR.is_empty());
|
||||
//~^ const_is_empty
|
||||
}
|
||||
|
||||
const {
|
||||
|
|
|
|||
|
|
@ -158,16 +158,10 @@ LL | let _ = val.is_empty();
|
|||
| ^^^^^^^^^^^^^^
|
||||
|
||||
error: this expression always evaluates to true
|
||||
--> tests/ui/const_is_empty.rs:198:17
|
||||
|
|
||||
LL | assert!(EMPTY_STR.is_empty());
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: this expression always evaluates to true
|
||||
--> tests/ui/const_is_empty.rs:203:9
|
||||
--> tests/ui/const_is_empty.rs:202:9
|
||||
|
|
||||
LL | EMPTY_STR.is_empty();
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 28 previous errors
|
||||
error: aborting due to 27 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#![warn(clippy::incompatible_msrv)]
|
||||
#![feature(custom_inner_attributes)]
|
||||
#![allow(stable_features, clippy::diverging_sub_expression)]
|
||||
#![allow(stable_features)]
|
||||
#![feature(strict_provenance)] // For use in test
|
||||
#![clippy::msrv = "1.3.0"]
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue