Skip to content

Commit ef8abd5

Browse files
spastorinopietroalbini
authored andcommitted
fix RPIT ICE for implicit HRTB when missing dyn
1 parent c8b2529 commit ef8abd5

File tree

4 files changed

+44
-2
lines changed

4 files changed

+44
-2
lines changed

Diff for: compiler/rustc_ast_lowering/src/lib.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1577,8 +1577,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
15771577

15781578
LifetimeRes::Fresh { param, binder: _ } => {
15791579
debug_assert_eq!(lifetime.ident.name, kw::UnderscoreLifetime);
1580-
let old_def_id = self.local_def_id(param);
1581-
if remapping.get(&old_def_id).is_none() {
1580+
if let Some(old_def_id) = self.opt_local_def_id(param) && remapping.get(&old_def_id).is_none() {
15821581
let node_id = self.next_node_id();
15831582

15841583
let new_def_id = self.create_def(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0277]: the trait bound `(): AsRef<(dyn for<'r> Fn(&'r ()) + 'static)>` is not satisfied
2+
--> $DIR/generic-with-implicit-hrtb-without-dyn.rs:6:13
3+
|
4+
LL | fn ice() -> impl AsRef<Fn(&())> {
5+
| ^^^^^^^^^^^^^^^^^^^ the trait `AsRef<(dyn for<'r> Fn(&'r ()) + 'static)>` is not implemented for `()`
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0277`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
error[E0782]: trait objects must include the `dyn` keyword
2+
--> $DIR/generic-with-implicit-hrtb-without-dyn.rs:6:24
3+
|
4+
LL | fn ice() -> impl AsRef<Fn(&())> {
5+
| ^^^^^^^
6+
|
7+
help: add `dyn` keyword before this trait
8+
|
9+
LL - fn ice() -> impl AsRef<Fn(&())> {
10+
LL + fn ice() -> impl AsRef<dyn Fn(&())> {
11+
|
12+
13+
error[E0277]: the trait bound `(): AsRef<(dyn for<'r> Fn(&'r ()) + 'static)>` is not satisfied
14+
--> $DIR/generic-with-implicit-hrtb-without-dyn.rs:6:13
15+
|
16+
LL | fn ice() -> impl AsRef<Fn(&())> {
17+
| ^^^^^^^^^^^^^^^^^^^ the trait `AsRef<(dyn for<'r> Fn(&'r ()) + 'static)>` is not implemented for `()`
18+
19+
error: aborting due to 2 previous errors
20+
21+
Some errors have detailed explanations: E0277, E0782.
22+
For more information about an error, try `rustc --explain E0277`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// revisions: edition2015 edition2021
2+
//[edition2021]edition:2021
3+
4+
#![allow(warnings)]
5+
6+
fn ice() -> impl AsRef<Fn(&())> {
7+
//~^ ERROR: the trait bound `(): AsRef<(dyn for<'r> Fn(&'r ()) + 'static)>` is not satisfied [E0277]
8+
//[edition2021]~| ERROR: trait objects must include the `dyn` keyword [E0782]
9+
todo!()
10+
}
11+
12+
fn main() {}

0 commit comments

Comments
 (0)