Skip to content

Commit c3b2291

Browse files
authored
Rollup merge of #98509 - rust-lang:notriddle/precise-pin-diag, r=compiler-errors
diagnostics: consider parameter count when suggesting smart pointers Fixes #96834
2 parents d774bc3 + 0ea59f3 commit c3b2291

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

compiler/rustc_typeck/src/check/method/suggest.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -994,6 +994,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
994994
span,
995995
rcvr_ty,
996996
item_name,
997+
args.map(|args| args.len()),
997998
source,
998999
out_of_scope_traits,
9991000
&unsatisfied_predicates,
@@ -1732,6 +1733,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
17321733
span: Span,
17331734
rcvr_ty: Ty<'tcx>,
17341735
item_name: Ident,
1736+
inputs_len: Option<usize>,
17351737
source: SelfSource<'tcx>,
17361738
valid_out_of_scope_traits: Vec<DefId>,
17371739
unsatisfied_predicates: &[(
@@ -1808,7 +1810,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
18081810
// Explicitly ignore the `Pin::as_ref()` method as `Pin` does not
18091811
// implement the `AsRef` trait.
18101812
let skip = skippable.contains(&did)
1811-
|| (("Pin::new" == *pre) && (sym::as_ref == item_name.name));
1813+
|| (("Pin::new" == *pre) && (sym::as_ref == item_name.name))
1814+
|| inputs_len.map_or(false, |inputs_len| pick.item.kind == ty::AssocKind::Fn && self.tcx.fn_sig(pick.item.def_id).skip_binder().inputs().len() != inputs_len);
18121815
// Make sure the method is defined for the *actual* receiver: we don't
18131816
// want to treat `Box<Self>` as a receiver if it only works because of
18141817
// an autoderef to `&self`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// https://github.com/rust-lang/rust/issues/96834
2+
//
3+
// This test case verifies that rustc does not make an unhelpful suggestion:
4+
//
5+
// help: consider wrapping the receiver expression with the appropriate type
6+
// |
7+
// 14 | Pin::new(&mut a).set(0, 3);
8+
// | +++++++++++++ +
9+
//
10+
// We can tell that it isn't helpful, because `Pin::set` takes two parameters (including
11+
// the receiver), but the function call on line 14 supplies three.
12+
fn main() {
13+
let mut a = [0u8; 1];
14+
a.set(0, 3); //~ERROR
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0599]: no method named `set` found for array `[u8; 1]` in the current scope
2+
--> $DIR/dont-suggest-pin-array-dot-set.rs:14:7
3+
|
4+
LL | a.set(0, 3);
5+
| ^^^ help: there is an associated function with a similar name: `get`
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0599`.

0 commit comments

Comments
 (0)