Auto merge of #8190 - camsteffen:no-in-band-liftetimes, r=flip1995
Stop using `in_band_lifetimes` Per rust-lang/rust#91867 changelog: none
This commit is contained in:
commit
ae01c4ab3c
@ -42,7 +42,7 @@ fn is_bool_lit(e: &Expr<'_>) -> bool {
|
||||
) && !e.span.from_expansion()
|
||||
}
|
||||
|
||||
fn is_impl_not_trait_with_bool_out(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> bool {
|
||||
fn is_impl_not_trait_with_bool_out(cx: &LateContext<'_>, e: &Expr<'_>) -> bool {
|
||||
let ty = cx.typeck_results().expr_ty(e);
|
||||
|
||||
cx.tcx
|
||||
|
@ -67,7 +67,7 @@ fn check_case_sensitive_file_extension_comparison(ctx: &LateContext<'_>, expr: &
|
||||
None
|
||||
}
|
||||
|
||||
impl LateLintPass<'tcx> for CaseSensitiveFileExtensionComparisons {
|
||||
impl<'tcx> LateLintPass<'tcx> for CaseSensitiveFileExtensionComparisons {
|
||||
fn check_expr(&mut self, ctx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) {
|
||||
if let Some(span) = check_case_sensitive_file_extension_comparison(ctx, expr) {
|
||||
span_lint_and_help(
|
||||
|
@ -9,7 +9,7 @@ use rustc_span::symbol::sym;
|
||||
|
||||
use super::CAST_PTR_ALIGNMENT;
|
||||
|
||||
pub(super) fn check(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
|
||||
pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>) {
|
||||
if let ExprKind::Cast(cast_expr, cast_to) = expr.kind {
|
||||
if is_hir_ty_cfg_dependant(cx, cast_to) {
|
||||
return;
|
||||
|
@ -6,7 +6,7 @@ use rustc_middle::ty;
|
||||
|
||||
use super::CAST_REF_TO_MUT;
|
||||
|
||||
pub(super) fn check(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
|
||||
pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>) {
|
||||
if_chain! {
|
||||
if let ExprKind::Unary(UnOp::Deref, e) = &expr.kind;
|
||||
if let ExprKind::Cast(e, t) = &e.kind;
|
||||
|
@ -9,7 +9,7 @@ use rustc_middle::ty::{self, UintTy};
|
||||
|
||||
use super::CHAR_LIT_AS_U8;
|
||||
|
||||
pub(super) fn check(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
|
||||
pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>) {
|
||||
if_chain! {
|
||||
if let ExprKind::Cast(e, _) = &expr.kind;
|
||||
if let ExprKind::Lit(l) = &e.kind;
|
||||
|
@ -12,7 +12,7 @@ use rustc_semver::RustcVersion;
|
||||
|
||||
use super::PTR_AS_PTR;
|
||||
|
||||
pub(super) fn check(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, msrv: &Option<RustcVersion>) {
|
||||
pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, msrv: &Option<RustcVersion>) {
|
||||
if !meets_msrv(msrv.as_ref(), &msrvs::POINTER_CAST) {
|
||||
return;
|
||||
}
|
||||
|
@ -316,7 +316,7 @@ struct BlockEqual {
|
||||
|
||||
/// This function can also trigger the `IF_SAME_THEN_ELSE` in which case it'll return `None` to
|
||||
/// abort any further processing and avoid duplicate lint triggers.
|
||||
fn scan_block_for_eq(cx: &LateContext<'tcx>, blocks: &[&Block<'tcx>]) -> Option<BlockEqual> {
|
||||
fn scan_block_for_eq(cx: &LateContext<'_>, blocks: &[&Block<'_>]) -> Option<BlockEqual> {
|
||||
let mut start_eq = usize::MAX;
|
||||
let mut end_eq = usize::MAX;
|
||||
let mut expr_eq = true;
|
||||
@ -385,11 +385,7 @@ fn scan_block_for_eq(cx: &LateContext<'tcx>, blocks: &[&Block<'tcx>]) -> Option<
|
||||
})
|
||||
}
|
||||
|
||||
fn check_for_warn_of_moved_symbol(
|
||||
cx: &LateContext<'tcx>,
|
||||
symbols: &FxHashSet<Symbol>,
|
||||
if_expr: &'tcx Expr<'_>,
|
||||
) -> bool {
|
||||
fn check_for_warn_of_moved_symbol(cx: &LateContext<'_>, symbols: &FxHashSet<Symbol>, if_expr: &Expr<'_>) -> bool {
|
||||
get_enclosing_block(cx, if_expr.hir_id).map_or(false, |block| {
|
||||
let ignore_span = block.span.shrink_to_lo().to(if_expr.span);
|
||||
|
||||
@ -419,13 +415,13 @@ fn check_for_warn_of_moved_symbol(
|
||||
}
|
||||
|
||||
fn emit_branches_sharing_code_lint(
|
||||
cx: &LateContext<'tcx>,
|
||||
cx: &LateContext<'_>,
|
||||
start_stmts: usize,
|
||||
end_stmts: usize,
|
||||
lint_end: bool,
|
||||
warn_about_moved_symbol: bool,
|
||||
blocks: &[&Block<'tcx>],
|
||||
if_expr: &'tcx Expr<'_>,
|
||||
blocks: &[&Block<'_>],
|
||||
if_expr: &Expr<'_>,
|
||||
) {
|
||||
if start_stmts == 0 && !lint_end {
|
||||
return;
|
||||
|
@ -77,7 +77,7 @@ pub struct Default {
|
||||
|
||||
impl_lint_pass!(Default => [DEFAULT_TRAIT_ACCESS, FIELD_REASSIGN_WITH_DEFAULT]);
|
||||
|
||||
impl LateLintPass<'_> for Default {
|
||||
impl<'tcx> LateLintPass<'tcx> for Default {
|
||||
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
|
||||
if_chain! {
|
||||
if !expr.span.from_expansion();
|
||||
@ -110,7 +110,7 @@ impl LateLintPass<'_> for Default {
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_lines)]
|
||||
fn check_block<'tcx>(&mut self, cx: &LateContext<'tcx>, block: &Block<'tcx>) {
|
||||
fn check_block(&mut self, cx: &LateContext<'tcx>, block: &Block<'tcx>) {
|
||||
// start from the `let mut _ = _::default();` and look at all the following
|
||||
// statements, see if they re-assign the fields of the binding
|
||||
let stmts_head = match block.stmts {
|
||||
|
@ -54,7 +54,7 @@ declare_clippy_lint! {
|
||||
|
||||
declare_lint_pass!(DefaultNumericFallback => [DEFAULT_NUMERIC_FALLBACK]);
|
||||
|
||||
impl LateLintPass<'_> for DefaultNumericFallback {
|
||||
impl<'tcx> LateLintPass<'tcx> for DefaultNumericFallback {
|
||||
fn check_body(&mut self, cx: &LateContext<'tcx>, body: &'tcx Body<'_>) {
|
||||
let mut visitor = NumericFallbackVisitor::new(cx);
|
||||
visitor.visit_body(body);
|
||||
|
@ -355,7 +355,7 @@ impl<'tcx> LateLintPass<'tcx> for Dereferencing {
|
||||
}
|
||||
}
|
||||
|
||||
fn try_parse_ref_op(
|
||||
fn try_parse_ref_op<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
typeck: &'tcx TypeckResults<'_>,
|
||||
expr: &'tcx Expr<'_>,
|
||||
@ -387,7 +387,7 @@ fn try_parse_ref_op(
|
||||
|
||||
// Checks whether the type for a deref call actually changed the type, not just the mutability of
|
||||
// the reference.
|
||||
fn deref_method_same_type(result_ty: Ty<'tcx>, arg_ty: Ty<'tcx>) -> bool {
|
||||
fn deref_method_same_type(result_ty: Ty<'_>, arg_ty: Ty<'_>) -> bool {
|
||||
match (result_ty.kind(), arg_ty.kind()) {
|
||||
(ty::Ref(_, result_ty, _), ty::Ref(_, arg_ty, _)) => TyS::same_type(result_ty, arg_ty),
|
||||
|
||||
@ -457,7 +457,7 @@ fn is_linted_explicit_deref_position(parent: Option<Node<'_>>, child_id: HirId,
|
||||
}
|
||||
|
||||
/// Adjustments are sometimes made in the parent block rather than the expression itself.
|
||||
fn find_adjustments(
|
||||
fn find_adjustments<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
typeck: &'tcx TypeckResults<'_>,
|
||||
expr: &'tcx Expr<'_>,
|
||||
@ -499,7 +499,7 @@ fn find_adjustments(
|
||||
}
|
||||
|
||||
#[allow(clippy::needless_pass_by_value)]
|
||||
fn report(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, state: State, data: StateData) {
|
||||
fn report(cx: &LateContext<'_>, expr: &Expr<'_>, state: State, data: StateData) {
|
||||
match state {
|
||||
State::DerefMethod {
|
||||
ty_changed_count,
|
||||
@ -568,7 +568,7 @@ fn report(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, state: State, data: Stat
|
||||
}
|
||||
|
||||
impl Dereferencing {
|
||||
fn check_local_usage(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>, local: HirId) {
|
||||
fn check_local_usage(&mut self, cx: &LateContext<'_>, e: &Expr<'_>, local: HirId) {
|
||||
if let Some(outer_pat) = self.ref_locals.get_mut(&local) {
|
||||
if let Some(pat) = outer_pat {
|
||||
// Check for auto-deref
|
||||
|
@ -233,7 +233,7 @@ struct ContainsExpr<'tcx> {
|
||||
key: &'tcx Expr<'tcx>,
|
||||
call_ctxt: SyntaxContext,
|
||||
}
|
||||
fn try_parse_contains(cx: &LateContext<'_>, expr: &'tcx Expr<'_>) -> Option<(MapType, ContainsExpr<'tcx>)> {
|
||||
fn try_parse_contains<'tcx>(cx: &LateContext<'_>, expr: &'tcx Expr<'_>) -> Option<(MapType, ContainsExpr<'tcx>)> {
|
||||
let mut negated = false;
|
||||
let expr = peel_hir_expr_while(expr, |e| match e.kind {
|
||||
ExprKind::Unary(UnOp::Not, e) => {
|
||||
@ -280,7 +280,7 @@ struct InsertExpr<'tcx> {
|
||||
key: &'tcx Expr<'tcx>,
|
||||
value: &'tcx Expr<'tcx>,
|
||||
}
|
||||
fn try_parse_insert(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Option<InsertExpr<'tcx>> {
|
||||
fn try_parse_insert<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Option<InsertExpr<'tcx>> {
|
||||
if let ExprKind::MethodCall(_, _, [map, key, value], _) = expr.kind {
|
||||
let id = cx.typeck_results().type_dependent_def_id(expr.hir_id)?;
|
||||
if match_def_path(cx, id, &paths::BTREEMAP_INSERT) || match_def_path(cx, id, &paths::HASHMAP_INSERT) {
|
||||
@ -301,7 +301,7 @@ enum Edit<'tcx> {
|
||||
/// An insertion into the map.
|
||||
Insertion(Insertion<'tcx>),
|
||||
}
|
||||
impl Edit<'tcx> {
|
||||
impl<'tcx> Edit<'tcx> {
|
||||
fn as_insertion(self) -> Option<Insertion<'tcx>> {
|
||||
if let Self::Insertion(i) = self { Some(i) } else { None }
|
||||
}
|
||||
@ -532,7 +532,7 @@ struct InsertSearchResults<'tcx> {
|
||||
allow_insert_closure: bool,
|
||||
is_single_insert: bool,
|
||||
}
|
||||
impl InsertSearchResults<'tcx> {
|
||||
impl<'tcx> InsertSearchResults<'tcx> {
|
||||
fn as_single_insertion(&self) -> Option<Insertion<'tcx>> {
|
||||
self.is_single_insert.then(|| self.edits[0].as_insertion().unwrap())
|
||||
}
|
||||
@ -633,7 +633,7 @@ impl InsertSearchResults<'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
fn find_insert_calls(
|
||||
fn find_insert_calls<'tcx>(
|
||||
cx: &LateContext<'tcx>,
|
||||
contains_expr: &ContainsExpr<'tcx>,
|
||||
expr: &'tcx Expr<'_>,
|
||||
|
@ -56,7 +56,7 @@ fn unary_pattern(pat: &Pat<'_>) -> bool {
|
||||
}
|
||||
}
|
||||
|
||||
fn is_structural_partial_eq(cx: &LateContext<'tcx>, ty: Ty<'tcx>, other: Ty<'tcx>) -> bool {
|
||||
fn is_structural_partial_eq<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>, other: Ty<'tcx>) -> bool {
|
||||
if let Some(def_id) = cx.tcx.lang_items().eq_trait() {
|
||||
implements_trait(cx, ty, def_id, &[other.into()])
|
||||
} else {
|
||||
|
@ -50,13 +50,19 @@ impl<'tcx> LateLintPass<'tcx> for ErasingOp {
|
||||
}
|
||||
}
|
||||
|
||||
fn different_types(tck: &TypeckResults<'tcx>, input: &'tcx Expr<'_>, output: &'tcx Expr<'_>) -> bool {
|
||||
fn different_types(tck: &TypeckResults<'_>, input: &Expr<'_>, output: &Expr<'_>) -> bool {
|
||||
let input_ty = tck.expr_ty(input).peel_refs();
|
||||
let output_ty = tck.expr_ty(output).peel_refs();
|
||||
!same_type_and_consts(input_ty, output_ty)
|
||||
}
|
||||
|
||||
fn check(cx: &LateContext<'cx>, tck: &TypeckResults<'cx>, op: &Expr<'cx>, other: &Expr<'cx>, parent: &Expr<'cx>) {
|
||||
fn check<'tcx>(
|
||||
cx: &LateContext<'tcx>,
|
||||
tck: &TypeckResults<'tcx>,
|
||||
op: &Expr<'tcx>,
|
||||
other: &Expr<'tcx>,
|
||||
parent: &Expr<'tcx>,
|
||||
) {
|
||||
if constant_simple(cx, tck, op) == Some(Constant::Int(0)) {
|
||||
if different_types(tck, other, parent) {
|
||||
return;
|
||||
|
@ -53,7 +53,7 @@ impl FromOverInto {
|
||||
|
||||
impl_lint_pass!(FromOverInto => [FROM_OVER_INTO]);
|
||||
|
||||
impl LateLintPass<'_> for FromOverInto {
|
||||
impl<'tcx> LateLintPass<'tcx> for FromOverInto {
|
||||
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) {
|
||||
if !meets_msrv(self.msrv.as_ref(), &msrvs::RE_REBALANCING_COHERENCE) {
|
||||
return;
|
||||
|
@ -43,7 +43,7 @@ declare_clippy_lint! {
|
||||
|
||||
declare_lint_pass!(FromStrRadix10 => [FROM_STR_RADIX_10]);
|
||||
|
||||
impl LateLintPass<'tcx> for FromStrRadix10 {
|
||||
impl<'tcx> LateLintPass<'tcx> for FromStrRadix10 {
|
||||
fn check_expr(&mut self, cx: &LateContext<'tcx>, exp: &Expr<'tcx>) {
|
||||
if_chain! {
|
||||
if let ExprKind::Call(maybe_path, arguments) = &exp.kind;
|
||||
|
@ -18,7 +18,7 @@ use clippy_utils::{match_def_path, must_use_attr, return_ty, trait_ref_of_method
|
||||
|
||||
use super::{DOUBLE_MUST_USE, MUST_USE_CANDIDATE, MUST_USE_UNIT};
|
||||
|
||||
pub(super) fn check_item(cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) {
|
||||
pub(super) fn check_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) {
|
||||
let attrs = cx.tcx.hir().attrs(item.hir_id());
|
||||
let attr = must_use_attr(attrs);
|
||||
if let hir::ItemKind::Fn(ref sig, ref _generics, ref body_id) = item.kind {
|
||||
@ -40,7 +40,7 @@ pub(super) fn check_item(cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) {
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn check_impl_item(cx: &LateContext<'tcx>, item: &'tcx hir::ImplItem<'_>) {
|
||||
pub(super) fn check_impl_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::ImplItem<'_>) {
|
||||
if let hir::ImplItemKind::Fn(ref sig, ref body_id) = item.kind {
|
||||
let is_public = cx.access_levels.is_exported(item.def_id);
|
||||
let fn_header_span = item.span.with_hi(sig.decl.output.span().hi());
|
||||
@ -62,7 +62,7 @@ pub(super) fn check_impl_item(cx: &LateContext<'tcx>, item: &'tcx hir::ImplItem<
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn check_trait_item(cx: &LateContext<'tcx>, item: &'tcx hir::TraitItem<'_>) {
|
||||
pub(super) fn check_trait_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::TraitItem<'_>) {
|
||||
if let hir::TraitItemKind::Fn(ref sig, ref eid) = item.kind {
|
||||
let is_public = cx.access_levels.is_exported(item.def_id);
|
||||
let fn_header_span = item.span.with_hi(sig.decl.output.span().hi());
|
||||
|
@ -9,7 +9,7 @@ use clippy_utils::{iter_input_pats, path_to_local};
|
||||
|
||||
use super::NOT_UNSAFE_PTR_ARG_DEREF;
|
||||
|
||||
pub(super) fn check_fn(
|
||||
pub(super) fn check_fn<'tcx>(
|
||||
cx: &LateContext<'tcx>,
|
||||
kind: intravisit::FnKind<'tcx>,
|
||||
decl: &'tcx hir::FnDecl<'tcx>,
|
||||
@ -25,14 +25,14 @@ pub(super) fn check_fn(
|
||||
check_raw_ptr(cx, unsafety, decl, body, cx.tcx.hir().local_def_id(hir_id));
|
||||
}
|
||||
|
||||
pub(super) fn check_trait_item(cx: &LateContext<'tcx>, item: &'tcx hir::TraitItem<'_>) {
|
||||
pub(super) fn check_trait_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::TraitItem<'_>) {
|
||||
if let hir::TraitItemKind::Fn(ref sig, hir::TraitFn::Provided(eid)) = item.kind {
|
||||
let body = cx.tcx.hir().body(eid);
|
||||
check_raw_ptr(cx, sig.header.unsafety, sig.decl, body, item.def_id);
|
||||
}
|
||||
}
|
||||
|
||||
fn check_raw_ptr(
|
||||
fn check_raw_ptr<'tcx>(
|
||||
cx: &LateContext<'tcx>,
|
||||
unsafety: hir::Unsafety,
|
||||
decl: &'tcx hir::FnDecl<'tcx>,
|
||||
|
@ -13,7 +13,7 @@ use clippy_utils::ty::is_type_diagnostic_item;
|
||||
|
||||
use super::RESULT_UNIT_ERR;
|
||||
|
||||
pub(super) fn check_item(cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) {
|
||||
pub(super) fn check_item(cx: &LateContext<'_>, item: &hir::Item<'_>) {
|
||||
if let hir::ItemKind::Fn(ref sig, ref _generics, _) = item.kind {
|
||||
let is_public = cx.access_levels.is_exported(item.def_id);
|
||||
let fn_header_span = item.span.with_hi(sig.decl.output.span().hi());
|
||||
@ -23,7 +23,7 @@ pub(super) fn check_item(cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) {
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn check_impl_item(cx: &LateContext<'tcx>, item: &'tcx hir::ImplItem<'_>) {
|
||||
pub(super) fn check_impl_item(cx: &LateContext<'_>, item: &hir::ImplItem<'_>) {
|
||||
if let hir::ImplItemKind::Fn(ref sig, _) = item.kind {
|
||||
let is_public = cx.access_levels.is_exported(item.def_id);
|
||||
let fn_header_span = item.span.with_hi(sig.decl.output.span().hi());
|
||||
@ -33,7 +33,7 @@ pub(super) fn check_impl_item(cx: &LateContext<'tcx>, item: &'tcx hir::ImplItem<
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn check_trait_item(cx: &LateContext<'tcx>, item: &'tcx hir::TraitItem<'_>) {
|
||||
pub(super) fn check_trait_item(cx: &LateContext<'_>, item: &hir::TraitItem<'_>) {
|
||||
if let hir::TraitItemKind::Fn(ref sig, _) = item.kind {
|
||||
let is_public = cx.access_levels.is_exported(item.def_id);
|
||||
let fn_header_span = item.span.with_hi(sig.decl.output.span().hi());
|
||||
|
@ -9,9 +9,9 @@ use clippy_utils::is_trait_impl_item;
|
||||
use super::TOO_MANY_ARGUMENTS;
|
||||
|
||||
pub(super) fn check_fn(
|
||||
cx: &LateContext<'tcx>,
|
||||
kind: intravisit::FnKind<'tcx>,
|
||||
decl: &'tcx hir::FnDecl<'_>,
|
||||
cx: &LateContext<'_>,
|
||||
kind: intravisit::FnKind<'_>,
|
||||
decl: &hir::FnDecl<'_>,
|
||||
span: Span,
|
||||
hir_id: hir::HirId,
|
||||
too_many_arguments_threshold: u64,
|
||||
@ -39,11 +39,7 @@ pub(super) fn check_fn(
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn check_trait_item(
|
||||
cx: &LateContext<'tcx>,
|
||||
item: &'tcx hir::TraitItem<'_>,
|
||||
too_many_arguments_threshold: u64,
|
||||
) {
|
||||
pub(super) fn check_trait_item(cx: &LateContext<'_>, item: &hir::TraitItem<'_>, too_many_arguments_threshold: u64) {
|
||||
if let hir::TraitItemKind::Fn(ref sig, _) = item.kind {
|
||||
// don't lint extern functions decls, it's not their fault
|
||||
if sig.header.abi == Abi::Rust {
|
||||
|
@ -11,9 +11,9 @@ use super::TOO_MANY_LINES;
|
||||
|
||||
pub(super) fn check_fn(
|
||||
cx: &LateContext<'_>,
|
||||
kind: FnKind<'tcx>,
|
||||
kind: FnKind<'_>,
|
||||
span: Span,
|
||||
body: &'tcx hir::Body<'_>,
|
||||
body: &hir::Body<'_>,
|
||||
too_many_lines_threshold: u64,
|
||||
) {
|
||||
// Closures must be contained in a parent body, which will be checked for `too_many_lines`.
|
||||
|
@ -55,7 +55,7 @@ impl IfThenSomeElseNone {
|
||||
|
||||
impl_lint_pass!(IfThenSomeElseNone => [IF_THEN_SOME_ELSE_NONE]);
|
||||
|
||||
impl LateLintPass<'_> for IfThenSomeElseNone {
|
||||
impl<'tcx> LateLintPass<'tcx> for IfThenSomeElseNone {
|
||||
fn check_expr(&mut self, cx: &LateContext<'_>, expr: &'tcx Expr<'_>) {
|
||||
if !meets_msrv(self.msrv.as_ref(), &msrvs::BOOL_THEN) {
|
||||
return;
|
||||
|
@ -94,8 +94,8 @@ fn get_call_site(span: Span, ctxt: SyntaxContext) -> Option<Span> {
|
||||
}
|
||||
|
||||
fn lint_implicit_returns(
|
||||
cx: &LateContext<'tcx>,
|
||||
expr: &'tcx Expr<'_>,
|
||||
cx: &LateContext<'_>,
|
||||
expr: &Expr<'_>,
|
||||
// The context of the function body.
|
||||
ctxt: SyntaxContext,
|
||||
// Whether the expression is from a macro expansion.
|
||||
|
@ -63,7 +63,7 @@ declare_clippy_lint! {
|
||||
|
||||
declare_lint_pass!(InconsistentStructConstructor => [INCONSISTENT_STRUCT_CONSTRUCTOR]);
|
||||
|
||||
impl LateLintPass<'_> for InconsistentStructConstructor {
|
||||
impl<'tcx> LateLintPass<'tcx> for InconsistentStructConstructor {
|
||||
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) {
|
||||
if_chain! {
|
||||
if !expr.span.from_expansion();
|
||||
|
@ -69,7 +69,7 @@ impl IndexRefutableSlice {
|
||||
|
||||
impl_lint_pass!(IndexRefutableSlice => [INDEX_REFUTABLE_SLICE]);
|
||||
|
||||
impl LateLintPass<'_> for IndexRefutableSlice {
|
||||
impl<'tcx> LateLintPass<'tcx> for IndexRefutableSlice {
|
||||
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) {
|
||||
if_chain! {
|
||||
if !expr.span.from_expansion() || is_expn_of(expr.span, "if_chain").is_some();
|
||||
|
@ -39,7 +39,7 @@ declare_clippy_lint! {
|
||||
|
||||
declare_lint_pass!(IterNotReturningIterator => [ITER_NOT_RETURNING_ITERATOR]);
|
||||
|
||||
impl LateLintPass<'_> for IterNotReturningIterator {
|
||||
impl<'tcx> LateLintPass<'tcx> for IterNotReturningIterator {
|
||||
fn check_trait_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx TraitItem<'_>) {
|
||||
let name = item.ident.name.as_str();
|
||||
if matches!(name, "iter" | "iter_mut") {
|
||||
|
@ -245,7 +245,7 @@ enum LenOutput<'tcx> {
|
||||
Option(DefId),
|
||||
Result(DefId, Ty<'tcx>),
|
||||
}
|
||||
fn parse_len_output(cx: &LateContext<'_>, sig: FnSig<'tcx>) -> Option<LenOutput<'tcx>> {
|
||||
fn parse_len_output<'tcx>(cx: &LateContext<'_>, sig: FnSig<'tcx>) -> Option<LenOutput<'tcx>> {
|
||||
match *sig.output().kind() {
|
||||
ty::Int(_) | ty::Uint(_) => Some(LenOutput::Integral),
|
||||
ty::Adt(adt, subs) if cx.tcx.is_diagnostic_item(sym::Option, adt.did) => {
|
||||
|
@ -4,7 +4,6 @@
|
||||
#![feature(box_patterns)]
|
||||
#![feature(control_flow_enum)]
|
||||
#![feature(drain_filter)]
|
||||
#![feature(in_band_lifetimes)]
|
||||
#![feature(iter_intersperse)]
|
||||
#![feature(let_else)]
|
||||
#![feature(once_cell)]
|
||||
|
@ -5,7 +5,7 @@ use clippy_utils::{is_in_panic_handler, is_no_std_crate};
|
||||
use rustc_hir::{Block, Expr};
|
||||
use rustc_lint::LateContext;
|
||||
|
||||
pub(super) fn check(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, loop_block: &'tcx Block<'_>) {
|
||||
pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, loop_block: &Block<'_>) {
|
||||
if loop_block.stmts.is_empty() && loop_block.expr.is_none() && !is_in_panic_handler(cx, expr) {
|
||||
let msg = "empty `loop {}` wastes CPU cycles";
|
||||
let help = if is_no_std_crate(cx) {
|
||||
|
@ -8,7 +8,7 @@ use rustc_lint::LateContext;
|
||||
use rustc_middle::ty::TyS;
|
||||
use rustc_span::symbol::sym;
|
||||
|
||||
pub(super) fn check(cx: &LateContext<'_>, self_arg: &'hir Expr<'hir>, call_expr: &Expr<'_>) {
|
||||
pub(super) fn check(cx: &LateContext<'_>, self_arg: &Expr<'_>, call_expr: &Expr<'_>) {
|
||||
let self_ty = cx.typeck_results().expr_ty(self_arg);
|
||||
let self_ty_adjusted = cx.typeck_results().expr_ty_adjusted(self_arg);
|
||||
if !(TyS::same_type(self_ty, self_ty_adjusted) && is_trait_method(cx, call_expr, sym::IntoIterator)) {
|
||||
|
@ -203,7 +203,7 @@ fn build_manual_memcpy_suggestion<'tcx>(
|
||||
#[derive(Clone)]
|
||||
struct MinifyingSugg<'a>(Sugg<'a>);
|
||||
|
||||
impl Display for MinifyingSugg<'a> {
|
||||
impl<'a> Display for MinifyingSugg<'a> {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
self.0.fmt(f)
|
||||
}
|
||||
|
@ -147,7 +147,7 @@ impl BreakAfterExprVisitor {
|
||||
}
|
||||
}
|
||||
|
||||
impl intravisit::Visitor<'tcx> for BreakAfterExprVisitor {
|
||||
impl<'tcx> intravisit::Visitor<'tcx> for BreakAfterExprVisitor {
|
||||
type Map = Map<'tcx>;
|
||||
|
||||
fn nested_visit_map(&mut self) -> NestedVisitorMap<Self::Map> {
|
||||
|
@ -339,8 +339,8 @@ fn detect_iter_and_into_iters<'tcx: 'a, 'a>(
|
||||
}
|
||||
}
|
||||
|
||||
fn get_captured_ids(cx: &LateContext<'tcx>, ty: &'_ TyS<'_>) -> HirIdSet {
|
||||
fn get_captured_ids_recursive(cx: &LateContext<'tcx>, ty: &'_ TyS<'_>, set: &mut HirIdSet) {
|
||||
fn get_captured_ids(cx: &LateContext<'_>, ty: &'_ TyS<'_>) -> HirIdSet {
|
||||
fn get_captured_ids_recursive(cx: &LateContext<'_>, ty: &'_ TyS<'_>, set: &mut HirIdSet) {
|
||||
match ty.kind() {
|
||||
ty::Adt(_, generics) => {
|
||||
for generic in *generics {
|
||||
|
@ -10,8 +10,8 @@ use rustc_span::Span;
|
||||
use std::iter::{once, Iterator};
|
||||
|
||||
pub(super) fn check(
|
||||
cx: &LateContext<'tcx>,
|
||||
block: &'tcx Block<'_>,
|
||||
cx: &LateContext<'_>,
|
||||
block: &Block<'_>,
|
||||
loop_id: HirId,
|
||||
span: Span,
|
||||
for_loop: Option<&ForLoop<'_>>,
|
||||
|
@ -7,7 +7,7 @@ use rustc_hir::{Block, Expr, ExprKind, MatchSource, Pat, StmtKind};
|
||||
use rustc_lint::{LateContext, LintContext};
|
||||
use rustc_middle::lint::in_external_macro;
|
||||
|
||||
pub(super) fn check(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, loop_block: &'tcx Block<'_>) {
|
||||
pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, loop_block: &'tcx Block<'_>) {
|
||||
// extract the expression from the first statement (if any) in a block
|
||||
let inner_stmt_expr = extract_expr_from_first_stmt(loop_block);
|
||||
// or extract the first expression (if any) from the block
|
||||
|
@ -13,7 +13,7 @@ use rustc_lint::LateContext;
|
||||
use rustc_middle::ty::adjustment::Adjust;
|
||||
use rustc_span::{symbol::sym, Symbol};
|
||||
|
||||
pub(super) fn check(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
|
||||
pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
|
||||
let (scrutinee_expr, iter_expr_struct, iter_expr, some_pat, loop_expr) = if_chain! {
|
||||
if let Some(higher::WhileLet { if_then, let_pat, let_expr }) = higher::WhileLet::hir(expr);
|
||||
// check for `Some(..)` pattern
|
||||
@ -191,7 +191,7 @@ fn is_expr_same_child_or_parent_field(cx: &LateContext<'_>, expr: &Expr<'_>, fie
|
||||
|
||||
/// Strips off all field and path expressions. This will return true if a field or path has been
|
||||
/// skipped. Used to skip them after failing to check for equality.
|
||||
fn skip_fields_and_path(expr: &'tcx Expr<'_>) -> (Option<&'tcx Expr<'tcx>>, bool) {
|
||||
fn skip_fields_and_path<'tcx>(expr: &'tcx Expr<'_>) -> (Option<&'tcx Expr<'tcx>>, bool) {
|
||||
let mut e = expr;
|
||||
let e = loop {
|
||||
match e.kind {
|
||||
@ -204,13 +204,13 @@ fn skip_fields_and_path(expr: &'tcx Expr<'_>) -> (Option<&'tcx Expr<'tcx>>, bool
|
||||
}
|
||||
|
||||
/// Checks if the given expression uses the iterator.
|
||||
fn uses_iter(cx: &LateContext<'tcx>, iter_expr: &IterExpr, container: &'tcx Expr<'_>) -> bool {
|
||||
fn uses_iter<'tcx>(cx: &LateContext<'tcx>, iter_expr: &IterExpr, container: &'tcx Expr<'_>) -> bool {
|
||||
struct V<'a, 'b, 'tcx> {
|
||||
cx: &'a LateContext<'tcx>,
|
||||
iter_expr: &'b IterExpr,
|
||||
uses_iter: bool,
|
||||
}
|
||||
impl Visitor<'tcx> for V<'_, '_, 'tcx> {
|
||||
impl<'tcx> Visitor<'tcx> for V<'_, '_, 'tcx> {
|
||||
type Map = ErasedMap<'tcx>;
|
||||
fn nested_visit_map(&mut self) -> NestedVisitorMap<Self::Map> {
|
||||
NestedVisitorMap::None
|
||||
@ -245,7 +245,7 @@ fn uses_iter(cx: &LateContext<'tcx>, iter_expr: &IterExpr, container: &'tcx Expr
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_lines)]
|
||||
fn needs_mutable_borrow(cx: &LateContext<'tcx>, iter_expr: &IterExpr, loop_expr: &'tcx Expr<'_>) -> bool {
|
||||
fn needs_mutable_borrow(cx: &LateContext<'_>, iter_expr: &IterExpr, loop_expr: &Expr<'_>) -> bool {
|
||||
struct AfterLoopVisitor<'a, 'b, 'tcx> {
|
||||
cx: &'a LateContext<'tcx>,
|
||||
iter_expr: &'b IterExpr,
|
||||
@ -253,7 +253,7 @@ fn needs_mutable_borrow(cx: &LateContext<'tcx>, iter_expr: &IterExpr, loop_expr:
|
||||
after_loop: bool,
|
||||
used_iter: bool,
|
||||
}
|
||||
impl Visitor<'tcx> for AfterLoopVisitor<'_, '_, 'tcx> {
|
||||
impl<'tcx> Visitor<'tcx> for AfterLoopVisitor<'_, '_, 'tcx> {
|
||||
type Map = ErasedMap<'tcx>;
|
||||
fn nested_visit_map(&mut self) -> NestedVisitorMap<Self::Map> {
|
||||
NestedVisitorMap::None
|
||||
@ -292,7 +292,7 @@ fn needs_mutable_borrow(cx: &LateContext<'tcx>, iter_expr: &IterExpr, loop_expr:
|
||||
found_local: bool,
|
||||
used_after: bool,
|
||||
}
|
||||
impl Visitor<'tcx> for NestedLoopVisitor<'a, 'b, 'tcx> {
|
||||
impl<'a, 'b, 'tcx> Visitor<'tcx> for NestedLoopVisitor<'a, 'b, 'tcx> {
|
||||
type Map = ErasedMap<'tcx>;
|
||||
|
||||
fn nested_visit_map(&mut self) -> NestedVisitorMap<Self::Map> {
|
||||
|
@ -35,7 +35,7 @@ declare_clippy_lint! {
|
||||
|
||||
declare_lint_pass!(ManualAssert => [MANUAL_ASSERT]);
|
||||
|
||||
impl LateLintPass<'_> for ManualAssert {
|
||||
impl<'tcx> LateLintPass<'tcx> for ManualAssert {
|
||||
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &Expr<'tcx>) {
|
||||
if_chain! {
|
||||
if let ExprKind::If(cond, then, None) = expr.kind;
|
||||
|
@ -45,7 +45,7 @@ declare_clippy_lint! {
|
||||
|
||||
declare_lint_pass!(ManualMap => [MANUAL_MAP]);
|
||||
|
||||
impl LateLintPass<'_> for ManualMap {
|
||||
impl<'tcx> LateLintPass<'tcx> for ManualMap {
|
||||
#[allow(clippy::too_many_lines)]
|
||||
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
|
||||
let (scrutinee, then_pat, then_body, else_pat, else_body) = match IfLetOrMatch::parse(cx, expr) {
|
||||
@ -219,7 +219,7 @@ impl LateLintPass<'_> for ManualMap {
|
||||
|
||||
// Checks whether the expression could be passed as a function, or whether a closure is needed.
|
||||
// Returns the function to be passed to `map` if it exists.
|
||||
fn can_pass_as_func(cx: &LateContext<'tcx>, binding: HirId, expr: &'tcx Expr<'_>) -> Option<&'tcx Expr<'tcx>> {
|
||||
fn can_pass_as_func<'tcx>(cx: &LateContext<'tcx>, binding: HirId, expr: &'tcx Expr<'_>) -> Option<&'tcx Expr<'tcx>> {
|
||||
match expr.kind {
|
||||
ExprKind::Call(func, [arg])
|
||||
if path_to_local_id(arg, binding)
|
||||
@ -251,8 +251,13 @@ struct SomeExpr<'tcx> {
|
||||
|
||||
// Try to parse into a recognized `Option` pattern.
|
||||
// i.e. `_`, `None`, `Some(..)`, or a reference to any of those.
|
||||
fn try_parse_pattern(cx: &LateContext<'tcx>, pat: &'tcx Pat<'_>, ctxt: SyntaxContext) -> Option<OptionPat<'tcx>> {
|
||||
fn f(cx: &LateContext<'tcx>, pat: &'tcx Pat<'_>, ref_count: usize, ctxt: SyntaxContext) -> Option<OptionPat<'tcx>> {
|
||||
fn try_parse_pattern<'tcx>(cx: &LateContext<'tcx>, pat: &'tcx Pat<'_>, ctxt: SyntaxContext) -> Option<OptionPat<'tcx>> {
|
||||
fn f<'tcx>(
|
||||
cx: &LateContext<'tcx>,
|
||||
pat: &'tcx Pat<'_>,
|
||||
ref_count: usize,
|
||||
ctxt: SyntaxContext,
|
||||
) -> Option<OptionPat<'tcx>> {
|
||||
match pat.kind {
|
||||
PatKind::Wild => Some(OptionPat::Wild),
|
||||
PatKind::Ref(pat, _) => f(cx, pat, ref_count + 1, ctxt),
|
||||
@ -269,7 +274,7 @@ fn try_parse_pattern(cx: &LateContext<'tcx>, pat: &'tcx Pat<'_>, ctxt: SyntaxCon
|
||||
}
|
||||
|
||||
// Checks for an expression wrapped by the `Some` constructor. Returns the contained expression.
|
||||
fn get_some_expr(
|
||||
fn get_some_expr<'tcx>(
|
||||
cx: &LateContext<'tcx>,
|
||||
expr: &'tcx Expr<'_>,
|
||||
needs_unsafe_block: bool,
|
||||
@ -306,6 +311,6 @@ fn get_some_expr(
|
||||
}
|
||||
|
||||
// Checks for the `None` value.
|
||||
fn is_none_expr(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> bool {
|
||||
fn is_none_expr(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
|
||||
matches!(peel_blocks(expr).kind, ExprKind::Path(ref qpath) if is_lang_ctor(cx, qpath, OptionNone))
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ declare_clippy_lint! {
|
||||
|
||||
declare_lint_pass!(ManualOkOr => [MANUAL_OK_OR]);
|
||||
|
||||
impl LateLintPass<'_> for ManualOkOr {
|
||||
impl<'tcx> LateLintPass<'tcx> for ManualOkOr {
|
||||
fn check_expr(&mut self, cx: &LateContext<'tcx>, scrutinee: &'tcx Expr<'tcx>) {
|
||||
if in_external_macro(cx.sess(), scrutinee.span) {
|
||||
return;
|
||||
|
@ -43,7 +43,7 @@ declare_clippy_lint! {
|
||||
|
||||
declare_lint_pass!(ManualUnwrapOr => [MANUAL_UNWRAP_OR]);
|
||||
|
||||
impl LateLintPass<'_> for ManualUnwrapOr {
|
||||
impl<'tcx> LateLintPass<'tcx> for ManualUnwrapOr {
|
||||
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) {
|
||||
if in_external_macro(cx.sess(), expr.span) || in_constant(cx, expr.hir_id) {
|
||||
return;
|
||||
|
@ -55,7 +55,7 @@ enum CaseMethod {
|
||||
AsciiUppercase,
|
||||
}
|
||||
|
||||
impl LateLintPass<'_> for MatchStrCaseMismatch {
|
||||
impl<'tcx> LateLintPass<'tcx> for MatchStrCaseMismatch {
|
||||
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
|
||||
if_chain! {
|
||||
if !in_external_macro(cx.tcx.sess, expr.span);
|
||||
|
@ -999,7 +999,7 @@ enum CommonPrefixSearcher<'a> {
|
||||
Path(&'a [PathSegment<'a>]),
|
||||
Mixed,
|
||||
}
|
||||
impl CommonPrefixSearcher<'a> {
|
||||
impl<'a> CommonPrefixSearcher<'a> {
|
||||
fn with_path(&mut self, path: &'a [PathSegment<'a>]) {
|
||||
match path {
|
||||
[path @ .., _] => self.with_prefix(path),
|
||||
@ -1804,11 +1804,15 @@ mod redundant_pattern_match {
|
||||
/// Checks if the drop order for a type matters. Some std types implement drop solely to
|
||||
/// deallocate memory. For these types, and composites containing them, changing the drop order
|
||||
/// won't result in any observable side effects.
|
||||
fn type_needs_ordered_drop(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool {
|
||||
fn type_needs_ordered_drop<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool {
|
||||
type_needs_ordered_drop_inner(cx, ty, &mut FxHashSet::default())
|
||||
}
|
||||
|
||||
fn type_needs_ordered_drop_inner(cx: &LateContext<'tcx>, ty: Ty<'tcx>, seen: &mut FxHashSet<Ty<'tcx>>) -> bool {
|
||||
fn type_needs_ordered_drop_inner<'tcx>(
|
||||
cx: &LateContext<'tcx>,
|
||||
ty: Ty<'tcx>,
|
||||
seen: &mut FxHashSet<Ty<'tcx>>,
|
||||
) -> bool {
|
||||
if !seen.insert(ty) {
|
||||
return false;
|
||||
}
|
||||
@ -1870,7 +1874,7 @@ mod redundant_pattern_match {
|
||||
|
||||
// Checks if there are any temporaries created in the given expression for which drop order
|
||||
// matters.
|
||||
fn temporaries_need_ordered_drop(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> bool {
|
||||
fn temporaries_need_ordered_drop<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> bool {
|
||||
struct V<'a, 'tcx> {
|
||||
cx: &'a LateContext<'tcx>,
|
||||
res: bool,
|
||||
|
@ -14,7 +14,7 @@ use super::EXPECT_FUN_CALL;
|
||||
|
||||
/// Checks for the `EXPECT_FUN_CALL` lint.
|
||||
#[allow(clippy::too_many_lines)]
|
||||
pub(super) fn check(
|
||||
pub(super) fn check<'tcx>(
|
||||
cx: &LateContext<'tcx>,
|
||||
expr: &hir::Expr<'_>,
|
||||
method_span: Span,
|
||||
|
@ -37,7 +37,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, args: &[hir::Exp
|
||||
}
|
||||
}
|
||||
|
||||
fn extract_turbofish(cx: &LateContext<'_>, expr: &hir::Expr<'_>, ty: Ty<'tcx>) -> String {
|
||||
fn extract_turbofish(cx: &LateContext<'_>, expr: &hir::Expr<'_>, ty: Ty<'_>) -> String {
|
||||
fn strip_angle_brackets(s: &str) -> Option<&str> {
|
||||
s.strip_prefix('<')?.strip_suffix('>')
|
||||
}
|
||||
|
@ -124,7 +124,7 @@ struct IterUsage {
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_lines)]
|
||||
fn parse_iter_usage(
|
||||
fn parse_iter_usage<'tcx>(
|
||||
cx: &LateContext<'tcx>,
|
||||
ctxt: SyntaxContext,
|
||||
mut iter: impl Iterator<Item = (HirId, Node<'tcx>)>,
|
||||
@ -281,7 +281,7 @@ pub(super) fn check_needless_splitn(
|
||||
}
|
||||
}
|
||||
|
||||
fn check_iter(
|
||||
fn check_iter<'tcx>(
|
||||
cx: &LateContext<'tcx>,
|
||||
ctxt: SyntaxContext,
|
||||
mut iter: impl Iterator<Item = (HirId, Node<'tcx>)>,
|
||||
|
@ -12,7 +12,7 @@ use rustc_span::{sym, Symbol};
|
||||
|
||||
use super::UNNECESSARY_TO_OWNED;
|
||||
|
||||
pub fn check(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>, method_name: Symbol, receiver: &'tcx Expr<'tcx>) -> bool {
|
||||
pub fn check(cx: &LateContext<'_>, expr: &Expr<'_>, method_name: Symbol, receiver: &Expr<'_>) -> bool {
|
||||
if_chain! {
|
||||
if let Some(parent) = get_parent_expr(cx, expr);
|
||||
if let Some(callee_def_id) = fn_def_id(cx, parent);
|
||||
@ -30,10 +30,10 @@ pub fn check(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>, method_name: Symbol
|
||||
/// include this code directly is so that it can be called from
|
||||
/// `unnecessary_into_owned::check_into_iter_call_arg`.
|
||||
pub fn check_for_loop_iter(
|
||||
cx: &LateContext<'tcx>,
|
||||
expr: &'tcx Expr<'tcx>,
|
||||
cx: &LateContext<'_>,
|
||||
expr: &Expr<'_>,
|
||||
method_name: Symbol,
|
||||
receiver: &'tcx Expr<'tcx>,
|
||||
receiver: &Expr<'_>,
|
||||
cloned_before_iter: bool,
|
||||
) -> bool {
|
||||
if_chain! {
|
||||
@ -101,7 +101,7 @@ pub fn check_for_loop_iter(
|
||||
|
||||
/// The core logic of `check_for_loop_iter` above, this function wraps a use of
|
||||
/// `CloneOrCopyVisitor`.
|
||||
fn clone_or_copy_needed(
|
||||
fn clone_or_copy_needed<'tcx>(
|
||||
cx: &LateContext<'tcx>,
|
||||
pat: &Pat<'tcx>,
|
||||
body: &'tcx Expr<'tcx>,
|
||||
|
@ -16,7 +16,7 @@ use std::cmp::max;
|
||||
|
||||
use super::UNNECESSARY_TO_OWNED;
|
||||
|
||||
pub fn check(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>, method_name: Symbol, args: &'tcx [Expr<'tcx>]) {
|
||||
pub fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>, method_name: Symbol, args: &'tcx [Expr<'tcx>]) {
|
||||
if_chain! {
|
||||
if let Some(method_def_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id);
|
||||
if let [receiver] = args;
|
||||
@ -44,11 +44,11 @@ pub fn check(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>, method_name: Symbol
|
||||
/// call of a `to_owned`-like function is unnecessary.
|
||||
#[allow(clippy::too_many_lines)]
|
||||
fn check_addr_of_expr(
|
||||
cx: &LateContext<'tcx>,
|
||||
expr: &'tcx Expr<'tcx>,
|
||||
cx: &LateContext<'_>,
|
||||
expr: &Expr<'_>,
|
||||
method_name: Symbol,
|
||||
method_def_id: DefId,
|
||||
receiver: &'tcx Expr<'tcx>,
|
||||
receiver: &Expr<'_>,
|
||||
) -> bool {
|
||||
if_chain! {
|
||||
if let Some(parent) = get_parent_expr(cx, expr);
|
||||
@ -171,12 +171,7 @@ fn check_addr_of_expr(
|
||||
|
||||
/// Checks whether `expr` is an argument in an `into_iter` call and, if so, determines whether its
|
||||
/// call of a `to_owned`-like function is unnecessary.
|
||||
fn check_into_iter_call_arg(
|
||||
cx: &LateContext<'tcx>,
|
||||
expr: &'tcx Expr<'tcx>,
|
||||
method_name: Symbol,
|
||||
receiver: &'tcx Expr<'tcx>,
|
||||
) -> bool {
|
||||
fn check_into_iter_call_arg(cx: &LateContext<'_>, expr: &Expr<'_>, method_name: Symbol, receiver: &Expr<'_>) -> bool {
|
||||
if_chain! {
|
||||
if let Some(parent) = get_parent_expr(cx, expr);
|
||||
if let Some(callee_def_id) = fn_def_id(cx, parent);
|
||||
@ -221,7 +216,7 @@ fn check_into_iter_call_arg(
|
||||
|
||||
/// Checks whether `expr` is an argument in a function call and, if so, determines whether its call
|
||||
/// of a `to_owned`-like function is unnecessary.
|
||||
fn check_other_call_arg(
|
||||
fn check_other_call_arg<'tcx>(
|
||||
cx: &LateContext<'tcx>,
|
||||
expr: &'tcx Expr<'tcx>,
|
||||
method_name: Symbol,
|
||||
@ -287,7 +282,7 @@ fn check_other_call_arg(
|
||||
|
||||
/// Walks an expression's ancestors until it finds a non-`AddrOf` expression. Returns the first such
|
||||
/// expression found (if any) along with the immediately prior expression.
|
||||
fn skip_addr_of_ancestors(
|
||||
fn skip_addr_of_ancestors<'tcx>(
|
||||
cx: &LateContext<'tcx>,
|
||||
mut expr: &'tcx Expr<'tcx>,
|
||||
) -> Option<(&'tcx Expr<'tcx>, &'tcx Expr<'tcx>)> {
|
||||
@ -303,7 +298,7 @@ fn skip_addr_of_ancestors(
|
||||
|
||||
/// Checks whether an expression is a function or method call and, if so, returns its `DefId`,
|
||||
/// `Substs`, and arguments.
|
||||
fn get_callee_substs_and_args(
|
||||
fn get_callee_substs_and_args<'tcx>(
|
||||
cx: &LateContext<'tcx>,
|
||||
expr: &'tcx Expr<'tcx>,
|
||||
) -> Option<(DefId, SubstsRef<'tcx>, &'tcx [Expr<'tcx>])> {
|
||||
@ -328,7 +323,7 @@ fn get_callee_substs_and_args(
|
||||
}
|
||||
|
||||
/// Returns the `TraitPredicate`s and `ProjectionPredicate`s for a function's input type.
|
||||
fn get_input_traits_and_projections(
|
||||
fn get_input_traits_and_projections<'tcx>(
|
||||
cx: &LateContext<'tcx>,
|
||||
callee_def_id: DefId,
|
||||
input: Ty<'tcx>,
|
||||
@ -368,7 +363,11 @@ fn get_input_traits_and_projections(
|
||||
}
|
||||
|
||||
/// Composes two substitutions by applying the latter to the types of the former.
|
||||
fn compose_substs(cx: &LateContext<'tcx>, left: &[GenericArg<'tcx>], right: SubstsRef<'tcx>) -> Vec<GenericArg<'tcx>> {
|
||||
fn compose_substs<'tcx>(
|
||||
cx: &LateContext<'tcx>,
|
||||
left: &[GenericArg<'tcx>],
|
||||
right: SubstsRef<'tcx>,
|
||||
) -> Vec<GenericArg<'tcx>> {
|
||||
left.iter()
|
||||
.map(|arg| {
|
||||
if let GenericArgKind::Type(arg_ty) = arg.unpack() {
|
||||
|
@ -717,7 +717,7 @@ fn check_cast(cx: &LateContext<'_>, span: Span, e: &Expr<'_>, ty: &hir::Ty<'_>)
|
||||
}
|
||||
}
|
||||
|
||||
fn check_binary(
|
||||
fn check_binary<'a>(
|
||||
cx: &LateContext<'a>,
|
||||
expr: &Expr<'_>,
|
||||
cmp: &rustc_span::source_map::Spanned<rustc_hir::BinOpKind>,
|
||||
|
@ -48,7 +48,7 @@ declare_clippy_lint! {
|
||||
|
||||
declare_lint_pass!(NeedlessForEach => [NEEDLESS_FOR_EACH]);
|
||||
|
||||
impl LateLintPass<'_> for NeedlessForEach {
|
||||
impl<'tcx> LateLintPass<'tcx> for NeedlessForEach {
|
||||
fn check_stmt(&mut self, cx: &LateContext<'tcx>, stmt: &'tcx Stmt<'_>) {
|
||||
let expr = match stmt.kind {
|
||||
StmtKind::Expr(expr) | StmtKind::Semi(expr) => expr,
|
||||
|
@ -330,7 +330,7 @@ fn check<'tcx>(
|
||||
Some(())
|
||||
}
|
||||
|
||||
impl LateLintPass<'tcx> for NeedlessLateInit {
|
||||
impl<'tcx> LateLintPass<'tcx> for NeedlessLateInit {
|
||||
fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx Local<'tcx>) {
|
||||
let mut parents = cx.tcx.hir().parent_iter(local.hir_id);
|
||||
|
||||
|
@ -82,7 +82,7 @@ impl<'tcx> LateLintPass<'tcx> for NoEffect {
|
||||
}
|
||||
}
|
||||
|
||||
fn check_no_effect(cx: &LateContext<'tcx>, stmt: &'tcx Stmt<'_>) -> bool {
|
||||
fn check_no_effect(cx: &LateContext<'_>, stmt: &Stmt<'_>) -> bool {
|
||||
if let StmtKind::Semi(expr) = stmt.kind {
|
||||
if has_no_effect(cx, expr) {
|
||||
span_lint_hir(cx, NO_EFFECT, expr.hir_id, stmt.span, "statement with no effect");
|
||||
@ -155,7 +155,7 @@ fn has_no_effect(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
|
||||
}
|
||||
}
|
||||
|
||||
fn check_unnecessary_operation(cx: &LateContext<'tcx>, stmt: &'tcx Stmt<'_>) {
|
||||
fn check_unnecessary_operation(cx: &LateContext<'_>, stmt: &Stmt<'_>) {
|
||||
if_chain! {
|
||||
if let StmtKind::Semi(expr) = stmt.kind;
|
||||
if let Some(reduced) = reduce_expression(cx, expr);
|
||||
|
@ -40,7 +40,7 @@ declare_clippy_lint! {
|
||||
|
||||
declare_lint_pass!(NonOctalUnixPermissions => [NON_OCTAL_UNIX_PERMISSIONS]);
|
||||
|
||||
impl LateLintPass<'_> for NonOctalUnixPermissions {
|
||||
impl<'tcx> LateLintPass<'tcx> for NonOctalUnixPermissions {
|
||||
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) {
|
||||
match &expr.kind {
|
||||
ExprKind::MethodCall(path, _, [func, param], _) => {
|
||||
|
@ -50,7 +50,7 @@ declare_clippy_lint! {
|
||||
declare_lint_pass!(OctalEscapes => [OCTAL_ESCAPES]);
|
||||
|
||||
impl EarlyLintPass for OctalEscapes {
|
||||
fn check_expr(&mut self, cx: &EarlyContext<'tcx>, expr: &Expr) {
|
||||
fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) {
|
||||
if in_external_macro(cx.sess, expr.span) {
|
||||
return;
|
||||
}
|
||||
@ -65,7 +65,7 @@ impl EarlyLintPass for OctalEscapes {
|
||||
}
|
||||
}
|
||||
|
||||
fn check_lit(cx: &EarlyContext<'tcx>, lit: &Lit, span: Span, is_string: bool) {
|
||||
fn check_lit(cx: &EarlyContext<'_>, lit: &Lit, span: Span, is_string: bool) {
|
||||
let contents = lit.symbol.as_str();
|
||||
let mut iter = contents.char_indices().peekable();
|
||||
let mut found = vec![];
|
||||
|
@ -39,7 +39,7 @@ declare_lint_pass!(PtrEq => [PTR_EQ]);
|
||||
|
||||
static LINT_MSG: &str = "use `std::ptr::eq` when comparing raw pointers";
|
||||
|
||||
impl LateLintPass<'_> for PtrEq {
|
||||
impl<'tcx> LateLintPass<'tcx> for PtrEq {
|
||||
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
|
||||
if expr.span.from_expansion() {
|
||||
return;
|
||||
|
@ -42,7 +42,7 @@ declare_clippy_lint! {
|
||||
|
||||
declare_lint_pass!(RedundantSlicing => [REDUNDANT_SLICING]);
|
||||
|
||||
impl LateLintPass<'_> for RedundantSlicing {
|
||||
impl<'tcx> LateLintPass<'tcx> for RedundantSlicing {
|
||||
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
|
||||
if expr.span.from_expansion() {
|
||||
return;
|
||||
|
@ -66,7 +66,7 @@ declare_clippy_lint! {
|
||||
|
||||
declare_lint_pass!(ReturnSelfNotMustUse => [RETURN_SELF_NOT_MUST_USE]);
|
||||
|
||||
fn check_method(cx: &LateContext<'tcx>, decl: &'tcx FnDecl<'tcx>, fn_def: LocalDefId, span: Span, hir_id: HirId) {
|
||||
fn check_method(cx: &LateContext<'_>, decl: &FnDecl<'_>, fn_def: LocalDefId, span: Span, hir_id: HirId) {
|
||||
if_chain! {
|
||||
// If it comes from an external macro, better ignore it.
|
||||
if !in_external_macro(cx.sess(), span);
|
||||
|
@ -37,7 +37,7 @@ declare_clippy_lint! {
|
||||
|
||||
declare_lint_pass!(SemicolonIfNothingReturned => [SEMICOLON_IF_NOTHING_RETURNED]);
|
||||
|
||||
impl LateLintPass<'_> for SemicolonIfNothingReturned {
|
||||
impl<'tcx> LateLintPass<'tcx> for SemicolonIfNothingReturned {
|
||||
fn check_block(&mut self, cx: &LateContext<'tcx>, block: &'tcx Block<'tcx>) {
|
||||
if_chain! {
|
||||
if !block.span.from_expansion();
|
||||
|
@ -37,7 +37,7 @@ declare_clippy_lint! {
|
||||
|
||||
declare_lint_pass!(SizeOfInElementCount => [SIZE_OF_IN_ELEMENT_COUNT]);
|
||||
|
||||
fn get_size_of_ty(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, inverted: bool) -> Option<Ty<'tcx>> {
|
||||
fn get_size_of_ty<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, inverted: bool) -> Option<Ty<'tcx>> {
|
||||
match expr.kind {
|
||||
ExprKind::Call(count_func, _func_args) => {
|
||||
if_chain! {
|
||||
@ -64,7 +64,10 @@ fn get_size_of_ty(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, inverted: bool)
|
||||
}
|
||||
}
|
||||
|
||||
fn get_pointee_ty_and_count_expr(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Option<(Ty<'tcx>, &'tcx Expr<'tcx>)> {
|
||||
fn get_pointee_ty_and_count_expr<'tcx>(
|
||||
cx: &LateContext<'tcx>,
|
||||
expr: &'tcx Expr<'_>,
|
||||
) -> Option<(Ty<'tcx>, &'tcx Expr<'tcx>)> {
|
||||
const FUNCTIONS: [&[&str]; 8] = [
|
||||
&paths::PTR_COPY_NONOVERLAPPING,
|
||||
&paths::PTR_COPY,
|
||||
|
@ -381,7 +381,7 @@ declare_clippy_lint! {
|
||||
|
||||
declare_lint_pass!(StrToString => [STR_TO_STRING]);
|
||||
|
||||
impl LateLintPass<'_> for StrToString {
|
||||
impl<'tcx> LateLintPass<'tcx> for StrToString {
|
||||
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &Expr<'_>) {
|
||||
if_chain! {
|
||||
if let ExprKind::MethodCall(path, _, [self_arg, ..], _) = &expr.kind;
|
||||
@ -431,7 +431,7 @@ declare_clippy_lint! {
|
||||
|
||||
declare_lint_pass!(StringToString => [STRING_TO_STRING]);
|
||||
|
||||
impl LateLintPass<'_> for StringToString {
|
||||
impl<'tcx> LateLintPass<'tcx> for StringToString {
|
||||
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &Expr<'_>) {
|
||||
if_chain! {
|
||||
if let ExprKind::MethodCall(path, _, [self_arg, ..], _) = &expr.kind;
|
||||
|
@ -39,7 +39,7 @@ declare_clippy_lint! {
|
||||
|
||||
declare_lint_pass!(StrlenOnCStrings => [STRLEN_ON_C_STRINGS]);
|
||||
|
||||
impl LateLintPass<'tcx> for StrlenOnCStrings {
|
||||
impl<'tcx> LateLintPass<'tcx> for StrlenOnCStrings {
|
||||
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
|
||||
if_chain! {
|
||||
if !expr.span.from_expansion();
|
||||
|
@ -355,7 +355,7 @@ struct BinaryOp<'exprs> {
|
||||
right: &'exprs Expr,
|
||||
}
|
||||
|
||||
impl BinaryOp<'exprs> {
|
||||
impl<'exprs> BinaryOp<'exprs> {
|
||||
fn new(op: BinOpKind, span: Span, (left, right): (&'exprs Expr, &'exprs Expr)) -> Self {
|
||||
Self { op, span, left, right }
|
||||
}
|
||||
@ -419,7 +419,7 @@ fn chained_binops(kind: &ExprKind) -> Option<Vec<BinaryOp<'_>>> {
|
||||
}
|
||||
}
|
||||
|
||||
fn chained_binops_helper(left_outer: &'expr Expr, right_outer: &'expr Expr) -> Option<Vec<BinaryOp<'expr>>> {
|
||||
fn chained_binops_helper<'expr>(left_outer: &'expr Expr, right_outer: &'expr Expr) -> Option<Vec<BinaryOp<'expr>>> {
|
||||
match (&left_outer.kind, &right_outer.kind) {
|
||||
(
|
||||
ExprKind::Paren(ref left_e) | ExprKind::Unary(_, ref left_e),
|
||||
|
@ -53,7 +53,7 @@ impl<'tcx> LateLintPass<'tcx> for TrailingEmptyArray {
|
||||
}
|
||||
}
|
||||
|
||||
fn is_struct_with_trailing_zero_sized_array(cx: &LateContext<'tcx>, item: &'tcx Item<'tcx>) -> bool {
|
||||
fn is_struct_with_trailing_zero_sized_array(cx: &LateContext<'_>, item: &Item<'_>) -> bool {
|
||||
if_chain! {
|
||||
// First check if last field is an array
|
||||
if let ItemKind::Struct(data, _) = &item.kind;
|
||||
|
@ -113,8 +113,8 @@ impl LateLintPass<'_> for UndocumentedUnsafeBlocks {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'hir> Visitor<'hir> for UndocumentedUnsafeBlocks {
|
||||
type Map = Map<'hir>;
|
||||
impl<'v> Visitor<'v> for UndocumentedUnsafeBlocks {
|
||||
type Map = Map<'v>;
|
||||
|
||||
fn nested_visit_map(&mut self) -> NestedVisitorMap<Self::Map> {
|
||||
NestedVisitorMap::None
|
||||
|
@ -36,7 +36,7 @@ declare_clippy_lint! {
|
||||
|
||||
declare_lint_pass!(UndroppedManuallyDrops => [UNDROPPED_MANUALLY_DROPS]);
|
||||
|
||||
impl LateLintPass<'tcx> for UndroppedManuallyDrops {
|
||||
impl<'tcx> LateLintPass<'tcx> for UndroppedManuallyDrops {
|
||||
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
|
||||
if let Some([arg_0, ..]) = match_function_call(cx, expr, &paths::DROP) {
|
||||
let ty = cx.typeck_results().expr_ty(arg_0);
|
||||
|
@ -78,7 +78,7 @@ impl<'tcx> LateLintPass<'tcx> for UninitVec {
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_uninit_vec_pair(
|
||||
fn handle_uninit_vec_pair<'tcx>(
|
||||
cx: &LateContext<'tcx>,
|
||||
maybe_init_or_reserve: &'tcx Stmt<'tcx>,
|
||||
maybe_set_len: &'tcx Expr<'tcx>,
|
||||
@ -196,7 +196,7 @@ fn is_reserve(cx: &LateContext<'_>, path: &PathSegment<'_>, self_expr: &Expr<'_>
|
||||
}
|
||||
|
||||
/// Returns self if the expression is `Vec::set_len()`
|
||||
fn extract_set_len_self(cx: &LateContext<'_>, expr: &'tcx Expr<'_>) -> Option<(&'tcx Expr<'tcx>, Span)> {
|
||||
fn extract_set_len_self<'tcx>(cx: &LateContext<'_>, expr: &'tcx Expr<'_>) -> Option<(&'tcx Expr<'tcx>, Span)> {
|
||||
// peel unsafe blocks in `unsafe { vec.set_len() }`
|
||||
let expr = peel_hir_expr_while(expr, |e| {
|
||||
if let ExprKind::Block(block, _) = e.kind {
|
||||
|
@ -46,7 +46,7 @@ declare_clippy_lint! {
|
||||
}
|
||||
declare_lint_pass!(UnitHash => [UNIT_HASH]);
|
||||
|
||||
impl LateLintPass<'tcx> for UnitHash {
|
||||
impl<'tcx> LateLintPass<'tcx> for UnitHash {
|
||||
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) {
|
||||
if_chain! {
|
||||
if let ExprKind::MethodCall(name_ident, _, args, _) = &expr.kind;
|
||||
|
@ -577,7 +577,7 @@ fn get_lint_version(cx: &LateContext<'_>, item: &Item<'_>) -> String {
|
||||
fn get_lint_group_and_level_or_lint(
|
||||
cx: &LateContext<'_>,
|
||||
lint_name: &str,
|
||||
item: &'hir Item<'_>,
|
||||
item: &Item<'_>,
|
||||
) -> Option<(String, &'static str)> {
|
||||
let result = cx
|
||||
.lint_store
|
||||
@ -696,20 +696,20 @@ fn extract_emission_info<'hir>(
|
||||
}
|
||||
|
||||
/// Resolves the possible lints that this expression could reference
|
||||
fn resolve_lints(cx: &LateContext<'hir>, expr: &'hir hir::Expr<'hir>) -> Vec<String> {
|
||||
fn resolve_lints<'hir>(cx: &LateContext<'hir>, expr: &'hir hir::Expr<'hir>) -> Vec<String> {
|
||||
let mut resolver = LintResolver::new(cx);
|
||||
resolver.visit_expr(expr);
|
||||
resolver.lints
|
||||
}
|
||||
|
||||
/// This function tries to resolve the linked applicability to the given expression.
|
||||
fn resolve_applicability(cx: &LateContext<'hir>, expr: &'hir hir::Expr<'hir>) -> Option<usize> {
|
||||
fn resolve_applicability<'hir>(cx: &LateContext<'hir>, expr: &'hir hir::Expr<'hir>) -> Option<usize> {
|
||||
let mut resolver = ApplicabilityResolver::new(cx);
|
||||
resolver.visit_expr(expr);
|
||||
resolver.complete()
|
||||
}
|
||||
|
||||
fn check_is_multi_part(cx: &LateContext<'hir>, closure_expr: &'hir hir::Expr<'hir>) -> bool {
|
||||
fn check_is_multi_part<'hir>(cx: &LateContext<'hir>, closure_expr: &'hir hir::Expr<'hir>) -> bool {
|
||||
if let ExprKind::Closure(_, _, body_id, _, _) = closure_expr.kind {
|
||||
let mut scanner = IsMultiSpanScanner::new(cx);
|
||||
intravisit::walk_body(&mut scanner, cx.tcx.hir().body(body_id));
|
||||
@ -824,7 +824,7 @@ impl<'a, 'hir> intravisit::Visitor<'hir> for ApplicabilityResolver<'a, 'hir> {
|
||||
}
|
||||
|
||||
/// This returns the parent local node if the expression is a reference one
|
||||
fn get_parent_local(cx: &LateContext<'hir>, expr: &'hir hir::Expr<'hir>) -> Option<&'hir hir::Local<'hir>> {
|
||||
fn get_parent_local<'hir>(cx: &LateContext<'hir>, expr: &'hir hir::Expr<'hir>) -> Option<&'hir hir::Local<'hir>> {
|
||||
if let ExprKind::Path(QPath::Resolved(_, path)) = expr.kind {
|
||||
if let hir::def::Res::Local(local_hir) = path.res {
|
||||
return get_parent_local_hir_id(cx, local_hir);
|
||||
@ -834,7 +834,7 @@ fn get_parent_local(cx: &LateContext<'hir>, expr: &'hir hir::Expr<'hir>) -> Opti
|
||||
None
|
||||
}
|
||||
|
||||
fn get_parent_local_hir_id(cx: &LateContext<'hir>, hir_id: hir::HirId) -> Option<&'hir hir::Local<'hir>> {
|
||||
fn get_parent_local_hir_id<'hir>(cx: &LateContext<'hir>, hir_id: hir::HirId) -> Option<&'hir hir::Local<'hir>> {
|
||||
let map = cx.tcx.hir();
|
||||
|
||||
match map.find(map.get_parent_node(hir_id)) {
|
||||
|
@ -77,7 +77,7 @@ impl VecPushSearcher {
|
||||
}
|
||||
}
|
||||
|
||||
impl LateLintPass<'_> for VecInitThenPush {
|
||||
impl<'tcx> LateLintPass<'tcx> for VecInitThenPush {
|
||||
fn check_block(&mut self, _: &LateContext<'tcx>, _: &'tcx Block<'tcx>) {
|
||||
self.searcher = None;
|
||||
}
|
||||
|
@ -223,7 +223,7 @@ pub fn constant_simple<'tcx>(
|
||||
constant(lcx, typeck_results, e).and_then(|(cst, res)| if res { None } else { Some(cst) })
|
||||
}
|
||||
|
||||
pub fn constant_full_int(
|
||||
pub fn constant_full_int<'tcx>(
|
||||
lcx: &LateContext<'tcx>,
|
||||
typeck_results: &ty::TypeckResults<'tcx>,
|
||||
e: &Expr<'_>,
|
||||
|
@ -45,7 +45,12 @@ impl ops::BitOrAssign for EagernessSuggestion {
|
||||
}
|
||||
|
||||
/// Determine the eagerness of the given function call.
|
||||
fn fn_eagerness(cx: &LateContext<'tcx>, fn_id: DefId, name: Symbol, args: &'tcx [Expr<'_>]) -> EagernessSuggestion {
|
||||
fn fn_eagerness<'tcx>(
|
||||
cx: &LateContext<'tcx>,
|
||||
fn_id: DefId,
|
||||
name: Symbol,
|
||||
args: &'tcx [Expr<'_>],
|
||||
) -> EagernessSuggestion {
|
||||
use EagernessSuggestion::{Eager, Lazy, NoChange};
|
||||
let name = name.as_str();
|
||||
|
||||
@ -92,7 +97,7 @@ fn fn_eagerness(cx: &LateContext<'tcx>, fn_id: DefId, name: Symbol, args: &'tcx
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_lines)]
|
||||
fn expr_eagerness(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> EagernessSuggestion {
|
||||
fn expr_eagerness<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> EagernessSuggestion {
|
||||
struct V<'cx, 'tcx> {
|
||||
cx: &'cx LateContext<'tcx>,
|
||||
eagerness: EagernessSuggestion,
|
||||
@ -225,11 +230,11 @@ fn expr_eagerness(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> EagernessSuggest
|
||||
}
|
||||
|
||||
/// Whether the given expression should be changed to evaluate eagerly
|
||||
pub fn switch_to_eager_eval(cx: &'_ LateContext<'tcx>, expr: &'tcx Expr<'_>) -> bool {
|
||||
pub fn switch_to_eager_eval<'tcx>(cx: &'_ LateContext<'tcx>, expr: &'tcx Expr<'_>) -> bool {
|
||||
expr_eagerness(cx, expr) == EagernessSuggestion::Eager
|
||||
}
|
||||
|
||||
/// Whether the given expression should be changed to evaluate lazily
|
||||
pub fn switch_to_lazy_eval(cx: &'_ LateContext<'tcx>, expr: &'tcx Expr<'_>) -> bool {
|
||||
pub fn switch_to_lazy_eval<'tcx>(cx: &'_ LateContext<'tcx>, expr: &'tcx Expr<'_>) -> bool {
|
||||
expr_eagerness(cx, expr) == EagernessSuggestion::Lazy
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
#![feature(box_patterns)]
|
||||
#![feature(control_flow_enum)]
|
||||
#![feature(in_band_lifetimes)]
|
||||
#![feature(let_else)]
|
||||
#![feature(once_cell)]
|
||||
#![feature(rustc_private)]
|
||||
@ -128,7 +127,7 @@ macro_rules! extract_msrv_attr {
|
||||
extract_msrv_attr!(@EarlyContext);
|
||||
};
|
||||
(@$context:ident$(, $call:tt)?) => {
|
||||
fn enter_lint_attrs(&mut self, cx: &rustc_lint::$context<'tcx>, attrs: &'tcx [rustc_ast::ast::Attribute]) {
|
||||
fn enter_lint_attrs(&mut self, cx: &rustc_lint::$context<'_>, attrs: &[rustc_ast::ast::Attribute]) {
|
||||
use $crate::get_unique_inner_attr;
|
||||
match get_unique_inner_attr(cx.sess$($call)?, attrs, "msrv") {
|
||||
Some(msrv_attr) => {
|
||||
@ -277,7 +276,11 @@ pub fn is_wild(pat: &Pat<'_>) -> bool {
|
||||
}
|
||||
|
||||
/// Checks if the first type parameter is a lang item.
|
||||
pub fn is_ty_param_lang_item(cx: &LateContext<'_>, qpath: &QPath<'tcx>, item: LangItem) -> Option<&'tcx hir::Ty<'tcx>> {
|
||||
pub fn is_ty_param_lang_item<'tcx>(
|
||||
cx: &LateContext<'_>,
|
||||
qpath: &QPath<'tcx>,
|
||||
item: LangItem,
|
||||
) -> Option<&'tcx hir::Ty<'tcx>> {
|
||||
let ty = get_qpath_generic_tys(qpath).next()?;
|
||||
|
||||
if let TyKind::Path(qpath) = &ty.kind {
|
||||
@ -293,7 +296,7 @@ pub fn is_ty_param_lang_item(cx: &LateContext<'_>, qpath: &QPath<'tcx>, item: La
|
||||
}
|
||||
|
||||
/// Checks if the first type parameter is a diagnostic item.
|
||||
pub fn is_ty_param_diagnostic_item(
|
||||
pub fn is_ty_param_diagnostic_item<'tcx>(
|
||||
cx: &LateContext<'_>,
|
||||
qpath: &QPath<'tcx>,
|
||||
item: Symbol,
|
||||
@ -370,7 +373,7 @@ pub fn last_path_segment<'tcx>(path: &QPath<'tcx>) -> &'tcx PathSegment<'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_qpath_generics(path: &QPath<'tcx>) -> Option<&'tcx GenericArgs<'tcx>> {
|
||||
pub fn get_qpath_generics<'tcx>(path: &QPath<'tcx>) -> Option<&'tcx GenericArgs<'tcx>> {
|
||||
match path {
|
||||
QPath::Resolved(_, p) => p.segments.last().and_then(|s| s.args),
|
||||
QPath::TypeRelative(_, s) => s.args,
|
||||
@ -378,7 +381,7 @@ pub fn get_qpath_generics(path: &QPath<'tcx>) -> Option<&'tcx GenericArgs<'tcx>>
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_qpath_generic_tys(path: &QPath<'tcx>) -> impl Iterator<Item = &'tcx hir::Ty<'tcx>> {
|
||||
pub fn get_qpath_generic_tys<'tcx>(path: &QPath<'tcx>) -> impl Iterator<Item = &'tcx hir::Ty<'tcx>> {
|
||||
get_qpath_generics(path)
|
||||
.map_or([].as_ref(), |a| a.args)
|
||||
.iter()
|
||||
@ -767,7 +770,7 @@ pub fn is_default_equivalent(cx: &LateContext<'_>, e: &Expr<'_>) -> bool {
|
||||
///
|
||||
/// Note that this check is not recursive, so passing the `if` expression will always return true
|
||||
/// even though sub-expressions might return false.
|
||||
pub fn can_move_expr_to_closure_no_visit(
|
||||
pub fn can_move_expr_to_closure_no_visit<'tcx>(
|
||||
cx: &LateContext<'tcx>,
|
||||
expr: &'tcx Expr<'_>,
|
||||
loop_ids: &[HirId],
|
||||
@ -842,7 +845,7 @@ impl std::ops::BitOrAssign for CaptureKind {
|
||||
/// Note as this will walk up to parent expressions until the capture can be determined it should
|
||||
/// only be used while making a closure somewhere a value is consumed. e.g. a block, match arm, or
|
||||
/// function argument (other than a receiver).
|
||||
pub fn capture_local_usage(cx: &LateContext<'tcx>, e: &Expr<'_>) -> CaptureKind {
|
||||
pub fn capture_local_usage<'tcx>(cx: &LateContext<'tcx>, e: &Expr<'_>) -> CaptureKind {
|
||||
fn pat_capture_kind(cx: &LateContext<'_>, pat: &Pat<'_>) -> CaptureKind {
|
||||
let mut capture = CaptureKind::Ref(Mutability::Not);
|
||||
pat.each_binding_or_first(&mut |_, id, span, _| match cx
|
||||
@ -942,7 +945,7 @@ pub fn capture_local_usage(cx: &LateContext<'tcx>, e: &Expr<'_>) -> CaptureKind
|
||||
|
||||
/// Checks if the expression can be moved into a closure as is. This will return a list of captures
|
||||
/// if so, otherwise, `None`.
|
||||
pub fn can_move_expr_to_closure(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Option<HirIdMap<CaptureKind>> {
|
||||
pub fn can_move_expr_to_closure<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Option<HirIdMap<CaptureKind>> {
|
||||
struct V<'cx, 'tcx> {
|
||||
cx: &'cx LateContext<'tcx>,
|
||||
// Stack of potential break targets contained in the expression.
|
||||
@ -955,7 +958,7 @@ pub fn can_move_expr_to_closure(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) ->
|
||||
/// mutable reference.
|
||||
captures: HirIdMap<CaptureKind>,
|
||||
}
|
||||
impl Visitor<'tcx> for V<'_, 'tcx> {
|
||||
impl<'tcx> Visitor<'tcx> for V<'_, 'tcx> {
|
||||
type Map = ErasedMap<'tcx>;
|
||||
fn nested_visit_map(&mut self) -> NestedVisitorMap<Self::Map> {
|
||||
NestedVisitorMap::None
|
||||
@ -1212,7 +1215,7 @@ pub fn get_enclosing_block<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId) -> Optio
|
||||
}
|
||||
|
||||
/// Gets the loop or closure enclosing the given expression, if any.
|
||||
pub fn get_enclosing_loop_or_closure(tcx: TyCtxt<'tcx>, expr: &Expr<'_>) -> Option<&'tcx Expr<'tcx>> {
|
||||
pub fn get_enclosing_loop_or_closure<'tcx>(tcx: TyCtxt<'tcx>, expr: &Expr<'_>) -> Option<&'tcx Expr<'tcx>> {
|
||||
for (_, node) in tcx.hir().parent_iter(expr.hir_id) {
|
||||
match node {
|
||||
Node::Expr(
|
||||
@ -1720,7 +1723,7 @@ pub fn is_async_fn(kind: FnKind<'_>) -> bool {
|
||||
}
|
||||
|
||||
/// Peels away all the compiler generated code surrounding the body of an async function,
|
||||
pub fn get_async_fn_body(tcx: TyCtxt<'tcx>, body: &Body<'_>) -> Option<&'tcx Expr<'tcx>> {
|
||||
pub fn get_async_fn_body<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'_>) -> Option<&'tcx Expr<'tcx>> {
|
||||
if let ExprKind::Call(
|
||||
_,
|
||||
&[
|
||||
@ -1824,7 +1827,7 @@ pub fn is_expr_identity_function(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool
|
||||
}
|
||||
|
||||
/// Gets the node where an expression is either used, or it's type is unified with another branch.
|
||||
pub fn get_expr_use_or_unification_node(tcx: TyCtxt<'tcx>, expr: &Expr<'_>) -> Option<Node<'tcx>> {
|
||||
pub fn get_expr_use_or_unification_node<'tcx>(tcx: TyCtxt<'tcx>, expr: &Expr<'_>) -> Option<Node<'tcx>> {
|
||||
let mut child_id = expr.hir_id;
|
||||
let mut iter = tcx.hir().parent_iter(child_id);
|
||||
loop {
|
||||
@ -2030,8 +2033,8 @@ where
|
||||
|
||||
/// Peels off all references on the pattern. Returns the underlying pattern and the number of
|
||||
/// references removed.
|
||||
pub fn peel_hir_pat_refs(pat: &'a Pat<'a>) -> (&'a Pat<'a>, usize) {
|
||||
fn peel(pat: &'a Pat<'a>, count: usize) -> (&'a Pat<'a>, usize) {
|
||||
pub fn peel_hir_pat_refs<'a>(pat: &'a Pat<'a>) -> (&'a Pat<'a>, usize) {
|
||||
fn peel<'a>(pat: &'a Pat<'a>, count: usize) -> (&'a Pat<'a>, usize) {
|
||||
if let PatKind::Ref(pat, _) = pat.kind {
|
||||
peel(pat, count + 1)
|
||||
} else {
|
||||
@ -2054,7 +2057,7 @@ pub fn peel_hir_expr_while<'tcx>(
|
||||
|
||||
/// Peels off up to the given number of references on the expression. Returns the underlying
|
||||
/// expression and the number of references removed.
|
||||
pub fn peel_n_hir_expr_refs(expr: &'a Expr<'a>, count: usize) -> (&'a Expr<'a>, usize) {
|
||||
pub fn peel_n_hir_expr_refs<'a>(expr: &'a Expr<'a>, count: usize) -> (&'a Expr<'a>, usize) {
|
||||
let mut remaining = count;
|
||||
let e = peel_hir_expr_while(expr, |e| match e.kind {
|
||||
ExprKind::AddrOf(ast::BorrowKind::Ref, _, e) if remaining != 0 => {
|
||||
@ -2068,7 +2071,7 @@ pub fn peel_n_hir_expr_refs(expr: &'a Expr<'a>, count: usize) -> (&'a Expr<'a>,
|
||||
|
||||
/// Peels off all references on the expression. Returns the underlying expression and the number of
|
||||
/// references removed.
|
||||
pub fn peel_hir_expr_refs(expr: &'a Expr<'a>) -> (&'a Expr<'a>, usize) {
|
||||
pub fn peel_hir_expr_refs<'a>(expr: &'a Expr<'a>) -> (&'a Expr<'a>, usize) {
|
||||
let mut count = 0;
|
||||
let e = peel_hir_expr_while(expr, |e| match e.kind {
|
||||
ExprKind::AddrOf(ast::BorrowKind::Ref, _, e) => {
|
||||
@ -2151,7 +2154,7 @@ impl<'hir> ItemLikeVisitor<'hir> for TestItemNamesVisitor<'hir> {
|
||||
|
||||
static TEST_ITEM_NAMES_CACHE: SyncOnceCell<Mutex<FxHashMap<LocalDefId, Vec<Symbol>>>> = SyncOnceCell::new();
|
||||
|
||||
fn with_test_item_names(tcx: TyCtxt<'tcx>, module: LocalDefId, f: impl Fn(&[Symbol]) -> bool) -> bool {
|
||||
fn with_test_item_names<'tcx>(tcx: TyCtxt<'tcx>, module: LocalDefId, f: impl Fn(&[Symbol]) -> bool) -> bool {
|
||||
let cache = TEST_ITEM_NAMES_CACHE.get_or_init(|| Mutex::new(FxHashMap::default()));
|
||||
let mut map: MutexGuard<'_, FxHashMap<LocalDefId, Vec<Symbol>>> = cache.lock().unwrap();
|
||||
match map.entry(module) {
|
||||
|
@ -283,7 +283,7 @@ fn find_assert_within_debug_assert<'a>(
|
||||
found
|
||||
}
|
||||
|
||||
fn is_assert_arg(cx: &LateContext<'_>, expr: &'a Expr<'a>, assert_expn: ExpnId) -> bool {
|
||||
fn is_assert_arg(cx: &LateContext<'_>, expr: &Expr<'_>, assert_expn: ExpnId) -> bool {
|
||||
if !expr.span.from_expansion() {
|
||||
return true;
|
||||
}
|
||||
@ -322,7 +322,7 @@ pub struct FormatArgsExpn<'tcx> {
|
||||
pub specs: Vec<&'tcx Expr<'tcx>>,
|
||||
}
|
||||
|
||||
impl FormatArgsExpn<'tcx> {
|
||||
impl<'tcx> FormatArgsExpn<'tcx> {
|
||||
/// Parses an expanded `format_args!` or `format_args_nl!` invocation
|
||||
pub fn parse(cx: &LateContext<'_>, expr: &'tcx Expr<'tcx>) -> Option<Self> {
|
||||
macro_backtrace(expr.span).find(|macro_call| {
|
||||
|
@ -19,7 +19,7 @@ use std::borrow::Cow;
|
||||
|
||||
type McfResult = Result<(), (Span, Cow<'static, str>)>;
|
||||
|
||||
pub fn is_min_const_fn(tcx: TyCtxt<'tcx>, body: &'a Body<'tcx>, msrv: Option<&RustcVersion>) -> McfResult {
|
||||
pub fn is_min_const_fn<'a, 'tcx>(tcx: TyCtxt<'tcx>, body: &'a Body<'tcx>, msrv: Option<&RustcVersion>) -> McfResult {
|
||||
let def_id = body.source.def_id();
|
||||
let mut current = def_id;
|
||||
loop {
|
||||
@ -85,7 +85,7 @@ pub fn is_min_const_fn(tcx: TyCtxt<'tcx>, body: &'a Body<'tcx>, msrv: Option<&Ru
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn check_ty(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, span: Span) -> McfResult {
|
||||
fn check_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, span: Span) -> McfResult {
|
||||
for arg in ty.walk(tcx) {
|
||||
let ty = match arg.unpack() {
|
||||
GenericArgKind::Type(ty) => ty,
|
||||
@ -133,7 +133,13 @@ fn check_ty(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, span: Span) -> McfResult {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn check_rvalue(tcx: TyCtxt<'tcx>, body: &Body<'tcx>, def_id: DefId, rvalue: &Rvalue<'tcx>, span: Span) -> McfResult {
|
||||
fn check_rvalue<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
body: &Body<'tcx>,
|
||||
def_id: DefId,
|
||||
rvalue: &Rvalue<'tcx>,
|
||||
span: Span,
|
||||
) -> McfResult {
|
||||
match rvalue {
|
||||
Rvalue::ThreadLocalRef(_) => Err((span, "cannot access thread local storage in const fn".into())),
|
||||
Rvalue::Repeat(operand, _) | Rvalue::Use(operand) => check_operand(tcx, operand, span, body),
|
||||
@ -211,7 +217,12 @@ fn check_rvalue(tcx: TyCtxt<'tcx>, body: &Body<'tcx>, def_id: DefId, rvalue: &Rv
|
||||
}
|
||||
}
|
||||
|
||||
fn check_statement(tcx: TyCtxt<'tcx>, body: &Body<'tcx>, def_id: DefId, statement: &Statement<'tcx>) -> McfResult {
|
||||
fn check_statement<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
body: &Body<'tcx>,
|
||||
def_id: DefId,
|
||||
statement: &Statement<'tcx>,
|
||||
) -> McfResult {
|
||||
let span = statement.source_info.span;
|
||||
match &statement.kind {
|
||||
StatementKind::Assign(box (place, rval)) => {
|
||||
@ -240,7 +251,7 @@ fn check_statement(tcx: TyCtxt<'tcx>, body: &Body<'tcx>, def_id: DefId, statemen
|
||||
}
|
||||
}
|
||||
|
||||
fn check_operand(tcx: TyCtxt<'tcx>, operand: &Operand<'tcx>, span: Span, body: &Body<'tcx>) -> McfResult {
|
||||
fn check_operand<'tcx>(tcx: TyCtxt<'tcx>, operand: &Operand<'tcx>, span: Span, body: &Body<'tcx>) -> McfResult {
|
||||
match operand {
|
||||
Operand::Move(place) | Operand::Copy(place) => check_place(tcx, *place, span, body),
|
||||
Operand::Constant(c) => match c.check_static_ptr(tcx) {
|
||||
@ -250,7 +261,7 @@ fn check_operand(tcx: TyCtxt<'tcx>, operand: &Operand<'tcx>, span: Span, body: &
|
||||
}
|
||||
}
|
||||
|
||||
fn check_place(tcx: TyCtxt<'tcx>, place: Place<'tcx>, span: Span, body: &Body<'tcx>) -> McfResult {
|
||||
fn check_place<'tcx>(tcx: TyCtxt<'tcx>, place: Place<'tcx>, span: Span, body: &Body<'tcx>) -> McfResult {
|
||||
let mut cursor = place.projection.as_ref();
|
||||
while let [ref proj_base @ .., elem] = *cursor {
|
||||
cursor = proj_base;
|
||||
@ -275,7 +286,7 @@ fn check_place(tcx: TyCtxt<'tcx>, place: Place<'tcx>, span: Span, body: &Body<'t
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn check_terminator(
|
||||
fn check_terminator<'a, 'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
body: &'a Body<'tcx>,
|
||||
terminator: &Terminator<'tcx>,
|
||||
|
@ -281,7 +281,7 @@ pub fn snippet_block_with_applicability<'a, T: LintContext>(
|
||||
/// correctly get a snippet of `vec![]`.
|
||||
///
|
||||
/// This will also return whether or not the snippet is a macro call.
|
||||
pub fn snippet_with_context(
|
||||
pub fn snippet_with_context<'a>(
|
||||
cx: &LateContext<'_>,
|
||||
span: Span,
|
||||
outer: SyntaxContext,
|
||||
|
@ -461,7 +461,7 @@ impl Neg for Sugg<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
impl Not for Sugg<'a> {
|
||||
impl<'a> Not for Sugg<'a> {
|
||||
type Output = Sugg<'a>;
|
||||
fn not(self) -> Sugg<'a> {
|
||||
use AssocOp::{Equal, Greater, GreaterEqual, Less, LessEqual, NotEqual};
|
||||
@ -846,7 +846,7 @@ struct DerefDelegate<'a, 'tcx> {
|
||||
applicability: Applicability,
|
||||
}
|
||||
|
||||
impl DerefDelegate<'_, 'tcx> {
|
||||
impl<'tcx> DerefDelegate<'_, 'tcx> {
|
||||
/// build final suggestion:
|
||||
/// - create the ending part of suggestion
|
||||
/// - concatenate starting and ending parts
|
||||
|
@ -25,7 +25,7 @@ pub fn is_copy<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool {
|
||||
}
|
||||
|
||||
/// Checks whether a type can be partially moved.
|
||||
pub fn can_partially_move_ty(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool {
|
||||
pub fn can_partially_move_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool {
|
||||
if has_drop(cx, ty) || is_copy(cx, ty) {
|
||||
return false;
|
||||
}
|
||||
@ -366,7 +366,7 @@ pub fn walk_ptrs_ty_depth(ty: Ty<'_>) -> (Ty<'_>, usize) {
|
||||
|
||||
/// Returns `true` if types `a` and `b` are same types having same `Const` generic args,
|
||||
/// otherwise returns `false`
|
||||
pub fn same_type_and_consts(a: Ty<'tcx>, b: Ty<'tcx>) -> bool {
|
||||
pub fn same_type_and_consts<'tcx>(a: Ty<'tcx>, b: Ty<'tcx>) -> bool {
|
||||
match (&a.kind(), &b.kind()) {
|
||||
(&ty::Adt(did_a, substs_a), &ty::Adt(did_b, substs_b)) => {
|
||||
if did_a != did_b {
|
||||
|
@ -173,7 +173,7 @@ pub trait Visitable<'tcx> {
|
||||
}
|
||||
macro_rules! visitable_ref {
|
||||
($t:ident, $f:ident) => {
|
||||
impl Visitable<'tcx> for &'tcx $t<'tcx> {
|
||||
impl<'tcx> Visitable<'tcx> for &'tcx $t<'tcx> {
|
||||
fn visit<V: Visitor<'tcx>>(self, visitor: &mut V) {
|
||||
visitor.$f(self);
|
||||
}
|
||||
@ -217,7 +217,7 @@ pub fn is_res_used(cx: &LateContext<'_>, res: Res, body: BodyId) -> bool {
|
||||
}
|
||||
|
||||
/// Checks if the given local is used.
|
||||
pub fn is_local_used(cx: &LateContext<'tcx>, visitable: impl Visitable<'tcx>, id: HirId) -> bool {
|
||||
pub fn is_local_used<'tcx>(cx: &LateContext<'tcx>, visitable: impl Visitable<'tcx>, id: HirId) -> bool {
|
||||
let mut is_used = false;
|
||||
let mut visitor = expr_visitor(cx, |expr| {
|
||||
if !is_used {
|
||||
@ -231,7 +231,7 @@ pub fn is_local_used(cx: &LateContext<'tcx>, visitable: impl Visitable<'tcx>, id
|
||||
}
|
||||
|
||||
/// Checks if the given expression is a constant.
|
||||
pub fn is_const_evaluatable(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> bool {
|
||||
pub fn is_const_evaluatable<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> bool {
|
||||
struct V<'a, 'tcx> {
|
||||
cx: &'a LateContext<'tcx>,
|
||||
is_const: bool,
|
||||
@ -321,7 +321,7 @@ pub fn is_const_evaluatable(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> bool {
|
||||
}
|
||||
|
||||
/// Checks if the given expression performs an unsafe operation outside of an unsafe block.
|
||||
pub fn is_expr_unsafe(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> bool {
|
||||
pub fn is_expr_unsafe<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> bool {
|
||||
struct V<'a, 'tcx> {
|
||||
cx: &'a LateContext<'tcx>,
|
||||
is_unsafe: bool,
|
||||
|
@ -60,7 +60,7 @@ Two noticeable items here:
|
||||
Starting with an `expr`, you can check whether it is calling a specific method `some_method`:
|
||||
|
||||
```rust
|
||||
impl LateLintPass<'_> for MyStructLint {
|
||||
impl<'tcx> LateLintPass<'tcx> for MyStructLint {
|
||||
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) {
|
||||
if_chain! {
|
||||
// Check our expr is calling a method
|
||||
|
Loading…
x
Reference in New Issue
Block a user