Skip to content

Commit 42c5024

Browse files
matthewjasperMark-Simulacrum
authored andcommitted
Ensure that associated async fns have unique fresh param names
1 parent cf05730 commit 42c5024

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/librustc/hir/lowering.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -873,7 +873,7 @@ impl<'a> LoweringContext<'a> {
873873
/// header, we convert it to an in-band lifetime.
874874
fn collect_fresh_in_band_lifetime(&mut self, span: Span) -> ParamName {
875875
assert!(self.is_collecting_in_band_lifetimes);
876-
let index = self.lifetimes_to_define.len();
876+
let index = self.lifetimes_to_define.len() + self.in_scope_lifetimes.len();
877877
let hir_name = ParamName::Fresh(index);
878878
self.lifetimes_to_define.push((span, hir_name));
879879
hir_name
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// check-pass
2+
// Check that the anonymous lifetimes used here aren't considered to shadow one
3+
// another. Note that `async fn` is different to `fn` here because the lifetimes
4+
// are numbered by HIR lowering, rather than lifetime resolution.
5+
6+
// edition:2018
7+
8+
struct A<'a, 'b>(&'a &'b i32);
9+
struct B<'a>(&'a i32);
10+
11+
impl A<'_, '_> {
12+
async fn assoc(x: &u32, y: B<'_>) {
13+
async fn nested(x: &u32, y: A<'_, '_>) {}
14+
}
15+
16+
async fn assoc2(x: &u32, y: A<'_, '_>) {
17+
impl A<'_, '_> {
18+
async fn nested_assoc(x: &u32, y: B<'_>) {}
19+
}
20+
}
21+
}
22+
23+
fn main() {}

0 commit comments

Comments
 (0)