Skip to content

Commit e1b313a

Browse files
We are able to resolve methods even if they need subst
1 parent 8c60012 commit e1b313a

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

compiler/rustc_lint/src/noop_method_call.rs

-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use crate::context::LintContext;
2-
use crate::rustc_middle::ty::TypeVisitable;
32
use crate::LateContext;
43
use crate::LateLintPass;
54
use rustc_errors::fluent;
@@ -65,11 +64,6 @@ impl<'tcx> LateLintPass<'tcx> for NoopMethodCall {
6564
let substs = cx
6665
.tcx
6766
.normalize_erasing_regions(cx.param_env, cx.typeck_results().node_substs(expr.hir_id));
68-
if substs.needs_subst() {
69-
// We can't resolve on types that require monomorphization, so we don't handle them if
70-
// we need to perform substitution.
71-
return;
72-
}
7367
// Resolve the trait method instance.
7468
let Ok(Some(i)) = ty::Instance::resolve(cx.tcx, cx.param_env, did, substs) else {
7569
return

src/test/ui/lint/noop-method-call.rs

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ fn main() {
4646

4747
fn generic<T>(non_clone_type: &PlainType<T>) {
4848
non_clone_type.clone();
49+
//~^ WARNING call to `.clone()` on a reference in this situation does nothing
4950
}
5051

5152
fn non_generic(non_clone_type: &PlainType<u32>) {

src/test/ui/lint/noop-method-call.stderr

+10-2
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,20 @@ LL | let non_borrow_type_borrow: &PlainType<u32> = non_borrow_type.borrow();
2828
= note: the type `&PlainType<u32>` which `borrow` is being called on is the same as the type returned from `borrow`, so the method call does not do anything and can be removed
2929

3030
warning: call to `.clone()` on a reference in this situation does nothing
31-
--> $DIR/noop-method-call.rs:52:19
31+
--> $DIR/noop-method-call.rs:48:19
32+
|
33+
LL | non_clone_type.clone();
34+
| ^^^^^^^^ unnecessary method call
35+
|
36+
= note: the type `&PlainType<T>` which `clone` is being called on is the same as the type returned from `clone`, so the method call does not do anything and can be removed
37+
38+
warning: call to `.clone()` on a reference in this situation does nothing
39+
--> $DIR/noop-method-call.rs:53:19
3240
|
3341
LL | non_clone_type.clone();
3442
| ^^^^^^^^ unnecessary method call
3543
|
3644
= note: the type `&PlainType<u32>` which `clone` is being called on is the same as the type returned from `clone`, so the method call does not do anything and can be removed
3745

38-
warning: 4 warnings emitted
46+
warning: 5 warnings emitted
3947

0 commit comments

Comments
 (0)