Skip to content

Commit

Permalink
Merge #37
Browse files Browse the repository at this point in the history
37: Fix parsing of macro metavariable in attribute arguments r=taiki-e a=taiki-e



Co-authored-by: Taiki Endo <[email protected]>
  • Loading branch information
bors[bot] and taiki-e authored May 16, 2021
2 parents 5556b9a + 905d8f9 commit 1ba0594
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Note: In this file, do not use the hard wrap in the middle of a sentence for com

## [Unreleased]

- [Fix parsing of macro metavariable in attribute arguments.](https://github.com/taiki-e/const_fn/pull/37)

## [0.4.7] - 2021-04-17

- [Support compiling with `RUSTFLAGS='-Z assume-incomplete-release'` on nightly compiler.](https://github.com/taiki-e/const_fn/pull/35)
Expand Down
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ use proc_macro::{Delimiter, TokenStream, TokenTree};
use crate::{
ast::{Func, LitStr},
error::Error,
iter::TokenIter,
to_tokens::ToTokens,
utils::{cfg_attrs, parse_as_empty, tt_span},
};
Expand Down Expand Up @@ -155,7 +156,7 @@ enum Arg {
}

fn parse_arg(tokens: TokenStream) -> Result<Arg> {
let mut iter = tokens.into_iter();
let mut iter = TokenIter::new(tokens);

let next = iter.next();
let next_span = tt_span(next.as_ref());
Expand Down
18 changes: 18 additions & 0 deletions test_suite/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,3 +240,21 @@ pub mod cfg {
assert_eq!(A::const_unstable(const_vec_new::<u8>()), A(Vec::new()));
}
}

pub mod macros {
#![allow(dead_code)]

use const_fn::const_fn;

macro_rules! args {
($args:expr) => {
#[const_fn($args)]
const fn args<T>(x: T) -> T {
x
}
};
}

args!("1.31");
const _: () = args(());
}

0 comments on commit 1ba0594

Please sign in to comment.