diff options
| author | Jason Newcomb <jsnewcomb@pm.me> | 2023-07-30 03:47:13 -0400 |
|---|---|---|
| committer | Jason Newcomb <jsnewcomb@pm.me> | 2023-07-30 03:47:42 -0400 |
| commit | 8277e7d15482f0f7a2b2517243814b3a302d50ef (patch) | |
| tree | e167d8655fc6b32ae11c3d028179b30b95d5306d | |
| parent | 4c2f460dccf78b9f94df0a235de6ea10b0d495d3 (diff) | |
| download | rust-8277e7d15482f0f7a2b2517243814b3a302d50ef.tar.gz rust-8277e7d15482f0f7a2b2517243814b3a302d50ef.zip | |
Don't pass extra generic arguments in `needless_borrow`
| -rw-r--r-- | clippy_lints/src/dereference.rs | 16 | ||||
| -rw-r--r-- | tests/ui/needless_borrow.fixed | 13 | ||||
| -rw-r--r-- | tests/ui/needless_borrow.rs | 13 |
3 files changed, 33 insertions, 9 deletions
diff --git a/clippy_lints/src/dereference.rs b/clippy_lints/src/dereference.rs index a5ec979ccd9..328a797d9e0 100644 --- a/clippy_lints/src/dereference.rs +++ b/clippy_lints/src/dereference.rs @@ -3,7 +3,7 @@ use clippy_utils::mir::{enclosing_mir, expr_local, local_assignments, used_exact use clippy_utils::msrvs::{self, Msrv}; use clippy_utils::source::{snippet_with_applicability, snippet_with_context}; use clippy_utils::sugg::has_enclosing_paren; -use clippy_utils::ty::{is_copy, peel_mid_ty_refs}; +use clippy_utils::ty::{implements_trait, is_copy, peel_mid_ty_refs}; use clippy_utils::{ expr_use_ctxt, get_parent_expr, get_parent_node, is_lint_allowed, path_to_local, DefinedTy, ExprUseNode, }; @@ -33,7 +33,6 @@ use rustc_middle::ty::{ use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::symbol::sym; use rustc_span::{Span, Symbol}; -use rustc_trait_selection::infer::InferCtxtExt as _; use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt as _; use rustc_trait_selection::traits::{Obligation, ObligationCause}; use std::collections::VecDeque; @@ -452,13 +451,12 @@ impl<'tcx> LateLintPass<'tcx> for Dereferencing<'tcx> { // Trait methods taking `self` arg_ty } && impl_ty.is_ref() - && cx.tcx.infer_ctxt().build() - .type_implements_trait( - trait_id, - [impl_ty.into()].into_iter().chain(args.iter().copied()), - cx.param_env, - ) - .must_apply_modulo_regions() + && implements_trait( + cx, + impl_ty, + trait_id, + &args[..cx.tcx.generics_of(trait_id).params.len() - 1], + ) { false } else { diff --git a/tests/ui/needless_borrow.fixed b/tests/ui/needless_borrow.fixed index 1dfbee150d7..e90669bb0df 100644 --- a/tests/ui/needless_borrow.fixed +++ b/tests/ui/needless_borrow.fixed @@ -504,3 +504,16 @@ mod issue_10535 { { } } + +mod issue_10253 { + struct S; + trait X { + fn f<T>(&self); + } + impl X for &S { + fn f<T>(&self) {} + } + fn f() { + (&S).f::<()>(); + } +} diff --git a/tests/ui/needless_borrow.rs b/tests/ui/needless_borrow.rs index 3c0d73f5f02..43b037c46b6 100644 --- a/tests/ui/needless_borrow.rs +++ b/tests/ui/needless_borrow.rs @@ -504,3 +504,16 @@ mod issue_10535 { { } } + +mod issue_10253 { + struct S; + trait X { + fn f<T>(&self); + } + impl X for &S { + fn f<T>(&self) {} + } + fn f() { + (&S).f::<()>(); + } +} |
