Skip to content
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

Empty TokenStream is provided to attribute procedural macro on trait alias #79825

Closed
ghost opened this issue Dec 8, 2020 · 3 comments · Fixed by #83015
Closed

Empty TokenStream is provided to attribute procedural macro on trait alias #79825

ghost opened this issue Dec 8, 2020 · 3 comments · Fixed by #83015
Labels
A-proc-macros Area: Procedural macros C-bug Category: This is a bug. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. F-trait_alias `#![feature(trait_alias)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@ghost
Copy link

ghost commented Dec 8, 2020

I tried this code:

use proc_macro::TokenStream;

#[proc_macro_attribute]
pub fn give_me_trait_alias(_: TokenStream, input: TokenStream) -> TokenStream {
    assert!(!input.is_empty());
    Default::default()
}

and

#[give_me_trait_alias]
trait Alias = Sized;

I expected to see this happen: the compiler complained #![feature(trait_alias)] was missing, or on nightly, after adding #![feature(trait_alias)], compiled successfully, just like built-in #[allow] on trait alias.

Instead, this happened: the assertion failed. The compiler gave an empty TokenStream as input to the procedural macro:

error: custom attribute panicked
 --> tests/trait_alias.rs:3:1
  |
3 | #[give_me_trait_alias]
  | ^^^^^^^^^^^^^^^^^^^^^^
  |
  = help: message: assertion failed: !input.is_empty()

Edit: I found this in the compiler's log:

INFO rustc_parse cached tokens found, but they're not "probably equal", going with stringified version
INFO rustc_parse cached   tokens: trait Alias = Sized ;
INFO rustc_parse reparsed tokens: 
INFO rustc_parse cached   tokens debug: TokenStream([(Token(Token { kind: Ident("trait", false), span: tests/trait_alias.rs:4:1: 4:6 (#0) }), Alone), (Token(Token { kind: Ident("Alias", false), span: tests/trait_alias.rs:4:7: 4:12 (#0) }), Alone), (Token(Token { kind: Eq, span: tests/trait_alias.rs:4:13: 4:14 (#0) }), Alone), (Token(Token { kind: Ident("Sized", false), span: tests/trait_alias.rs:4:15: 4:20 (#0) }), Joint), (Token(Token { kind: Semi, span: tests/trait_alias.rs:4:20: 4:21 (#0) }), Alone)])
INFO rustc_parse reparsed tokens debug: TokenStream([])

info!(
"cached tokens found, but they're not \"probably equal\", \
going with stringified version"
);

Meta

I tried this with:

cc #41517

@ghost ghost added the C-bug Category: This is a bug. label Dec 8, 2020
@rustbot rustbot added A-proc-macros Area: Procedural macros F-trait_alias `#![feature(trait_alias)]` labels Dec 8, 2020
@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Feb 24, 2021
@Aaron1011
Copy link
Member

Aaron1011 commented Feb 24, 2021

The pretty-print/reparse check has been removed, so this should hopefully be fixed on the latest nightly.

@ghost
Copy link
Author

ghost commented Feb 24, 2021

Confirmed that this is fixed in latest nightly, thanks! ❤️ Do I need to leave this issue open (possibly for a regression test)?

@Aaron1011
Copy link
Member

That sounds like a good idea.

@Aaron1011 Aaron1011 added E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. labels Feb 24, 2021
bors added a commit to rust-lang-ci/rust that referenced this issue Apr 1, 2021
Rollup of 5 pull requests

Successful merges:

 - rust-lang#83015 (Add regression tests for rust-lang#79825 and rust-lang#81555)
 - rust-lang#83699 (Add a regression test for issue-68830)
 - rust-lang#83700 (Fix documentation of conversion from String to OsString)
 - rust-lang#83711 (Clarify `--print target-list` is a rustc's option)
 - rust-lang#83712 (Update LLVM with another wasm simd fix)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors closed this as completed in 9e30e57 Apr 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-proc-macros Area: Procedural macros C-bug Category: This is a bug. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. F-trait_alias `#![feature(trait_alias)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants