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

#![warn(rust_2018_idioms)] proposes incorrect resolution to extern crate #52832

Closed
johnthagen opened this issue Jul 29, 2018 · 1 comment
Closed
Labels
A-edition-2018 Area: The 2018 edition A-lints Area: Lints (warnings about flaws in source code) such as unused_mut.

Comments

@johnthagen
Copy link
Contributor

Reported from discussion on internals forum about transitioning to Rust 2018.

> rustup show
Default host: x86_64-pc-windows-msvc

...

active toolchain
----------------

nightly-x86_64-pc-windows-msvc (default)
rustc 1.29.0-nightly (6a1c0637c 2018-07-23)

main.rs:

//! Rust belt is a 2D video game inspired by Asteroids.
//! It runs atop the Piston game engine for graphics and SDL2 for sound.
#![feature(rust_2018_preview)]
#![warn(rust_2018_idioms)]

extern crate ai_behavior;
extern crate music;
extern crate opengl_graphics;
extern crate piston_window;
extern crate rand;
extern crate sprite;

use piston_window::{OpenGL, PistonWindow, Size, WindowSettings};
use opengl_graphics::GlGraphics;

mod game;
mod menu;
mod settings;
mod story;

/// Creates a new window and runs the game starts the main menu.
fn main() {
    let game_title = "Rust Belt";
    let game_window_size = Size {
        width: 1024,
        height: 768,
    };

    let opengl = OpenGL::V3_2;

    let mut window: PistonWindow = WindowSettings::new(
        game_title,
        [game_window_size.width, game_window_size.height],
    ).opengl(opengl)
        .samples(4)
        .exit_on_esc(true)
        .build()
        .unwrap_or_else(|error| panic!("Failed to build PistonWindow: {}", error));

    let mut gl = GlGraphics::new(opengl);

    menu::run(&mut window, &mut gl, game_window_size);
}

Cargo.toml:

cargo-features = ["edition"]

[package]
name = "rust-belt"
version = "1.2.0"
authors = [
    "johnthagen <johnthagen@gmail.com>",
    "theandrewdavis <theandrewdavis@gmail.com>",
    "mcdenhoed <mcdenhoed@gmail.com>",
]
edition = '2018'

[dependencies]
piston_window = "0.80.0"
piston2d-opengl_graphics = "0.53.0"
piston-music = "0.24.0"
piston2d-sprite = "0.45.0"
piston-ai_behavior = "0.24.0"
rand = "0.5.4"
>cargo +nightly fix --allow-dirty
    Checking rust-belt v1.2.0 (file:///C:/Users/User/PycharmProjects/rust-belt)
      Fixing src\story.rs (3 fixes)
      Fixing src\game\models\vector.rs (8 fixes)
      Fixing src\game\mod.rs (9 fixes)
      Fixing src\menu.rs (7 fixes)
      Fixing src\game\models\mod.rs (7 fixes)
      Fixing src\game\models\player.rs (14 fixes)
      Fixing src\game\color.rs (9 fixes)
      Fixing src\settings.rs (3 fixes)
      Fixing src\game\models\bullet.rs (3 fixes)
      Fixing src\game\models\asteroid.rs (4 fixes)
warning: unused extern crate
 --> src\main.rs:6:1
  |
6 | extern crate ai_behavior;
  | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove it
  |
note: lint level defined here
 --> src\main.rs:4:9
  |
4 | #![warn(rust_2018_idioms)]
  |         ^^^^^^^^^^^^^^^^
  = note: #[warn(unused_extern_crates)] implied by #[warn(rust_2018_idioms)]

warning: `extern crate` is not idiomatic in the new edition
 --> src\main.rs:7:1
  |
7 | extern crate music;
  | ^^^^^^^^^^^^^^^^^^^ help: convert it to a `use`

warning: unused extern crate
 --> src\main.rs:8:1
  |
8 | extern crate opengl_graphics;
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove it

warning: unused extern crate
 --> src\main.rs:9:1
  |
9 | extern crate piston_window;
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove it

warning: `extern crate` is not idiomatic in the new edition
  --> src\main.rs:10:1
   |
10 | extern crate rand;
   | ^^^^^^^^^^^^^^^^^^ help: convert it to a `use`

warning: unused extern crate
  --> src\main.rs:11:1
   |
11 | extern crate sprite;
   | ^^^^^^^^^^^^^^^^^^^^ help: remove it

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

The lints that say help: convert it to a 'use' should all say remove it. If you change it to use, the next time you build, you get an "unused use" warning, at which point you have to remove it anyway to remove the warning.

@alexcrichton
Copy link
Member

I'm gonna close this in favor of #52829 as I think it's basically the same issue. Implementing #52829 as an auto-fixable solution would fix this, and fixing this is likely going to entail basically doing #52829

@fmease fmease added A-edition-2018 Area: The 2018 edition A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. and removed A-edition-2018-lints labels Dec 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-edition-2018 Area: The 2018 edition A-lints Area: Lints (warnings about flaws in source code) such as unused_mut.
Projects
None yet
Development

No branches or pull requests

4 participants