Attention to detail in errors

I have a project where I store a template configuration file in the application binary using include_str!(). I did a little refactoring which moved the directory from which the file is included, and the compiler told me:

 1  error: couldn't read `app/src/cmdproc/../conf.toml`: No such file or directory (os error 2)
  --> app/src/cmdproc/mkconf.rs:6:30
   |
 6 |   const CONF_TOML: &str = include_str!("../conf.toml");
   |                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: this error originates in the macro `include_str` (in Nightly builds, run with -Z macro-backtrace for more info)
 help: there is a file with the same name in a different directory
   |
 6 |   const CONF_TOML: &str = include_str!("../../conf.toml");
   |                                        ~~~~~~~~~~~~~~~~~~

The compiler is even telling me the exact relative path of the file I intended to include.

I thought that was unexpectedly helpful, even for Rust.

16 Likes

Thank you – I've implemented that :slight_smile:

I've got a workspace with a shared tests directory, and got tired of guessing how many ../../ I needed.

24 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.