File tree 3 files changed +57
-4
lines changed
compiler/rustc_middle/src/hir/map
tests/ui/async-await/async-fn
3 files changed +57
-4
lines changed Original file line number Diff line number Diff line change @@ -246,14 +246,22 @@ impl<'hir> Map<'hir> {
246
246
self . tcx . hir_node ( hir_id) . fn_sig ( )
247
247
}
248
248
249
- #[ track_caller]
250
- pub fn enclosing_body_owner ( self , hir_id : HirId ) -> LocalDefId {
249
+ pub fn opt_enclosing_body_owner ( self , hir_id : HirId ) -> Option < LocalDefId > {
251
250
for ( _, node) in self . parent_iter ( hir_id) {
252
251
if let Some ( ( def_id, _) ) = node. associated_body ( ) {
253
- return def_id;
252
+ return Some ( def_id) ;
254
253
}
255
254
}
256
255
256
+ None
257
+ }
258
+
259
+ #[ track_caller]
260
+ pub fn enclosing_body_owner ( self , hir_id : HirId ) -> LocalDefId {
261
+ if let Some ( hir_id) = self . opt_enclosing_body_owner ( hir_id) {
262
+ return hir_id;
263
+ }
264
+
257
265
bug ! ( "no `enclosing_body_owner` for hir_id `{}`" , hir_id) ;
258
266
}
259
267
@@ -554,7 +562,9 @@ impl<'hir> Map<'hir> {
554
562
/// }
555
563
/// ```
556
564
pub fn get_fn_id_for_return_block ( self , id : HirId ) -> Option < HirId > {
557
- let enclosing_body_owner = self . tcx . local_def_id_to_hir_id ( self . enclosing_body_owner ( id) ) ;
565
+ // Id may not have a owner if it's a fn itself
566
+ let enclosing_body_owner =
567
+ self . tcx . local_def_id_to_hir_id ( self . opt_enclosing_body_owner ( id) ?) ;
558
568
559
569
// Return `None` if the `id` expression is not the returned value of the enclosing body
560
570
let mut iter = [ id] . into_iter ( ) . chain ( self . parent_id_iter ( id) ) . peekable ( ) ;
Original file line number Diff line number Diff line change
1
+ //@ edition: 2021
2
+
3
+ async fn a ( ) {
4
+ //~^ ERROR `()` is not a future
5
+ //~| ERROR mismatched types
6
+ a ( ) //~ ERROR `()` is not a future
7
+ }
8
+
9
+ fn main ( ) { }
Original file line number Diff line number Diff line change
1
+ error[E0277]: `()` is not a future
2
+ --> $DIR/recurse-ice-129215.rs:6:5
3
+ |
4
+ LL | a()
5
+ | ^^^ `()` is not a future
6
+ |
7
+ = help: the trait `Future` is not implemented for `()`
8
+
9
+ error[E0277]: `()` is not a future
10
+ --> $DIR/recurse-ice-129215.rs:3:1
11
+ |
12
+ LL | async fn a() {
13
+ | ^^^^^^^^^^^^ `()` is not a future
14
+ |
15
+ = help: the trait `Future` is not implemented for `()`
16
+
17
+ error[E0308]: mismatched types
18
+ --> $DIR/recurse-ice-129215.rs:3:14
19
+ |
20
+ LL | async fn a() {
21
+ | ______________^
22
+ LL | |
23
+ LL | |
24
+ LL | | a()
25
+ LL | | }
26
+ | |_^ expected `()`, found `async` fn body
27
+ |
28
+ = note: expected unit type `()`
29
+ found `async` fn body `{async fn body of a()}`
30
+
31
+ error: aborting due to 3 previous errors
32
+
33
+ Some errors have detailed explanations: E0277, E0308.
34
+ For more information about an error, try `rustc --explain E0277`.
You can’t perform that action at this time.
0 commit comments