Eliminate $crate in --pretty=expanded · Issue #38016 · rust-lang/rust (original) (raw)

Similar to #37637 so cc @jseyfried.

cat src/main.rs

fn main() { println!("rust"); }

rustc --pretty=expanded -Zunstable-options src/main.rs

#![feature(prelude_import)] #![no_std] #[prelude_import] use std::prelude::v1::*; #[macro_use] extern crate std as std; fn main() { $crate::io::_print(::std::fmt::Arguments::new_v1({ static __STATIC_FMTSTR: &'static [&'static str] = &["rust\n"]; __STATIC_FMTSTR }, &match () { () => [], }));

The $crate prevents the expanded code from being parsed by rustfmt.

rustc --pretty=expanded -Zunstable-options src/main.rs | rustfmt

error: expected expression, found `$`
--> stdin:8:5
 |
8 |     $crate::io::_print(::std::fmt::Arguments::new_v1({
 |     ^

This breaks cargo expand which runs the code through rustfmt by default.

I think --pretty=expanded should produce valid Rust code which means either eliminate $crate like we did for #37637, or allow rustfmt to parse it.