Skip to content

Commit 4b97023

Browse files
committed
Fix ICE when forgetting to Box a parameter to a Self::func call
1 parent 4559140 commit 4b97023

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
420420
..
421421
},
422422
method,
423-
)) if Some(recv_ty.def_id()) == pin_did && method.ident.name == sym::new => {
423+
)) if recv_ty.opt_def_id() == pin_did && method.ident.name == sym::new => {
424424
err.span_suggestion(
425425
fn_name.span,
426426
"use `Box::pin` to pin and box this expression",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Checks that we do not ICE when comparing `Self` to `Pin`
2+
// edition:2021
3+
4+
struct S;
5+
6+
impl S {
7+
fn foo(_: Box<Option<S>>) {}
8+
fn bar() {
9+
Self::foo(None) //~ ERROR mismatched types
10+
}
11+
}
12+
13+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/issue-90213-expected-boxfuture-self-ice.rs:9:19
3+
|
4+
LL | Self::foo(None)
5+
| ^^^^ expected struct `Box`, found enum `Option`
6+
|
7+
= note: expected struct `Box<Option<S>>`
8+
found enum `Option<_>`
9+
= 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
10+
help: store this in the heap by calling `Box::new`
11+
|
12+
LL | Self::foo(Box::new(None))
13+
| +++++++++ +
14+
15+
error: aborting due to previous error
16+
17+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)