8000 Rollup of 8 pull requests by Centril · Pull Request #70024 · rust-lang/rust · GitHub
[go: up one dir, main page]

Skip to content

Rollup of 8 pull requests #70024

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Mar 15, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
2a29726
Implement From<&mut str> for String
lopopolo Mar 3, 2020
51b9396
Add unborrow to reset RefCell borrow state
197g Feb 27, 2020
18feaa3
Add stable feature name
lopopolo Mar 11, 2020
533784d
Add docs for From::<&mut str>::from String impl
lopopolo Mar 11, 2020
e809e02
ast: `Mac`/`Macro` -> `MacCall`
petrochenkov Feb 29, 2020
01a0c6d
rustc_metadata: Remove `rmeta::MacroDef`
petrochenkov Mar 13, 2020
d7e6649
Return feature gate as a `Symbol`
ecstatic-morse Mar 14, 2020
2093d83
def_collector: Fully visit async functions
petrochenkov Mar 14, 2020
401a3f3
Fix "since" field for `Once::is_complete`'s `#[stable]` attribute
LukasKalbertodt Mar 15, 2020
78f01ec
resolve: Prevent fresh bindings from shadowing ambiguity items
petrochenkov Mar 14, 2020
83aad6b
Rollup merge of #69528 - HeroicKatora:finalize-ref-cell, r=dtolnay
Centril Mar 15, 2020
d1e943f
Rollup merge of #69589 - petrochenkov:maccall, r=Centril
Centril Mar 15, 2020
cc16232
Rollup merge of #69661 - lopopolo:string-from-mut-str, r=sfackler
Centril Mar 15, 2020
8bca839
Rollup merge of #69988 - petrochenkov:nomacrodef, r=Centril
Centril Mar 15, 2020
d986a70
Rollup merge of #70006 - petrochenkov:fresh, r=Centril
Centril Mar 15, 2020
8000
d74c5cd
Rollup merge of #70011 - petrochenkov:asyncice, r=Centril
Centril Mar 15, 2020
b46ef3d
Rollup merge of #70013 - ecstatic-morse:check-consts-feature-gate, r=…
Centril Mar 15, 2020
bde77af
Rollup merge of #70018 - LukasKalbertodt:fix-once-is-complete-since, …
Centril Mar 15, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
def_collector: Fully visit async functions
  • Loading branch information
petrochenkov committed Mar 15, 2020
commit 2093d83afc56d54d061e733a4892c5a5f195e58e
83 changes: 22 additions & 61 deletions src/librustc_resolve/def_collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use log::debug;
use rustc::hir::map::definitions::*;
use rustc_ast::ast::*;
use rustc_ast::token::{self, Token};
use rustc_ast::visit;
use rustc_ast::visit::{self, FnKind};
use rustc_expand::expand::AstFragment;
use rustc_hir::def_id::DefIndex;
use rustc_span::hygiene::ExpnId;
Expand Down Expand Up @@ -38,42 +38,6 @@ impl<'a> DefCollector<'a> {
self.parent_def = orig_parent_def;
}

fn visit_async_fn(
&mut self,
id: NodeId,
name: Name,
span: Span,
header: &FnHeader,
generics: &'a Generics,
decl: &'a FnDecl,
body: Option<&'a Block>,
) {
let (closure_id, return_impl_trait_id) = match header.asyncness {
Async::Yes { span: _, closure_id, return_impl_trait_id } => {
(closure_id, return_impl_trait_id)
}
_ => unreachable!(),
};

// For async functions, we need to create their inner defs inside of a
// closure to match their desugared representation.
let fn_def_data = DefPathData::ValueNs(name);
let fn_def = self.create_def(id, fn_def_data, span);
return self.with_parent(fn_def, |this| {
this.create_def(return_impl_trait_id, DefPathData::ImplTrait, span);

visit::walk_generics(this, generics);
visit::walk_fn_decl(this, decl);

let closure_def = this.create_def(closure_id, DefPathData::ClosureExpr, span);
this.with_parent(closure_def, |this| {
if let Some(body) = body {
visit::walk_block(this, body);
}
})
});
}

fn collect_field(&mut self, field: &'a StructField, index: Option<usize>) {
let index = |this: &Self| {
index.unwrap_or_else(|| {
Expand Down Expand Up @@ -117,17 +81,6 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
| ItemKind::ExternCrate(..)
| ItemKind::ForeignMod(..)
| ItemKind::TyAlias(..) => DefPathData::TypeNs(i.ident.name),
ItemKind::Fn(_, sig, generics, body) if sig.header.asyncness.is_async() => {
return self.visit_async_fn(
i.id,
i.ident.name,
i.span,
&sig.header,
generics,
&sig.decl,
body.as_deref(),
);
}
ItemKind::Static(..) | ItemKind::Const(..) | ItemKind::Fn(..) => {
DefPathData::ValueNs(i.ident.name)
}
Expand All @@ -154,6 +107,27 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
});
}

fn visit_fn(&mut self, fn_kind: FnKind<'a>, span: Span, _: NodeId) {
if let FnKind::Fn(_, _, sig, _, body) = fn_kind {
if let Async::Yes { closure_id, return_impl_trait_id, .. } = sig.header.asyncness {
self.create_def(return_impl_trait_id, DefPathData::ImplTrait, span);

// For async functions, we need to create their inner defs inside of a
// closure to match their desugared representation. Besides that,
// we must mirror everything that `visit::walk_fn` below does.
self.visit_fn_header(&sig.header);
visit::walk_fn_decl(self, &sig.decl);
if let Some(body) = body {
let closure_def = self.create_def(closure_id, DefPathData::ClosureExpr, span);
self.with_parent(closure_def, |this| this.visit_block(body));
}
return;
}
}

visit::walk_fn(self, fn_kind, span);
}

fn visit_use_tree(&mut self, use_tree: &'a UseTree, id: NodeId, _nested: bool) {
self.create_def(id, DefPathData::Misc, use_tree.span);
visit::walk_use_tree(self, use_tree, id);
Expand Down Expand Up @@ -215,19 +189,6 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {

fn visit_assoc_item(&mut self, i: &'a AssocItem, ctxt: visit::AssocCtxt) {
let def_data = match &i.kind {
AssocItemKind::Fn(_, FnSig { header, decl }, generics, body)
if header.asyncness.is_async() =>
{
return self.visit_async_fn(
i.id,
i.ident.name,
i.span,
header,
generics,
decl,
body.as_deref(),
);
}
AssocItemKind::Fn(..) | AssocItemKind::Const(..) => DefPathData::ValueNs(i.ident.name),
AssocItemKind::TyAlias(..) => DefPathData::TypeNs(i.ident.name),
AssocItemKind::Macro(..) => return self.visit_macro_invoc(i.id),
Expand Down
13 changes: 13 additions & 0 deletions src/test/ui/async-await/expansion-in-attrs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// check-pass
// edition:2018

macro_rules! with_doc {
($doc: expr) => {
#[doc = $doc]
async fn f() {}
};
}

with_doc!(concat!(""));

fn main() {}
0