Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion compiler/rustc_typeck/src/check/method/suggest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -994,6 +994,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
span,
rcvr_ty,
item_name,
args.map(|args| args.len()),
source,
out_of_scope_traits,
&unsatisfied_predicates,
Expand Down Expand Up @@ -1732,6 +1733,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
span: Span,
rcvr_ty: Ty<'tcx>,
item_name: Ident,
inputs_len: Option<usize>,
source: SelfSource<'tcx>,
valid_out_of_scope_traits: Vec<DefId>,
unsatisfied_predicates: &[(
Expand Down Expand Up @@ -1808,7 +1810,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// Explicitly ignore the `Pin::as_ref()` method as `Pin` does not
// implement the `AsRef` trait.
let skip = skippable.contains(&did)
|| (("Pin::new" == *pre) && (sym::as_ref == item_name.name));
|| (("Pin::new" == *pre) && (sym::as_ref == item_name.name))
|| 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);
// Make sure the method is defined for the *actual* receiver: we don't
// want to treat `Box<Self>` as a receiver if it only works because of
// an autoderef to `&self`
Expand Down
15 changes: 15 additions & 0 deletions src/test/ui/suggestions/dont-suggest-pin-array-dot-set.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// https://github.com/rust-lang/rust/issues/96834
//
// This test case verifies that rustc does not make an unhelpful suggestion:
//
// help: consider wrapping the receiver expression with the appropriate type
// |
// 14 | Pin::new(&mut a).set(0, 3);
// | +++++++++++++ +
//
// We can tell that it isn't helpful, because `Pin::set` takes two parameters (including
// the receiver), but the function call on line 14 supplies three.
fn main() {
let mut a = [0u8; 1];
a.set(0, 3); //~ERROR
}
9 changes: 9 additions & 0 deletions src/test/ui/suggestions/dont-suggest-pin-array-dot-set.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
error[E0599]: no method named `set` found for array `[u8; 1]` in the current scope
--> $DIR/dont-suggest-pin-array-dot-set.rs:14:7
|
LL | a.set(0, 3);
| ^^^ help: there is an associated function with a similar name: `get`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0599`.