about summary refs log tree commit diff
path: root/compiler
diff options
context:
space:
mode:
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_borrowck/src/region_infer/mod.rs18
1 files changed, 18 insertions, 0 deletions
diff --git a/compiler/rustc_borrowck/src/region_infer/mod.rs b/compiler/rustc_borrowck/src/region_infer/mod.rs
index d9120ff2457..0f0d3eaa293 100644
--- a/compiler/rustc_borrowck/src/region_infer/mod.rs
+++ b/compiler/rustc_borrowck/src/region_infer/mod.rs
@@ -2156,6 +2156,24 @@ impl<'tcx> RegionInferenceContext<'tcx> {
                 }
             }
 
+            // When in async fn, prefer errors that come from inside the closure.
+            if !categorized_path[i].from_closure {
+                let span = categorized_path.iter().find_map(|p| {
+                    if p.from_closure
+                        && p.category == categorized_path[i].category
+                        && categorized_path[i].cause.span.contains(p.cause.span)
+                    {
+                        Some(p.cause.span)
+                    } else {
+                        None
+                    }
+                });
+
+                if let Some(span) = span {
+                    categorized_path[i].cause.span = span;
+                }
+            }
+
             return categorized_path[i].clone();
         }