Auto merge of #12921 - flip1995:rustup, r=flip1995
Rustup r? `@ghost` changelog: none
This commit is contained in:
commit
3e5a02b13b
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "clippy"
|
||||
version = "0.1.80"
|
||||
version = "0.1.81"
|
||||
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.80"
|
||||
version = "0.1.81"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "clippy_lints"
|
||||
version = "0.1.80"
|
||||
version = "0.1.81"
|
||||
description = "A bunch of helpful lints to avoid common pitfalls in Rust"
|
||||
repository = "https://github.com/rust-lang/rust-clippy"
|
||||
readme = "README.md"
|
||||
|
@ -48,7 +48,7 @@
|
||||
declare_lint_pass!(DefaultNumericFallback => [DEFAULT_NUMERIC_FALLBACK]);
|
||||
|
||||
impl<'tcx> LateLintPass<'tcx> for DefaultNumericFallback {
|
||||
fn check_body(&mut self, cx: &LateContext<'tcx>, body: &'tcx Body<'_>) {
|
||||
fn check_body(&mut self, cx: &LateContext<'tcx>, body: &Body<'tcx>) {
|
||||
let hir = cx.tcx.hir();
|
||||
let is_parent_const = matches!(
|
||||
hir.body_const_context(hir.body_owner_def_id(body.id())),
|
||||
|
@ -643,7 +643,7 @@ fn check_pat(&mut self, cx: &LateContext<'tcx>, pat: &'tcx Pat<'_>) {
|
||||
}
|
||||
}
|
||||
|
||||
fn check_body_post(&mut self, cx: &LateContext<'tcx>, body: &'tcx Body<'_>) {
|
||||
fn check_body_post(&mut self, cx: &LateContext<'tcx>, body: &Body<'_>) {
|
||||
if Some(body.id()) == self.current_body {
|
||||
for pat in self.ref_locals.drain(..).filter_map(|(_, x)| x) {
|
||||
let replacements = pat.replacements;
|
||||
|
@ -8,7 +8,7 @@
|
||||
use rustc_errors::emitter::HumanEmitter;
|
||||
use rustc_errors::{Diag, DiagCtxt};
|
||||
use rustc_lint::LateContext;
|
||||
use rustc_parse::maybe_new_parser_from_source_str;
|
||||
use rustc_parse::new_parser_from_source_str;
|
||||
use rustc_parse::parser::ForceCollect;
|
||||
use rustc_session::parse::ParseSess;
|
||||
use rustc_span::edition::Edition;
|
||||
@ -50,7 +50,7 @@ fn check_code_sample(code: String, edition: Edition, ignore: bool) -> (bool, Vec
|
||||
let sm = Lrc::new(SourceMap::new(FilePathMapping::empty()));
|
||||
let psess = ParseSess::with_dcx(dcx, sm);
|
||||
|
||||
let mut parser = match maybe_new_parser_from_source_str(&psess, filename, code) {
|
||||
let mut parser = match new_parser_from_source_str(&psess, filename, code) {
|
||||
Ok(p) => p,
|
||||
Err(errs) => {
|
||||
errs.into_iter().for_each(Diag::cancel);
|
||||
|
@ -9,7 +9,7 @@
|
||||
use rustc_infer::infer::TyCtxtInferExt;
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
use rustc_middle::ty::{
|
||||
self, Binder, ClosureArgs, ClosureKind, FnSig, GenericArg, GenericArgKind, List, Region, RegionKind, Ty,
|
||||
self, Binder, ClosureArgs, ClosureKind, FnSig, GenericArg, GenericArgKind, List, Region, RegionKind, Ty, TyCtxt,
|
||||
TypeVisitableExt, TypeckResults,
|
||||
};
|
||||
use rustc_session::declare_lint_pass;
|
||||
@ -251,7 +251,7 @@ fn check_inputs(
|
||||
})
|
||||
}
|
||||
|
||||
fn check_sig<'tcx>(cx: &LateContext<'tcx>, closure: ClosureArgs<'tcx>, call_sig: FnSig<'_>) -> bool {
|
||||
fn check_sig<'tcx>(cx: &LateContext<'tcx>, closure: ClosureArgs<TyCtxt<'tcx>>, call_sig: FnSig<'_>) -> bool {
|
||||
call_sig.safety == Safety::Safe
|
||||
&& !has_late_bound_to_non_late_bound_regions(
|
||||
cx.tcx.signature_unclosure(closure.sig(), Safety::Safe).skip_binder(),
|
||||
|
@ -79,7 +79,7 @@ fn check_fn(
|
||||
let send_trait = cx.tcx.get_diagnostic_item(sym::Send).unwrap();
|
||||
let span = decl.output.span();
|
||||
let infcx = cx.tcx.infer_ctxt().build();
|
||||
let ocx = ObligationCtxt::new(&infcx);
|
||||
let ocx = ObligationCtxt::new_with_diagnostics(&infcx);
|
||||
let cause = traits::ObligationCause::misc(span, fn_def_id);
|
||||
ocx.register_bound(cause, cx.param_env, ret_ty, send_trait);
|
||||
let send_errors = ocx.select_all_or_error();
|
||||
|
@ -328,7 +328,7 @@ fn new(cx: &'a LateContext<'tcx>, target: &'b ImplicitHasherType<'tcx>) -> Self
|
||||
impl<'a, 'b, 'tcx> Visitor<'tcx> for ImplicitHasherConstructorVisitor<'a, 'b, 'tcx> {
|
||||
type NestedFilter = nested_filter::OnlyBodies;
|
||||
|
||||
fn visit_body(&mut self, body: &'tcx Body<'_>) {
|
||||
fn visit_body(&mut self, body: &Body<'tcx>) {
|
||||
let old_maybe_typeck_results = self.maybe_typeck_results.replace(self.cx.tcx.typeck_body(body.id()));
|
||||
walk_body(self, body);
|
||||
self.maybe_typeck_results = old_maybe_typeck_results;
|
||||
|
@ -3,8 +3,8 @@
|
||||
use rustc_errors::{Applicability, SuggestionStyle};
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_hir::{
|
||||
GenericArg, GenericBound, GenericBounds, ItemKind, PredicateOrigin, TraitBoundModifier, TyKind, TypeBinding,
|
||||
WherePredicate,
|
||||
AssocItemConstraint, GenericArg, GenericBound, GenericBounds, ItemKind, PredicateOrigin, TraitBoundModifier,
|
||||
TyKind, WherePredicate,
|
||||
};
|
||||
use rustc_hir_analysis::lower_ty;
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
@ -54,9 +54,9 @@ fn emit_lint(
|
||||
poly_trait: &rustc_hir::PolyTraitRef<'_>,
|
||||
bounds: GenericBounds<'_>,
|
||||
index: usize,
|
||||
// The bindings that were implied, used for suggestion purposes since removing a bound with associated types
|
||||
// means we might need to then move it to a different bound
|
||||
implied_bindings: &[TypeBinding<'_>],
|
||||
// The constraints that were implied, used for suggestion purposes since removing a bound with
|
||||
// associated types means we might need to then move it to a different bound.
|
||||
implied_constraints: &[AssocItemConstraint<'_>],
|
||||
bound: &ImplTraitBound<'_>,
|
||||
) {
|
||||
let implied_by = snippet(cx, bound.span, "..");
|
||||
@ -83,29 +83,29 @@ fn emit_lint(
|
||||
|
||||
let mut sugg = vec![(implied_span_extended, String::new())];
|
||||
|
||||
// We also might need to include associated type binding that were specified in the implied bound,
|
||||
// but omitted in the implied-by bound:
|
||||
// We also might need to include associated item constraints that were specified in the implied
|
||||
// bound, but omitted in the implied-by bound:
|
||||
// `fn f() -> impl Deref<Target = u8> + DerefMut`
|
||||
// If we're going to suggest removing `Deref<..>`, we'll need to put `<Target = u8>` on `DerefMut`
|
||||
let omitted_assoc_tys: Vec<_> = implied_bindings
|
||||
let omitted_constraints: Vec<_> = implied_constraints
|
||||
.iter()
|
||||
.filter(|binding| !bound.bindings.iter().any(|b| b.ident == binding.ident))
|
||||
.filter(|constraint| !bound.constraints.iter().any(|c| c.ident == constraint.ident))
|
||||
.collect();
|
||||
|
||||
if !omitted_assoc_tys.is_empty() {
|
||||
// `<>` needs to be added if there aren't yet any generic arguments or bindings
|
||||
let needs_angle_brackets = bound.args.is_empty() && bound.bindings.is_empty();
|
||||
let insert_span = match (bound.args, bound.bindings) {
|
||||
([.., arg], [.., binding]) => arg.span().max(binding.span).shrink_to_hi(),
|
||||
if !omitted_constraints.is_empty() {
|
||||
// `<>` needs to be added if there aren't yet any generic arguments or constraints
|
||||
let needs_angle_brackets = bound.args.is_empty() && bound.constraints.is_empty();
|
||||
let insert_span = match (bound.args, bound.constraints) {
|
||||
([.., arg], [.., constraint]) => arg.span().max(constraint.span).shrink_to_hi(),
|
||||
([.., arg], []) => arg.span().shrink_to_hi(),
|
||||
([], [.., binding]) => binding.span.shrink_to_hi(),
|
||||
([], [.., constraint]) => constraint.span.shrink_to_hi(),
|
||||
([], []) => bound.span.shrink_to_hi(),
|
||||
};
|
||||
|
||||
let mut associated_tys_sugg = if needs_angle_brackets {
|
||||
let mut constraints_sugg = if needs_angle_brackets {
|
||||
"<".to_owned()
|
||||
} else {
|
||||
// If angle brackets aren't needed (i.e., there are already generic arguments or bindings),
|
||||
// If angle brackets aren't needed (i.e., there are already generic arguments or constraints),
|
||||
// we need to add a comma:
|
||||
// `impl A<B, C >`
|
||||
// ^ if we insert `Assoc=i32` without a comma here, that'd be invalid syntax:
|
||||
@ -113,16 +113,16 @@ fn emit_lint(
|
||||
", ".to_owned()
|
||||
};
|
||||
|
||||
for (index, binding) in omitted_assoc_tys.into_iter().enumerate() {
|
||||
for (index, constraint) in omitted_constraints.into_iter().enumerate() {
|
||||
if index > 0 {
|
||||
associated_tys_sugg += ", ";
|
||||
constraints_sugg += ", ";
|
||||
}
|
||||
associated_tys_sugg += &snippet(cx, binding.span, "..");
|
||||
constraints_sugg += &snippet(cx, constraint.span, "..");
|
||||
}
|
||||
if needs_angle_brackets {
|
||||
associated_tys_sugg += ">";
|
||||
constraints_sugg += ">";
|
||||
}
|
||||
sugg.push((insert_span, associated_tys_sugg));
|
||||
sugg.push((insert_span, constraints_sugg));
|
||||
}
|
||||
|
||||
diag.multipart_suggestion_with_style(
|
||||
@ -229,8 +229,8 @@ struct ImplTraitBound<'tcx> {
|
||||
trait_def_id: DefId,
|
||||
/// The generic arguments on the `impl Trait` bound
|
||||
args: &'tcx [GenericArg<'tcx>],
|
||||
/// The associated types on this bound
|
||||
bindings: &'tcx [TypeBinding<'tcx>],
|
||||
/// The associated item constraints of this bound
|
||||
constraints: &'tcx [AssocItemConstraint<'tcx>],
|
||||
}
|
||||
|
||||
/// Given an `impl Trait` type, gets all the supertraits from each bound ("implied bounds").
|
||||
@ -253,7 +253,7 @@ fn collect_supertrait_bounds<'tcx>(cx: &LateContext<'tcx>, bounds: GenericBounds
|
||||
Some(ImplTraitBound {
|
||||
predicates,
|
||||
args: path.args.map_or([].as_slice(), |p| p.args),
|
||||
bindings: path.args.map_or([].as_slice(), |p| p.bindings),
|
||||
constraints: path.args.map_or([].as_slice(), |p| p.constraints),
|
||||
trait_def_id,
|
||||
span: bound.span(),
|
||||
})
|
||||
@ -310,20 +310,20 @@ fn check<'tcx>(cx: &LateContext<'tcx>, bounds: GenericBounds<'tcx>) {
|
||||
if let GenericBound::Trait(poly_trait, TraitBoundModifier::None) = bound
|
||||
&& let [.., path] = poly_trait.trait_ref.path.segments
|
||||
&& let implied_args = path.args.map_or([].as_slice(), |a| a.args)
|
||||
&& let implied_bindings = path.args.map_or([].as_slice(), |a| a.bindings)
|
||||
&& let implied_constraints = path.args.map_or([].as_slice(), |a| a.constraints)
|
||||
&& let Some(def_id) = poly_trait.trait_ref.path.res.opt_def_id()
|
||||
&& let Some(bound) = find_bound_in_supertraits(cx, def_id, implied_args, &supertraits)
|
||||
// If the implied bound has a type binding that also exists in the implied-by trait,
|
||||
// then we shouldn't lint. See #11880 for an example.
|
||||
&& let assocs = cx.tcx.associated_items(bound.trait_def_id)
|
||||
&& !implied_bindings.iter().any(|binding| {
|
||||
&& !implied_constraints.iter().any(|constraint| {
|
||||
assocs
|
||||
.filter_by_name_unhygienic(binding.ident.name)
|
||||
.filter_by_name_unhygienic(constraint.ident.name)
|
||||
.next()
|
||||
.is_some_and(|assoc| assoc.kind == ty::AssocKind::Type)
|
||||
})
|
||||
{
|
||||
emit_lint(cx, poly_trait, bounds, index, implied_bindings, bound);
|
||||
emit_lint(cx, poly_trait, bounds, index, implied_constraints, bound);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -54,8 +54,8 @@ fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
|
||||
&& generics.params.is_empty() && !generics.has_where_clause_predicates
|
||||
&& let ty = cx.tcx.type_of(item.owner_id).instantiate_identity()
|
||||
&& let ty::Array(element_type, cst) = ty.kind()
|
||||
&& let ConstKind::Value(ty::ValTree::Leaf(element_count)) = cst.kind()
|
||||
&& let Ok(element_count) = element_count.try_to_target_usize(cx.tcx)
|
||||
&& let ConstKind::Value(_, ty::ValTree::Leaf(element_count)) = cst.kind()
|
||||
&& let element_count = element_count.to_target_usize(cx.tcx)
|
||||
&& let Ok(element_size) = cx.layout_of(*element_type).map(|l| l.size.bytes())
|
||||
&& self.maximum_allowed_size < u128::from(element_count) * u128::from(element_size)
|
||||
{
|
||||
|
@ -64,8 +64,8 @@ fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &Expr<'tcx>) {
|
||||
if let ExprKind::Repeat(_, _) | ExprKind::Array(_) = expr.kind
|
||||
&& !self.is_from_vec_macro(cx, expr.span)
|
||||
&& let ty::Array(element_type, cst) = cx.typeck_results().expr_ty(expr).kind()
|
||||
&& let ConstKind::Value(ty::ValTree::Leaf(element_count)) = cst.kind()
|
||||
&& let Ok(element_count) = element_count.try_to_target_usize(cx.tcx)
|
||||
&& let ConstKind::Value(_, ty::ValTree::Leaf(element_count)) = cst.kind()
|
||||
&& let element_count = element_count.to_target_usize(cx.tcx)
|
||||
&& let Ok(element_size) = cx.layout_of(*element_type).map(|l| l.size.bytes())
|
||||
&& !cx.tcx.hir().parent_iter(expr.hir_id).any(|(_, node)| {
|
||||
matches!(
|
||||
|
@ -9,7 +9,7 @@
|
||||
use rustc_hir::{
|
||||
AssocItemKind, BinOpKind, Expr, ExprKind, FnRetTy, GenericArg, GenericBound, ImplItem, ImplItemKind,
|
||||
ImplicitSelfKind, Item, ItemKind, Mutability, Node, OpaqueTyOrigin, PatKind, PathSegment, PrimTy, QPath,
|
||||
TraitItemRef, TyKind, TypeBindingKind,
|
||||
TraitItemRef, TyKind,
|
||||
};
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
use rustc_middle::ty::{self, AssocKind, FnSig, Ty};
|
||||
@ -253,7 +253,7 @@ fn is_named_self(cx: &LateContext<'_>, item: &TraitItemRef, name: Symbol) -> boo
|
||||
// fill the set with current and super traits
|
||||
fn fill_trait_set(traitt: DefId, set: &mut DefIdSet, cx: &LateContext<'_>) {
|
||||
if set.insert(traitt) {
|
||||
for supertrait in rustc_trait_selection::traits::supertrait_def_ids(cx.tcx, traitt) {
|
||||
for supertrait in cx.tcx.supertrait_def_ids(traitt) {
|
||||
fill_trait_set(supertrait, set, cx);
|
||||
}
|
||||
}
|
||||
@ -307,17 +307,12 @@ fn extract_future_output<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option<&
|
||||
&& let [GenericBound::Trait(trait_ref, _)] = &opaque.bounds
|
||||
&& let Some(segment) = trait_ref.trait_ref.path.segments.last()
|
||||
&& let Some(generic_args) = segment.args
|
||||
&& generic_args.bindings.len() == 1
|
||||
&& let TypeBindingKind::Equality {
|
||||
term:
|
||||
rustc_hir::Term::Ty(rustc_hir::Ty {
|
||||
kind: TyKind::Path(QPath::Resolved(_, path)),
|
||||
..
|
||||
}),
|
||||
} = &generic_args.bindings[0].kind
|
||||
&& path.segments.len() == 1
|
||||
&& let [constraint] = generic_args.constraints
|
||||
&& let Some(ty) = constraint.ty()
|
||||
&& let TyKind::Path(QPath::Resolved(_, path)) = ty.kind
|
||||
&& let [segment] = path.segments
|
||||
{
|
||||
return Some(&path.segments[0]);
|
||||
return Some(segment);
|
||||
}
|
||||
|
||||
None
|
||||
|
@ -186,7 +186,7 @@ fn visit_expr(&mut self, e: &'tcx Expr<'tcx>) {
|
||||
}
|
||||
|
||||
impl<'tcx> LateLintPass<'tcx> for ExprMetavarsInUnsafe {
|
||||
fn check_body(&mut self, cx: &LateContext<'tcx>, body: &'tcx rustc_hir::Body<'tcx>) {
|
||||
fn check_body(&mut self, cx: &LateContext<'tcx>, body: &rustc_hir::Body<'tcx>) {
|
||||
if is_lint_allowed(cx, MACRO_METAVARS_IN_UNSAFE, body.value.hir_id) {
|
||||
return;
|
||||
}
|
||||
|
@ -4,8 +4,7 @@
|
||||
use rustc_hir::intravisit::FnKind;
|
||||
use rustc_hir::{
|
||||
Block, Body, Closure, ClosureKind, CoroutineDesugaring, CoroutineKind, CoroutineSource, Expr, ExprKind, FnDecl,
|
||||
FnRetTy, GenericArg, GenericBound, ImplItem, Item, ItemKind, LifetimeName, Node, Term, TraitRef, Ty, TyKind,
|
||||
TypeBindingKind,
|
||||
FnRetTy, GenericArg, GenericBound, ImplItem, Item, ItemKind, LifetimeName, Node, TraitRef, Ty, TyKind,
|
||||
};
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
use rustc_session::declare_lint_pass;
|
||||
@ -138,10 +137,9 @@ fn future_trait_ref<'tcx>(
|
||||
fn future_output_ty<'tcx>(trait_ref: &'tcx TraitRef<'tcx>) -> Option<&'tcx Ty<'tcx>> {
|
||||
if let Some(segment) = trait_ref.path.segments.last()
|
||||
&& let Some(args) = segment.args
|
||||
&& args.bindings.len() == 1
|
||||
&& let binding = &args.bindings[0]
|
||||
&& binding.ident.name == sym::Output
|
||||
&& let TypeBindingKind::Equality { term: Term::Ty(output) } = binding.kind
|
||||
&& let [constraint] = args.constraints
|
||||
&& constraint.ident.name == sym::Output
|
||||
&& let Some(output) = constraint.ty()
|
||||
{
|
||||
return Some(output);
|
||||
}
|
||||
|
@ -37,14 +37,14 @@ fn all_ranges<'tcx>(cx: &LateContext<'tcx>, arms: &'tcx [Arm<'_>], ty: Ty<'tcx>)
|
||||
Some(lhs) => constant(cx, cx.typeck_results(), lhs)?,
|
||||
None => {
|
||||
let min_val_const = ty.numeric_min_val(cx.tcx)?;
|
||||
mir_to_const(cx, mir::Const::from_ty_const(min_val_const, cx.tcx))?
|
||||
mir_to_const(cx, mir::Const::from_ty_const(min_val_const, ty, cx.tcx))?
|
||||
},
|
||||
};
|
||||
let rhs_const = match rhs {
|
||||
Some(rhs) => constant(cx, cx.typeck_results(), rhs)?,
|
||||
None => {
|
||||
let max_val_const = ty.numeric_max_val(cx.tcx)?;
|
||||
mir_to_const(cx, mir::Const::from_ty_const(max_val_const, cx.tcx))?
|
||||
mir_to_const(cx, mir::Const::from_ty_const(max_val_const, ty, cx.tcx))?
|
||||
},
|
||||
};
|
||||
let lhs_val = lhs_const.int_value(cx, ty)?;
|
||||
|
@ -42,7 +42,7 @@ fn is_arg_ty_unified_in_fn<'tcx>(
|
||||
cx.tcx.predicates_of(fn_id).predicates.iter().any(|(clause, _)| {
|
||||
clause
|
||||
.as_projection_clause()
|
||||
.and_then(|p| p.map_bound(|p| p.term.ty()).transpose())
|
||||
.and_then(|p| p.map_bound(|p| p.term.as_type()).transpose())
|
||||
.is_some_and(|ty| ty.skip_binder() == arg_ty_in_args)
|
||||
}) || fn_sig
|
||||
.inputs()
|
||||
|
@ -59,7 +59,7 @@ pub(super) fn check<'tcx>(
|
||||
};
|
||||
|
||||
let map = cx.tcx.hir();
|
||||
let body = map.body(map.body_owned_by(map.enclosing_body_owner(expr.hir_id)));
|
||||
let body = map.body_owned_by(map.enclosing_body_owner(expr.hir_id));
|
||||
reference_visitor.visit_body(body);
|
||||
|
||||
if reference_visitor.found_reference {
|
||||
|
@ -129,7 +129,7 @@ fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
|
||||
}
|
||||
}
|
||||
|
||||
fn check_body_post(&mut self, cx: &LateContext<'tcx>, body: &'tcx Body<'_>) {
|
||||
fn check_body_post(&mut self, cx: &LateContext<'tcx>, body: &Body<'_>) {
|
||||
if self.possible_borrowers.last().map_or(false, |&(local_def_id, _)| {
|
||||
local_def_id == cx.tcx.hir().body_owner_def_id(body.id())
|
||||
}) {
|
||||
@ -311,7 +311,7 @@ fn is_mixed_projection_predicate<'tcx>(
|
||||
) -> bool {
|
||||
let generics = cx.tcx.generics_of(callee_def_id);
|
||||
// The predicate requires the projected type to equal a type parameter from the parent context.
|
||||
if let Some(term_ty) = projection_predicate.term.ty()
|
||||
if let Some(term_ty) = projection_predicate.term.as_type()
|
||||
&& let ty::Param(term_param_ty) = term_ty.kind()
|
||||
&& (term_param_ty.index as usize) < generics.parent_count
|
||||
{
|
||||
@ -370,7 +370,7 @@ fn replace_types<'tcx>(
|
||||
if replaced.insert(param_ty.index) {
|
||||
for projection_predicate in projection_predicates {
|
||||
if projection_predicate.projection_term.self_ty() == param_ty.to_ty(cx.tcx)
|
||||
&& let Some(term_ty) = projection_predicate.term.ty()
|
||||
&& let Some(term_ty) = projection_predicate.term.as_type()
|
||||
&& let ty::Param(term_param_ty) = term_ty.kind()
|
||||
{
|
||||
let projection = projection_predicate
|
||||
|
@ -207,7 +207,7 @@ fn is_value_unfrozen_raw_inner(cx: &LateContext<'tcx>, val: ty::ValTree<'tcx>, t
|
||||
.any(|field| Self::is_value_unfrozen_raw_inner(cx, *field, ty)),
|
||||
ty::Adt(def, args) if def.is_enum() => {
|
||||
let (&variant_index, fields) = val.unwrap_branch().split_first().unwrap();
|
||||
let variant_index = VariantIdx::from_u32(variant_index.unwrap_leaf().try_to_u32().ok().unwrap());
|
||||
let variant_index = VariantIdx::from_u32(variant_index.unwrap_leaf().to_u32());
|
||||
fields
|
||||
.iter()
|
||||
.copied()
|
||||
|
@ -221,7 +221,7 @@ pub struct OnlyUsedInRecursion {
|
||||
}
|
||||
|
||||
impl<'tcx> LateLintPass<'tcx> for OnlyUsedInRecursion {
|
||||
fn check_body(&mut self, cx: &LateContext<'tcx>, body: &'tcx Body<'tcx>) {
|
||||
fn check_body(&mut self, cx: &LateContext<'tcx>, body: &Body<'tcx>) {
|
||||
if body.value.span.from_expansion() {
|
||||
return;
|
||||
}
|
||||
@ -350,7 +350,7 @@ fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'tcx>) {
|
||||
}
|
||||
}
|
||||
|
||||
fn check_body_post(&mut self, cx: &LateContext<'tcx>, body: &'tcx Body<'tcx>) {
|
||||
fn check_body_post(&mut self, cx: &LateContext<'tcx>, body: &Body<'tcx>) {
|
||||
if self.entered_body == Some(body.value.hir_id) {
|
||||
self.entered_body = None;
|
||||
self.params.flag_for_linting();
|
||||
|
@ -868,11 +868,11 @@ fn check_expr_post(&mut self, _: &LateContext<'_>, e: &Expr<'_>) {
|
||||
self.arithmetic_context.expr_post(e.hir_id);
|
||||
}
|
||||
|
||||
fn check_body(&mut self, cx: &LateContext<'tcx>, b: &'tcx Body<'_>) {
|
||||
fn check_body(&mut self, cx: &LateContext<'tcx>, b: &Body<'_>) {
|
||||
self.arithmetic_context.enter_body(cx, b);
|
||||
}
|
||||
|
||||
fn check_body_post(&mut self, cx: &LateContext<'tcx>, b: &'tcx Body<'_>) {
|
||||
fn check_body_post(&mut self, cx: &LateContext<'tcx>, b: &Body<'_>) {
|
||||
self.arithmetic_context.body_post(cx, b);
|
||||
}
|
||||
}
|
||||
|
@ -188,7 +188,7 @@ fn check_trait_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx TraitItem<'_>
|
||||
}
|
||||
}
|
||||
|
||||
fn check_body(&mut self, cx: &LateContext<'tcx>, body: &'tcx Body<'_>) {
|
||||
fn check_body(&mut self, cx: &LateContext<'tcx>, body: &Body<'tcx>) {
|
||||
let hir = cx.tcx.hir();
|
||||
let mut parents = hir.parent_iter(body.value.hir_id);
|
||||
let (item_id, sig, is_trait_item) = match parents.next() {
|
||||
@ -525,7 +525,7 @@ fn check_fn_args<'cx, 'tcx: 'cx>(
|
||||
})
|
||||
}
|
||||
|
||||
fn check_mut_from_ref<'tcx>(cx: &LateContext<'tcx>, sig: &FnSig<'_>, body: Option<&'tcx Body<'_>>) {
|
||||
fn check_mut_from_ref<'tcx>(cx: &LateContext<'tcx>, sig: &FnSig<'_>, body: Option<&Body<'tcx>>) {
|
||||
if let FnRetTy::Return(ty) = sig.decl.output
|
||||
&& let Some((out, Mutability::Mut, _)) = get_ref_lm(ty)
|
||||
{
|
||||
@ -559,7 +559,7 @@ fn check_mut_from_ref<'tcx>(cx: &LateContext<'tcx>, sig: &FnSig<'_>, body: Optio
|
||||
}
|
||||
|
||||
#[expect(clippy::too_many_lines)]
|
||||
fn check_ptr_arg_usage<'tcx>(cx: &LateContext<'tcx>, body: &'tcx Body<'_>, args: &[PtrArg<'tcx>]) -> Vec<PtrArgResult> {
|
||||
fn check_ptr_arg_usage<'tcx>(cx: &LateContext<'tcx>, body: &Body<'tcx>, args: &[PtrArg<'tcx>]) -> Vec<PtrArgResult> {
|
||||
struct V<'cx, 'tcx> {
|
||||
cx: &'cx LateContext<'tcx>,
|
||||
/// Map from a local id to which argument it came from (index into `Self::args` and
|
||||
|
@ -370,11 +370,11 @@ fn check_block(&mut self, cx: &LateContext<'tcx>, block: &'tcx Block<'tcx>) {
|
||||
}
|
||||
}
|
||||
|
||||
fn check_body(&mut self, _: &LateContext<'tcx>, _: &'tcx Body<'tcx>) {
|
||||
fn check_body(&mut self, _: &LateContext<'tcx>, _: &Body<'tcx>) {
|
||||
self.try_block_depth_stack.push(0);
|
||||
}
|
||||
|
||||
fn check_body_post(&mut self, _: &LateContext<'tcx>, _: &'tcx Body<'tcx>) {
|
||||
fn check_body_post(&mut self, _: &LateContext<'tcx>, _: &Body<'tcx>) {
|
||||
self.try_block_depth_stack.pop();
|
||||
}
|
||||
|
||||
|
@ -86,7 +86,6 @@ fn is_function_allowed(
|
||||
.tcx
|
||||
.hir()
|
||||
.maybe_body_owned_by(fn_def_id)
|
||||
.map(|body| cx.tcx.hir().body(body))
|
||||
.map_or(true, |body| is_in_test_function(cx.tcx, body.value.hir_id))
|
||||
|| match cx.tcx.hir_node(fn_hir_id) {
|
||||
Node::Item(item) => is_from_proc_macro(cx, item),
|
||||
|
@ -30,8 +30,7 @@ fn get_parent_local_binding_ty<'tcx>(cx: &LateContext<'tcx>, expr_hir_id: HirId)
|
||||
|
||||
fn is_function_block(cx: &LateContext<'_>, expr_hir_id: HirId) -> bool {
|
||||
let def_id = cx.tcx.hir().enclosing_body_owner(expr_hir_id);
|
||||
if let Some(body_id) = cx.tcx.hir().maybe_body_owned_by(def_id) {
|
||||
let body = cx.tcx.hir().body(body_id);
|
||||
if let Some(body) = cx.tcx.hir().maybe_body_owned_by(def_id) {
|
||||
return body.value.peel_blocks().hir_id == expr_hir_id;
|
||||
}
|
||||
false
|
||||
|
@ -336,7 +336,7 @@ fn init_default_impl_for_type_if_needed(&mut self, cx: &LateContext<'_>) {
|
||||
// We need to use typeck here to infer the actual function being called.
|
||||
&& let body_def_id = cx.tcx.hir().enclosing_body_owner(call_expr.hir_id)
|
||||
&& let Some(body_owner) = cx.tcx.hir().maybe_body_owned_by(body_def_id)
|
||||
&& let typeck = cx.tcx.typeck_body(body_owner)
|
||||
&& let typeck = cx.tcx.typeck_body(body_owner.id())
|
||||
&& let Some(call_def_id) = typeck.type_dependent_def_id(call_expr.hir_id)
|
||||
{
|
||||
self.default_impl_for_type.insert(self_def_id, call_def_id);
|
||||
|
@ -100,12 +100,12 @@ fn get_args_to_check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> Ve
|
||||
{
|
||||
if ord_preds
|
||||
.iter()
|
||||
.any(|ord| Some(ord.self_ty()) == return_ty_pred.term.ty())
|
||||
.any(|ord| Some(ord.self_ty()) == return_ty_pred.term.as_type())
|
||||
{
|
||||
args_to_check.push((i, "Ord".to_string()));
|
||||
} else if partial_ord_preds
|
||||
.iter()
|
||||
.any(|pord| pord.self_ty() == return_ty_pred.term.ty().unwrap())
|
||||
.any(|pord| pord.self_ty() == return_ty_pred.term.expect_type())
|
||||
{
|
||||
args_to_check.push((i, "PartialOrd".to_string()));
|
||||
}
|
||||
|
@ -137,9 +137,9 @@ fn check_stmt(&mut self, cx: &LateContext<'tcx>, stmt: &'tcx hir::Stmt<'_>) {
|
||||
|
||||
fn check_item(cx: &LateContext<'_>, hir_id: HirId) {
|
||||
let hir = cx.tcx.hir();
|
||||
if let Some(body_id) = hir.maybe_body_owned_by(hir_id.expect_owner().def_id) {
|
||||
if let Some(body) = hir.maybe_body_owned_by(hir_id.expect_owner().def_id) {
|
||||
check_node(cx, hir_id, |v| {
|
||||
v.expr(&v.bind("expr", hir.body(body_id).value));
|
||||
v.expr(&v.bind("expr", body.value));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -213,7 +213,7 @@ fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
|
||||
output: &mut self.registered_lints,
|
||||
cx,
|
||||
};
|
||||
let body_id = cx.tcx.hir().body_owned_by(
|
||||
let body = cx.tcx.hir().body_owned_by(
|
||||
impl_item_refs
|
||||
.iter()
|
||||
.find(|iiref| iiref.ident.as_str() == "get_lints")
|
||||
@ -222,7 +222,7 @@ fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
|
||||
.owner_id
|
||||
.def_id,
|
||||
);
|
||||
collector.visit_expr(cx.tcx.hir().body(body_id).value);
|
||||
collector.visit_expr(body.value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -719,7 +719,7 @@ fn get_lint_group_and_level_or_lint(
|
||||
Some(sym::clippy),
|
||||
&std::iter::once(Ident::with_dummy_span(sym::clippy)).collect(),
|
||||
);
|
||||
if let CheckLintNameResult::Tool(Ok(lint_lst)) = result {
|
||||
if let CheckLintNameResult::Tool(lint_lst, None) = result {
|
||||
if let Some(group) = get_lint_group(cx, lint_lst[0]) {
|
||||
if EXCLUDED_LINT_GROUPS.contains(&group.as_str()) {
|
||||
return None;
|
||||
|
@ -55,9 +55,8 @@ fn check_expr(&mut self, cx: &LateContext<'_>, expr: &'_ rustc_hir::Expr<'_>) {
|
||||
inner_check(cx, expr, inner_expr, true);
|
||||
} else if let ExprKind::Repeat(inner_expr, _) = expr.kind
|
||||
&& let ty::Array(_, cst) = cx.typeck_results().expr_ty(expr).kind()
|
||||
&& let ConstKind::Value(ty::ValTree::Leaf(element_count)) = cst.kind()
|
||||
&& let Ok(element_count) = element_count.try_to_target_usize(cx.tcx)
|
||||
&& element_count == 0
|
||||
&& let ConstKind::Value(_, ty::ValTree::Leaf(element_count)) = cst.kind()
|
||||
&& element_count.to_target_usize(cx.tcx) == 0
|
||||
{
|
||||
inner_check(cx, expr, inner_expr, false);
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "clippy_utils"
|
||||
version = "0.1.80"
|
||||
version = "0.1.81"
|
||||
edition = "2021"
|
||||
publish = false
|
||||
|
||||
|
@ -108,7 +108,7 @@ pub fn eq_generic_args(l: &GenericArgs, r: &GenericArgs) -> bool {
|
||||
pub fn eq_angle_arg(l: &AngleBracketedArg, r: &AngleBracketedArg) -> bool {
|
||||
match (l, r) {
|
||||
(AngleBracketedArg::Arg(l), AngleBracketedArg::Arg(r)) => eq_generic_arg(l, r),
|
||||
(AngleBracketedArg::Constraint(l), AngleBracketedArg::Constraint(r)) => eq_assoc_constraint(l, r),
|
||||
(AngleBracketedArg::Constraint(l), AngleBracketedArg::Constraint(r)) => eq_assoc_item_constraint(l, r),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
@ -308,13 +308,15 @@ pub fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool {
|
||||
ty: lt,
|
||||
mutability: lm,
|
||||
expr: le,
|
||||
safety: ls,
|
||||
}),
|
||||
Static(box StaticItem {
|
||||
ty: rt,
|
||||
mutability: rm,
|
||||
expr: re,
|
||||
safety: rs,
|
||||
}),
|
||||
) => lm == rm && eq_ty(lt, rt) && eq_expr_opt(le, re),
|
||||
) => lm == rm && ls == rs && eq_ty(lt, rt) && eq_expr_opt(le, re),
|
||||
(
|
||||
Const(box ConstItem {
|
||||
defaultness: ld,
|
||||
@ -451,13 +453,15 @@ pub fn eq_foreign_item_kind(l: &ForeignItemKind, r: &ForeignItemKind) -> bool {
|
||||
ty: lt,
|
||||
mutability: lm,
|
||||
expr: le,
|
||||
safety: ls,
|
||||
}),
|
||||
Static(box StaticForeignItem {
|
||||
ty: rt,
|
||||
mutability: rm,
|
||||
expr: re,
|
||||
safety: rs,
|
||||
}),
|
||||
) => lm == rm && eq_ty(lt, rt) && eq_expr_opt(le, re),
|
||||
) => lm == rm && eq_ty(lt, rt) && eq_expr_opt(le, re) && ls == rs,
|
||||
(
|
||||
Fn(box ast::Fn {
|
||||
defaultness: ld,
|
||||
@ -802,8 +806,8 @@ fn eq_term(l: &Term, r: &Term) -> bool {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn eq_assoc_constraint(l: &AssocConstraint, r: &AssocConstraint) -> bool {
|
||||
use AssocConstraintKind::*;
|
||||
pub fn eq_assoc_item_constraint(l: &AssocItemConstraint, r: &AssocItemConstraint) -> bool {
|
||||
use AssocItemConstraintKind::*;
|
||||
eq_id(l.ident, r.ident)
|
||||
&& match (&l.kind, &r.kind) {
|
||||
(Equality { term: l }, Equality { term: r }) => eq_term(l, r),
|
||||
|
@ -6,7 +6,7 @@
|
||||
use rustc_ast::ast::{self, LitFloatType, LitKind};
|
||||
use rustc_data_structures::sync::Lrc;
|
||||
use rustc_hir::def::{DefKind, Res};
|
||||
use rustc_hir::{BinOp, BinOpKind, Block, Expr, ExprKind, HirId, Item, ItemKind, Node, QPath, UnOp};
|
||||
use rustc_hir::{BinOp, BinOpKind, Block, ConstBlock, Expr, ExprKind, HirId, Item, ItemKind, Node, QPath, UnOp};
|
||||
use rustc_lexer::tokenize;
|
||||
use rustc_lint::LateContext;
|
||||
use rustc_middle::mir::interpret::{alloc_range, Scalar};
|
||||
@ -412,7 +412,8 @@ pub fn new(lcx: &'a LateContext<'tcx>, typeck_results: &'a ty::TypeckResults<'tc
|
||||
/// Simple constant folding: Insert an expression, get a constant or none.
|
||||
pub fn expr(&mut self, e: &Expr<'_>) -> Option<Constant<'tcx>> {
|
||||
match e.kind {
|
||||
ExprKind::ConstBlock(e) | ExprKind::DropTemps(e) => self.expr(e),
|
||||
ExprKind::ConstBlock(ConstBlock { body, .. }) => self.expr(self.lcx.tcx.hir().body(body).value),
|
||||
ExprKind::DropTemps(e) => self.expr(e),
|
||||
ExprKind::Path(ref qpath) => {
|
||||
self.fetch_path_and_apply(qpath, e.hir_id, self.typeck_results.expr_ty(e), |this, result| {
|
||||
let result = mir_to_const(this.lcx, result)?;
|
||||
@ -490,7 +491,8 @@ pub fn expr(&mut self, e: &Expr<'_>) -> Option<Constant<'tcx>> {
|
||||
/// leaves the local crate.
|
||||
pub fn expr_is_empty(&mut self, e: &Expr<'_>) -> Option<bool> {
|
||||
match e.kind {
|
||||
ExprKind::ConstBlock(e) | ExprKind::DropTemps(e) => self.expr_is_empty(e),
|
||||
ExprKind::ConstBlock(ConstBlock { body, .. }) => self.expr_is_empty(self.lcx.tcx.hir().body(body).value),
|
||||
ExprKind::DropTemps(e) => self.expr_is_empty(e),
|
||||
ExprKind::Path(ref qpath) => {
|
||||
if !self
|
||||
.typeck_results
|
||||
@ -810,14 +812,10 @@ pub fn mir_to_const<'tcx>(lcx: &LateContext<'tcx>, result: mir::Const<'tcx>) ->
|
||||
(ConstValue::Scalar(Scalar::Int(int)), _) => match result.ty().kind() {
|
||||
ty::Adt(adt_def, _) if adt_def.is_struct() => Some(Constant::Adt(result)),
|
||||
ty::Bool => Some(Constant::Bool(int == ScalarInt::TRUE)),
|
||||
ty::Uint(_) | ty::Int(_) => Some(Constant::Int(int.assert_bits(int.size()))),
|
||||
ty::Float(FloatTy::F32) => Some(Constant::F32(f32::from_bits(
|
||||
int.try_into().expect("invalid f32 bit representation"),
|
||||
))),
|
||||
ty::Float(FloatTy::F64) => Some(Constant::F64(f64::from_bits(
|
||||
int.try_into().expect("invalid f64 bit representation"),
|
||||
))),
|
||||
ty::RawPtr(_, _) => Some(Constant::RawPtr(int.assert_bits(int.size()))),
|
||||
ty::Uint(_) | ty::Int(_) => Some(Constant::Int(int.to_bits(int.size()))),
|
||||
ty::Float(FloatTy::F32) => Some(Constant::F32(f32::from_bits(int.into()))),
|
||||
ty::Float(FloatTy::F64) => Some(Constant::F64(f64::from_bits(int.into()))),
|
||||
ty::RawPtr(_, _) => Some(Constant::RawPtr(int.to_bits(int.size()))),
|
||||
_ => None,
|
||||
},
|
||||
(_, ty::Ref(_, inner_ty, _)) if matches!(inner_ty.kind(), ty::Str) => {
|
||||
|
@ -7,9 +7,9 @@
|
||||
use rustc_hir::def::Res;
|
||||
use rustc_hir::MatchSource::TryDesugar;
|
||||
use rustc_hir::{
|
||||
ArrayLen, BinOpKind, BindingMode, Block, BodyId, Closure, Expr, ExprField, ExprKind, FnRetTy, GenericArg,
|
||||
GenericArgs, HirId, HirIdMap, InlineAsmOperand, LetExpr, Lifetime, LifetimeName, Pat, PatField, PatKind, Path,
|
||||
PathSegment, PrimTy, QPath, Stmt, StmtKind, Ty, TyKind, TypeBinding,
|
||||
ArrayLen, AssocItemConstraint, BinOpKind, BindingMode, Block, BodyId, Closure, Expr, ExprField, ExprKind, FnRetTy,
|
||||
GenericArg, GenericArgs, HirId, HirIdMap, InlineAsmOperand, LetExpr, Lifetime, LifetimeName, Pat, PatField,
|
||||
PatKind, Path, PathSegment, PrimTy, QPath, Stmt, StmtKind, Ty, TyKind,
|
||||
};
|
||||
use rustc_lexer::{tokenize, TokenKind};
|
||||
use rustc_lint::LateContext;
|
||||
@ -295,7 +295,7 @@ pub fn eq_expr(&mut self, left: &Expr<'_>, right: &Expr<'_>) -> bool {
|
||||
self.eq_expr(lx, rx) && self.eq_ty(lt, rt)
|
||||
},
|
||||
(&ExprKind::Closure(_l), &ExprKind::Closure(_r)) => false,
|
||||
(&ExprKind::ConstBlock(lb), &ExprKind::ConstBlock(rb)) => self.eq_expr(lb, rb),
|
||||
(&ExprKind::ConstBlock(lb), &ExprKind::ConstBlock(rb)) => self.eq_body(lb.body, rb.body),
|
||||
(&ExprKind::Continue(li), &ExprKind::Continue(ri)) => {
|
||||
both(&li.label, &ri.label, |l, r| l.ident.name == r.ident.name)
|
||||
},
|
||||
@ -486,7 +486,7 @@ pub fn eq_path(&mut self, left: &Path<'_>, right: &Path<'_>) -> bool {
|
||||
fn eq_path_parameters(&mut self, left: &GenericArgs<'_>, right: &GenericArgs<'_>) -> bool {
|
||||
if left.parenthesized == right.parenthesized {
|
||||
over(left.args, right.args, |l, r| self.eq_generic_arg(l, r)) // FIXME(flip1995): may not work
|
||||
&& over(left.bindings, right.bindings, |l, r| self.eq_type_binding(l, r))
|
||||
&& over(left.constraints, right.constraints, |l, r| self.eq_assoc_type_binding(l, r))
|
||||
} else {
|
||||
false
|
||||
}
|
||||
@ -518,8 +518,12 @@ pub fn eq_ty(&mut self, left: &Ty<'_>, right: &Ty<'_>) -> bool {
|
||||
}
|
||||
}
|
||||
|
||||
fn eq_type_binding(&mut self, left: &TypeBinding<'_>, right: &TypeBinding<'_>) -> bool {
|
||||
left.ident.name == right.ident.name && self.eq_ty(left.ty(), right.ty())
|
||||
fn eq_assoc_type_binding(&mut self, left: &AssocItemConstraint<'_>, right: &AssocItemConstraint<'_>) -> bool {
|
||||
left.ident.name == right.ident.name
|
||||
&& self.eq_ty(
|
||||
left.ty().expect("expected assoc type binding"),
|
||||
right.ty().expect("expected assoc type binding"),
|
||||
)
|
||||
}
|
||||
|
||||
fn check_ctxt(&mut self, left: SyntaxContext, right: SyntaxContext) -> bool {
|
||||
@ -769,8 +773,8 @@ pub fn hash_expr(&mut self, e: &Expr<'_>) {
|
||||
// closures inherit TypeckResults
|
||||
self.hash_expr(self.cx.tcx.hir().body(body).value);
|
||||
},
|
||||
ExprKind::ConstBlock(l_id) => {
|
||||
self.hash_expr(l_id);
|
||||
ExprKind::ConstBlock(ref l_id) => {
|
||||
self.hash_body(l_id.body);
|
||||
},
|
||||
ExprKind::DropTemps(e) | ExprKind::Yield(e, _) => {
|
||||
self.hash_expr(e);
|
||||
|
@ -656,7 +656,7 @@ fn item_children_by_name(tcx: TyCtxt<'_>, def_id: DefId, name: Symbol) -> Vec<Re
|
||||
/// This function is expensive and should be used sparingly.
|
||||
pub fn def_path_res(cx: &LateContext<'_>, path: &[&str]) -> Vec<Res> {
|
||||
fn find_crates(tcx: TyCtxt<'_>, name: Symbol) -> impl Iterator<Item = DefId> + '_ {
|
||||
tcx.crates_including_speculative(())
|
||||
tcx.crates(())
|
||||
.iter()
|
||||
.copied()
|
||||
.filter(move |&num| tcx.crate_name(num) == name)
|
||||
@ -1543,7 +1543,7 @@ pub fn is_range_full(cx: &LateContext<'_>, expr: &Expr<'_>, container_path: Opti
|
||||
if let rustc_ty::Adt(_, subst) = ty.kind()
|
||||
&& let bnd_ty = subst.type_at(0)
|
||||
&& let Some(min_val) = bnd_ty.numeric_min_val(cx.tcx)
|
||||
&& let Some(min_const) = mir_to_const(cx, Const::from_ty_const(min_val, cx.tcx))
|
||||
&& let Some(min_const) = mir_to_const(cx, Const::from_ty_const(min_val, bnd_ty, cx.tcx))
|
||||
&& let Some(start_const) = constant(cx, cx.typeck_results(), start)
|
||||
{
|
||||
start_const == min_const
|
||||
@ -1556,7 +1556,7 @@ pub fn is_range_full(cx: &LateContext<'_>, expr: &Expr<'_>, container_path: Opti
|
||||
if let rustc_ty::Adt(_, subst) = ty.kind()
|
||||
&& let bnd_ty = subst.type_at(0)
|
||||
&& let Some(max_val) = bnd_ty.numeric_max_val(cx.tcx)
|
||||
&& let Some(max_const) = mir_to_const(cx, Const::from_ty_const(max_val, cx.tcx))
|
||||
&& let Some(max_const) = mir_to_const(cx, Const::from_ty_const(max_val, bnd_ty, cx.tcx))
|
||||
&& let Some(end_const) = constant(cx, cx.typeck_results(), end)
|
||||
{
|
||||
end_const == max_const
|
||||
|
@ -23,7 +23,7 @@
|
||||
};
|
||||
use rustc_span::symbol::Ident;
|
||||
use rustc_span::{sym, Span, Symbol, DUMMY_SP};
|
||||
use rustc_target::abi::{Size, VariantIdx};
|
||||
use rustc_target::abi::VariantIdx;
|
||||
use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt as _;
|
||||
use rustc_trait_selection::traits::query::normalize::QueryNormalizeExt;
|
||||
use rustc_trait_selection::traits::{Obligation, ObligationCause};
|
||||
@ -750,7 +750,7 @@ pub fn ty_sig<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option<ExprFnSig<'t
|
||||
let output = bounds
|
||||
.projection_bounds()
|
||||
.find(|p| lang_items.fn_once_output().map_or(false, |id| id == p.item_def_id()))
|
||||
.map(|p| p.map_bound(|p| p.term.ty().unwrap()));
|
||||
.map(|p| p.map_bound(|p| p.term.expect_type()));
|
||||
Some(ExprFnSig::Trait(bound.map_bound(|b| b.args.type_at(0)), output, None))
|
||||
},
|
||||
_ => None,
|
||||
@ -798,7 +798,7 @@ fn sig_from_bounds<'tcx>(
|
||||
// Multiple different fn trait impls. Is this even allowed?
|
||||
return None;
|
||||
}
|
||||
output = Some(pred.kind().rebind(p.term.ty().unwrap()));
|
||||
output = Some(pred.kind().rebind(p.term.expect_type()));
|
||||
},
|
||||
_ => (),
|
||||
}
|
||||
@ -836,7 +836,7 @@ fn sig_for_projection<'tcx>(cx: &LateContext<'tcx>, ty: AliasTy<'tcx>) -> Option
|
||||
// Multiple different fn trait impls. Is this even allowed?
|
||||
return None;
|
||||
}
|
||||
output = pred.kind().rebind(p.term.ty()).transpose();
|
||||
output = pred.kind().rebind(p.term.as_type()).transpose();
|
||||
},
|
||||
_ => (),
|
||||
}
|
||||
@ -861,26 +861,11 @@ fn add(self, n: u32) -> Self::Output {
|
||||
}
|
||||
|
||||
/// Attempts to read the given constant as though it were an enum value.
|
||||
#[expect(clippy::cast_possible_truncation, clippy::cast_possible_wrap)]
|
||||
pub fn read_explicit_enum_value(tcx: TyCtxt<'_>, id: DefId) -> Option<EnumValue> {
|
||||
if let Ok(ConstValue::Scalar(Scalar::Int(value))) = tcx.const_eval_poly(id) {
|
||||
match tcx.type_of(id).instantiate_identity().kind() {
|
||||
ty::Int(_) => Some(EnumValue::Signed(match value.size().bytes() {
|
||||
1 => i128::from(value.assert_bits(Size::from_bytes(1)) as u8 as i8),
|
||||
2 => i128::from(value.assert_bits(Size::from_bytes(2)) as u16 as i16),
|
||||
4 => i128::from(value.assert_bits(Size::from_bytes(4)) as u32 as i32),
|
||||
8 => i128::from(value.assert_bits(Size::from_bytes(8)) as u64 as i64),
|
||||
16 => value.assert_bits(Size::from_bytes(16)) as i128,
|
||||
_ => return None,
|
||||
})),
|
||||
ty::Uint(_) => Some(EnumValue::Unsigned(match value.size().bytes() {
|
||||
1 => value.assert_bits(Size::from_bytes(1)),
|
||||
2 => value.assert_bits(Size::from_bytes(2)),
|
||||
4 => value.assert_bits(Size::from_bytes(4)),
|
||||
8 => value.assert_bits(Size::from_bytes(8)),
|
||||
16 => value.assert_bits(Size::from_bytes(16)),
|
||||
_ => return None,
|
||||
})),
|
||||
ty::Int(_) => Some(EnumValue::Signed(value.to_int(value.size()))),
|
||||
ty::Uint(_) => Some(EnumValue::Unsigned(value.to_uint(value.size()))),
|
||||
_ => None,
|
||||
}
|
||||
} else {
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "declare_clippy_lint"
|
||||
version = "0.1.80"
|
||||
version = "0.1.81"
|
||||
edition = "2021"
|
||||
publish = false
|
||||
|
||||
|
@ -1,3 +1,3 @@
|
||||
[toolchain]
|
||||
channel = "nightly-2024-05-30"
|
||||
channel = "nightly-2024-06-13"
|
||||
components = ["cargo", "llvm-tools", "rust-src", "rust-std", "rustc", "rustc-dev", "rustfmt"]
|
||||
|
@ -1,35 +1,11 @@
|
||||
error: arithmetic operation that can potentially result in unexpected side-effects
|
||||
--> tests/ui/arithmetic_side_effects.rs:188:36
|
||||
|
|
||||
LL | let _ = const { let mut n = 1; n += 1; n };
|
||||
| ^^^^^^
|
||||
|
|
||||
= note: `-D clippy::arithmetic-side-effects` implied by `-D warnings`
|
||||
= help: to override `-D warnings` add `#[allow(clippy::arithmetic_side_effects)]`
|
||||
|
||||
error: arithmetic operation that can potentially result in unexpected side-effects
|
||||
--> tests/ui/arithmetic_side_effects.rs:191:40
|
||||
|
|
||||
LL | let _ = const { let mut n = 1; n = n + 1; n };
|
||||
| ^^^^^
|
||||
|
||||
error: arithmetic operation that can potentially result in unexpected side-effects
|
||||
--> tests/ui/arithmetic_side_effects.rs:194:40
|
||||
|
|
||||
LL | let _ = const { let mut n = 1; n = 1 + n; n };
|
||||
| ^^^^^
|
||||
|
||||
error: arithmetic operation that can potentially result in unexpected side-effects
|
||||
--> tests/ui/arithmetic_side_effects.rs:200:59
|
||||
|
|
||||
LL | let _ = const { let mut n = 1; n = -1; n = -(-1); n = -n; n };
|
||||
| ^^
|
||||
|
||||
error: arithmetic operation that can potentially result in unexpected side-effects
|
||||
--> tests/ui/arithmetic_side_effects.rs:304:5
|
||||
|
|
||||
LL | _n += 1;
|
||||
| ^^^^^^^
|
||||
|
|
||||
= note: `-D clippy::arithmetic-side-effects` implied by `-D warnings`
|
||||
= help: to override `-D warnings` add `#[allow(clippy::arithmetic_side_effects)]`
|
||||
|
||||
error: arithmetic operation that can potentially result in unexpected side-effects
|
||||
--> tests/ui/arithmetic_side_effects.rs:305:5
|
||||
@ -751,5 +727,5 @@ error: arithmetic operation that can potentially result in unexpected side-effec
|
||||
LL | one.sub_assign(1);
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 125 previous errors
|
||||
error: aborting due to 121 previous errors
|
||||
|
||||
|
@ -16,7 +16,7 @@ fn foo(
|
||||
|
||||
fn skip_on_statements() {
|
||||
#[rustfmt::skip]
|
||||
{ 5+3; }
|
||||
5+3;
|
||||
}
|
||||
|
||||
#[rustfmt::skip]
|
||||
@ -33,11 +33,11 @@ mod foo {
|
||||
#[clippy::msrv = "1.29"]
|
||||
fn msrv_1_29() {
|
||||
#[cfg_attr(rustfmt, rustfmt::skip)]
|
||||
{ 1+29; }
|
||||
1+29;
|
||||
}
|
||||
|
||||
#[clippy::msrv = "1.30"]
|
||||
fn msrv_1_30() {
|
||||
#[rustfmt::skip]
|
||||
{ 1+30; }
|
||||
1+30;
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ fn foo(
|
||||
|
||||
fn skip_on_statements() {
|
||||
#[cfg_attr(rustfmt, rustfmt::skip)]
|
||||
{ 5+3; }
|
||||
5+3;
|
||||
}
|
||||
|
||||
#[cfg_attr(rustfmt, rustfmt_skip)]
|
||||
@ -33,11 +33,11 @@ pub fn f() {}
|
||||
#[clippy::msrv = "1.29"]
|
||||
fn msrv_1_29() {
|
||||
#[cfg_attr(rustfmt, rustfmt::skip)]
|
||||
{ 1+29; }
|
||||
1+29;
|
||||
}
|
||||
|
||||
#[clippy::msrv = "1.30"]
|
||||
fn msrv_1_30() {
|
||||
#[cfg_attr(rustfmt, rustfmt::skip)]
|
||||
{ 1+30; }
|
||||
1+30;
|
||||
}
|
||||
|
@ -45,8 +45,8 @@ fn std_instead_of_core() {
|
||||
|
||||
let _ = std::env!("PATH");
|
||||
|
||||
// do not lint until `error_in_core` is stable
|
||||
use std::error::Error;
|
||||
use core::error::Error;
|
||||
//~^ ERROR: used import from `std` instead of `core`
|
||||
|
||||
// lint items re-exported from private modules, `core::iter::traits::iterator::Iterator`
|
||||
use core::iter::Iterator;
|
||||
|
@ -45,8 +45,8 @@ fn std_instead_of_core() {
|
||||
|
||||
let _ = std::env!("PATH");
|
||||
|
||||
// do not lint until `error_in_core` is stable
|
||||
use std::error::Error;
|
||||
//~^ ERROR: used import from `std` instead of `core`
|
||||
|
||||
// lint items re-exported from private modules, `core::iter::traits::iterator::Iterator`
|
||||
use std::iter::Iterator;
|
||||
|
@ -49,6 +49,12 @@ error: used import from `std` instead of `core`
|
||||
LL | let cell_absolute = ::std::cell::Cell::new(8u32);
|
||||
| ^^^ help: consider importing the item from `core`: `core`
|
||||
|
||||
error: used import from `std` instead of `core`
|
||||
--> tests/ui/std_instead_of_core.rs:48:9
|
||||
|
|
||||
LL | use std::error::Error;
|
||||
| ^^^ help: consider importing the item from `core`: `core`
|
||||
|
||||
error: used import from `std` instead of `core`
|
||||
--> tests/ui/std_instead_of_core.rs:52:9
|
||||
|
|
||||
@ -79,5 +85,5 @@ LL | use alloc::slice::from_ref;
|
||||
= note: `-D clippy::alloc-instead-of-core` implied by `-D warnings`
|
||||
= help: to override `-D warnings` add `#[allow(clippy::alloc_instead_of_core)]`
|
||||
|
||||
error: aborting due to 12 previous errors
|
||||
error: aborting due to 13 previous errors
|
||||
|
||||
|
@ -1,35 +1,11 @@
|
||||
error: using tabs in doc comments is not recommended
|
||||
--> tests/ui/tabs_in_doc_comments.rs:6:5
|
||||
|
|
||||
LL | /// - first one
|
||||
| ^^^^ help: consider using four spaces per tab
|
||||
|
|
||||
= note: `-D clippy::tabs-in-doc-comments` implied by `-D warnings`
|
||||
= help: to override `-D warnings` add `#[allow(clippy::tabs_in_doc_comments)]`
|
||||
|
||||
error: using tabs in doc comments is not recommended
|
||||
--> tests/ui/tabs_in_doc_comments.rs:6:13
|
||||
|
|
||||
LL | /// - first one
|
||||
| ^^^^^^^^ help: consider using four spaces per tab
|
||||
|
||||
error: using tabs in doc comments is not recommended
|
||||
--> tests/ui/tabs_in_doc_comments.rs:7:5
|
||||
|
|
||||
LL | /// - second one
|
||||
| ^^^^ help: consider using four spaces per tab
|
||||
|
||||
error: using tabs in doc comments is not recommended
|
||||
--> tests/ui/tabs_in_doc_comments.rs:7:14
|
||||
|
|
||||
LL | /// - second one
|
||||
| ^^^^ help: consider using four spaces per tab
|
||||
|
||||
error: using tabs in doc comments is not recommended
|
||||
--> tests/ui/tabs_in_doc_comments.rs:10:9
|
||||
|
|
||||
LL | /// - First String:
|
||||
| ^^^^ help: consider using four spaces per tab
|
||||
|
|
||||
= note: `-D clippy::tabs-in-doc-comments` implied by `-D warnings`
|
||||
= help: to override `-D warnings` add `#[allow(clippy::tabs_in_doc_comments)]`
|
||||
|
||||
error: using tabs in doc comments is not recommended
|
||||
--> tests/ui/tabs_in_doc_comments.rs:11:9
|
||||
@ -49,5 +25,29 @@ error: using tabs in doc comments is not recommended
|
||||
LL | /// - needs to be inside here
|
||||
| ^^^^^^^^ help: consider using four spaces per tab
|
||||
|
||||
error: using tabs in doc comments is not recommended
|
||||
--> tests/ui/tabs_in_doc_comments.rs:6:5
|
||||
|
|
||||
LL | /// - first one
|
||||
| ^^^^ help: consider using four spaces per tab
|
||||
|
||||
error: using tabs in doc comments is not recommended
|
||||
--> tests/ui/tabs_in_doc_comments.rs:6:13
|
||||
|
|
||||
LL | /// - first one
|
||||
| ^^^^^^^^ help: consider using four spaces per tab
|
||||
|
||||
error: using tabs in doc comments is not recommended
|
||||
--> tests/ui/tabs_in_doc_comments.rs:7:5
|
||||
|
|
||||
LL | /// - second one
|
||||
| ^^^^ help: consider using four spaces per tab
|
||||
|
||||
error: using tabs in doc comments is not recommended
|
||||
--> tests/ui/tabs_in_doc_comments.rs:7:14
|
||||
|
|
||||
LL | /// - second one
|
||||
| ^^^^ help: consider using four spaces per tab
|
||||
|
||||
error: aborting due to 8 previous errors
|
||||
|
||||
|
@ -11,7 +11,7 @@ error: invisible character detected
|
||||
--> tests/ui/unicode.rs:7:12
|
||||
|
|
||||
LL | print!("Here >< is a SHY, and another");
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider replacing the string with: `"Here >\u{AD}< is a SHY, and \u{AD}another"`
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider replacing the string with: `"Here >\u{AD}< is a SHY, and \u{AD}another"`
|
||||
|
||||
error: invisible character detected
|
||||
--> tests/ui/unicode.rs:9:12
|
||||
|
Loading…
Reference in New Issue
Block a user