Auto merge of #12632 - flip1995:rustup, r=flip1995
Rustup r? `@ghost` changelog: none
This commit is contained in:
commit
9725c4a162
book/src/development
clippy_config/src
clippy_lints/src
assigning_clones.rs
attrs
box_default.rscasts
as_ptr_cast_mut.rscast_ptr_alignment.rscast_slice_different_sizes.rscast_slice_from_raw_parts.rsptr_as_ptr.rsptr_cast_constness.rsref_as_ptr.rsunnecessary_cast.rs
cognitive_complexity.rscollection_is_never_read.rsderive.rsequatable_if_let.rseta_reduction.rsfloat_literal.rsfrom_raw_with_void_ptr.rsfunctions
future_not_send.rsignored_unit_patterns.rsimplicit_hasher.rsimplied_bounds_in_impls.rsindex_refutable_slice.rsiter_without_into_iter.rslen_zero.rslet_underscore.rslet_with_type_underscore.rsloops
manual_hash_one.rsmanual_rem_euclid.rsmatches
infallible_destructuring_match.rsmatch_as_ref.rsmatch_same_arms.rsmatch_single_binding.rsmod.rsneedless_match.rsredundant_guards.rssignificant_drop_in_scrutinee.rs
methods
clone_on_copy.rsiter_kv_map.rsiter_on_single_or_empty_collections.rsneedless_collect.rsreadonly_write_lock.rsstr_splitn.rsunnecessary_fold.rsunnecessary_to_owned.rszst_offset.rs
misc.rsmissing_doc.rsmixed_read_write_in_expression.rsmut_key.rsmut_reference.rsmutex_atomic.rsneedless_late_init.rsnon_send_fields_in_send_ty.rspattern_type_mismatch.rsptr.rsquestion_mark.rsraw_strings.rsread_zero_byte_vec.rsredundant_else.rsredundant_locals.rsredundant_type_annotations.rsreserve_after_initialization.rsshadow.rssignificant_drop_tightening.rssize_of_in_element_count.rssuspicious_operation_groupings.rsswap.rstransmute
crosspointer_transmute.rsmissing_transmute_annotations.rstransmute_ptr_to_ptr.rstransmute_ptr_to_ref.rstransmute_ref_to_ref.rstransmute_undefined_repr.rsuseless_transmute.rsutils.rswrong_transmute.rs
tuple_array_conversions.rstypes
unconditional_recursion.rsundocumented_unsafe_blocks.rsuninhabited_references.rsunit_types
unnested_or_patterns.rsunused_io_amount.rsunused_peekable.rs@ -118,10 +118,10 @@ Here the HIR sees the types without "thinking" about them, it knows that the fun
|
||||
an `u32`. As far as `hir::Ty` is concerned those might be different types. But at the `ty::Ty` level the compiler
|
||||
understands that they're the same type, in-depth lifetimes, etc...
|
||||
|
||||
To get from a `hir::Ty` to a `ty::Ty`, you can use the [`hir_ty_to_ty`][hir_ty_to_ty] function outside of bodies or
|
||||
To get from a `hir::Ty` to a `ty::Ty`, you can use the [`lower_ty`][lower_ty] function outside of bodies or
|
||||
the [`TypeckResults::node_type()`][node_type] method inside of bodies.
|
||||
|
||||
> **Warning**: Don't use `hir_ty_to_ty` inside of bodies, because this can cause ICEs.
|
||||
> **Warning**: Don't use `lower_ty` inside of bodies, because this can cause ICEs.
|
||||
|
||||
## Creating Types programmatically
|
||||
|
||||
@ -162,6 +162,6 @@ in this chapter:
|
||||
[Ty]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.Ty.html
|
||||
[TyKind]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_type_ir/ty_kind/enum.TyKind.html
|
||||
[TypeckResults]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TypeckResults.html
|
||||
[middle_ty]: https://doc.rust-lang.org/beta/nightly-rustc/rustc_middle/ty/struct.Ty.html
|
||||
[hir_ty]: https://doc.rust-lang.org/beta/nightly-rustc/rustc_hir/struct.Ty.html
|
||||
[hir_ty_to_ty]: https://doc.rust-lang.org/beta/nightly-rustc/rustc_hir_analysis/fn.hir_ty_to_ty.html
|
||||
[middle_ty]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.Ty.html
|
||||
[hir_ty]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/struct.Ty.html
|
||||
[lower_ty]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir_analysis/fn.lower_ty.html
|
||||
|
@ -856,11 +856,6 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
assert!(
|
||||
names.remove("allow-one-hash-in-raw-strings"),
|
||||
"remove this when #11481 is fixed"
|
||||
);
|
||||
|
||||
assert!(
|
||||
names.is_empty(),
|
||||
"Configuration variable lacks test: {names:?}\nAdd a test to `tests/ui-toml`"
|
||||
|
@ -143,13 +143,13 @@ impl Msrv {
|
||||
None
|
||||
}
|
||||
|
||||
pub fn enter_lint_attrs(&mut self, sess: &Session, attrs: &[Attribute]) {
|
||||
pub fn check_attributes(&mut self, sess: &Session, attrs: &[Attribute]) {
|
||||
if let Some(version) = Self::parse_attr(sess, attrs) {
|
||||
self.stack.push(version);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn exit_lint_attrs(&mut self, sess: &Session, attrs: &[Attribute]) {
|
||||
pub fn check_attributes_post(&mut self, sess: &Session, attrs: &[Attribute]) {
|
||||
if Self::parse_attr(sess, attrs).is_some() {
|
||||
self.stack.pop();
|
||||
}
|
||||
|
@ -163,7 +163,7 @@ fn is_ok_to_suggest<'tcx>(cx: &LateContext<'tcx>, lhs: &Expr<'tcx>, call: &CallC
|
||||
// TODO: This check currently bails if the local variable has no initializer.
|
||||
// That is overly conservative - the lint should fire even if there was no initializer,
|
||||
// but the variable has been initialized before `lhs` was evaluated.
|
||||
if let Some(Node::Local(local)) = cx.tcx.hir().parent_id_iter(local).next().map(|p| cx.tcx.hir_node(p))
|
||||
if let Some(Node::LetStmt(local)) = cx.tcx.hir().parent_id_iter(local).next().map(|p| cx.tcx.hir_node(p))
|
||||
&& local.init.is_none()
|
||||
{
|
||||
return false;
|
||||
|
@ -25,7 +25,6 @@ fn emit_if_duplicated(
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::needless_return)]
|
||||
fn check_duplicated_attr(
|
||||
cx: &EarlyContext<'_>,
|
||||
attr: &MetaItem,
|
||||
@ -49,7 +48,8 @@ fn check_duplicated_attr(
|
||||
// FIXME: We don't correctly check `cfg`s for now, so if it's more complex than just a one
|
||||
// level `cfg`, we leave.
|
||||
return;
|
||||
} else if let Some(value) = attr.value_str() {
|
||||
}
|
||||
if let Some(value) = attr.value_str() {
|
||||
emit_if_duplicated(cx, attr, attr_paths, format!("{}:{name}={value}", parent.join(":")));
|
||||
} else if let Some(sub_attrs) = attr.meta_item_list() {
|
||||
parent.push(name.as_str().to_string());
|
||||
|
@ -5,7 +5,7 @@ use clippy_utils::{is_default_equivalent, path_def_id};
|
||||
use rustc_errors::Applicability;
|
||||
use rustc_hir::def::Res;
|
||||
use rustc_hir::intravisit::{walk_ty, Visitor};
|
||||
use rustc_hir::{Block, Expr, ExprKind, Local, Node, QPath, Ty, TyKind};
|
||||
use rustc_hir::{Block, Expr, ExprKind, LetStmt, Node, QPath, Ty, TyKind};
|
||||
use rustc_lint::{LateContext, LateLintPass, LintContext};
|
||||
use rustc_middle::lint::in_external_macro;
|
||||
use rustc_session::declare_lint_pass;
|
||||
@ -102,7 +102,7 @@ impl<'tcx> Visitor<'tcx> for InferVisitor {
|
||||
|
||||
fn given_type(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
|
||||
match cx.tcx.parent_hir_node(expr.hir_id) {
|
||||
Node::Local(Local { ty: Some(ty), .. }) => {
|
||||
Node::LetStmt(LetStmt { ty: Some(ty), .. }) => {
|
||||
let mut v = InferVisitor::default();
|
||||
v.visit_ty(ty);
|
||||
!v.0
|
||||
|
@ -4,18 +4,13 @@ use rustc_errors::Applicability;
|
||||
use rustc_hir::{Expr, ExprKind};
|
||||
use rustc_lint::LateContext;
|
||||
use rustc_middle::mir::Mutability;
|
||||
use rustc_middle::ty::{self, Ty, TypeAndMut};
|
||||
use rustc_middle::ty::{self, Ty};
|
||||
|
||||
use super::AS_PTR_CAST_MUT;
|
||||
|
||||
pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_expr: &Expr<'_>, cast_to: Ty<'_>) {
|
||||
if let ty::RawPtr(TypeAndMut {
|
||||
mutbl: Mutability::Mut,
|
||||
ty: ptrty,
|
||||
}) = cast_to.kind()
|
||||
&& let ty::RawPtr(TypeAndMut {
|
||||
mutbl: Mutability::Not, ..
|
||||
}) = cx.typeck_results().node_type(cast_expr.hir_id).kind()
|
||||
if let ty::RawPtr(ptrty, Mutability::Mut) = cast_to.kind()
|
||||
&& let ty::RawPtr(_, Mutability::Not) = cx.typeck_results().node_type(cast_expr.hir_id).kind()
|
||||
&& let ExprKind::MethodCall(method_name, receiver, [], _) = cast_expr.peel_blocks().kind
|
||||
&& method_name.ident.name == rustc_span::sym::as_ptr
|
||||
&& let Some(as_ptr_did) = cx
|
||||
|
@ -33,13 +33,13 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>) {
|
||||
}
|
||||
|
||||
fn lint_cast_ptr_alignment<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>, cast_from: Ty<'tcx>, cast_to: Ty<'tcx>) {
|
||||
if let ty::RawPtr(from_ptr_ty) = &cast_from.kind()
|
||||
&& let ty::RawPtr(to_ptr_ty) = &cast_to.kind()
|
||||
&& let Ok(from_layout) = cx.layout_of(from_ptr_ty.ty)
|
||||
&& let Ok(to_layout) = cx.layout_of(to_ptr_ty.ty)
|
||||
if let ty::RawPtr(from_ptr_ty, _) = *cast_from.kind()
|
||||
&& let ty::RawPtr(to_ptr_ty, _) = *cast_to.kind()
|
||||
&& let Ok(from_layout) = cx.layout_of(from_ptr_ty)
|
||||
&& let Ok(to_layout) = cx.layout_of(to_ptr_ty)
|
||||
&& from_layout.align.abi < to_layout.align.abi
|
||||
// with c_void, we inherently need to trust the user
|
||||
&& !is_c_void(cx, from_ptr_ty.ty)
|
||||
&& !is_c_void(cx, from_ptr_ty)
|
||||
// when casting from a ZST, we don't know enough to properly lint
|
||||
&& !from_layout.is_zst()
|
||||
&& !is_used_as_unaligned(cx, expr)
|
||||
|
@ -87,7 +87,7 @@ fn is_child_of_cast(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
|
||||
/// the type is one of those slices
|
||||
fn get_raw_slice_ty_mut(ty: Ty<'_>) -> Option<TypeAndMut<'_>> {
|
||||
match ty.kind() {
|
||||
ty::RawPtr(TypeAndMut { ty: slice_ty, mutbl }) => match slice_ty.kind() {
|
||||
ty::RawPtr(slice_ty, mutbl) => match slice_ty.kind() {
|
||||
ty::Slice(ty) => Some(TypeAndMut { ty: *ty, mutbl: *mutbl }),
|
||||
_ => None,
|
||||
},
|
||||
|
@ -25,8 +25,8 @@ fn raw_parts_kind(cx: &LateContext<'_>, did: DefId) -> Option<RawPartsKind> {
|
||||
|
||||
pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_expr: &Expr<'_>, cast_to: Ty<'_>, msrv: &Msrv) {
|
||||
if msrv.meets(msrvs::PTR_SLICE_RAW_PARTS)
|
||||
&& let ty::RawPtr(ptrty) = cast_to.kind()
|
||||
&& let ty::Slice(_) = ptrty.ty.kind()
|
||||
&& let ty::RawPtr(ptrty, _) = cast_to.kind()
|
||||
&& let ty::Slice(_) = ptrty.kind()
|
||||
&& let ExprKind::Call(fun, [ptr_arg, len_arg]) = cast_expr.peel_blocks().kind
|
||||
&& let ExprKind::Path(ref qpath) = fun.kind
|
||||
&& let Some(fun_def_id) = cx.qpath_res(qpath, fun.hir_id).opt_def_id()
|
||||
|
@ -6,7 +6,7 @@ use rustc_errors::Applicability;
|
||||
use rustc_hir::{Expr, ExprKind, Mutability, QPath, TyKind};
|
||||
use rustc_hir_pretty::qpath_to_string;
|
||||
use rustc_lint::LateContext;
|
||||
use rustc_middle::ty::{self, TypeAndMut};
|
||||
use rustc_middle::ty;
|
||||
use rustc_span::sym;
|
||||
|
||||
use super::PTR_AS_PTR;
|
||||
@ -33,8 +33,8 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, msrv: &Msrv) {
|
||||
|
||||
if let ExprKind::Cast(cast_expr, cast_to_hir_ty) = expr.kind
|
||||
&& let (cast_from, cast_to) = (cx.typeck_results().expr_ty(cast_expr), cx.typeck_results().expr_ty(expr))
|
||||
&& let ty::RawPtr(TypeAndMut { mutbl: from_mutbl, .. }) = cast_from.kind()
|
||||
&& let ty::RawPtr(TypeAndMut { ty: to_pointee_ty, mutbl: to_mutbl }) = cast_to.kind()
|
||||
&& let ty::RawPtr(_, from_mutbl) = cast_from.kind()
|
||||
&& let ty::RawPtr(to_pointee_ty, to_mutbl) = cast_to.kind()
|
||||
&& matches!((from_mutbl, to_mutbl),
|
||||
(Mutability::Not, Mutability::Not) | (Mutability::Mut, Mutability::Mut))
|
||||
// The `U` in `pointer::cast` have to be `Sized`
|
||||
|
@ -4,7 +4,7 @@ use clippy_utils::sugg::Sugg;
|
||||
use rustc_errors::Applicability;
|
||||
use rustc_hir::{Expr, Mutability};
|
||||
use rustc_lint::LateContext;
|
||||
use rustc_middle::ty::{self, Ty, TypeAndMut};
|
||||
use rustc_middle::ty::{self, Ty};
|
||||
|
||||
use super::PTR_CAST_CONSTNESS;
|
||||
|
||||
@ -17,14 +17,8 @@ pub(super) fn check<'tcx>(
|
||||
msrv: &Msrv,
|
||||
) {
|
||||
if msrv.meets(msrvs::POINTER_CAST_CONSTNESS)
|
||||
&& let ty::RawPtr(TypeAndMut {
|
||||
mutbl: from_mutbl,
|
||||
ty: from_ty,
|
||||
}) = cast_from.kind()
|
||||
&& let ty::RawPtr(TypeAndMut {
|
||||
mutbl: to_mutbl,
|
||||
ty: to_ty,
|
||||
}) = cast_to.kind()
|
||||
&& let ty::RawPtr(from_ty, from_mutbl) = cast_from.kind()
|
||||
&& let ty::RawPtr(to_ty, to_mutbl) = cast_to.kind()
|
||||
&& matches!(
|
||||
(from_mutbl, to_mutbl),
|
||||
(Mutability::Not, Mutability::Mut) | (Mutability::Mut, Mutability::Not)
|
||||
|
@ -5,7 +5,7 @@ use clippy_utils::{expr_use_ctxt, is_no_std_crate, ExprUseNode};
|
||||
use rustc_errors::Applicability;
|
||||
use rustc_hir::{Expr, Mutability, Ty, TyKind};
|
||||
use rustc_lint::LateContext;
|
||||
use rustc_middle::ty::{self, TypeAndMut};
|
||||
use rustc_middle::ty;
|
||||
|
||||
use super::REF_AS_PTR;
|
||||
|
||||
@ -21,10 +21,10 @@ pub(super) fn check<'tcx>(
|
||||
);
|
||||
|
||||
if matches!(cast_from.kind(), ty::Ref(..))
|
||||
&& let ty::RawPtr(TypeAndMut { mutbl: to_mutbl, .. }) = cast_to.kind()
|
||||
&& let ty::RawPtr(_, to_mutbl) = cast_to.kind()
|
||||
&& let Some(use_cx) = expr_use_ctxt(cx, expr)
|
||||
// TODO: only block the lint if `cast_expr` is a temporary
|
||||
&& !matches!(use_cx.node, ExprUseNode::Local(_) | ExprUseNode::ConstStatic(_))
|
||||
&& !matches!(use_cx.node, ExprUseNode::LetStmt(_) | ExprUseNode::ConstStatic(_))
|
||||
{
|
||||
let core_or_std = if is_no_std_crate(cx) { "core" } else { "std" };
|
||||
let fn_name = match to_mutbl {
|
||||
|
@ -66,7 +66,7 @@ pub(super) fn check<'tcx>(
|
||||
&& let QPath::Resolved(None, Path { res, .. }) = qpath
|
||||
&& let Res::Local(hir_id) = res
|
||||
&& let parent = cx.tcx.parent_hir_node(*hir_id)
|
||||
&& let Node::Local(local) = parent
|
||||
&& let Node::LetStmt(local) = parent
|
||||
{
|
||||
if let Some(ty) = local.ty
|
||||
&& let TyKind::Path(qpath) = ty.kind
|
||||
@ -275,7 +275,7 @@ fn is_cast_from_ty_alias<'tcx>(cx: &LateContext<'tcx>, expr: impl Visitable<'tcx
|
||||
}
|
||||
// Local usage
|
||||
} else if let Res::Local(hir_id) = res
|
||||
&& let Node::Local(l) = cx.tcx.parent_hir_node(hir_id)
|
||||
&& let Node::LetStmt(l) = cx.tcx.parent_hir_node(hir_id)
|
||||
{
|
||||
if let Some(e) = l.init
|
||||
&& is_cast_from_ty_alias(cx, e, cast_from)
|
||||
|
@ -158,10 +158,10 @@ impl<'tcx> LateLintPass<'tcx> for CognitiveComplexity {
|
||||
}
|
||||
}
|
||||
|
||||
fn enter_lint_attrs(&mut self, cx: &LateContext<'tcx>, attrs: &'tcx [Attribute]) {
|
||||
fn check_attributes(&mut self, cx: &LateContext<'tcx>, attrs: &'tcx [Attribute]) {
|
||||
self.limit.push_attrs(cx.sess(), attrs, "cognitive_complexity");
|
||||
}
|
||||
fn exit_lint_attrs(&mut self, cx: &LateContext<'tcx>, attrs: &'tcx [Attribute]) {
|
||||
fn check_attributes_post(&mut self, cx: &LateContext<'tcx>, attrs: &'tcx [Attribute]) {
|
||||
self.limit.pop_attrs(cx.sess(), attrs, "cognitive_complexity");
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ use clippy_utils::ty::{is_type_diagnostic_item, is_type_lang_item};
|
||||
use clippy_utils::visitors::for_each_expr_with_closures;
|
||||
use clippy_utils::{get_enclosing_block, path_to_local_id};
|
||||
use core::ops::ControlFlow;
|
||||
use rustc_hir::{Block, ExprKind, HirId, LangItem, Local, Node, PatKind};
|
||||
use rustc_hir::{Block, ExprKind, HirId, LangItem, LetStmt, Node, PatKind};
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
use rustc_session::declare_lint_pass;
|
||||
use rustc_span::symbol::sym;
|
||||
@ -58,7 +58,7 @@ static COLLECTIONS: [Symbol; 9] = [
|
||||
];
|
||||
|
||||
impl<'tcx> LateLintPass<'tcx> for CollectionIsNeverRead {
|
||||
fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx Local<'tcx>) {
|
||||
fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx LetStmt<'tcx>) {
|
||||
// Look for local variables whose type is a container. Search surrounding bock for read access.
|
||||
if match_acceptable_type(cx, local, &COLLECTIONS)
|
||||
&& let PatKind::Binding(_, local_id, _, _) = local.pat.kind
|
||||
@ -70,7 +70,7 @@ impl<'tcx> LateLintPass<'tcx> for CollectionIsNeverRead {
|
||||
}
|
||||
}
|
||||
|
||||
fn match_acceptable_type(cx: &LateContext<'_>, local: &Local<'_>, collections: &[Symbol]) -> bool {
|
||||
fn match_acceptable_type(cx: &LateContext<'_>, local: &LetStmt<'_>, collections: &[Symbol]) -> bool {
|
||||
let ty = cx.typeck_results().pat_ty(local.pat);
|
||||
collections.iter().any(|&sym| is_type_diagnostic_item(cx, ty, sym))
|
||||
// String type is a lang item but not a diagnostic item for now so we need a separate check
|
||||
|
@ -11,8 +11,7 @@ use rustc_lint::{LateContext, LateLintPass};
|
||||
use rustc_middle::hir::nested_filter;
|
||||
use rustc_middle::traits::Reveal;
|
||||
use rustc_middle::ty::{
|
||||
self, ClauseKind, GenericArgKind, GenericParamDefKind, ImplPolarity, ParamEnv, ToPredicate, TraitPredicate, Ty,
|
||||
TyCtxt,
|
||||
self, ClauseKind, GenericArgKind, GenericParamDefKind, ParamEnv, ToPredicate, TraitPredicate, Ty, TyCtxt,
|
||||
};
|
||||
use rustc_session::declare_lint_pass;
|
||||
use rustc_span::def_id::LocalDefId;
|
||||
@ -502,7 +501,7 @@ fn param_env_for_derived_eq(tcx: TyCtxt<'_>, did: DefId, eq_trait_id: DefId) ->
|
||||
params.iter().filter(|&&(_, needs_eq)| needs_eq).map(|&(param, _)| {
|
||||
ClauseKind::Trait(TraitPredicate {
|
||||
trait_ref: ty::TraitRef::new(tcx, eq_trait_id, [tcx.mk_param_from_def(param)]),
|
||||
polarity: ImplPolarity::Positive,
|
||||
polarity: ty::PredicatePolarity::Positive,
|
||||
})
|
||||
.to_predicate(tcx)
|
||||
}),
|
||||
|
@ -55,7 +55,7 @@ fn unary_pattern(pat: &Pat<'_>) -> bool {
|
||||
| PatKind::Err(_) => false,
|
||||
PatKind::Struct(_, a, etc) => !etc && a.iter().all(|x| unary_pattern(x.pat)),
|
||||
PatKind::Tuple(a, etc) | PatKind::TupleStruct(_, a, etc) => etc.as_opt_usize().is_none() && array_rec(a),
|
||||
PatKind::Ref(x, _) | PatKind::Box(x) => unary_pattern(x),
|
||||
PatKind::Ref(x, _) | PatKind::Box(x) | PatKind::Deref(x) => unary_pattern(x),
|
||||
PatKind::Path(_) | PatKind::Lit(_) => true,
|
||||
}
|
||||
}
|
||||
|
@ -9,8 +9,8 @@ use rustc_hir::{BindingAnnotation, Expr, ExprKind, FnRetTy, Param, PatKind, QPat
|
||||
use rustc_infer::infer::TyCtxtInferExt;
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
use rustc_middle::ty::{
|
||||
self, Binder, ClosureArgs, ClosureKind, FnSig, GenericArg, GenericArgKind, ImplPolarity, List, Region, RegionKind,
|
||||
Ty, TypeVisitableExt, TypeckResults,
|
||||
self, Binder, ClosureArgs, ClosureKind, FnSig, GenericArg, GenericArgKind, List, Region, RegionKind, Ty,
|
||||
TypeVisitableExt, TypeckResults,
|
||||
};
|
||||
use rustc_session::declare_lint_pass;
|
||||
use rustc_span::symbol::sym;
|
||||
@ -173,7 +173,7 @@ impl<'tcx> LateLintPass<'tcx> for EtaReduction {
|
||||
if let Ok((ClosureKind::FnMut, _)) = cx.tcx.infer_ctxt().build().type_implements_fn_trait(
|
||||
cx.param_env,
|
||||
Binder::bind_with_vars(callee_ty_adjusted, List::empty()),
|
||||
ImplPolarity::Positive,
|
||||
ty::PredicatePolarity::Positive,
|
||||
) && path_to_local(callee).map_or(false, |l| {
|
||||
local_used_in(cx, l, args) || local_used_after_expr(cx, l, expr)
|
||||
}) {
|
||||
|
@ -83,7 +83,10 @@ impl<'tcx> LateLintPass<'tcx> for FloatLiteral {
|
||||
LitFloatType::Unsuffixed => None,
|
||||
};
|
||||
let (is_whole, is_inf, mut float_str) = match fty {
|
||||
FloatTy::F16 => unimplemented!("f16_f128"),
|
||||
FloatTy::F16 | FloatTy::F128 => {
|
||||
// FIXME(f16_f128): do a check like the others when parsing is available
|
||||
return;
|
||||
},
|
||||
FloatTy::F32 => {
|
||||
let value = sym_str.parse::<f32>().unwrap();
|
||||
|
||||
@ -94,7 +97,6 @@ impl<'tcx> LateLintPass<'tcx> for FloatLiteral {
|
||||
|
||||
(value.fract() == 0.0, value.is_infinite(), formatter.format(value))
|
||||
},
|
||||
FloatTy::F128 => unimplemented!("f16_f128"),
|
||||
};
|
||||
|
||||
if is_inf {
|
||||
@ -139,10 +141,11 @@ impl<'tcx> LateLintPass<'tcx> for FloatLiteral {
|
||||
#[must_use]
|
||||
fn max_digits(fty: FloatTy) -> u32 {
|
||||
match fty {
|
||||
FloatTy::F16 => unimplemented!("f16_f128"),
|
||||
// FIXME(f16_f128): replace the magic numbers once `{f16,f128}::DIGITS` are available
|
||||
FloatTy::F16 => 3,
|
||||
FloatTy::F32 => f32::DIGITS,
|
||||
FloatTy::F64 => f64::DIGITS,
|
||||
FloatTy::F128 => unimplemented!("f16_f128"),
|
||||
FloatTy::F128 => 33,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,7 @@ use clippy_utils::ty::is_c_void;
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_hir::{Expr, ExprKind, QPath};
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
use rustc_middle::ty::{RawPtr, TypeAndMut};
|
||||
use rustc_middle::ty::RawPtr;
|
||||
use rustc_session::declare_lint_pass;
|
||||
use rustc_span::sym;
|
||||
|
||||
@ -44,7 +44,7 @@ impl LateLintPass<'_> for FromRawWithVoidPtr {
|
||||
&& seg.ident.name == sym!(from_raw)
|
||||
&& let Some(type_str) = path_def_id(cx, ty).and_then(|id| def_id_matches_type(cx, id))
|
||||
&& let arg_kind = cx.typeck_results().expr_ty(arg).kind()
|
||||
&& let RawPtr(TypeAndMut { ty, .. }) = arg_kind
|
||||
&& let RawPtr(ty, _) = arg_kind
|
||||
&& is_c_void(cx, *ty)
|
||||
{
|
||||
let msg = format!("creating a `{type_str}` from a void raw pointer");
|
||||
|
@ -24,13 +24,13 @@ pub fn check_fn(cx: &LateContext<'_>, kind: FnKind<'_>, decl: &FnDecl<'_>, body:
|
||||
let name = ident.name.as_str();
|
||||
|
||||
let name = match decl.implicit_self {
|
||||
ImplicitSelfKind::MutRef => {
|
||||
ImplicitSelfKind::RefMut => {
|
||||
let Some(name) = name.strip_suffix("_mut") else {
|
||||
return;
|
||||
};
|
||||
name
|
||||
},
|
||||
ImplicitSelfKind::Imm | ImplicitSelfKind::Mut | ImplicitSelfKind::ImmRef => name,
|
||||
ImplicitSelfKind::Imm | ImplicitSelfKind::Mut | ImplicitSelfKind::RefImm => name,
|
||||
ImplicitSelfKind::None => return,
|
||||
};
|
||||
|
||||
|
@ -207,9 +207,7 @@ fn is_mutable_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>, tys: &mut DefIdSet)
|
||||
},
|
||||
ty::Tuple(args) => args.iter().any(|ty| is_mutable_ty(cx, ty, tys)),
|
||||
ty::Array(ty, _) | ty::Slice(ty) => is_mutable_ty(cx, ty, tys),
|
||||
ty::RawPtr(ty::TypeAndMut { ty, mutbl }) | ty::Ref(_, ty, mutbl) => {
|
||||
mutbl == hir::Mutability::Mut || is_mutable_ty(cx, ty, tys)
|
||||
},
|
||||
ty::RawPtr(ty, mutbl) | ty::Ref(_, ty, mutbl) => mutbl == hir::Mutability::Mut || is_mutable_ty(cx, ty, tys),
|
||||
// calling something constitutes a side effect, so return true on all callables
|
||||
// also never calls need not be used, so return true for them, too
|
||||
_ => true,
|
||||
|
@ -75,7 +75,7 @@ fn check_raw_ptr<'tcx>(
|
||||
}
|
||||
|
||||
fn raw_ptr_arg(cx: &LateContext<'_>, arg: &hir::Param<'_>) -> Option<hir::HirId> {
|
||||
if let (&hir::PatKind::Binding(_, id, _, _), Some(&ty::RawPtr(_))) = (
|
||||
if let (&hir::PatKind::Binding(_, id, _, _), Some(&ty::RawPtr(_, _))) = (
|
||||
&arg.pat.kind,
|
||||
cx.maybe_typeck_results()
|
||||
.map(|typeck_results| typeck_results.pat_ty(arg.pat).kind()),
|
||||
|
@ -64,7 +64,7 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend {
|
||||
}
|
||||
let ret_ty = return_ty(cx, cx.tcx.local_def_id_to_hir_id(fn_def_id).expect_owner());
|
||||
if let ty::Alias(ty::Opaque, AliasTy { def_id, args, .. }) = *ret_ty.kind() {
|
||||
let preds = cx.tcx.explicit_item_bounds(def_id);
|
||||
let preds = cx.tcx.explicit_item_super_predicates(def_id);
|
||||
let mut is_future = false;
|
||||
for (p, _span) in preds.iter_instantiated_copied(cx.tcx, args) {
|
||||
if let Some(trait_pred) = p.as_trait_clause() {
|
||||
|
@ -46,7 +46,7 @@ impl<'tcx> LateLintPass<'tcx> for IgnoredUnitPatterns {
|
||||
// Ignore function parameters
|
||||
return;
|
||||
},
|
||||
Node::Local(local) if local.ty.is_some() => {
|
||||
Node::LetStmt(local) if local.ty.is_some() => {
|
||||
// Ignore let bindings with explicit type
|
||||
return;
|
||||
},
|
||||
|
@ -5,7 +5,7 @@ use rustc_errors::Diag;
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::intravisit::{walk_body, walk_expr, walk_inf, walk_ty, Visitor};
|
||||
use rustc_hir::{Body, Expr, ExprKind, GenericArg, Item, ItemKind, QPath, TyKind};
|
||||
use rustc_hir_analysis::hir_ty_to_ty;
|
||||
use rustc_hir_analysis::lower_ty;
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
use rustc_middle::hir::nested_filter;
|
||||
use rustc_middle::ty::{Ty, TypeckResults};
|
||||
@ -227,7 +227,7 @@ impl<'tcx> ImplicitHasherType<'tcx> {
|
||||
.collect();
|
||||
let params_len = params.len();
|
||||
|
||||
let ty = hir_ty_to_ty(cx.tcx, hir_ty);
|
||||
let ty = lower_ty(cx.tcx, hir_ty);
|
||||
|
||||
if is_type_diagnostic_item(cx, ty, sym::HashMap) && params_len == 2 {
|
||||
Some(ImplicitHasherType::HashMap(
|
||||
|
@ -6,7 +6,7 @@ use rustc_hir::{
|
||||
GenericArg, GenericBound, GenericBounds, ItemKind, PredicateOrigin, TraitBoundModifier, TyKind, TypeBinding,
|
||||
WherePredicate,
|
||||
};
|
||||
use rustc_hir_analysis::hir_ty_to_ty;
|
||||
use rustc_hir_analysis::lower_ty;
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
use rustc_middle::ty::{self, ClauseKind, Generics, Ty, TyCtxt};
|
||||
use rustc_session::declare_lint_pass;
|
||||
@ -146,7 +146,7 @@ fn try_resolve_type<'tcx>(
|
||||
index: usize,
|
||||
) -> Option<Ty<'tcx>> {
|
||||
match args.get(index - 1) {
|
||||
Some(GenericArg::Type(ty)) => Some(hir_ty_to_ty(tcx, ty)),
|
||||
Some(GenericArg::Type(ty)) => Some(lower_ty(tcx, ty)),
|
||||
Some(_) => None,
|
||||
None => Some(tcx.type_of(generics.params[index].def_id).skip_binder()),
|
||||
}
|
||||
|
@ -97,7 +97,7 @@ fn find_slice_values(cx: &LateContext<'_>, pat: &hir::Pat<'_>) -> FxIndexMap<hir
|
||||
value_hir_id,
|
||||
ident,
|
||||
sub_pat,
|
||||
) = pat.kind
|
||||
) = pat.kind && by_ref != hir::ByRef::Yes(hir::Mutability::Mut)
|
||||
{
|
||||
// This block catches bindings with sub patterns. It would be hard to build a correct suggestion
|
||||
// for them and it's likely that the user knows what they are doing in such a case.
|
||||
@ -115,7 +115,7 @@ fn find_slice_values(cx: &LateContext<'_>, pat: &hir::Pat<'_>) -> FxIndexMap<hir
|
||||
if let ty::Slice(inner_ty) | ty::Array(inner_ty, _) = bound_ty.peel_refs().kind() {
|
||||
// The values need to use the `ref` keyword if they can't be copied.
|
||||
// This will need to be adjusted if the lint want to support mutable access in the future
|
||||
let src_is_ref = bound_ty.is_ref() && by_ref != hir::ByRef::Yes;
|
||||
let src_is_ref = bound_ty.is_ref() && by_ref == hir::ByRef::No;
|
||||
let needs_ref = !(src_is_ref || is_copy(cx, *inner_ty));
|
||||
|
||||
let slice_info = slices
|
||||
|
@ -216,8 +216,8 @@ impl {self_ty_without_ref} {{
|
||||
fn check_impl_item(&mut self, cx: &LateContext<'_>, item: &rustc_hir::ImplItem<'_>) {
|
||||
let item_did = item.owner_id.to_def_id();
|
||||
let (borrow_prefix, expected_implicit_self) = match item.ident.name {
|
||||
sym::iter => ("&", ImplicitSelfKind::ImmRef),
|
||||
sym::iter_mut => ("&mut ", ImplicitSelfKind::MutRef),
|
||||
sym::iter => ("&", ImplicitSelfKind::RefImm),
|
||||
sym::iter_mut => ("&mut ", ImplicitSelfKind::RefMut),
|
||||
_ => return,
|
||||
};
|
||||
|
||||
|
@ -398,8 +398,8 @@ impl LenOutput {
|
||||
|
||||
fn expected_sig(self, self_kind: ImplicitSelfKind) -> String {
|
||||
let self_ref = match self_kind {
|
||||
ImplicitSelfKind::ImmRef => "&",
|
||||
ImplicitSelfKind::MutRef => "&mut ",
|
||||
ImplicitSelfKind::RefImm => "&",
|
||||
ImplicitSelfKind::RefMut => "&mut ",
|
||||
_ => "",
|
||||
};
|
||||
match self {
|
||||
@ -425,8 +425,8 @@ fn check_is_empty_sig<'tcx>(
|
||||
[arg, res] if len_output.matches_is_empty_output(cx, *res) => {
|
||||
matches!(
|
||||
(arg.kind(), self_kind),
|
||||
(ty::Ref(_, _, Mutability::Not), ImplicitSelfKind::ImmRef)
|
||||
| (ty::Ref(_, _, Mutability::Mut), ImplicitSelfKind::MutRef)
|
||||
(ty::Ref(_, _, Mutability::Not), ImplicitSelfKind::RefImm)
|
||||
| (ty::Ref(_, _, Mutability::Mut), ImplicitSelfKind::RefMut)
|
||||
) || (!arg.is_ref() && matches!(self_kind, ImplicitSelfKind::Imm | ImplicitSelfKind::Mut))
|
||||
},
|
||||
_ => false,
|
||||
|
@ -1,7 +1,7 @@
|
||||
use clippy_utils::diagnostics::span_lint_and_help;
|
||||
use clippy_utils::ty::{implements_trait, is_must_use_ty, match_type};
|
||||
use clippy_utils::{is_from_proc_macro, is_must_use_func_call, paths};
|
||||
use rustc_hir::{Local, LocalSource, PatKind};
|
||||
use rustc_hir::{LetStmt, LocalSource, PatKind};
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
use rustc_middle::lint::in_external_macro;
|
||||
use rustc_middle::ty::{GenericArgKind, IsSuggestable};
|
||||
@ -138,7 +138,7 @@ const SYNC_GUARD_PATHS: [&[&str]; 3] = [
|
||||
];
|
||||
|
||||
impl<'tcx> LateLintPass<'tcx> for LetUnderscore {
|
||||
fn check_local(&mut self, cx: &LateContext<'tcx>, local: &Local<'tcx>) {
|
||||
fn check_local(&mut self, cx: &LateContext<'tcx>, local: &LetStmt<'tcx>) {
|
||||
if matches!(local.source, LocalSource::Normal)
|
||||
&& !in_external_macro(cx.tcx.sess, local.span)
|
||||
&& let PatKind::Wild = local.pat.kind
|
||||
|
@ -1,6 +1,6 @@
|
||||
use clippy_utils::diagnostics::span_lint_and_help;
|
||||
use clippy_utils::source::snippet;
|
||||
use rustc_hir::{Local, TyKind};
|
||||
use rustc_hir::{LetStmt, TyKind};
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
use rustc_middle::lint::in_external_macro;
|
||||
use rustc_session::declare_lint_pass;
|
||||
@ -26,7 +26,7 @@ declare_clippy_lint! {
|
||||
declare_lint_pass!(UnderscoreTyped => [LET_WITH_TYPE_UNDERSCORE]);
|
||||
|
||||
impl LateLintPass<'_> for UnderscoreTyped {
|
||||
fn check_local(&mut self, cx: &LateContext<'_>, local: &Local<'_>) {
|
||||
fn check_local(&mut self, cx: &LateContext<'_>, local: &LetStmt<'_>) {
|
||||
if !in_external_macro(cx.tcx.sess, local.span)
|
||||
&& let Some(ty) = local.ty // Ensure that it has a type defined
|
||||
&& let TyKind::Infer = &ty.kind // that type is '_'
|
||||
|
@ -10,7 +10,7 @@ use rustc_errors::Applicability;
|
||||
use rustc_hir::{Expr, Mutability};
|
||||
use rustc_lint::LateContext;
|
||||
use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow, AutoBorrowMutability};
|
||||
use rustc_middle::ty::{self, EarlyBinder, Ty, TypeAndMut};
|
||||
use rustc_middle::ty::{self, EarlyBinder, Ty};
|
||||
use rustc_span::sym;
|
||||
|
||||
pub(super) fn check(
|
||||
@ -160,7 +160,7 @@ fn is_ref_iterable<'tcx>(
|
||||
let self_ty = if mutbl.is_mut() {
|
||||
self_ty
|
||||
} else {
|
||||
Ty::new_ref(cx.tcx, region, TypeAndMut { ty, mutbl })
|
||||
Ty::new_ref(cx.tcx, region, ty, mutbl)
|
||||
};
|
||||
if implements_trait(cx, self_ty, trait_id, &[])
|
||||
&& let Some(ty) =
|
||||
@ -175,7 +175,7 @@ fn is_ref_iterable<'tcx>(
|
||||
&& !self_ty.is_ref()
|
||||
{
|
||||
// Attempt to borrow
|
||||
let self_ty = Ty::new_ref(cx.tcx, cx.tcx.lifetimes.re_erased, TypeAndMut { ty: self_ty, mutbl });
|
||||
let self_ty = Ty::new_ref(cx.tcx, cx.tcx.lifetimes.re_erased, self_ty, mutbl);
|
||||
if implements_trait(cx, self_ty, trait_id, &[])
|
||||
&& let Some(ty) = make_normalized_projection(cx.tcx, cx.param_env, trait_id, sym!(IntoIter), [self_ty])
|
||||
&& ty == res_ty
|
||||
|
@ -62,7 +62,7 @@ pub(super) fn check<'tcx>(
|
||||
if let Node::Pat(pat) = node
|
||||
&& let PatKind::Binding(bind_ann, ..) = pat.kind
|
||||
&& !matches!(bind_ann, BindingAnnotation(_, Mutability::Mut))
|
||||
&& let Node::Local(parent_let_expr) = cx.tcx.parent_hir_node(hir_id)
|
||||
&& let Node::LetStmt(parent_let_expr) = cx.tcx.parent_hir_node(hir_id)
|
||||
&& let Some(init) = parent_let_expr.init
|
||||
{
|
||||
match init.kind {
|
||||
|
@ -3,7 +3,7 @@ use clippy_utils::{get_parent_expr, is_integer_const, path_to_local, path_to_loc
|
||||
use rustc_ast::ast::{LitIntType, LitKind};
|
||||
use rustc_errors::Applicability;
|
||||
use rustc_hir::intravisit::{walk_expr, walk_local, Visitor};
|
||||
use rustc_hir::{BinOpKind, BorrowKind, Expr, ExprKind, HirId, HirIdMap, Local, Mutability, PatKind};
|
||||
use rustc_hir::{BinOpKind, BorrowKind, Expr, ExprKind, HirId, HirIdMap, LetStmt, Mutability, PatKind};
|
||||
use rustc_lint::LateContext;
|
||||
use rustc_middle::hir::nested_filter;
|
||||
use rustc_middle::ty::{self, Ty};
|
||||
@ -141,7 +141,7 @@ impl<'a, 'tcx> InitializeVisitor<'a, 'tcx> {
|
||||
impl<'a, 'tcx> Visitor<'tcx> for InitializeVisitor<'a, 'tcx> {
|
||||
type NestedFilter = nested_filter::OnlyBodies;
|
||||
|
||||
fn visit_local(&mut self, l: &'tcx Local<'_>) {
|
||||
fn visit_local(&mut self, l: &'tcx LetStmt<'_>) {
|
||||
// Look for declarations of the variable
|
||||
if l.pat.hir_id == self.var_id
|
||||
&& let PatKind::Binding(.., ident, _) = l.pat.kind
|
||||
|
@ -5,13 +5,13 @@ use clippy_utils::source::snippet_with_applicability;
|
||||
use clippy_utils::ty::needs_ordered_drop;
|
||||
use clippy_utils::visitors::any_temporaries_need_ordered_drop;
|
||||
use rustc_errors::Applicability;
|
||||
use rustc_hir::{Block, Expr, ExprKind, Local, MatchSource, Pat, StmtKind};
|
||||
use rustc_hir::{Block, Expr, ExprKind, LetStmt, MatchSource, Pat, StmtKind};
|
||||
use rustc_lint::LateContext;
|
||||
|
||||
pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, loop_block: &'tcx Block<'_>) {
|
||||
let (init, has_trailing_exprs) = match (loop_block.stmts, loop_block.expr) {
|
||||
([stmt, stmts @ ..], expr) => {
|
||||
if let StmtKind::Let(&Local {
|
||||
if let StmtKind::Let(&LetStmt {
|
||||
init: Some(e),
|
||||
els: None,
|
||||
..
|
||||
|
@ -6,7 +6,7 @@ use clippy_utils::{get_enclosing_loop_or_multi_call_closure, higher, is_refutabl
|
||||
use rustc_errors::Applicability;
|
||||
use rustc_hir::def::Res;
|
||||
use rustc_hir::intravisit::{walk_expr, Visitor};
|
||||
use rustc_hir::{Closure, Expr, ExprKind, HirId, LangItem, Local, Mutability, PatKind, UnOp};
|
||||
use rustc_hir::{Closure, Expr, ExprKind, HirId, LangItem, LetStmt, Mutability, PatKind, UnOp};
|
||||
use rustc_lint::LateContext;
|
||||
use rustc_middle::hir::nested_filter::OnlyBodies;
|
||||
use rustc_middle::ty::adjustment::Adjust;
|
||||
@ -286,7 +286,7 @@ fn needs_mutable_borrow(cx: &LateContext<'_>, iter_expr: &IterExpr, loop_expr: &
|
||||
self.cx.tcx.hir()
|
||||
}
|
||||
|
||||
fn visit_local(&mut self, l: &'tcx Local<'_>) {
|
||||
fn visit_local(&mut self, l: &'tcx LetStmt<'_>) {
|
||||
if !self.after_loop {
|
||||
l.pat.each_binding_or_first(&mut |_, id, _, _| {
|
||||
if id == self.local_id {
|
||||
|
@ -4,7 +4,7 @@ use clippy_utils::source::snippet_opt;
|
||||
use clippy_utils::visitors::{is_local_used, local_used_once};
|
||||
use clippy_utils::{is_trait_method, path_to_local_id};
|
||||
use rustc_errors::Applicability;
|
||||
use rustc_hir::{BindingAnnotation, ExprKind, Local, Node, PatKind, StmtKind};
|
||||
use rustc_hir::{BindingAnnotation, ExprKind, LetStmt, Node, PatKind, StmtKind};
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
use rustc_session::impl_lint_pass;
|
||||
use rustc_span::sym;
|
||||
@ -60,7 +60,7 @@ impl ManualHashOne {
|
||||
impl_lint_pass!(ManualHashOne => [MANUAL_HASH_ONE]);
|
||||
|
||||
impl LateLintPass<'_> for ManualHashOne {
|
||||
fn check_local(&mut self, cx: &LateContext<'_>, local: &Local<'_>) {
|
||||
fn check_local(&mut self, cx: &LateContext<'_>, local: &LetStmt<'_>) {
|
||||
// `let mut hasher = seg.build_hasher();`
|
||||
if let PatKind::Binding(BindingAnnotation::MUT, hasher, _, None) = local.pat.kind
|
||||
&& let Some(init) = local.init
|
||||
|
@ -81,7 +81,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualRemEuclid {
|
||||
// Apply only to params or locals with annotated types
|
||||
match cx.tcx.parent_hir_node(hir_id) {
|
||||
Node::Param(..) => (),
|
||||
Node::Local(local) => {
|
||||
Node::LetStmt(local) => {
|
||||
let Some(ty) = local.ty else { return };
|
||||
if matches!(ty.kind, TyKind::Infer) {
|
||||
return;
|
||||
|
@ -2,12 +2,12 @@ use clippy_utils::diagnostics::span_lint_and_sugg;
|
||||
use clippy_utils::source::snippet_with_applicability;
|
||||
use clippy_utils::{path_to_local_id, peel_blocks, strip_pat_refs};
|
||||
use rustc_errors::Applicability;
|
||||
use rustc_hir::{ByRef, ExprKind, Local, MatchSource, PatKind, QPath};
|
||||
use rustc_hir::{ExprKind, LetStmt, MatchSource, PatKind, QPath};
|
||||
use rustc_lint::LateContext;
|
||||
|
||||
use super::INFALLIBLE_DESTRUCTURING_MATCH;
|
||||
|
||||
pub(crate) fn check(cx: &LateContext<'_>, local: &Local<'_>) -> bool {
|
||||
pub(crate) fn check(cx: &LateContext<'_>, local: &LetStmt<'_>) -> bool {
|
||||
if !local.span.from_expansion()
|
||||
&& let Some(expr) = local.init
|
||||
&& let ExprKind::Match(target, arms, MatchSource::Normal) = expr.kind
|
||||
@ -30,7 +30,7 @@ pub(crate) fn check(cx: &LateContext<'_>, local: &Local<'_>) -> bool {
|
||||
format!(
|
||||
"let {}({}{}) = {};",
|
||||
snippet_with_applicability(cx, variant_name.span, "..", &mut applicability),
|
||||
if binding.0 == ByRef::Yes { "ref " } else { "" },
|
||||
binding.prefix_str(),
|
||||
snippet_with_applicability(cx, local.pat.span, "..", &mut applicability),
|
||||
snippet_with_applicability(cx, target.span, "..", &mut applicability),
|
||||
),
|
||||
|
@ -67,7 +67,7 @@ fn is_none_arm(cx: &LateContext<'_>, arm: &Arm<'_>) -> bool {
|
||||
fn is_ref_some_arm(cx: &LateContext<'_>, arm: &Arm<'_>) -> Option<Mutability> {
|
||||
if let PatKind::TupleStruct(ref qpath, [first_pat, ..], _) = arm.pat.kind
|
||||
&& is_res_lang_ctor(cx, cx.qpath_res(qpath, arm.pat.hir_id), LangItem::OptionSome)
|
||||
&& let PatKind::Binding(BindingAnnotation(ByRef::Yes, mutabl), .., ident, _) = first_pat.kind
|
||||
&& let PatKind::Binding(BindingAnnotation(ByRef::Yes(mutabl), _), .., ident, _) = first_pat.kind
|
||||
&& let ExprKind::Call(e, [arg]) = peel_blocks(arm.body).kind
|
||||
&& is_res_lang_ctor(cx, path_res(cx, e), LangItem::OptionSome)
|
||||
&& let ExprKind::Path(QPath::Resolved(_, path2)) = arg.kind
|
||||
|
@ -243,7 +243,7 @@ impl<'a> NormalizedPat<'a> {
|
||||
fn from_pat(cx: &LateContext<'_>, arena: &'a DroplessArena, pat: &'a Pat<'_>) -> Self {
|
||||
match pat.kind {
|
||||
PatKind::Wild | PatKind::Binding(.., None) => Self::Wild,
|
||||
PatKind::Binding(.., Some(pat)) | PatKind::Box(pat) | PatKind::Ref(pat, _) => {
|
||||
PatKind::Binding(.., Some(pat)) | PatKind::Box(pat) | PatKind::Deref(pat) | PatKind::Ref(pat, _) => {
|
||||
Self::from_pat(cx, arena, pat)
|
||||
},
|
||||
PatKind::Never => Self::Never,
|
||||
|
@ -148,7 +148,7 @@ pub(crate) fn check<'a>(cx: &LateContext<'a>, ex: &Expr<'a>, arms: &[Arm<'_>], e
|
||||
fn opt_parent_assign_span<'a>(cx: &LateContext<'a>, ex: &Expr<'a>) -> Option<AssignmentExpr> {
|
||||
if let Node::Expr(parent_arm_expr) = cx.tcx.parent_hir_node(ex.hir_id) {
|
||||
return match cx.tcx.parent_hir_node(parent_arm_expr.hir_id) {
|
||||
Node::Local(parent_let_expr) => Some(AssignmentExpr::Local {
|
||||
Node::LetStmt(parent_let_expr) => Some(AssignmentExpr::Local {
|
||||
span: parent_let_expr.span,
|
||||
pat_span: parent_let_expr.pat.span(),
|
||||
}),
|
||||
|
@ -27,7 +27,7 @@ mod wild_in_or_pats;
|
||||
use clippy_config::msrvs::{self, Msrv};
|
||||
use clippy_utils::source::walk_span_to_context;
|
||||
use clippy_utils::{higher, in_constant, is_direct_expn_of, is_span_match, span_contains_cfg};
|
||||
use rustc_hir::{Arm, Expr, ExprKind, Local, MatchSource, Pat};
|
||||
use rustc_hir::{Arm, Expr, ExprKind, LetStmt, MatchSource, Pat};
|
||||
use rustc_lint::{LateContext, LateLintPass, LintContext};
|
||||
use rustc_middle::lint::in_external_macro;
|
||||
use rustc_session::impl_lint_pass;
|
||||
@ -1123,7 +1123,7 @@ impl<'tcx> LateLintPass<'tcx> for Matches {
|
||||
}
|
||||
}
|
||||
|
||||
fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx Local<'_>) {
|
||||
fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx LetStmt<'_>) {
|
||||
self.infallible_destructuring_match_linted |=
|
||||
local.els.is_none() && infallible_destructuring_match::check(cx, local);
|
||||
}
|
||||
|
@ -125,7 +125,7 @@ fn strip_return<'hir>(expr: &'hir Expr<'hir>) -> &'hir Expr<'hir> {
|
||||
fn expr_ty_matches_p_ty(cx: &LateContext<'_>, expr: &Expr<'_>, p_expr: &Expr<'_>) -> bool {
|
||||
match cx.tcx.parent_hir_node(p_expr.hir_id) {
|
||||
// Compare match_expr ty with local in `let local = match match_expr {..}`
|
||||
Node::Local(local) => {
|
||||
Node::LetStmt(local) => {
|
||||
let results = cx.typeck_results();
|
||||
return same_type_and_consts(results.node_type(local.hir_id), results.expr_ty(expr));
|
||||
},
|
||||
@ -178,7 +178,7 @@ fn pat_same_as_expr(pat: &Pat<'_>, expr: &Expr<'_>) -> bool {
|
||||
},
|
||||
)),
|
||||
) => {
|
||||
return !matches!(annot, BindingAnnotation(ByRef::Yes, _)) && pat_ident.name == first_seg.ident.name;
|
||||
return !matches!(annot, BindingAnnotation(ByRef::Yes(_), _)) && pat_ident.name == first_seg.ident.name;
|
||||
},
|
||||
// Example: `Custom::TypeA => Custom::TypeB`, or `None => None`
|
||||
(PatKind::Path(QPath::Resolved(_, p_path)), ExprKind::Path(QPath::Resolved(_, e_path))) => {
|
||||
|
@ -182,7 +182,7 @@ fn get_pat_binding<'tcx>(
|
||||
if let PatKind::Binding(bind_annot, hir_id, ident, _) = pat.kind
|
||||
&& hir_id == local
|
||||
{
|
||||
if matches!(bind_annot.0, rustc_ast::ByRef::Yes) {
|
||||
if matches!(bind_annot.0, rustc_ast::ByRef::Yes(_)) {
|
||||
let _ = byref_ident.insert(ident);
|
||||
}
|
||||
// the second call of `replace()` returns a `Some(span)`, meaning a multi-binding pattern
|
||||
|
@ -149,7 +149,7 @@ impl<'a, 'tcx> SigDropChecker<'a, 'tcx> {
|
||||
false
|
||||
},
|
||||
rustc_middle::ty::Array(ty, _)
|
||||
| rustc_middle::ty::RawPtr(TypeAndMut { ty, .. })
|
||||
| rustc_middle::ty::RawPtr(ty, _)
|
||||
| rustc_middle::ty::Ref(_, ty, _)
|
||||
| rustc_middle::ty::Slice(ty) => self.has_sig_drop_attr(cx, *ty),
|
||||
_ => false,
|
||||
|
@ -69,7 +69,7 @@ pub(super) fn check(
|
||||
_ => false,
|
||||
},
|
||||
// local binding capturing a reference
|
||||
Node::Local(l) if matches!(l.pat.kind, PatKind::Binding(BindingAnnotation(ByRef::Yes, _), ..)) => {
|
||||
Node::LetStmt(l) if matches!(l.pat.kind, PatKind::Binding(BindingAnnotation(ByRef::Yes(_), _), ..)) => {
|
||||
return;
|
||||
},
|
||||
_ => false,
|
||||
|
@ -60,8 +60,6 @@ pub(super) fn check<'tcx>(
|
||||
applicability,
|
||||
);
|
||||
} else {
|
||||
let ref_annotation = if annotation.0 == ByRef::Yes { "ref " } else { "" };
|
||||
let mut_annotation = if annotation.1 == Mutability::Mut { "mut " } else { "" };
|
||||
span_lint_and_sugg(
|
||||
cx,
|
||||
ITER_KV_MAP,
|
||||
@ -69,7 +67,8 @@ pub(super) fn check<'tcx>(
|
||||
format!("iterating on a map's {replacement_kind}s"),
|
||||
"try",
|
||||
format!(
|
||||
"{recv_snippet}.{into_prefix}{replacement_kind}s().map(|{ref_annotation}{mut_annotation}{bound_ident}| {})",
|
||||
"{recv_snippet}.{into_prefix}{replacement_kind}s().map(|{}{bound_ident}| {})",
|
||||
annotation.prefix_str(),
|
||||
snippet_with_applicability(cx, body_expr.span, "/* body */", &mut applicability)
|
||||
),
|
||||
applicability,
|
||||
|
@ -50,7 +50,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, method_name: &str, re
|
||||
| ExprKind::Break(_, _) => true,
|
||||
_ => false,
|
||||
},
|
||||
Some((Node::Stmt(_) | Node::Local(_), _)) => false,
|
||||
Some((Node::Stmt(_) | Node::LetStmt(_), _)) => false,
|
||||
_ => true,
|
||||
};
|
||||
|
||||
|
@ -11,7 +11,7 @@ use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_errors::{Applicability, MultiSpan};
|
||||
use rustc_hir::intravisit::{walk_block, walk_expr, Visitor};
|
||||
use rustc_hir::{
|
||||
BindingAnnotation, Block, Expr, ExprKind, HirId, HirIdSet, Local, Mutability, Node, PatKind, Stmt, StmtKind,
|
||||
BindingAnnotation, Block, Expr, ExprKind, HirId, HirIdSet, LetStmt, Mutability, Node, PatKind, Stmt, StmtKind,
|
||||
};
|
||||
use rustc_lint::LateContext;
|
||||
use rustc_middle::hir::nested_filter;
|
||||
@ -85,7 +85,7 @@ pub(super) fn check<'tcx>(
|
||||
);
|
||||
}
|
||||
},
|
||||
Node::Local(l) => {
|
||||
Node::LetStmt(l) => {
|
||||
if let PatKind::Binding(BindingAnnotation::NONE | BindingAnnotation::MUT, id, _, None) = l.pat.kind
|
||||
&& let ty = cx.typeck_results().expr_ty(collect_expr)
|
||||
&& [sym::Vec, sym::VecDeque, sym::BinaryHeap, sym::LinkedList]
|
||||
@ -424,7 +424,7 @@ fn get_expr_and_hir_id_from_stmt<'v>(stmt: &'v Stmt<'v>) -> Option<(&'v Expr<'v>
|
||||
match stmt.kind {
|
||||
StmtKind::Expr(expr) | StmtKind::Semi(expr) => Some((expr, None)),
|
||||
StmtKind::Item(..) => None,
|
||||
StmtKind::Let(Local { init, pat, .. }) => {
|
||||
StmtKind::Let(LetStmt { init, pat, .. }) => {
|
||||
if let PatKind::Binding(_, hir_id, ..) = pat.kind {
|
||||
init.map(|init_expr| (init_expr, Some(hir_id)))
|
||||
} else {
|
||||
|
@ -24,7 +24,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, receiver
|
||||
&& let Node::Expr(unwrap_call_expr) = cx.tcx.parent_hir_node(expr.hir_id)
|
||||
&& is_unwrap_call(cx, unwrap_call_expr)
|
||||
&& let parent = cx.tcx.parent_hir_node(unwrap_call_expr.hir_id)
|
||||
&& let Node::Local(local) = parent
|
||||
&& let Node::LetStmt(local) = parent
|
||||
&& let Some(mir) = enclosing_mir(cx.tcx, expr.hir_id)
|
||||
&& let Some((local, _)) = mir
|
||||
.local_decls
|
||||
|
@ -8,7 +8,7 @@ use clippy_utils::{is_diag_item_method, match_def_path, path_to_local_id, paths}
|
||||
use core::ops::ControlFlow;
|
||||
use rustc_errors::Applicability;
|
||||
use rustc_hir::{
|
||||
BindingAnnotation, Expr, ExprKind, HirId, LangItem, Local, MatchSource, Node, Pat, PatKind, QPath, Stmt, StmtKind,
|
||||
BindingAnnotation, Expr, ExprKind, HirId, LangItem, LetStmt, MatchSource, Node, Pat, PatKind, QPath, Stmt, StmtKind,
|
||||
};
|
||||
use rustc_lint::LateContext;
|
||||
use rustc_middle::ty;
|
||||
@ -128,7 +128,7 @@ fn check_manual_split_once_indirect(
|
||||
) -> Option<()> {
|
||||
let ctxt = expr.span.ctxt();
|
||||
let mut parents = cx.tcx.hir().parent_iter(expr.hir_id);
|
||||
if let (_, Node::Local(local)) = parents.next()?
|
||||
if let (_, Node::LetStmt(local)) = parents.next()?
|
||||
&& let PatKind::Binding(BindingAnnotation::MUT, iter_binding_id, iter_ident, None) = local.pat.kind
|
||||
&& let (iter_stmt_id, Node::Stmt(_)) = parents.next()?
|
||||
&& let (_, Node::Block(enclosing_block)) = parents.next()?
|
||||
@ -198,7 +198,7 @@ fn indirect_usage<'tcx>(
|
||||
binding: HirId,
|
||||
ctxt: SyntaxContext,
|
||||
) -> Option<IndirectUsage<'tcx>> {
|
||||
if let StmtKind::Let(&Local {
|
||||
if let StmtKind::Let(&LetStmt {
|
||||
pat: Pat {
|
||||
kind: PatKind::Binding(BindingAnnotation::NONE, _, ident, None),
|
||||
..
|
||||
|
@ -20,7 +20,7 @@ fn needs_turbofish(cx: &LateContext<'_>, expr: &hir::Expr<'_>) -> bool {
|
||||
|
||||
// some common cases where turbofish isn't needed:
|
||||
// - assigned to a local variable with a type annotation
|
||||
if let hir::Node::Local(local) = parent
|
||||
if let hir::Node::LetStmt(local) = parent
|
||||
&& local.ty.is_some()
|
||||
{
|
||||
return false;
|
||||
|
@ -12,14 +12,13 @@ use rustc_errors::Applicability;
|
||||
use rustc_hir::def::{DefKind, Res};
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_hir::{BorrowKind, Expr, ExprKind, ItemKind, LangItem, Node};
|
||||
use rustc_hir_typeck::{FnCtxt, Inherited};
|
||||
use rustc_hir_typeck::{FnCtxt, TypeckRootCtxt};
|
||||
use rustc_infer::infer::TyCtxtInferExt;
|
||||
use rustc_lint::LateContext;
|
||||
use rustc_middle::mir::Mutability;
|
||||
use rustc_middle::ty::adjustment::{Adjust, Adjustment, OverloadedDeref};
|
||||
use rustc_middle::ty::{
|
||||
self, ClauseKind, GenericArg, GenericArgKind, GenericArgsRef, ImplPolarity, ParamTy, ProjectionPredicate,
|
||||
TraitPredicate, Ty,
|
||||
self, ClauseKind, GenericArg, GenericArgKind, GenericArgsRef, ParamTy, ProjectionPredicate, TraitPredicate, Ty,
|
||||
};
|
||||
use rustc_span::{sym, Symbol};
|
||||
use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt as _;
|
||||
@ -336,12 +335,9 @@ fn check_other_call_arg<'tcx>(
|
||||
&& let Some((n_refs, receiver_ty)) = if n_refs > 0 || is_copy(cx, receiver_ty) {
|
||||
Some((n_refs, receiver_ty))
|
||||
} else if trait_predicate.def_id() != deref_trait_id {
|
||||
Some((1, Ty::new_ref(cx.tcx,
|
||||
Some((1, Ty::new_imm_ref(cx.tcx,
|
||||
cx.tcx.lifetimes.re_erased,
|
||||
ty::TypeAndMut {
|
||||
ty: receiver_ty,
|
||||
mutbl: Mutability::Not,
|
||||
},
|
||||
receiver_ty,
|
||||
)))
|
||||
} else {
|
||||
None
|
||||
@ -441,8 +437,8 @@ fn can_change_type<'a>(cx: &LateContext<'a>, mut expr: &'a Expr<'a>, mut ty: Ty<
|
||||
Node::Item(item) => {
|
||||
if let ItemKind::Fn(_, _, body_id) = &item.kind
|
||||
&& let output_ty = return_ty(cx, item.owner_id)
|
||||
&& let inherited = Inherited::new(cx.tcx, item.owner_id.def_id)
|
||||
&& let fn_ctxt = FnCtxt::new(&inherited, cx.param_env, item.owner_id.def_id)
|
||||
&& let root_ctxt = TypeckRootCtxt::new(cx.tcx, item.owner_id.def_id)
|
||||
&& let fn_ctxt = FnCtxt::new(&root_ctxt, cx.param_env, item.owner_id.def_id)
|
||||
&& fn_ctxt.can_coerce(ty, output_ty)
|
||||
{
|
||||
if has_lifetime(output_ty) && has_lifetime(ty) {
|
||||
@ -669,7 +665,7 @@ fn check_borrow_predicate<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'tcx>) {
|
||||
&& let Some(borrow_id) = cx.tcx.get_diagnostic_item(sym::Borrow)
|
||||
&& cx.tcx.predicates_of(method_def_id).predicates.iter().any(|(pred, _)| {
|
||||
if let ClauseKind::Trait(trait_pred) = pred.kind().skip_binder()
|
||||
&& trait_pred.polarity == ImplPolarity::Positive
|
||||
&& trait_pred.polarity == ty::PredicatePolarity::Positive
|
||||
&& trait_pred.trait_ref.def_id == borrow_id
|
||||
{
|
||||
true
|
||||
|
@ -6,7 +6,7 @@ use rustc_middle::ty;
|
||||
use super::ZST_OFFSET;
|
||||
|
||||
pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr<'_>) {
|
||||
if let ty::RawPtr(ty::TypeAndMut { ty, .. }) = cx.typeck_results().expr_ty(recv).kind()
|
||||
if let ty::RawPtr(ty, _) = cx.typeck_results().expr_ty(recv).kind()
|
||||
&& let Ok(layout) = cx.tcx.layout_of(cx.param_env.and(*ty))
|
||||
&& layout.is_zst()
|
||||
{
|
||||
|
@ -129,7 +129,7 @@ impl<'tcx> LateLintPass<'tcx> for LintPass {
|
||||
if !is_lint_allowed(cx, REF_PATTERNS, arg.pat.hir_id) {
|
||||
return;
|
||||
}
|
||||
if let PatKind::Binding(BindingAnnotation(ByRef::Yes, _), ..) = arg.pat.kind {
|
||||
if let PatKind::Binding(BindingAnnotation(ByRef::Yes(_), _), ..) = arg.pat.kind {
|
||||
span_lint(
|
||||
cx,
|
||||
TOPLEVEL_REF_ARG,
|
||||
@ -144,7 +144,7 @@ impl<'tcx> LateLintPass<'tcx> for LintPass {
|
||||
fn check_stmt(&mut self, cx: &LateContext<'tcx>, stmt: &'tcx Stmt<'_>) {
|
||||
if !in_external_macro(cx.tcx.sess, stmt.span)
|
||||
&& let StmtKind::Let(local) = stmt.kind
|
||||
&& let PatKind::Binding(BindingAnnotation(ByRef::Yes, mutabl), .., name, None) = local.pat.kind
|
||||
&& let PatKind::Binding(BindingAnnotation(ByRef::Yes(mutabl), _), .., name, None) = local.pat.kind
|
||||
&& let Some(init) = local.init
|
||||
// Do not emit if clippy::ref_patterns is not allowed to avoid having two lints for the same issue.
|
||||
&& is_lint_allowed(cx, REF_PATTERNS, local.pat.hir_id)
|
||||
|
@ -162,12 +162,12 @@ impl MissingDoc {
|
||||
impl_lint_pass!(MissingDoc => [MISSING_DOCS_IN_PRIVATE_ITEMS]);
|
||||
|
||||
impl<'tcx> LateLintPass<'tcx> for MissingDoc {
|
||||
fn enter_lint_attrs(&mut self, _: &LateContext<'tcx>, attrs: &'tcx [ast::Attribute]) {
|
||||
fn check_attributes(&mut self, _: &LateContext<'tcx>, attrs: &'tcx [ast::Attribute]) {
|
||||
let doc_hidden = self.doc_hidden() || is_doc_hidden(attrs);
|
||||
self.doc_hidden_stack.push(doc_hidden);
|
||||
}
|
||||
|
||||
fn exit_lint_attrs(&mut self, _: &LateContext<'tcx>, _: &'tcx [ast::Attribute]) {
|
||||
fn check_attributes_post(&mut self, _: &LateContext<'tcx>, _: &'tcx [ast::Attribute]) {
|
||||
self.doc_hidden_stack.pop().expect("empty doc_hidden_stack");
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
use clippy_utils::diagnostics::{span_lint, span_lint_and_note};
|
||||
use clippy_utils::{get_parent_expr, path_to_local, path_to_local_id};
|
||||
use rustc_hir::intravisit::{walk_expr, Visitor};
|
||||
use rustc_hir::{BinOpKind, Block, Expr, ExprKind, HirId, Local, Node, Stmt, StmtKind};
|
||||
use rustc_hir::{BinOpKind, Block, Expr, ExprKind, HirId, LetStmt, Node, Stmt, StmtKind};
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
use rustc_middle::ty;
|
||||
use rustc_session::declare_lint_pass;
|
||||
@ -98,7 +98,7 @@ impl<'tcx> LateLintPass<'tcx> for EvalOrderDependence {
|
||||
fn check_stmt(&mut self, cx: &LateContext<'tcx>, stmt: &'tcx Stmt<'_>) {
|
||||
match stmt.kind {
|
||||
StmtKind::Let(local) => {
|
||||
if let Local { init: Some(e), .. } = local {
|
||||
if let LetStmt { init: Some(e), .. } = local {
|
||||
DivergenceVisitor { cx }.visit_expr(e);
|
||||
}
|
||||
},
|
||||
|
@ -121,7 +121,7 @@ impl<'tcx> LateLintPass<'tcx> for MutableKeyType {
|
||||
}
|
||||
}
|
||||
|
||||
fn check_local(&mut self, cx: &LateContext<'_>, local: &hir::Local<'_>) {
|
||||
fn check_local(&mut self, cx: &LateContext<'_>, local: &hir::LetStmt<'_>) {
|
||||
if let hir::PatKind::Wild = local.pat.kind {
|
||||
return;
|
||||
}
|
||||
|
@ -83,10 +83,7 @@ fn check_arguments<'tcx>(
|
||||
let parameters = type_definition.fn_sig(cx.tcx).skip_binder().inputs();
|
||||
for (argument, parameter) in iter::zip(arguments, parameters) {
|
||||
match parameter.kind() {
|
||||
ty::Ref(_, _, Mutability::Not)
|
||||
| ty::RawPtr(ty::TypeAndMut {
|
||||
mutbl: Mutability::Not, ..
|
||||
}) => {
|
||||
ty::Ref(_, _, Mutability::Not) | ty::RawPtr(_, Mutability::Not) => {
|
||||
if let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Mut, _) = argument.kind {
|
||||
span_lint(
|
||||
cx,
|
||||
|
@ -127,7 +127,7 @@ fn get_atomic_name(ty: Ty<'_>) -> Option<&'static str> {
|
||||
IntTy::I128 => None,
|
||||
}
|
||||
},
|
||||
ty::RawPtr(_) => Some("AtomicPtr"),
|
||||
ty::RawPtr(_, _) => Some("AtomicPtr"),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ use clippy_utils::visitors::{for_each_expr, for_each_expr_with_closures, is_loca
|
||||
use core::ops::ControlFlow;
|
||||
use rustc_errors::{Applicability, MultiSpan};
|
||||
use rustc_hir::{
|
||||
BindingAnnotation, Block, Expr, ExprKind, HirId, Local, LocalSource, MatchSource, Node, Pat, PatKind, Stmt,
|
||||
BindingAnnotation, Block, Expr, ExprKind, HirId, LetStmt, LocalSource, MatchSource, Node, Pat, PatKind, Stmt,
|
||||
StmtKind,
|
||||
};
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
@ -237,7 +237,7 @@ fn first_usage<'tcx>(
|
||||
})
|
||||
}
|
||||
|
||||
fn local_snippet_without_semicolon(cx: &LateContext<'_>, local: &Local<'_>) -> Option<String> {
|
||||
fn local_snippet_without_semicolon(cx: &LateContext<'_>, local: &LetStmt<'_>) -> Option<String> {
|
||||
let span = local.span.with_hi(match local.ty {
|
||||
// let <pat>: <ty>;
|
||||
// ~~~~~~~~~~~~~~~
|
||||
@ -252,7 +252,7 @@ fn local_snippet_without_semicolon(cx: &LateContext<'_>, local: &Local<'_>) -> O
|
||||
|
||||
fn check<'tcx>(
|
||||
cx: &LateContext<'tcx>,
|
||||
local: &'tcx Local<'tcx>,
|
||||
local: &'tcx LetStmt<'tcx>,
|
||||
local_stmt: &'tcx Stmt<'tcx>,
|
||||
block: &'tcx Block<'tcx>,
|
||||
binding_id: HirId,
|
||||
@ -363,9 +363,9 @@ fn check<'tcx>(
|
||||
}
|
||||
|
||||
impl<'tcx> LateLintPass<'tcx> for NeedlessLateInit {
|
||||
fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx Local<'tcx>) {
|
||||
fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx LetStmt<'tcx>) {
|
||||
let mut parents = cx.tcx.hir().parent_iter(local.hir_id);
|
||||
if let Local {
|
||||
if let LetStmt {
|
||||
init: None,
|
||||
pat:
|
||||
&Pat {
|
||||
|
@ -219,7 +219,7 @@ fn ty_allowed_with_raw_pointer_heuristic<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'t
|
||||
}
|
||||
},
|
||||
// Raw pointers are `!Send` but allowed by the heuristic
|
||||
ty::RawPtr(_) => true,
|
||||
ty::RawPtr(_, _) => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
@ -229,7 +229,7 @@ fn contains_pointer_like<'tcx>(cx: &LateContext<'tcx>, target_ty: Ty<'tcx>) -> b
|
||||
for ty_node in target_ty.walk() {
|
||||
if let GenericArgKind::Type(inner_ty) = ty_node.unpack() {
|
||||
match inner_ty.kind() {
|
||||
ty::RawPtr(_) => {
|
||||
ty::RawPtr(_, _) => {
|
||||
return true;
|
||||
},
|
||||
ty::Adt(adt_def, _) => {
|
||||
|
@ -1,5 +1,7 @@
|
||||
use clippy_utils::diagnostics::span_lint_and_help;
|
||||
use rustc_hir::{intravisit, Body, Expr, ExprKind, FnDecl, Let, LocalSource, Mutability, Pat, PatKind, Stmt, StmtKind};
|
||||
use rustc_hir::{
|
||||
intravisit, Body, Expr, ExprKind, FnDecl, LetExpr, LocalSource, Mutability, Pat, PatKind, Stmt, StmtKind,
|
||||
};
|
||||
use rustc_lint::{LateContext, LateLintPass, LintContext};
|
||||
use rustc_middle::lint::in_external_macro;
|
||||
use rustc_middle::ty;
|
||||
@ -103,7 +105,7 @@ impl<'tcx> LateLintPass<'tcx> for PatternTypeMismatch {
|
||||
}
|
||||
}
|
||||
}
|
||||
if let ExprKind::Let(Let { pat, .. }) = expr.kind {
|
||||
if let ExprKind::Let(LetExpr { pat, .. }) = expr.kind {
|
||||
apply_lint(cx, pat, DerefPossible::Possible);
|
||||
}
|
||||
}
|
||||
|
@ -604,7 +604,7 @@ fn check_ptr_arg_usage<'tcx>(cx: &LateContext<'tcx>, body: &'tcx Body<'_>, args:
|
||||
|
||||
match get_expr_use_or_unification_node(self.cx.tcx, e) {
|
||||
Some((Node::Stmt(_), _)) => (),
|
||||
Some((Node::Local(l), _)) => {
|
||||
Some((Node::LetStmt(l), _)) => {
|
||||
// Only trace simple bindings. e.g `let x = y;`
|
||||
if let PatKind::Binding(BindingAnnotation::NONE, id, _, None) = l.pat.kind {
|
||||
self.bindings.insert(id, args_idx);
|
||||
|
@ -14,7 +14,8 @@ use rustc_errors::Applicability;
|
||||
use rustc_hir::def::Res;
|
||||
use rustc_hir::LangItem::{self, OptionNone, OptionSome, ResultErr, ResultOk};
|
||||
use rustc_hir::{
|
||||
BindingAnnotation, Block, ByRef, Expr, ExprKind, Local, Node, PatKind, PathSegment, QPath, Stmt, StmtKind,
|
||||
BindingAnnotation, Block, Body, ByRef, Expr, ExprKind, LetStmt, Mutability, Node, PatKind, PathSegment, QPath,
|
||||
Stmt, StmtKind,
|
||||
};
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
use rustc_middle::ty::Ty;
|
||||
@ -127,7 +128,7 @@ fn check_let_some_else_return_none(cx: &LateContext<'_>, stmt: &Stmt<'_>) {
|
||||
.map_or(false, |did| implements_trait(cx, init_ty, did, &[]))
|
||||
}
|
||||
|
||||
if let StmtKind::Let(Local {
|
||||
if let StmtKind::Let(LetStmt {
|
||||
pat,
|
||||
init: Some(init_expr),
|
||||
els: Some(els),
|
||||
@ -302,9 +303,13 @@ fn check_if_let_some_or_err_and_early_return<'tcx>(cx: &LateContext<'tcx>, expr:
|
||||
let mut applicability = Applicability::MachineApplicable;
|
||||
let receiver_str = snippet_with_applicability(cx, let_expr.span, "..", &mut applicability);
|
||||
let requires_semi = matches!(cx.tcx.parent_hir_node(expr.hir_id), Node::Stmt(_));
|
||||
let method_call_str = match by_ref {
|
||||
ByRef::Yes(Mutability::Mut) => ".as_mut()",
|
||||
ByRef::Yes(Mutability::Not) => ".as_ref()",
|
||||
ByRef::No => "",
|
||||
};
|
||||
let sugg = format!(
|
||||
"{receiver_str}{}?{}",
|
||||
if by_ref == ByRef::Yes { ".as_ref()" } else { "" },
|
||||
"{receiver_str}{method_call_str}?{}",
|
||||
if requires_semi { ";" } else { "" }
|
||||
);
|
||||
span_lint_and_sugg(
|
||||
@ -365,11 +370,11 @@ impl<'tcx> LateLintPass<'tcx> for QuestionMark {
|
||||
}
|
||||
}
|
||||
|
||||
fn check_body(&mut self, _: &LateContext<'tcx>, _: &'tcx rustc_hir::Body<'tcx>) {
|
||||
fn check_body(&mut self, _: &LateContext<'tcx>, _: &'tcx Body<'tcx>) {
|
||||
self.try_block_depth_stack.push(0);
|
||||
}
|
||||
|
||||
fn check_body_post(&mut self, _: &LateContext<'tcx>, _: &'tcx rustc_hir::Body<'tcx>) {
|
||||
fn check_body_post(&mut self, _: &LateContext<'tcx>, _: &'tcx Body<'tcx>) {
|
||||
self.try_block_depth_stack.pop();
|
||||
}
|
||||
|
||||
|
@ -108,7 +108,7 @@ impl EarlyLintPass for RawStrings {
|
||||
}
|
||||
}
|
||||
|
||||
let req = {
|
||||
let mut req = {
|
||||
let mut following_quote = false;
|
||||
let mut req = 0;
|
||||
// `once` so a raw string ending in hashes is still checked
|
||||
@ -136,7 +136,9 @@ impl EarlyLintPass for RawStrings {
|
||||
ControlFlow::Continue(num) | ControlFlow::Break(num) => num,
|
||||
}
|
||||
};
|
||||
|
||||
if self.allow_one_hash_in_raw_strings {
|
||||
req = req.max(1);
|
||||
}
|
||||
if req < max {
|
||||
span_lint_and_then(
|
||||
cx,
|
||||
|
@ -3,7 +3,7 @@ use clippy_utils::get_enclosing_block;
|
||||
use clippy_utils::higher::{get_vec_init_kind, VecInitKind};
|
||||
use clippy_utils::source::snippet;
|
||||
|
||||
use hir::{Expr, ExprKind, HirId, Local, PatKind, PathSegment, QPath, StmtKind};
|
||||
use hir::{Expr, ExprKind, HirId, LetStmt, PatKind, PathSegment, QPath, StmtKind};
|
||||
use rustc_errors::Applicability;
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def::Res;
|
||||
@ -57,7 +57,7 @@ impl<'tcx> LateLintPass<'tcx> for ReadZeroByteVec {
|
||||
}
|
||||
|
||||
if let StmtKind::Let(local) = stmt.kind
|
||||
&& let Local {
|
||||
&& let LetStmt {
|
||||
pat, init: Some(init), ..
|
||||
} = local
|
||||
&& let PatKind::Binding(_, id, ident, _) = pat.kind
|
||||
|
@ -105,7 +105,7 @@ impl<'ast> Visitor<'ast> for BreakVisitor {
|
||||
fn visit_expr(&mut self, expr: &'ast Expr) {
|
||||
self.is_break = match expr.kind {
|
||||
ExprKind::Break(..) | ExprKind::Continue(..) | ExprKind::Ret(..) => true,
|
||||
ExprKind::Match(_, ref arms) => arms.iter().all(|arm|
|
||||
ExprKind::Match(_, ref arms, _) => arms.iter().all(|arm|
|
||||
arm.body.is_none() || arm.body.as_deref().is_some_and(|body| self.check_expr(body))
|
||||
),
|
||||
ExprKind::If(_, ref then, Some(ref els)) => self.check_block(then) && self.check_expr(els),
|
||||
|
@ -3,7 +3,7 @@ use clippy_utils::is_from_proc_macro;
|
||||
use clippy_utils::ty::needs_ordered_drop;
|
||||
use rustc_ast::Mutability;
|
||||
use rustc_hir::def::Res;
|
||||
use rustc_hir::{BindingAnnotation, ByRef, ExprKind, HirId, Local, Node, Pat, PatKind, QPath};
|
||||
use rustc_hir::{BindingAnnotation, ByRef, ExprKind, HirId, LetStmt, Node, Pat, PatKind, QPath};
|
||||
use rustc_hir_typeck::expr_use_visitor::PlaceBase;
|
||||
use rustc_lint::{LateContext, LateLintPass, LintContext};
|
||||
use rustc_middle::lint::in_external_macro;
|
||||
@ -47,7 +47,7 @@ declare_clippy_lint! {
|
||||
declare_lint_pass!(RedundantLocals => [REDUNDANT_LOCALS]);
|
||||
|
||||
impl<'tcx> LateLintPass<'tcx> for RedundantLocals {
|
||||
fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx Local<'tcx>) {
|
||||
fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx LetStmt<'tcx>) {
|
||||
if !local.span.is_desugaring(DesugaringKind::Async)
|
||||
// the pattern is a single by-value binding
|
||||
&& let PatKind::Binding(BindingAnnotation(ByRef::No, mutability), _, ident, None) = local.pat.kind
|
||||
|
@ -131,7 +131,7 @@ fn extract_primty(ty_kind: &hir::TyKind<'_>) -> Option<hir::PrimTy> {
|
||||
}
|
||||
|
||||
impl LateLintPass<'_> for RedundantTypeAnnotations {
|
||||
fn check_local<'tcx>(&mut self, cx: &LateContext<'tcx>, local: &'tcx rustc_hir::Local<'tcx>) {
|
||||
fn check_local<'tcx>(&mut self, cx: &LateContext<'tcx>, local: &'tcx rustc_hir::LetStmt<'tcx>) {
|
||||
if !is_lint_allowed(cx, REDUNDANT_TYPE_ANNOTATIONS, local.hir_id)
|
||||
// type annotation part
|
||||
&& !local.span.from_expansion()
|
||||
|
@ -4,7 +4,7 @@ use clippy_utils::source::snippet;
|
||||
use clippy_utils::{is_from_proc_macro, path_to_local_id};
|
||||
use rustc_errors::Applicability;
|
||||
use rustc_hir::def::Res;
|
||||
use rustc_hir::{BindingAnnotation, Block, Expr, ExprKind, HirId, Local, PatKind, QPath, Stmt, StmtKind};
|
||||
use rustc_hir::{BindingAnnotation, Block, Expr, ExprKind, HirId, LetStmt, PatKind, QPath, Stmt, StmtKind};
|
||||
use rustc_lint::{LateContext, LateLintPass, LintContext};
|
||||
use rustc_middle::lint::in_external_macro;
|
||||
use rustc_session::impl_lint_pass;
|
||||
@ -69,7 +69,7 @@ impl<'tcx> LateLintPass<'tcx> for ReserveAfterInitialization {
|
||||
self.searcher = None;
|
||||
}
|
||||
|
||||
fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx Local<'tcx>) {
|
||||
fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx LetStmt<'tcx>) {
|
||||
if let Some(init_expr) = local.init
|
||||
&& let PatKind::Binding(BindingAnnotation::MUT, id, _, None) = local.pat.kind
|
||||
&& !in_external_macro(cx.sess(), local.span)
|
||||
|
@ -5,7 +5,7 @@ use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_hir::def::Res;
|
||||
use rustc_hir::def_id::LocalDefId;
|
||||
use rustc_hir::hir_id::ItemLocalId;
|
||||
use rustc_hir::{Block, Body, BodyOwnerKind, Expr, ExprKind, HirId, Let, Node, Pat, PatKind, QPath, UnOp};
|
||||
use rustc_hir::{Block, Body, BodyOwnerKind, Expr, ExprKind, HirId, LetExpr, Node, Pat, PatKind, QPath, UnOp};
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
use rustc_session::impl_lint_pass;
|
||||
use rustc_span::{Span, Symbol};
|
||||
@ -238,10 +238,10 @@ fn find_init<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId) -> Option<&'tcx Expr<'
|
||||
let init = match node {
|
||||
Node::Arm(_) | Node::Pat(_) => continue,
|
||||
Node::Expr(expr) => match expr.kind {
|
||||
ExprKind::Match(e, _, _) | ExprKind::Let(&Let { init: e, .. }) => Some(e),
|
||||
ExprKind::Match(e, _, _) | ExprKind::Let(&LetExpr { init: e, .. }) => Some(e),
|
||||
_ => None,
|
||||
},
|
||||
Node::Local(local) => local.init,
|
||||
Node::LetStmt(local) => local.init,
|
||||
_ => None,
|
||||
};
|
||||
return init;
|
||||
|
@ -7,7 +7,7 @@ use rustc_hir::def::{DefKind, Res};
|
||||
use rustc_hir::intravisit::{walk_expr, Visitor};
|
||||
use rustc_hir::{self as hir};
|
||||
use rustc_lint::{LateContext, LateLintPass, LintContext};
|
||||
use rustc_middle::ty::{GenericArgKind, Ty, TypeAndMut};
|
||||
use rustc_middle::ty::{GenericArgKind, Ty};
|
||||
use rustc_session::impl_lint_pass;
|
||||
use rustc_span::symbol::Ident;
|
||||
use rustc_span::{sym, Span, DUMMY_SP};
|
||||
@ -199,7 +199,7 @@ impl<'cx, 'others, 'tcx> AttrChecker<'cx, 'others, 'tcx> {
|
||||
false
|
||||
},
|
||||
rustc_middle::ty::Array(ty, _)
|
||||
| rustc_middle::ty::RawPtr(TypeAndMut { ty, .. })
|
||||
| rustc_middle::ty::RawPtr(ty, _)
|
||||
| rustc_middle::ty::Ref(_, ty, _)
|
||||
| rustc_middle::ty::Slice(ty) => self.has_sig_drop_attr(*ty),
|
||||
_ => false,
|
||||
|
@ -4,7 +4,7 @@
|
||||
use clippy_utils::diagnostics::span_lint_and_help;
|
||||
use rustc_hir::{BinOpKind, Expr, ExprKind};
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
use rustc_middle::ty::{self, Ty, TypeAndMut};
|
||||
use rustc_middle::ty::{self, Ty};
|
||||
use rustc_session::declare_lint_pass;
|
||||
use rustc_span::sym;
|
||||
|
||||
@ -107,7 +107,7 @@ fn get_pointee_ty_and_count_expr<'tcx>(
|
||||
&& METHODS.iter().any(|m| *m == method_ident)
|
||||
|
||||
// Get the pointee type
|
||||
&& let ty::RawPtr(TypeAndMut { ty: pointee_ty, .. }) =
|
||||
&& let ty::RawPtr(pointee_ty, _) =
|
||||
cx.typeck_results().expr_ty(ptr_self).kind()
|
||||
{
|
||||
return Some((*pointee_ty, count));
|
||||
|
@ -552,7 +552,7 @@ fn ident_difference_expr_with_base_location(
|
||||
| (Gen(_, _, _), Gen(_, _, _))
|
||||
| (Block(_, _), Block(_, _))
|
||||
| (Closure(_), Closure(_))
|
||||
| (Match(_, _), Match(_, _))
|
||||
| (Match(_, _, _), Match(_, _, _))
|
||||
| (Loop(_, _, _), Loop(_, _, _))
|
||||
| (ForLoop { .. }, ForLoop { .. })
|
||||
| (While(_, _, _), While(_, _, _))
|
||||
|
@ -10,7 +10,7 @@ use rustc_hir::intravisit::{walk_expr, Visitor};
|
||||
|
||||
use crate::FxHashSet;
|
||||
use rustc_errors::Applicability;
|
||||
use rustc_hir::{BinOpKind, Block, Expr, ExprKind, PatKind, QPath, Stmt, StmtKind};
|
||||
use rustc_hir::{BinOpKind, Block, Expr, ExprKind, LetStmt, PatKind, QPath, Stmt, StmtKind};
|
||||
use rustc_lint::{LateContext, LateLintPass, LintContext};
|
||||
use rustc_middle::lint::in_external_macro;
|
||||
use rustc_middle::ty;
|
||||
@ -392,7 +392,7 @@ impl<'a, 'tcx> IndexBinding<'a, 'tcx> {
|
||||
for stmt in self.block.stmts {
|
||||
match stmt.kind {
|
||||
StmtKind::Expr(expr) | StmtKind::Semi(expr) => v.visit_expr(expr),
|
||||
StmtKind::Let(rustc_hir::Local { ref init, .. }) => {
|
||||
StmtKind::Let(LetStmt { ref init, .. }) => {
|
||||
if let Some(init) = init.as_ref() {
|
||||
v.visit_expr(init);
|
||||
}
|
||||
|
@ -7,8 +7,8 @@ use rustc_middle::ty::{self, Ty};
|
||||
/// Checks for `crosspointer_transmute` lint.
|
||||
/// Returns `true` if it's triggered, otherwise returns `false`.
|
||||
pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>, from_ty: Ty<'tcx>, to_ty: Ty<'tcx>) -> bool {
|
||||
match (&from_ty.kind(), &to_ty.kind()) {
|
||||
(ty::RawPtr(from_ptr), _) if from_ptr.ty == to_ty => {
|
||||
match (*from_ty.kind(), *to_ty.kind()) {
|
||||
(ty::RawPtr(from_ptr_ty, _), _) if from_ptr_ty == to_ty => {
|
||||
span_lint(
|
||||
cx,
|
||||
CROSSPOINTER_TRANSMUTE,
|
||||
@ -17,7 +17,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>, from_ty: Ty
|
||||
);
|
||||
true
|
||||
},
|
||||
(_, ty::RawPtr(to_ptr)) if to_ptr.ty == from_ty => {
|
||||
(_, ty::RawPtr(to_ptr_ty, _)) if to_ptr_ty == from_ty => {
|
||||
span_lint(
|
||||
cx,
|
||||
CROSSPOINTER_TRANSMUTE,
|
||||
|
@ -1,17 +1,17 @@
|
||||
use clippy_utils::diagnostics::span_lint_and_sugg;
|
||||
use rustc_errors::Applicability;
|
||||
use rustc_hir::{GenericArg, HirId, Local, Node, Path, TyKind};
|
||||
use rustc_hir::{GenericArg, HirId, LetStmt, Node, Path, TyKind};
|
||||
use rustc_lint::LateContext;
|
||||
use rustc_middle::lint::in_external_macro;
|
||||
use rustc_middle::ty::Ty;
|
||||
|
||||
use crate::transmute::MISSING_TRANSMUTE_ANNOTATIONS;
|
||||
|
||||
fn get_parent_local_binding_ty<'tcx>(cx: &LateContext<'tcx>, expr_hir_id: HirId) -> Option<Local<'tcx>> {
|
||||
fn get_parent_local_binding_ty<'tcx>(cx: &LateContext<'tcx>, expr_hir_id: HirId) -> Option<LetStmt<'tcx>> {
|
||||
let mut parent_iter = cx.tcx.hir().parent_iter(expr_hir_id);
|
||||
if let Some((_, node)) = parent_iter.next() {
|
||||
match node {
|
||||
Node::Local(local) => Some(*local),
|
||||
Node::LetStmt(local) => Some(*local),
|
||||
Node::Block(_) => {
|
||||
if let Some((parent_hir_id, Node::Expr(expr))) = parent_iter.next()
|
||||
&& matches!(expr.kind, rustc_hir::ExprKind::Block(_, _))
|
||||
|
@ -16,7 +16,7 @@ pub(super) fn check<'tcx>(
|
||||
arg: &'tcx Expr<'_>,
|
||||
) -> bool {
|
||||
match (&from_ty.kind(), &to_ty.kind()) {
|
||||
(ty::RawPtr(_), ty::RawPtr(to_ty)) => {
|
||||
(ty::RawPtr(_, _), ty::RawPtr(to_ty, to_mutbl)) => {
|
||||
span_lint_and_then(
|
||||
cx,
|
||||
TRANSMUTE_PTR_TO_PTR,
|
||||
@ -24,7 +24,7 @@ pub(super) fn check<'tcx>(
|
||||
"transmute from a pointer to a pointer",
|
||||
|diag| {
|
||||
if let Some(arg) = sugg::Sugg::hir_opt(cx, arg) {
|
||||
let sugg = arg.as_ty(Ty::new_ptr(cx.tcx, *to_ty));
|
||||
let sugg = arg.as_ty(Ty::new_ptr(cx.tcx, *to_ty, *to_mutbl));
|
||||
diag.span_suggestion(e.span, "try", sugg, Applicability::Unspecified);
|
||||
}
|
||||
},
|
||||
|
@ -20,7 +20,7 @@ pub(super) fn check<'tcx>(
|
||||
msrv: &Msrv,
|
||||
) -> bool {
|
||||
match (&from_ty.kind(), &to_ty.kind()) {
|
||||
(ty::RawPtr(from_ptr_ty), ty::Ref(_, to_ref_ty, mutbl)) => {
|
||||
(ty::RawPtr(from_ptr_ty, _), ty::Ref(_, to_ref_ty, mutbl)) => {
|
||||
span_lint_and_then(
|
||||
cx,
|
||||
TRANSMUTE_PTR_TO_REF,
|
||||
@ -44,7 +44,7 @@ pub(super) fn check<'tcx>(
|
||||
} else {
|
||||
sugg::make_unop(deref, arg.as_ty(format!("{cast} {ty_snip}"))).to_string()
|
||||
}
|
||||
} else if from_ptr_ty.ty == *to_ref_ty {
|
||||
} else if *from_ptr_ty == *to_ref_ty {
|
||||
if from_ptr_ty.has_erased_regions() {
|
||||
if msrv.meets(msrvs::POINTER_CAST) {
|
||||
format!("{deref}{}.cast::<{to_ref_ty}>()", arg.maybe_par())
|
||||
|
@ -19,7 +19,7 @@ pub(super) fn check<'tcx>(
|
||||
) -> bool {
|
||||
let mut triggered = false;
|
||||
|
||||
if let (ty::Ref(_, ty_from, from_mutbl), ty::Ref(_, ty_to, to_mutbl)) = (&from_ty.kind(), &to_ty.kind()) {
|
||||
if let (ty::Ref(_, ty_from, from_mutbl), ty::Ref(_, ty_to, to_mutbl)) = (*from_ty.kind(), *to_ty.kind()) {
|
||||
if let ty::Slice(slice_ty) = *ty_from.kind()
|
||||
&& ty_to.is_str()
|
||||
&& let ty::Uint(ty::UintTy::U8) = slice_ty.kind()
|
||||
@ -27,7 +27,7 @@ pub(super) fn check<'tcx>(
|
||||
{
|
||||
let Some(top_crate) = std_or_core(cx) else { return true };
|
||||
|
||||
let postfix = if *from_mutbl == Mutability::Mut { "_mut" } else { "" };
|
||||
let postfix = if from_mutbl == Mutability::Mut { "_mut" } else { "" };
|
||||
|
||||
let snippet = snippet(cx, arg.span, "..");
|
||||
|
||||
@ -53,18 +53,10 @@ pub(super) fn check<'tcx>(
|
||||
"transmute from a reference to a reference",
|
||||
|diag| {
|
||||
if let Some(arg) = sugg::Sugg::hir_opt(cx, arg) {
|
||||
let ty_from_and_mut = ty::TypeAndMut {
|
||||
ty: *ty_from,
|
||||
mutbl: *from_mutbl,
|
||||
};
|
||||
let ty_to_and_mut = ty::TypeAndMut {
|
||||
ty: *ty_to,
|
||||
mutbl: *to_mutbl,
|
||||
};
|
||||
let sugg_paren = arg
|
||||
.as_ty(Ty::new_ptr(cx.tcx, ty_from_and_mut))
|
||||
.as_ty(Ty::new_ptr(cx.tcx, ty_to_and_mut));
|
||||
let sugg = if *to_mutbl == Mutability::Mut {
|
||||
.as_ty(Ty::new_ptr(cx.tcx, ty_from, from_mutbl))
|
||||
.as_ty(Ty::new_ptr(cx.tcx, ty_to, to_mutbl));
|
||||
let sugg = if to_mutbl == Mutability::Mut {
|
||||
sugg_paren.mut_addr_deref()
|
||||
} else {
|
||||
sugg_paren.addr_deref()
|
||||
|
@ -3,7 +3,7 @@ use clippy_utils::diagnostics::span_lint_and_then;
|
||||
use clippy_utils::ty::is_c_void;
|
||||
use rustc_hir::Expr;
|
||||
use rustc_lint::LateContext;
|
||||
use rustc_middle::ty::{self, GenericArgsRef, IntTy, Ty, TypeAndMut, UintTy};
|
||||
use rustc_middle::ty::{self, GenericArgsRef, IntTy, Ty, UintTy};
|
||||
|
||||
#[expect(clippy::too_many_lines)]
|
||||
pub(super) fn check<'tcx>(
|
||||
@ -45,8 +45,8 @@ pub(super) fn check<'tcx>(
|
||||
|
||||
// ptr <-> ptr
|
||||
(ReducedTy::Other(from_sub_ty), ReducedTy::Other(to_sub_ty))
|
||||
if matches!(from_sub_ty.kind(), ty::Ref(..) | ty::RawPtr(_))
|
||||
&& matches!(to_sub_ty.kind(), ty::Ref(..) | ty::RawPtr(_)) =>
|
||||
if matches!(from_sub_ty.kind(), ty::Ref(..) | ty::RawPtr(_, _))
|
||||
&& matches!(to_sub_ty.kind(), ty::Ref(..) | ty::RawPtr(_, _)) =>
|
||||
{
|
||||
from_ty = from_sub_ty;
|
||||
to_ty = to_sub_ty;
|
||||
@ -196,21 +196,21 @@ fn reduce_refs<'tcx>(cx: &LateContext<'tcx>, mut from_ty: Ty<'tcx>, mut to_ty: T
|
||||
let (from_fat_ptr, to_fat_ptr) = loop {
|
||||
break match (from_ty.kind(), to_ty.kind()) {
|
||||
(
|
||||
&(ty::Ref(_, from_sub_ty, _) | ty::RawPtr(TypeAndMut { ty: from_sub_ty, .. })),
|
||||
&(ty::Ref(_, to_sub_ty, _) | ty::RawPtr(TypeAndMut { ty: to_sub_ty, .. })),
|
||||
&(ty::Ref(_, from_sub_ty, _) | ty::RawPtr(from_sub_ty, _)),
|
||||
&(ty::Ref(_, to_sub_ty, _) | ty::RawPtr(to_sub_ty, _)),
|
||||
) => {
|
||||
from_raw_ptr = matches!(*from_ty.kind(), ty::RawPtr(_));
|
||||
from_raw_ptr = matches!(*from_ty.kind(), ty::RawPtr(_, _));
|
||||
from_ty = from_sub_ty;
|
||||
to_raw_ptr = matches!(*to_ty.kind(), ty::RawPtr(_));
|
||||
to_raw_ptr = matches!(*to_ty.kind(), ty::RawPtr(_, _));
|
||||
to_ty = to_sub_ty;
|
||||
continue;
|
||||
},
|
||||
(&(ty::Ref(_, unsized_ty, _) | ty::RawPtr(TypeAndMut { ty: unsized_ty, .. })), _)
|
||||
(&(ty::Ref(_, unsized_ty, _) | ty::RawPtr(unsized_ty, _)), _)
|
||||
if !unsized_ty.is_sized(cx.tcx, cx.param_env) =>
|
||||
{
|
||||
(true, false)
|
||||
},
|
||||
(_, &(ty::Ref(_, unsized_ty, _) | ty::RawPtr(TypeAndMut { ty: unsized_ty, .. })))
|
||||
(_, &(ty::Ref(_, unsized_ty, _) | ty::RawPtr(unsized_ty, _)))
|
||||
if !unsized_ty.is_sized(cx.tcx, cx.param_env) =>
|
||||
{
|
||||
(false, true)
|
||||
|
@ -15,7 +15,7 @@ pub(super) fn check<'tcx>(
|
||||
to_ty: Ty<'tcx>,
|
||||
arg: &'tcx Expr<'_>,
|
||||
) -> bool {
|
||||
match (&from_ty.kind(), &to_ty.kind()) {
|
||||
match (*from_ty.kind(), *to_ty.kind()) {
|
||||
_ if from_ty == to_ty && !from_ty.has_erased_regions() => {
|
||||
span_lint(
|
||||
cx,
|
||||
@ -25,7 +25,7 @@ pub(super) fn check<'tcx>(
|
||||
);
|
||||
true
|
||||
},
|
||||
(ty::Ref(_, rty, rty_mutbl), ty::RawPtr(ptr_ty)) => {
|
||||
(ty::Ref(_, rty, rty_mutbl), ty::RawPtr(ptr_ty, ptr_mutbl)) => {
|
||||
// No way to give the correct suggestion here. Avoid linting for now.
|
||||
if !rty.has_erased_regions() {
|
||||
span_lint_and_then(
|
||||
@ -35,15 +35,10 @@ pub(super) fn check<'tcx>(
|
||||
"transmute from a reference to a pointer",
|
||||
|diag| {
|
||||
if let Some(arg) = sugg::Sugg::hir_opt(cx, arg) {
|
||||
let rty_and_mut = ty::TypeAndMut {
|
||||
ty: *rty,
|
||||
mutbl: *rty_mutbl,
|
||||
};
|
||||
|
||||
let sugg = if *ptr_ty == rty_and_mut {
|
||||
let sugg = if ptr_ty == rty && rty_mutbl == ptr_mutbl {
|
||||
arg.as_ty(to_ty)
|
||||
} else {
|
||||
arg.as_ty(Ty::new_ptr(cx.tcx, rty_and_mut)).as_ty(to_ty)
|
||||
arg.as_ty(Ty::new_ptr(cx.tcx, rty, rty_mutbl)).as_ty(to_ty)
|
||||
};
|
||||
|
||||
diag.span_suggestion(e.span, "try", sugg, Applicability::Unspecified);
|
||||
@ -53,7 +48,7 @@ pub(super) fn check<'tcx>(
|
||||
}
|
||||
true
|
||||
},
|
||||
(ty::Int(_) | ty::Uint(_), ty::RawPtr(_)) => {
|
||||
(ty::Int(_) | ty::Uint(_), ty::RawPtr(_, _)) => {
|
||||
span_lint_and_then(
|
||||
cx,
|
||||
USELESS_TRANSMUTE,
|
||||
|
@ -1,6 +1,6 @@
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::Expr;
|
||||
use rustc_hir_typeck::{cast, FnCtxt, Inherited};
|
||||
use rustc_hir_typeck::{cast, FnCtxt, TypeckRootCtxt};
|
||||
use rustc_lint::LateContext;
|
||||
use rustc_middle::ty::cast::CastKind;
|
||||
use rustc_middle::ty::Ty;
|
||||
@ -34,8 +34,8 @@ pub(super) fn check_cast<'tcx>(
|
||||
let hir_id = e.hir_id;
|
||||
let local_def_id = hir_id.owner.def_id;
|
||||
|
||||
let inherited = Inherited::new(cx.tcx, local_def_id);
|
||||
let fn_ctxt = FnCtxt::new(&inherited, cx.param_env, local_def_id);
|
||||
let root_ctxt = TypeckRootCtxt::new(cx.tcx, local_def_id);
|
||||
let fn_ctxt = FnCtxt::new(&root_ctxt, cx.param_env, local_def_id);
|
||||
|
||||
if let Ok(check) = cast::CastCheck::new(
|
||||
&fn_ctxt,
|
||||
|
@ -8,7 +8,7 @@ use rustc_middle::ty::{self, Ty};
|
||||
/// Returns `true` if it's triggered, otherwise returns `false`.
|
||||
pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>, from_ty: Ty<'tcx>, to_ty: Ty<'tcx>) -> bool {
|
||||
match (&from_ty.kind(), &to_ty.kind()) {
|
||||
(ty::Float(_) | ty::Char, ty::Ref(..) | ty::RawPtr(_)) => {
|
||||
(ty::Float(_) | ty::Char, ty::Ref(..) | ty::RawPtr(_, _)) => {
|
||||
span_lint(
|
||||
cx,
|
||||
WRONG_TRANSMUTE,
|
||||
|
@ -159,7 +159,7 @@ fn all_bindings_are_for_conv<'tcx>(
|
||||
.iter()
|
||||
.map(|node| match node {
|
||||
Node::Pat(pat) => kind.eq(&pat.kind).then_some(pat.hir_id),
|
||||
Node::Local(l) => Some(l.hir_id),
|
||||
Node::LetStmt(l) => Some(l.hir_id),
|
||||
_ => None,
|
||||
})
|
||||
.all_equal()
|
||||
@ -170,7 +170,7 @@ fn all_bindings_are_for_conv<'tcx>(
|
||||
&& local_parents.first().is_some_and(|node| {
|
||||
let Some(ty) = match node {
|
||||
Node::Pat(pat) => Some(pat.hir_id),
|
||||
Node::Local(l) => Some(l.hir_id),
|
||||
Node::LetStmt(l) => Some(l.hir_id),
|
||||
_ => None,
|
||||
}
|
||||
.map(|hir_id| cx.typeck_results().node_type(hir_id)) else {
|
||||
|
@ -12,7 +12,7 @@ mod vec_box;
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::intravisit::FnKind;
|
||||
use rustc_hir::{
|
||||
Body, FnDecl, FnRetTy, GenericArg, ImplItem, ImplItemKind, Item, ItemKind, Local, MutTy, QPath, TraitItem,
|
||||
Body, FnDecl, FnRetTy, GenericArg, ImplItem, ImplItemKind, Item, ItemKind, LetStmt, MutTy, QPath, TraitItem,
|
||||
TraitItemKind, TyKind,
|
||||
};
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
@ -425,7 +425,7 @@ impl<'tcx> LateLintPass<'tcx> for Types {
|
||||
}
|
||||
}
|
||||
|
||||
fn check_local(&mut self, cx: &LateContext<'tcx>, local: &Local<'tcx>) {
|
||||
fn check_local(&mut self, cx: &LateContext<'tcx>, local: &LetStmt<'tcx>) {
|
||||
if let Some(ty) = local.ty {
|
||||
self.check_ty(
|
||||
cx,
|
||||
|
@ -4,7 +4,7 @@ use clippy_utils::{path_def_id, qpath_generic_tys};
|
||||
use rustc_errors::Applicability;
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_hir::{self as hir, QPath, TyKind};
|
||||
use rustc_hir_analysis::hir_ty_to_ty;
|
||||
use rustc_hir_analysis::lower_ty;
|
||||
use rustc_lint::LateContext;
|
||||
use rustc_middle::ty::TypeVisitableExt;
|
||||
use rustc_span::symbol::sym;
|
||||
@ -56,10 +56,10 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, hir_ty: &hir::Ty<'tcx>, qpath:
|
||||
};
|
||||
let inner_span = match qpath_generic_tys(inner_qpath).next() {
|
||||
Some(hir_ty) => {
|
||||
// Reallocation of a fat pointer causes it to become thin. `hir_ty_to_ty` is safe to use
|
||||
// Reallocation of a fat pointer causes it to become thin. `lower_ty` is safe to use
|
||||
// here because `mod.rs` guarantees this lint is only run on types outside of bodies and
|
||||
// is not run on locals.
|
||||
let ty = hir_ty_to_ty(cx.tcx, hir_ty);
|
||||
let ty = lower_ty(cx.tcx, hir_ty);
|
||||
if ty.has_escaping_bound_vars() || !ty.is_sized(cx.tcx, cx.param_env) {
|
||||
return false;
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ use clippy_utils::source::snippet;
|
||||
use rustc_errors::Applicability;
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_hir::{self as hir, GenericArg, LangItem, QPath, TyKind};
|
||||
use rustc_hir_analysis::hir_ty_to_ty;
|
||||
use rustc_hir_analysis::lower_ty;
|
||||
use rustc_lint::LateContext;
|
||||
use rustc_middle::ty::layout::LayoutOf;
|
||||
use rustc_middle::ty::TypeVisitableExt;
|
||||
@ -35,7 +35,7 @@ pub(super) fn check<'tcx>(
|
||||
&& let Some(GenericArg::Type(boxed_ty)) = last.args.first()
|
||||
// extract allocator from the Box for later
|
||||
&& let boxed_alloc_ty = last.args.get(1)
|
||||
&& let ty_ty = hir_ty_to_ty(cx.tcx, boxed_ty)
|
||||
&& let ty_ty = lower_ty(cx.tcx, boxed_ty)
|
||||
&& !ty_ty.has_escaping_bound_vars()
|
||||
&& ty_ty.is_sized(cx.tcx, cx.param_env)
|
||||
&& let Ok(ty_ty_size) = cx.layout_of(ty_ty).map(|l| l.size.bytes())
|
||||
@ -55,7 +55,7 @@ pub(super) fn check<'tcx>(
|
||||
}
|
||||
},
|
||||
(Some(GenericArg::Type(l)), Some(GenericArg::Type(r))) =>
|
||||
hir_ty_to_ty(cx.tcx, l) == hir_ty_to_ty(cx.tcx, r),
|
||||
lower_ty(cx.tcx, l) == lower_ty(cx.tcx, r),
|
||||
_ => false
|
||||
}
|
||||
{
|
||||
|
@ -7,7 +7,7 @@ use rustc_hir::def::{DefKind, Res};
|
||||
use rustc_hir::def_id::{DefId, LocalDefId};
|
||||
use rustc_hir::intravisit::{walk_body, walk_expr, FnKind, Visitor};
|
||||
use rustc_hir::{Body, Expr, ExprKind, FnDecl, HirId, Item, ItemKind, Node, QPath, TyKind};
|
||||
use rustc_hir_analysis::hir_ty_to_ty;
|
||||
use rustc_hir_analysis::lower_ty;
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
use rustc_middle::hir::map::Map;
|
||||
use rustc_middle::hir::nested_filter;
|
||||
@ -74,7 +74,7 @@ fn get_hir_ty_def_id<'tcx>(tcx: TyCtxt<'tcx>, hir_ty: rustc_hir::Ty<'tcx>) -> Op
|
||||
match qpath {
|
||||
QPath::Resolved(_, path) => path.res.opt_def_id(),
|
||||
QPath::TypeRelative(_, _) => {
|
||||
let ty = hir_ty_to_ty(tcx, &hir_ty);
|
||||
let ty = lower_ty(tcx, &hir_ty);
|
||||
|
||||
match ty.kind() {
|
||||
ty::Alias(ty::Projection, proj) => {
|
||||
|
@ -158,7 +158,7 @@ impl<'tcx> LateLintPass<'tcx> for UndocumentedUnsafeBlocks {
|
||||
}
|
||||
|
||||
fn check_stmt(&mut self, cx: &LateContext<'tcx>, stmt: &hir::Stmt<'tcx>) {
|
||||
let (hir::StmtKind::Let(&hir::Local { init: Some(expr), .. })
|
||||
let (hir::StmtKind::Let(&hir::LetStmt { init: Some(expr), .. })
|
||||
| hir::StmtKind::Expr(expr)
|
||||
| hir::StmtKind::Semi(expr)) = stmt.kind
|
||||
else {
|
||||
@ -342,7 +342,7 @@ fn block_parents_have_safety_comment(
|
||||
) -> bool {
|
||||
let (span, hir_id) = match cx.tcx.parent_hir_node(id) {
|
||||
Node::Expr(expr) => match cx.tcx.parent_hir_node(expr.hir_id) {
|
||||
Node::Local(hir::Local { span, hir_id, .. }) => (*span, *hir_id),
|
||||
Node::LetStmt(hir::LetStmt { span, hir_id, .. }) => (*span, *hir_id),
|
||||
Node::Item(hir::Item {
|
||||
kind: ItemKind::Const(..) | ItemKind::Static(..),
|
||||
span,
|
||||
@ -358,12 +358,12 @@ fn block_parents_have_safety_comment(
|
||||
},
|
||||
Node::Stmt(hir::Stmt {
|
||||
kind:
|
||||
hir::StmtKind::Let(hir::Local { span, hir_id, .. })
|
||||
hir::StmtKind::Let(hir::LetStmt { span, hir_id, .. })
|
||||
| hir::StmtKind::Expr(hir::Expr { span, hir_id, .. })
|
||||
| hir::StmtKind::Semi(hir::Expr { span, hir_id, .. }),
|
||||
..
|
||||
})
|
||||
| Node::Local(hir::Local { span, hir_id, .. }) => (*span, *hir_id),
|
||||
| Node::LetStmt(hir::LetStmt { span, hir_id, .. }) => (*span, *hir_id),
|
||||
Node::Item(hir::Item {
|
||||
kind: ItemKind::Const(..) | ItemKind::Static(..),
|
||||
span,
|
||||
@ -603,7 +603,7 @@ fn get_body_search_span(cx: &LateContext<'_>) -> Option<Span> {
|
||||
for (_, node) in map.parent_iter(body.hir_id) {
|
||||
match node {
|
||||
Node::Expr(e) => span = e.span,
|
||||
Node::Block(_) | Node::Arm(_) | Node::Stmt(_) | Node::Local(_) => (),
|
||||
Node::Block(_) | Node::Arm(_) | Node::Stmt(_) | Node::LetStmt(_) => (),
|
||||
Node::Item(hir::Item {
|
||||
kind: ItemKind::Const(..) | ItemKind::Static(..),
|
||||
..
|
||||
|
@ -1,7 +1,7 @@
|
||||
use clippy_utils::diagnostics::span_lint;
|
||||
use rustc_hir::intravisit::FnKind;
|
||||
use rustc_hir::{Body, Expr, ExprKind, FnDecl, FnRetTy, TyKind, UnOp};
|
||||
use rustc_hir_analysis::hir_ty_to_ty;
|
||||
use rustc_hir_analysis::lower_ty;
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
use rustc_middle::lint::in_external_macro;
|
||||
use rustc_session::declare_lint_pass;
|
||||
@ -71,7 +71,7 @@ impl LateLintPass<'_> for UninhabitedReferences {
|
||||
}
|
||||
if let FnRetTy::Return(hir_ty) = fndecl.output
|
||||
&& let TyKind::Ref(_, mut_ty) = hir_ty.kind
|
||||
&& hir_ty_to_ty(cx.tcx, mut_ty.ty).is_privately_uninhabited(cx.tcx, cx.param_env)
|
||||
&& lower_ty(cx.tcx, mut_ty.ty).is_privately_uninhabited(cx.tcx, cx.param_env)
|
||||
{
|
||||
span_lint(
|
||||
cx,
|
||||
|
@ -5,14 +5,14 @@ use core::ops::ControlFlow;
|
||||
use rustc_errors::Applicability;
|
||||
use rustc_hir::def::{DefKind, Res};
|
||||
use rustc_hir::intravisit::{walk_body, Visitor};
|
||||
use rustc_hir::{Expr, ExprKind, HirId, HirIdSet, Local, MatchSource, Node, PatKind, QPath, TyKind};
|
||||
use rustc_hir::{Expr, ExprKind, HirId, HirIdSet, LetStmt, MatchSource, Node, PatKind, QPath, TyKind};
|
||||
use rustc_lint::{LateContext, LintContext};
|
||||
use rustc_middle::lint::{in_external_macro, is_from_async_await};
|
||||
use rustc_middle::ty;
|
||||
|
||||
use super::LET_UNIT_VALUE;
|
||||
|
||||
pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, local: &'tcx Local<'tcx>) {
|
||||
pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, local: &'tcx LetStmt<'_>) {
|
||||
// skip `let () = { ... }`
|
||||
if let PatKind::Tuple(fields, ..) = local.pat.kind
|
||||
&& fields.is_empty()
|
||||
@ -144,7 +144,7 @@ fn expr_needs_inferred_result<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -
|
||||
return false;
|
||||
}
|
||||
while let Some(id) = locals_to_check.pop() {
|
||||
if let Node::Local(l) = cx.tcx.parent_hir_node(id) {
|
||||
if let Node::LetStmt(l) = cx.tcx.parent_hir_node(id) {
|
||||
if !l.ty.map_or(true, |ty| matches!(ty.kind, TyKind::Infer)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ mod unit_arg;
|
||||
mod unit_cmp;
|
||||
mod utils;
|
||||
|
||||
use rustc_hir::{Expr, Local};
|
||||
use rustc_hir::{Expr, LetStmt};
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
use rustc_session::declare_lint_pass;
|
||||
|
||||
@ -99,7 +99,7 @@ declare_clippy_lint! {
|
||||
declare_lint_pass!(UnitTypes => [LET_UNIT_VALUE, UNIT_CMP, UNIT_ARG]);
|
||||
|
||||
impl<'tcx> LateLintPass<'tcx> for UnitTypes {
|
||||
fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx Local<'tcx>) {
|
||||
fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx LetStmt<'tcx>) {
|
||||
let_unit_value::check(cx, local);
|
||||
}
|
||||
|
||||
|
@ -232,7 +232,7 @@ fn transform_with_focus_on_idx(alternatives: &mut ThinVec<P<Pat>>, focus_idx: us
|
||||
// In the case of only two patterns, replacement adds net characters.
|
||||
| Ref(_, Mutability::Not)
|
||||
// Dealt with elsewhere.
|
||||
| Or(_) | Paren(_) => false,
|
||||
| Or(_) | Paren(_) | Deref(_) => false,
|
||||
// Transform `box x | ... | box y` into `box (x | y)`.
|
||||
//
|
||||
// The cases below until `Slice(...)` deal with *singleton* products.
|
||||
|
@ -131,7 +131,7 @@ fn non_consuming_ok_arm<'a>(cx: &LateContext<'a>, arm: &hir::Arm<'a>) -> bool {
|
||||
fn check_expr<'a>(cx: &LateContext<'a>, expr: &'a hir::Expr<'a>) {
|
||||
match expr.kind {
|
||||
ExprKind::If(cond, _, _)
|
||||
if let ExprKind::Let(hir::Let { pat, init, .. }) = cond.kind
|
||||
if let ExprKind::Let(hir::LetExpr { pat, init, .. }) = cond.kind
|
||||
&& is_ok_wild_or_dotdot_pattern(cx, pat)
|
||||
&& let Some(op) = should_lint(cx, init) =>
|
||||
{
|
||||
|
@ -3,7 +3,7 @@ use clippy_utils::ty::{is_type_diagnostic_item, peel_mid_ty_refs_is_mutable};
|
||||
use clippy_utils::{fn_def_id, is_trait_method, path_to_local_id, peel_ref_operators};
|
||||
use rustc_ast::Mutability;
|
||||
use rustc_hir::intravisit::{walk_expr, Visitor};
|
||||
use rustc_hir::{Block, Expr, ExprKind, HirId, Local, Node, PatKind, PathSegment, StmtKind};
|
||||
use rustc_hir::{Block, Expr, ExprKind, HirId, LetStmt, Node, PatKind, PathSegment, StmtKind};
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
use rustc_middle::hir::nested_filter::OnlyBodies;
|
||||
use rustc_session::declare_lint_pass;
|
||||
@ -190,7 +190,7 @@ impl<'tcx> Visitor<'tcx> for PeekableVisitor<'_, 'tcx> {
|
||||
},
|
||||
}
|
||||
},
|
||||
Node::Local(Local { init: Some(init), .. }) => {
|
||||
Node::LetStmt(LetStmt { init: Some(init), .. }) => {
|
||||
if arg_is_mut_peekable(self.cx, init) {
|
||||
self.found_peek_call = true;
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user