tomassedovic / tcod-rs

Rust bindings for libtcod 1.6.3 (the Doryen library/roguelike toolkit)
Do What The F*ck You Want To Public License
229 stars 45 forks source link

Fix deprecation warnings on latest Rust #297

Closed tomassedovic closed 3 years ago

tomassedovic commented 5 years ago

Compiling with the latest Rust releases started showing deprecation warnings like this:

warning: trait objects without an explicit `dyn` are deprecated
   --> src/bsp.rs:223:22
    |
223 |         let cb: &mut FnMut(&mut Bsp) -> bool = &mut callback;
    |                      ^^^^^^^^^^^^^^^^^^^^^^^ help: use `dyn`: `dyn FnMut(&mut Bsp) -> bool`
    |
    = note: #[warn(bare_trait_objects)] on by default

and

warning: `...` range patterns are deprecated
  --> src/bindings.rs:43:15
   |
43 |         x @ 0 ... 66 => Some(unsafe { transmute(x) }),
   |               ^^^ help: use `..=` for an inclusive range
   |
   = note: #[warn(ellipsis_inclusive_range_patterns)] on by default

The first one is about adding the dyn keywoard wherever we use a trait object. E.g. Box<Trait> should be Box<dyn Trait>, &Trait -> &dyn Trait and &mut Trait -> &mut dyn Trait.

The second comes from our bindgen-generated files so we'll probably need to get a newer version of bindgen and regenerate those files.

vmedea commented 4 years ago

These have been solved in #294. However there are now new ones with rustc 1.46.0:

   Compiling tcod v0.15.0 (/home/user/game/tcod-rs)
warning: unnecessary parentheses around block return value
   --> /home/user/game/tcod-rs/src/pathfinding.rs:151:13
    |
151 |             (Some((x, y)))
    |             ^^^^^^^^^^^^^^ help: remove these parentheses
    |
    = note: `#[warn(unused_parens)]` on by default

warning: `...` range patterns are deprecated
  --> /home/user/game/tcod-rs/src/bindings.rs:43:15
   |
43 |         x @ 0 ... 66 => Some(unsafe { transmute(x) }),
   |               ^^^ help: use `..=` for an inclusive range
   |
   = note: `#[warn(ellipsis_inclusive_range_patterns)]` on by default

warning: use of deprecated item 'std::mem::uninitialized': use `mem::MaybeUninit` instead
   --> /home/user/game/tcod-rs/src/input.rs:193:53
    |
193 |     let mut c_key_state: ffi::TCOD_key_t = unsafe { mem::uninitialized() };
    |                                                     ^^^^^^^^^^^^^^^^^^
    |
    = note: `#[warn(deprecated)]` on by default

warning: use of deprecated item 'std::mem::uninitialized': use `mem::MaybeUninit` instead
   --> /home/user/game/tcod-rs/src/input.rs:194:57
    |
194 |     let mut c_mouse_state: ffi::TCOD_mouse_t = unsafe { mem::uninitialized() };
    |                                                         ^^^^^^^^^^^^^^^^^^

warning: use of deprecated item 'std::sync::ONCE_INIT': the `new` function is now preferred
  --> /home/user/game/tcod-rs/src/namegen.rs:12:1
   |
12 | / lazy_static! {
13 | |     static ref NAMEGEN_MUTEX: Mutex<()> = Mutex::new(());
14 | | }
   | |_^
   |
   = note: this warning originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

warning: use of deprecated item 'std::sync::ONCE_INIT': the `new` function is now preferred
  --> /home/user/game/tcod-rs/src/namegen.rs:12:1
   |
12 | / lazy_static! {
13 | |     static ref NAMEGEN_MUTEX: Mutex<()> = Mutex::new(());
14 | | }
   | |_^
   |
   = note: this warning originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

warning: 6 warnings emitted

The lazy_static ones are curious, maybe it can be solved to switching to a newer version of that.

ojhp commented 3 years ago

The men::uninitialized() warning has become breaking and has already been fixed. Updating lazy_static resolves those warnings and the others are fairly simple fixes. Latest stable rust should now give no warnings on cargo build --all-targets.