From 4b970231fd1254580fbddabab74a125404fea0de Mon Sep 17 00:00:00 2001 From: Jakob Degen Date: Sun, 24 Oct 2021 00:33:29 -0400 Subject: [PATCH] Fix ICE when forgetting to `Box` a parameter to a `Self::func` call --- .../src/check/fn_ctxt/suggestions.rs | 2 +- .../issue-90213-expected-boxfuture-self-ice.rs | 13 +++++++++++++ ...sue-90213-expected-boxfuture-self-ice.stderr | 17 +++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 src/test/ui/suggestions/issue-90213-expected-boxfuture-self-ice.rs create mode 100644 src/test/ui/suggestions/issue-90213-expected-boxfuture-self-ice.stderr diff --git a/compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs b/compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs index babc06822ac52..dcc635a1f00b1 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 0000000000000..1e36b2fabf2c0 --- /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>) {} + 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 0000000000000..c15b772b79ca4 --- /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>` + 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`.