Skip to content

Commit f13e1f4

Browse files
committed
Auto merge of rust-lang#11259 - Jarcho:ice_10253, r=dswij
Don't pass extra generic arguments in `needless_borrow` fixes rust-lang#10253 Also switches to using `implements_trait` which does ICE when clippy's debug assertions are enabled. changelog: None
2 parents 60a18b7 + 8277e7d commit f13e1f4

File tree

3 files changed

+33
-9
lines changed

3 files changed

+33
-9
lines changed

clippy_lints/src/dereference.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use clippy_utils::mir::{enclosing_mir, expr_local, local_assignments, used_exact
33
use clippy_utils::msrvs::{self, Msrv};
44
use clippy_utils::source::{snippet_with_applicability, snippet_with_context};
55
use clippy_utils::sugg::has_enclosing_paren;
6-
use clippy_utils::ty::{is_copy, peel_mid_ty_refs};
6+
use clippy_utils::ty::{implements_trait, is_copy, peel_mid_ty_refs};
77
use clippy_utils::{
88
expr_use_ctxt, get_parent_expr, get_parent_node, is_lint_allowed, path_to_local, DefinedTy, ExprUseNode,
99
};
@@ -33,7 +33,6 @@ use rustc_middle::ty::{
3333
use rustc_session::{declare_tool_lint, impl_lint_pass};
3434
use rustc_span::symbol::sym;
3535
use rustc_span::{Span, Symbol};
36-
use rustc_trait_selection::infer::InferCtxtExt as _;
3736
use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt as _;
3837
use rustc_trait_selection::traits::{Obligation, ObligationCause};
3938
use std::collections::VecDeque;
@@ -452,13 +451,12 @@ impl<'tcx> LateLintPass<'tcx> for Dereferencing<'tcx> {
452451
// Trait methods taking `self`
453452
arg_ty
454453
} && impl_ty.is_ref()
455-
&& cx.tcx.infer_ctxt().build()
456-
.type_implements_trait(
457-
trait_id,
458-
[impl_ty.into()].into_iter().chain(args.iter().copied()),
459-
cx.param_env,
460-
)
461-
.must_apply_modulo_regions()
454+
&& implements_trait(
455+
cx,
456+
impl_ty,
457+
trait_id,
458+
&args[..cx.tcx.generics_of(trait_id).params.len() - 1],
459+
)
462460
{
463461
false
464462
} else {

tests/ui/needless_borrow.fixed

+13
Original file line numberDiff line numberDiff line change
@@ -503,3 +503,16 @@ mod issue_10535 {
503503
{
504504
}
505505
}
506+
507+
mod issue_10253 {
508+
struct S;
509+
trait X {
510+
fn f<T>(&self);
511+
}
512+
impl X for &S {
513+
fn f<T>(&self) {}
514+
}
515+
fn f() {
516+
(&S).f::<()>();
517+
}
518+
}

tests/ui/needless_borrow.rs

+13
Original file line numberDiff line numberDiff line change
@@ -503,3 +503,16 @@ mod issue_10535 {
503503
{
504504
}
505505
}
506+
507+
mod issue_10253 {
508+
struct S;
509+
trait X {
510+
fn f<T>(&self);
511+
}
512+
impl X for &S {
513+
fn f<T>(&self) {}
514+
}
515+
fn f() {
516+
(&S).f::<()>();
517+
}
518+
}

0 commit comments

Comments
 (0)