Skip to content

Commit 5bd9eaa

Browse files
committed
Add a convenience method for getting the impl Trait NodeId of an IsAysnc
1 parent a85b279 commit 5bd9eaa

File tree

2 files changed

+22
-25
lines changed

2 files changed

+22
-25
lines changed

src/librustc/hir/lowering.rs

+15-25
Original file line numberDiff line numberDiff line change
@@ -1352,18 +1352,18 @@ impl<'a> LoweringContext<'a> {
13521352
}
13531353

13541354
fn visit_ty(&mut self, t: &'v hir::Ty) {
1355-
// Don't collect elided lifetimes used inside of `fn()` syntax
1355+
// Don't collect elided lifetimes used inside of `fn()` syntax
13561356
if let hir::Ty_::TyBareFn(_) = t.node {
1357-
let old_collect_elided_lifetimes = self.collect_elided_lifetimes;
1358-
self.collect_elided_lifetimes = false;
1357+
let old_collect_elided_lifetimes = self.collect_elided_lifetimes;
1358+
self.collect_elided_lifetimes = false;
13591359

1360-
// Record the "stack height" of `for<'a>` lifetime bindings
1361-
// to be able to later fully undo their introduction.
1362-
let old_len = self.currently_bound_lifetimes.len();
1363-
hir::intravisit::walk_ty(self, t);
1364-
self.currently_bound_lifetimes.truncate(old_len);
1360+
// Record the "stack height" of `for<'a>` lifetime bindings
1361+
// to be able to later fully undo their introduction.
1362+
let old_len = self.currently_bound_lifetimes.len();
1363+
hir::intravisit::walk_ty(self, t);
1364+
self.currently_bound_lifetimes.truncate(old_len);
13651365

1366-
self.collect_elided_lifetimes = old_collect_elided_lifetimes;
1366+
self.collect_elided_lifetimes = old_collect_elided_lifetimes;
13671367
} else {
13681368
hir::intravisit::walk_ty(self, t)
13691369
}
@@ -2579,17 +2579,12 @@ impl<'a> LoweringContext<'a> {
25792579
}
25802580
});
25812581

2582-
let asyncness = match header.asyncness {
2583-
IsAsync::Async { return_impl_trait_id, .. } => Some(return_impl_trait_id),
2584-
IsAsync::NotAsync => None,
2585-
};
2586-
25872582
let (generics, fn_decl) = this.add_in_band_defs(
25882583
generics,
25892584
fn_def_id,
25902585
AnonymousLifetimeMode::PassThrough,
25912586
|this| this.lower_fn_decl(
2592-
decl, Some(fn_def_id), true, asyncness)
2587+
decl, Some(fn_def_id), true, header.asyncness.opt_return_id())
25932588
);
25942589

25952590
hir::ItemFn(
@@ -3016,11 +3011,6 @@ impl<'a> LoweringContext<'a> {
30163011
});
30173012
let impl_trait_return_allow = !self.is_in_trait_impl;
30183013

3019-
let asyncness = match sig.header.asyncness {
3020-
IsAsync::Async { return_impl_trait_id, .. } => Some(return_impl_trait_id),
3021-
IsAsync::NotAsync => None,
3022-
};
3023-
30243014
self.add_in_band_defs(
30253015
&i.generics,
30263016
impl_item_def_id,
@@ -3031,7 +3021,7 @@ impl<'a> LoweringContext<'a> {
30313021
sig,
30323022
impl_item_def_id,
30333023
impl_trait_return_allow,
3034-
asyncness,
3024+
sig.header.asyncness.opt_return_id(),
30353025
),
30363026
body_id,
30373027
)
@@ -3136,8 +3126,8 @@ impl<'a> LoweringContext<'a> {
31363126
ItemKind::MacroDef(..) => SmallVector::new(),
31373127
ItemKind::Fn(ref decl, ref header, ..) => {
31383128
let mut ids = SmallVector::one(hir::ItemId { id: i.id });
3139-
if let IsAsync::Async { return_impl_trait_id, .. } = header.asyncness {
3140-
ids.push(hir::ItemId { id: return_impl_trait_id });
3129+
if let Some(id) = header.asyncness.opt_return_id() {
3130+
ids.push(hir::ItemId { id });
31413131
}
31423132
self.lower_impl_trait_ids(decl, &mut ids);
31433133
ids
@@ -3146,8 +3136,8 @@ impl<'a> LoweringContext<'a> {
31463136
let mut ids = SmallVector::one(hir::ItemId { id: i.id });
31473137
for item in items {
31483138
if let ImplItemKind::Method(ref sig, _) = item.node {
3149-
if let IsAsync::Async { return_impl_trait_id, .. } = sig.header.asyncness {
3150-
ids.push(hir::ItemId { id: return_impl_trait_id });
3139+
if let Some(id) = sig.header.asyncness.opt_return_id() {
3140+
ids.push(hir::ItemId { id });
31513141
}
31523142
self.lower_impl_trait_ids(&sig.decl, &mut ids);
31533143
}

src/libsyntax/ast.rs

+7
Original file line numberDiff line numberDiff line change
@@ -1737,6 +1737,13 @@ impl IsAsync {
17371737
false
17381738
}
17391739
}
1740+
/// In case this is an `Async` return the `NodeId` for the generated impl Trait item
1741+
pub fn opt_return_id(self) -> Option<NodeId> {
1742+
match self {
1743+
IsAsync::Async { return_impl_trait_id, .. } => Some(return_impl_trait_id),
1744+
IsAsync::NotAsync => None,
1745+
}
1746+
}
17401747
}
17411748

17421749
#[derive(Copy, Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]

0 commit comments

Comments
 (0)