about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJakob Degen <jakob@degen.com>2021-10-24 00:33:29 -0400
committerJakob Degen <jakob@degen.com>2021-10-24 00:33:29 -0400
commit4b970231fd1254580fbddabab74a125404fea0de (patch)
treee53c7ac3f15bc3d9c722482e850a972c6697fcc1
parent45591408b18e7f93fcf8c09210c9a5a102d84b37 (diff)
downloadrust-4b970231fd1254580fbddabab74a125404fea0de.tar.gz
rust-4b970231fd1254580fbddabab74a125404fea0de.zip
Fix ICE when forgetting to `Box` a parameter to a `Self::func` call
-rw-r--r--compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs2
-rw-r--r--src/test/ui/suggestions/issue-90213-expected-boxfuture-self-ice.rs13
-rw-r--r--src/test/ui/suggestions/issue-90213-expected-boxfuture-self-ice.stderr17
3 files changed, 31 insertions, 1 deletions
diff --git a/compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs b/compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs
index babc06822ac..dcc635a1f00 100644
--- a/compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs
+++ b/compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs
@@ -420,7 +420,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
                             ..
                         },
                         method,
-                    )) if Some(recv_ty.def_id()) == pin_did && method.ident.name == sym::new => {
+                    )) if recv_ty.opt_def_id() == pin_did && method.ident.name == sym::new => {
                         err.span_suggestion(
                             fn_name.span,
                             "use `Box::pin` to pin and box this expression",
diff --git a/src/test/ui/suggestions/issue-90213-expected-boxfuture-self-ice.rs b/src/test/ui/suggestions/issue-90213-expected-boxfuture-self-ice.rs
new file mode 100644
index 00000000000..1e36b2fabf2
--- /dev/null
+++ b/src/test/ui/suggestions/issue-90213-expected-boxfuture-self-ice.rs
@@ -0,0 +1,13 @@
+// Checks that we do not ICE when comparing `Self` to `Pin`
+// edition:2021
+
+struct S;
+
+impl S {
+    fn foo(_: Box<Option<S>>) {}
+    fn bar() {
+        Self::foo(None) //~ ERROR mismatched types
+    }
+}
+
+fn main() {}
diff --git a/src/test/ui/suggestions/issue-90213-expected-boxfuture-self-ice.stderr b/src/test/ui/suggestions/issue-90213-expected-boxfuture-self-ice.stderr
new file mode 100644
index 00000000000..c15b772b79c
--- /dev/null
+++ b/src/test/ui/suggestions/issue-90213-expected-boxfuture-self-ice.stderr
@@ -0,0 +1,17 @@
+error[E0308]: mismatched types
+  --> $DIR/issue-90213-expected-boxfuture-self-ice.rs:9:19
+   |
+LL |         Self::foo(None)
+   |                   ^^^^ expected struct `Box`, found enum `Option`
+   |
+   = note: expected struct `Box<Option<S>>`
+                found enum `Option<_>`
+   = note: for more on the distinction between the stack and the heap, read https://doc.rust-lang.org/book/ch15-01-box.html, https://doc.rust-lang.org/rust-by-example/std/box.html, and https://doc.rust-lang.org/std/boxed/index.html
+help: store this in the heap by calling `Box::new`
+   |
+LL |         Self::foo(Box::new(None))
+   |                   +++++++++    +
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0308`.