Skip to content

Printing a parsed Expr hits unreachable!() without "full" feature #1868

@arkeet

Description

@arkeet

This panics in the to_token_stream call when syn is built with just default features. I probably shouldn't be trying to parse expressions without the "full" feature, but I assume this should be failing to parse instead.

use quote::ToTokens;
use syn::{Expr, parse_quote};

fn main() {
    let e: Expr = parse_quote! { &() };
    e.to_token_stream();
}
thread 'main' panicked at ~/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/syn-2.0.101/src/expr.rs:3262:18:
internal error: entered unreachable code
stack backtrace:
   0: __rustc::rust_begin_unwind
             at /rustc/17067e9ac6d7ecb70e50f92c1944e545188d2359/library/std/src/panicking.rs:697:5
   1: core::panicking::panic_fmt
             at /rustc/17067e9ac6d7ecb70e50f92c1944e545188d2359/library/core/src/panicking.rs:75:14
   2: core::panicking::panic
             at /rustc/17067e9ac6d7ecb70e50f92c1944e545188d2359/library/core/src/panicking.rs:145:5
   3: syn::expr::printing::print_expr::{{closure}}
             at ~/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/syn-2.0.101/src/expr.rs:3262:18
   4: syn::expr::printing::print_expr
             at ~/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/syn-2.0.101/src/expr.rs:3268:13
   5: syn::expr::printing::print_subexpression::{{closure}}
             at ~/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/syn-2.0.101/src/expr.rs:3174:56
   6: syn::expr::printing::print_subexpression
             at ~/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/syn-2.0.101/src/expr.rs:3179:13
   7: syn::expr::printing::print_expr_reference
             at ~/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/syn-2.0.101/src/expr.rs:3847:9
   8: syn::expr::printing::<impl quote::to_tokens::ToTokens for syn::expr::ExprReference>::to_tokens
             at ~/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/syn-2.0.101/src/expr.rs:3834:13
   9: <syn::expr::Expr as quote::to_tokens::ToTokens>::to_tokens
             at ~/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/syn-2.0.101/src/macros.rs:124:68
  10: quote::to_tokens::ToTokens::to_token_stream
             at ~/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/quote-1.0.40/src/to_tokens.rs:58:9

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions