3

I'm using the latest stable version: rustc 1.46.0 (04488afe3 2020-08-24).

Rust Analyser needs the import:

use chrono::offset::TimeZone;

in order to accept the expression:

Utc.ymd(1970, 1, 1).and_hms_milli(0, 0, 0, 200)

(It highlights the .ymd as {unknown}.)

If I add the import, the compiler issues a warning:

   Compiling foo v0.1.0 (/home/fadedbee/foo)
warning: unused import: `chrono::offset::TimeZone`
 --> src/bar.rs:2:5
  |
2 | use chrono::offset::TimeZone;
  |     ^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

How can I make Rust Analyser (in vscode), and the compiler, both happy?


Update:

As rodrigo correctly deduced, the only uses of .ymd are within a #[cfg(test)] section.

fadedbee
  • 42,671
  • 44
  • 178
  • 308
  • You can try add `#[allow(unused_imports)]` before `use` statement – Dmitry Sep 01 '20 at 06:40
  • 2
    Running it locally without the import results in `ymd method not found in \`chrono::Utc\`` on `rustc 1.46.0` using `chrono 0.4`. What version of chrono are you using? – MindSwipe Sep 01 '20 at 07:10
  • 1
    Running it on the [Rust playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=5c8c6d2cf4a4e7927966fdf88670227d) results in the same error message with the help `the following trait is implemented but not in scope; perhaps add a `use` for it: use chrono::TimeZone;`, adding it solves the issue – MindSwipe Sep 01 '20 at 07:13
  • 3
    Maybe your use of `Utc.ymd(...)` is conditionally compiled, as in a `#[cfg(test)]`? – rodrigo Sep 01 '20 at 08:16
  • With the information provided, the problem cannot be reproduced. The code in the question compiles without warnings once the import is added. Could you provide a minimal example reproducing the problem? – Sven Marnach Sep 01 '20 at 09:03
  • 1
    @rodrigo Many thanks, that was an impressive leap. The only uses of `.ymd` were in a `#[cfg(test)]` section. Moving the `use` inside of that section solved the problem. – fadedbee Sep 02 '20 at 05:09

0 Answers0