Skip to content

Commit cad2d21

Browse files
author
Yuval Dolev
committed
Explicitly skipping suggestions for 'Pin' as it does not implement the 'AsRef' trait
1 parent e215149 commit cad2d21

File tree

2 files changed

+6
-19
lines changed

2 files changed

+6
-19
lines changed

Diff for: compiler/rustc_typeck/src/check/method/suggest.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use rustc_middle::ty::print::with_crate_prefix;
1515
use rustc_middle::ty::{self, ToPredicate, Ty, TyCtxt, TypeFoldable, WithConstness};
1616
use rustc_span::lev_distance;
1717
use rustc_span::symbol::{kw, sym, Ident};
18-
use rustc_span::{source_map, FileName, MultiSpan, Span};
18+
use rustc_span::{source_map, FileName, MultiSpan, Span, Symbol};
1919
use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt;
2020
use rustc_trait_selection::traits::{FulfillmentError, Obligation};
2121

@@ -1301,7 +1301,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
13011301
// We don't want to suggest a container type when the missing
13021302
// method is `.clone()` or `.deref()` otherwise we'd suggest
13031303
// `Arc::new(foo).clone()`, which is far from what the user wants.
1304-
let skip = skippable.contains(&did);
1304+
// Explicitly ignore the `Pin::as_ref()` method as `Pin` does not
1305+
// implement the `AsRef` trait.
1306+
let skip = skippable.contains(&did)
1307+
|| (("Pin::new" == *pre)
1308+
&& (Symbol::intern("as_ref") == item_name.name));
13051309
// Make sure the method is defined for the *actual* receiver: we don't
13061310
// want to treat `Box<Self>` as a receiver if it only works because of
13071311
// an autoderef to `&self`

Diff for: src/test/ui/typeck/issue-89806.stderr

-17
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,6 @@ error[E0599]: no method named `as_ref` found for type `u8` in the current scope
33
|
44
LL | 0u8.as_ref();
55
| ^^^^^^ method not found in `u8`
6-
|
7-
::: $SRC_DIR/core/src/pin.rs:LL:COL
8-
|
9-
LL | pub fn as_ref(&self) -> Pin<&P::Target> {
10-
| ------
11-
| |
12-
| the method is available for `Pin<&mut u8>` here
13-
| the method is available for `Pin<&u8>` here
14-
|
15-
help: consider wrapping the receiver expression with the appropriate type
16-
|
17-
LL | Pin::new(&mut 0u8).as_ref();
18-
| +++++++++++++ +
19-
help: consider wrapping the receiver expression with the appropriate type
20-
|
21-
LL | Pin::new(&0u8).as_ref();
22-
| ++++++++++ +
236

247
error: aborting due to previous error
258

0 commit comments

Comments
 (0)