Skip to content

Commit e215149

Browse files
author
Yuval Dolev
committed
Skip suggestions for the AsRef trait
1 parent 37f70a0 commit e215149

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

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

+1
Original file line numberDiff line numberDiff line change
@@ -1251,6 +1251,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
12511251
self.tcx.lang_items().deref_trait(),
12521252
self.tcx.lang_items().deref_mut_trait(),
12531253
self.tcx.lang_items().drop_trait(),
1254+
self.tcx.get_diagnostic_item(sym::AsRef),
12541255
];
12551256
// Try alternative arbitrary self types that could fulfill this call.
12561257
// FIXME: probe for all types that *could* be arbitrary self-types, not

src/test/ui/typeck/issue-89806.rs

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
0u8.as_ref(); //~ ERROR no method named `as_ref` found for type `u8` in the current scope
3+
}

src/test/ui/typeck/issue-89806.stderr

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
error[E0599]: no method named `as_ref` found for type `u8` in the current scope
2+
--> $DIR/issue-89806.rs:2:9
3+
|
4+
LL | 0u8.as_ref();
5+
| ^^^^^^ 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+
| ++++++++++ +
23+
24+
error: aborting due to previous error
25+
26+
For more information about this error, try `rustc --explain E0599`.

0 commit comments

Comments
 (0)