Panic in proc_macro::TokenStream::from_str (original) (raw)

TokenStream::from_str is supposed to return Result<proc_macro::TokenStream, proc_macro::LexError>. Currently it appears to print errors to stderr and then panic, rather than returning errors.

Cargo.toml

[package] name = "repro" version = "0.0.0" edition = "2018"

[lib] proc-macro = true

src/lib.rs

extern crate proc_macro;

use proc_macro::TokenStream; use std::str::FromStr;

#[proc_macro_derive(ParseTokenStream)] pub fn derive(_input: TokenStream) -> TokenStream { let _ = TokenStream::from_str("\s"); TokenStream::new() }

src/main.rs

#[derive(repro::ParseTokenStream)] struct S;

fn main() {}

Output of cargo check:

$ cargo check

error: unknown start of token:
--> src/main.rs:1:10 | 1 | #[derive(repro::ParseTokenStream)] | ^^^^^^^^^^^^^^^^^^^^^^^

error: proc-macro derive panicked --> src/main.rs:1:10 | 1 | #[derive(repro::ParseTokenStream)] | ^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 2 previous errors

Mentioning @eddyb, @petrochenkov, @alexcrichton.
Mentioning @canndrew who reported this in dtolnay/proc-macro2#168.