Skip to content

Commit

Permalink
use ParamName to track in-scope lifetimes instead of Ident
Browse files Browse the repository at this point in the history
This allows us to record "fresh" lifetime names for cases like `impl
Foo<'_>`.
  • Loading branch information
nikomatsakis committed Aug 12, 2019
1 parent 60960a2 commit 18e5453
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
12 changes: 8 additions & 4 deletions src/librustc/hir/lowering.rs
Expand Up @@ -136,7 +136,7 @@ pub struct LoweringContext<'a> {
/// When `is_collectin_in_band_lifetimes` is true, each lifetime is checked
/// against this list to see if it is already in-scope, or if a definition
/// needs to be created for it.
in_scope_lifetimes: Vec<Ident>,
in_scope_lifetimes: Vec<ParamName>,

current_module: NodeId,

Expand Down Expand Up @@ -865,7 +865,7 @@ impl<'a> LoweringContext<'a> {
return;
}

if self.in_scope_lifetimes.contains(&ident.modern()) {
if self.in_scope_lifetimes.contains(&ParamName::Plain(ident.modern())) {
return;
}

Expand Down Expand Up @@ -899,7 +899,7 @@ impl<'a> LoweringContext<'a> {
{
let old_len = self.in_scope_lifetimes.len();
let lt_def_names = params.iter().filter_map(|param| match param.kind {
GenericParamKind::Lifetime { .. } => Some(param.ident.modern()),
GenericParamKind::Lifetime { .. } => Some(ParamName::Plain(param.ident.modern())),
_ => None,
});
self.in_scope_lifetimes.extend(lt_def_names);
Expand Down Expand Up @@ -2267,10 +2267,14 @@ impl<'a> LoweringContext<'a> {
let lifetime_params: Vec<(Span, ParamName)> =
this.in_scope_lifetimes
.iter().cloned()
.map(|ident| (ident.span, ParamName::Plain(ident)))
.map(|name| (name.ident().span, name))
.chain(this.lifetimes_to_define.iter().cloned())
.collect();

debug!("lower_async_fn_ret_ty: in_scope_lifetimes={:#?}", this.in_scope_lifetimes);
debug!("lower_async_fn_ret_ty: lifetimes_to_define={:#?}", this.lifetimes_to_define);
debug!("lower_async_fn_ret_ty: lifetime_params={:#?}", lifetime_params);

let generic_params =
lifetime_params
.iter().cloned()
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/hir/lowering/item.rs
Expand Up @@ -123,7 +123,7 @@ impl LoweringContext<'_> {
_ => &[],
};
let lt_def_names = parent_generics.iter().filter_map(|param| match param.kind {
hir::GenericParamKind::Lifetime { .. } => Some(param.name.ident().modern()),
hir::GenericParamKind::Lifetime { .. } => Some(param.name),
_ => None,
});
self.in_scope_lifetimes.extend(lt_def_names);
Expand Down
16 changes: 16 additions & 0 deletions src/test/ui/async-await/async-fn-elided-impl-lifetime-parameter.rs
@@ -0,0 +1,16 @@
// Check that `async fn` inside of an impl with `'_`
// in the header compiles correctly.
//
// Regression test for #63500.
//
// check-pass

#![feature(async_await)]

struct Foo<'a>(&'a u8);

impl Foo<'_> {
async fn bar() {}
}

fn main() { }

0 comments on commit 18e5453

Please sign in to comment.