5766: Hacky support for fn-like proc macros r=matklad a=jonas-schievink

It turns out that this is all that's needed to get something like this working:

```rust
#[proc_macro]
pub fn function_like_macro(_args: TokenStream) -> TokenStream {
    TokenStream::from_str("fn fn_success() {}").unwrap()
}
```

```rust
function_like_macro!();

fn f() {
    fn_success();
}
```

The drawback is that it also makes this work, because there is no distinction between different proc macro kinds in the rest of r-a:

```rust
#[derive(function_like_macro)]
struct S {}

fn f() {
    fn_success();
}
```

Another issue is that it seems to panic, and then panic, when using this on the rustc code base, due to some issue in the inscrutable proc macro bridge code.

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
This commit is contained in:
bors[bot] 2020-08-16 20:03:06 +00:00 committed by GitHub
commit 0b2b9a5508
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -89,9 +89,8 @@ impl ProcMacroClient {
macros
.into_iter()
.filter_map(|(name, kind)| {
// FIXME: Support custom derive only for now.
match kind {
ProcMacroKind::CustomDerive => {
ProcMacroKind::CustomDerive | ProcMacroKind::FuncLike => {
let name = SmolStr::new(&name);
let expander: Arc<dyn tt::TokenExpander> =
Arc::new(ProcMacroProcessExpander {
@ -101,7 +100,8 @@ impl ProcMacroClient {
});
Some((name, expander))
}
_ => None,
// FIXME: Attribute macro are currently unsupported.
ProcMacroKind::Attr => None,
}
})
.collect()