Rust 2018 and log crate issues


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/
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:



Are you sure you’re using that version of log? This was fixed in 0.4.5:

1 Like


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



The Travis build is using log 0.4.1.



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

1 Like


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:



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.