]> git.lizzy.rs Git - rust.git/commitdiff
Skip suggestions for the AsRef trait
authorYuval Dolev <yuvaldolev2@gmail.com>
Wed, 27 Oct 2021 21:05:38 +0000 (00:05 +0300)
committerYuval Dolev <yuvaldolev2@gmail.com>
Fri, 29 Oct 2021 12:49:55 +0000 (15:49 +0300)
compiler/rustc_typeck/src/check/method/suggest.rs
src/test/ui/typeck/issue-89806.rs [new file with mode: 0644]
src/test/ui/typeck/issue-89806.stderr [new file with mode: 0644]

index 28b19981c2d40766f4442dbed32fca63481e827d..934b83bd700e1f5daabb61c5aee84b54e54a5610 100644 (file)
@@ -1251,6 +1251,7 @@ fn suggest_traits_to_import(
                 self.tcx.lang_items().deref_trait(),
                 self.tcx.lang_items().deref_mut_trait(),
                 self.tcx.lang_items().drop_trait(),
+                self.tcx.get_diagnostic_item(sym::AsRef),
             ];
             // Try alternative arbitrary self types that could fulfill this call.
             // FIXME: probe for all types that *could* be arbitrary self-types, not
diff --git a/src/test/ui/typeck/issue-89806.rs b/src/test/ui/typeck/issue-89806.rs
new file mode 100644 (file)
index 0000000..69cec08
--- /dev/null
@@ -0,0 +1,3 @@
+fn main() {
+    0u8.as_ref(); //~ ERROR no method named `as_ref` found for type `u8` in the current scope
+}
diff --git a/src/test/ui/typeck/issue-89806.stderr b/src/test/ui/typeck/issue-89806.stderr
new file mode 100644 (file)
index 0000000..9a54fac
--- /dev/null
@@ -0,0 +1,26 @@
+error[E0599]: no method named `as_ref` found for type `u8` in the current scope
+  --> $DIR/issue-89806.rs:2:9
+   |
+LL |     0u8.as_ref();
+   |         ^^^^^^ method not found in `u8`
+   |
+  ::: $SRC_DIR/core/src/pin.rs:LL:COL
+   |
+LL |     pub fn as_ref(&self) -> Pin<&P::Target> {
+   |            ------
+   |            |
+   |            the method is available for `Pin<&mut u8>` here
+   |            the method is available for `Pin<&u8>` here
+   |
+help: consider wrapping the receiver expression with the appropriate type
+   |
+LL |     Pin::new(&mut 0u8).as_ref();
+   |     +++++++++++++    +
+help: consider wrapping the receiver expression with the appropriate type
+   |
+LL |     Pin::new(&0u8).as_ref();
+   |     ++++++++++   +
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0599`.