Rollup merge of #51073 - dtolnay:empty, r=alexcrichton

Rename TokenStream::empty to TokenStream::new

There is no precedent for the `empty` name -- we do not have `Vec::empty` or `HashMap::empty` etc.

I would propose landing this but reflecting it in a non-breaking release of proc-macro2 that provides both `new` and a deprecated `empty` constructor.

Tracking issue: #38356

r? @alexcrichton
This commit is contained in:
kennytm 2018-05-26 19:32:33 +08:00 committed by GitHub
commit 84b2e14b9d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 7 additions and 7 deletions

View file

@ -26,7 +26,7 @@ pub fn assert1(_a: TokenStream, b: TokenStream) -> TokenStream {
#[proc_macro_derive(Foo, attributes(foo))]
pub fn assert2(a: TokenStream) -> TokenStream {
assert_eq(a, "pub struct MyStructc { _a: i32, }".parse().unwrap());
TokenStream::empty()
TokenStream::new()
}
fn assert_eq(a: TokenStream, b: TokenStream) {

View file

@ -20,13 +20,13 @@ use proc_macro::*;
#[proc_macro]
pub fn tokens(input: TokenStream) -> TokenStream {
assert_nothing_joint(input);
TokenStream::empty()
TokenStream::new()
}
#[proc_macro_attribute]
pub fn nothing(_: TokenStream, input: TokenStream) -> TokenStream {
assert_nothing_joint(input);
TokenStream::empty()
TokenStream::new()
}
fn assert_nothing_joint(s: TokenStream) {

View file

@ -50,7 +50,7 @@ fn parse(input: TokenStream) -> Result<(), Diagnostic> {
pub fn three_equals(input: TokenStream) -> TokenStream {
if let Err(diag) = parse(input) {
diag.emit();
return TokenStream::empty();
return TokenStream::new();
}
"3".parse().unwrap()