Skip to content

Eliminate $crate in --pretty=expanded #38016

Description

@dtolnay

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-decl-macros-1-2Area: Declarative macros 1.2C-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions