qryxip / cargo-equip

A Cargo subcommand to bundle your code into one `.rs` file for competitive programming
Apache License 2.0
76 stars 10 forks source link

Failed to minify Floating-point literals followed by `.` #116

Closed to-omer closed 3 years ago

to-omer commented 3 years ago
pub fn test() {
    dbg!(1. ..2.);
}

上のコードをバンドルした結果、minify で壊れました

$ cargo equip --example minify --minify libs --check
error: unexpected token: `...`
  --> examples\cargo-equip-check-output-acjm3glcr0fl7guq.rs:13:91
   |
13 | #[cfg_attr(any(),rustfmt::skip)]#[allow(unused)]pub mod minify_sample{pub fn test(){dbg!(1...2.);}}
   |                                                                                           ^^^
   |
help: use `..` for an exclusive range
   |
13 | #[cfg_attr(any(),rustfmt::skip)]#[allow(unused)]pub mod minify_sample{pub fn test(){dbg!(1..2.);}}
   |                                                                                           ^^
help: or `..=` for an inclusive range
   |
13 | #[cfg_attr(any(),rustfmt::skip)]#[allow(unused)]pub mod minify_sample{pub fn test(){dbg!(1..=2.);}}
   |                                                                                           ^^^

error[E0308]: mismatched types
  --> examples\cargo-equip-check-output-acjm3glcr0fl7guq.rs:13:94
   |
13 | #[cfg_attr(any(),rustfmt::skip)]#[allow(unused)]pub mod minify_sample{pub fn test(){dbg!(1...2.);}}
   |                                                                                              ^^ expected integer, found floating-point number

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0308`.
error: could not compile `cargo-equip-check-output-acjm3glcr0fl7guq`

To learn more, run the command again with --verbose.
error: the bundled code was not valid

参考:https://doc.rust-lang.org/stable/reference/tokens.html#floating-point-literals

qryxip commented 3 years ago

「literalの直後には安全にスペース無しで任意のpunctuationを詰められる」と思い込んでいました。後で直します。

https://github.com/qryxip/cargo-equip/blob/f37fdc9e83842a4db5ee42c3080694ee06a2200f/src/rust.rs#L1419-L1424 https://github.com/qryxip/cargo-equip/blob/f37fdc9e83842a4db5ee42c3080694ee06a2200f/src/rust.rs#L1452-L1453

qryxip commented 3 years ago

直してv0.13.1をリリースしました。

https://github.com/qryxip/cargo-equip/blob/22b566076a6641a664bc9382d82249f004f47d70/src/rust.rs#L1709