about summary refs log tree commit diff
diff options
context:
space:
mode:
authorTyler Mandry <tmandry@gmail.com>2019-10-06 11:41:57 -0700
committerGitHub <noreply@github.com>2019-10-06 11:41:57 -0700
commitc4bbc6dc3f0d800e138616d0f465c0a9f070418d (patch)
tree37132c4cabb99a54dded75ef38a0166c448407b8
parentc457b6fcbf2d5ea56cc4d2571dfd688b2eddc525 (diff)
parent1471f0bc1bc060922cf953250294e968b3e62c7f (diff)
downloadrust-c4bbc6dc3f0d800e138616d0f465c0a9f070418d.tar.gz
rust-c4bbc6dc3f0d800e138616d0f465c0a9f070418d.zip
Rollup merge of #65142 - matthewjasper:unshadow-anon-lifetimes, r=petrochenkov
Ensure that associated `async fn`s have unique fresh param names

Closes #64630
-rw-r--r--src/librustc/hir/lowering.rs2
-rw-r--r--src/test/ui/async-await/async-assoc-fn-anon-lifetimes.rs23
2 files changed, 24 insertions, 1 deletions
diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs
index 2238a56b29d..d773c454432 100644
--- a/src/librustc/hir/lowering.rs
+++ b/src/librustc/hir/lowering.rs
@@ -844,7 +844,7 @@ impl<'a> LoweringContext<'a> {
     /// header, we convert it to an in-band lifetime.
     fn collect_fresh_in_band_lifetime(&mut self, span: Span) -> ParamName {
         assert!(self.is_collecting_in_band_lifetimes);
-        let index = self.lifetimes_to_define.len();
+        let index = self.lifetimes_to_define.len() + self.in_scope_lifetimes.len();
         let hir_name = ParamName::Fresh(index);
         self.lifetimes_to_define.push((span, hir_name));
         hir_name
diff --git a/src/test/ui/async-await/async-assoc-fn-anon-lifetimes.rs b/src/test/ui/async-await/async-assoc-fn-anon-lifetimes.rs
new file mode 100644
index 00000000000..8e08b82b9d3
--- /dev/null
+++ b/src/test/ui/async-await/async-assoc-fn-anon-lifetimes.rs
@@ -0,0 +1,23 @@
+// check-pass
+// Check that the anonymous lifetimes used here aren't considered to shadow one
+// another. Note that `async fn` is different to `fn` here because the lifetimes
+// are numbered by HIR lowering, rather than lifetime resolution.
+
+// edition:2018
+
+struct A<'a, 'b>(&'a &'b i32);
+struct B<'a>(&'a i32);
+
+impl A<'_, '_> {
+    async fn assoc(x: &u32, y: B<'_>) {
+        async fn nested(x: &u32, y: A<'_, '_>) {}
+    }
+
+    async fn assoc2(x: &u32, y: A<'_, '_>) {
+        impl A<'_, '_> {
+            async fn nested_assoc(x: &u32, y: B<'_>) {}
+        }
+    }
+}
+
+fn main() {}