Rust 2018 and log crate issues

#1

Guys, I’m having problems with the log crate.

log = “0.4.6”
rust = 1.32.0

log crate docs gives us an easy example how to use it:

// If you use Rust 2018 (by setting edition = 2018 in your Cargo.toml), you can use instead the following code to import the crate macros:

use log::{info, trace, warn};

pub fn shave_the_yak(yak: &mut Yak) {
   // …
}

All works fine on my machine, but then build on travis, which uses Rust 1.32.0 as well, fails:

error: cannot find macro `log!` in this scope
   --> src/personas/maid_manager/mod.rs:654:13
    |
654 |             info!("Managing {} client accounts.", self.accounts.len());
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |

If I do use log::{info, log};, Rust on travis is happy, but then Rust on my local machine is not and it says:

error: unused import: `log`

I can’t explain this inconsistency and why Rust on travis would fail. Any ideas? :slight_smile:

Here’s the failing build log for the reference: https://travis-ci.org/maidsafe/safe_vault/jobs/482918391

0 Likes

#2

Are you sure you’re using that version of log? This was fixed in 0.4.5: https://github.com/rust-lang-nursery/log/blob/master/CHANGELOG.md#045---2018-09-03

1 Like

#3

I’ve seen you do not have committed a Cargo.lock, perhaps your local version and the one on Travis got out of sync?

0 Likes

#4

The Travis build is using log 0.4.1.

0 Likes

#5

So, given all that, change this line to log = "~0.4.5"

1 Like

#6

Yep, upgrading the log crate helped. Thanks guys!
I expected cargo would use the latest version anyway since I the tilde specifier was used - ~0.4.1. :thinking:

0 Likes

#7

The issue here is, Cargo treats 0.x.y and 0.0.z versions differently, basically the leftmost non-zero version is always the “major”. Ergo, ~0.4.1 is not compatible with 0.4.5, while ^0.4.1 is since it’s a minor-version change, not a patchlevel.

0 Likes