Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update and support Rust 2018 edition #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mariomka
Copy link

Hello!

Bundler can't work with Rust 2018 edition code because rustfmt doesn't understand new syntax. Related issue: #6

To solve this it's necessary to use new rustfmt-nightly, there are two options:

  • Use it programmatically. It requires Rust nightly and two environment variables: CFG_RELEASE_CHANNEL=nightly;CFG_RELEASE=nightly
  • Call it through the command-line program. It requires installing the component: rustup component add rustfmt

Then, I opted for adding a feature inner_rustfmt to select the desired option, it calls the CLI by default. (Based on https://github.com/hatoo/cargo-snippet/blob/master/src/writer.rs)

Also, I've updated the project to the 2018 edition and dependencies to the newest versions.

By last, I found a syntax that doesn't work properly. But I'm not sure how to fix it.
Taking a modified version of main.rs file from "complicated" test input:

extern crate my_lib;

fn main() {
    my_lib::a::a();
    self::my_lib::b::b();
    self::my_lib::c::d::d();
}

It bundles as:

pub mod a {
    pub fn a() {
        println!("a::a()");
    }
}
pub mod b {
    use crate::a;
    pub fn b() {
        a::a();
    }
}
pub mod c {
    pub mod d {
        pub fn d() {
            println!("c::d::d()");
        }
    }
}
fn main() {
    a::a();
    self::my_lib::b::b();
    self::my_lib::c::d::d();
}

self::my_lib is not replaced by self::.

But it works properly if syntax self::{lib_name} isn't used:

extern crate my_lib;

use my_lib::{a, b, c};

fn main() {
    a::a();
    self::b::b();
    self::c::d::d();
}

@Endle
Copy link

Endle commented Jun 22, 2021

Hi,

Edit: I imade a PR to fix the compile error mariomka#1

Original post:

I was trying to install your fork following this instruction

git clone https://github.com/mariomka/rust-bundler.git
cd rust-bundler
cargo install --path .

However, I failed to install it

lizhenbo@localhost rust-bundler$ cargo --version
cargo 1.49.0 (d00d64df9 2020-12-05)
lizhenbo@localhost rust-bundler$ cargo install --path .
  Installing bundler v0.1.1 (/home/lizhenbo/src/rust-bundler)
    Updating `git://mirrors.ustc.edu.cn/crates.io-index` index
   Compiling bundler v0.1.1 (/home/lizhenbo/src/rust-bundler)
error[E0432]: unresolved import `syn::export`
 --> src/lib.rs:7:10
  |
7 | use syn::export::ToTokens;
  |          ^^^^^^ could not find `export` in `syn`

error[E0599]: no method named `into_token_stream` found for struct `syn::File` in the current scope
  --> src/lib.rs:36:21
   |
36 |     let code = file.into_token_stream().to_string();
   |                     ^^^^^^^^^^^^^^^^^ method not found in `syn::File`
   | 
  ::: /home/lizhenbo/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/quote-1.0.9/src/to_tokens.rs:71:8
   |
71 |     fn into_token_stream(self) -> TokenStream
   |        -----------------
   |        |
   |        the method is available for `std::boxed::Box<syn::File>` here
   |        the method is available for `Rc<syn::File>` here
   |
   = help: items from traits can only be used if the trait is in scope
help: the following trait is implemented but not in scope; perhaps add a `use` for it:
   |
2  | use syn::__private::ToTokens;
   |

error: aborting due to 2 previous errors

Some errors have detailed explanations: E0432, E0599.
For more information about an error, try `rustc --explain E0432`.
error: failed to compile `bundler v0.1.1 (/home/lizhenbo/src/rust-bundler)`, intermediate artifacts can be found at `/home/lizhenbo/src/rust-bundler/target`

Caused by:
  could not compile `bundler`

To learn more, run the command again with --verbose

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants