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

embed_migrations! warning: unused import: EmbedMigrations #1739

Closed
pjenvey opened this issue May 29, 2018 · 4 comments
Closed

embed_migrations! warning: unused import: EmbedMigrations #1739

pjenvey opened this issue May 29, 2018 · 4 comments

Comments

@pjenvey
Copy link

pjenvey commented May 29, 2018

Beginning w/ diesel 1.3 (seen on rust 1.26.0 stable), the embed_migrations! macro produces a rustc warning:

warning: unused import: `EmbedMigrations`
   --> autopush_rs/src/lib.rs:136:1
    |
136 | embed_migrations!();
    | ^^^^^^^^^^^^^^^^^^^^
    |
    = note: #[warn(unused_imports)] on by default
    = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

(A couple others on the gitter have also reported seeing it)

@sgrif
Copy link
Member

sgrif commented May 30, 2018

Can you provide a minimal crate to reproduce the issue? Can you also provide the output of building with -Z external-macro-backtrace on a nightly compiler?

pjenvey added a commit to pjenvey/diesel1739 that referenced this issue May 31, 2018
@pjenvey
Copy link
Author

pjenvey commented May 31, 2018

Minimal crate: https://github.com/pjenvey/diesel1739

Not sure the external-macro-backtrace is too helpful here:

warning: unused import: `EmbedMigrations`
  --> <embed_migrations macros>:3:14
   |
1  | / (  ) => {
2  | | # [ allow ( dead_code ) ] mod embedded_migrations {
3  | | # [ derive ( EmbedMigrations ) ] struct _Dummy ; } } ; (
   | |              ^^^^^^^^^^^^^^^
4  | | $ migrations_path : expr ) => {
...  |
7  | | embed_migrations_options ( migrations_path = $ migrations_path ) ] struct
8  | | _Dummy ; } }
   | |____________- in this expansion of `embed_migrations!`
   | 
  ::: src/main.rs:10:1
   |
10 |   embed_migrations!();
   |   -------------------- in this macro invocation
   |
   = note: #[warn(unused_imports)] on by default

    Finished dev [unoptimized + debuginfo] target(s) in 47.02s

@Eijebong
Copy link
Member

cargo expand:

#![feature(prelude_import)]
#![no_std]
#[prelude_import]
use std::prelude::v1::*;
extern crate diesel;
#[macro_use]
extern crate diesel_migrations;
#[macro_use]
extern crate std;

fn main() {
    ::io::_print(::std::fmt::Arguments::new_v1(
        &["Hello, world!\n"],
        &match () {
            () => [],
        },
    ));
}
#[allow(dead_code)]
mod embedded_migrations {
    struct _Dummy;
    extern crate diesel;
    extern crate diesel_migrations;
    use self::diesel_migrations::*;
    use self::diesel::migration::*;
    use self::diesel::connection::SimpleConnection;
    use std::io;
    const ALL_MIGRATIONS: &[&Migration] =
        &[&EmbeddedMigration{version: "20180220220249",
                             up_sql:
                                 "CREATE TABLE broadcastsv1 (\n    broadcaster_id VARCHAR(64) NOT NULL,\n    bchannel_id VARCHAR(128) NOT NULL,\n    created TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,\n    last_updated TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP NOT NULL,\n    version VARCHAR(200) NOT NULL,\n    PRIMARY KEY(broadcaster_id, bchannel_id)\n);\n",}];
    struct EmbeddedMigration {
        version: &'static str,
        up_sql: &'static str,
    }
    impl Migration for EmbeddedMigration {
        fn version(&self) -> &str {
            self.version
        }
        fn run(&self, conn: &SimpleConnection) -> Result<(), RunMigrationsError> {
            conn.batch_execute(self.up_sql).map_err(Into::into)
        }
        fn revert(&self, _conn: &SimpleConnection) -> Result<(), RunMigrationsError> {
            {
                {
                    ::rt::begin_panic(
                        "internal error: entered unreachable code",
                        &("src/main.rs", 10u32, 1u32),
                    )
                }
            }
        }
    }
    pub fn run<C: MigrationConnection>(conn: &C) -> Result<(), RunMigrationsError> {
        run_with_output(conn, &mut io::sink())
    }
    pub fn run_with_output<C: MigrationConnection>(
        conn: &C,
        out: &mut io::Write,
    ) -> Result<(), RunMigrationsError> {
        run_migrations(conn, ALL_MIGRATIONS.iter().map(|v| *v), out)
    }

sgrif added a commit that referenced this issue Jun 1, 2018
The changes for barrel support led to `diesel_migrations` exporting
everything required by this macro, leading to the warning being
generated.

Fixes #1739
@rockstar
Copy link

Can we cut a release of diesel_migrations so that this change is in a released version?

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

No branches or pull requests

4 participants