Skip to main content

My (tiny) contribution to Rust 1.64

A couple of months ago, I was writing some Rust, and the compiler spat out an error:

error[E0412]: cannot find type `Boolean` in this scope
  --> src/fs_helpers.rs:29:33
   |
29 | pub fn is_ds_store(p: &Path) -> Boolean
   |                                 ^^^^^^^ not found in this scope

I’d spent all day writing Scala, and I’d used the name of Scala’s Boolean type by mistake.

It’s pretty obvious what I meant to do, and it only takes a few seconds to google the correct type – but wouldn’t it be nice if the error message could help me out here? I’m surely not the only Rust programmer who works across multiple languages, and can’t keep the types straight.

I know Rust really cares about helpful error messages, so I opened an issue to suggest an improvement. That got picked up by Yiming Lei, who wrote a patch – and if you look at the code, they’re modifying an existing function meant for exactly this kind of issue:

    // Returns the name of the Rust type approximately corresponding to
    // a type name in another programming language.
    fn likely_rust_type(path: &[Segment]) -> Option<Symbol> {

In the newly released Rust 1.64, their improved error message is now live. You get a help hint telling you that suggests the type you probably want:

error[E0412]: cannot find type `Boolean` in this scope
  --> src/fs_helpers.rs:29:33
   |
29 | pub fn is_ds_store(p: &Path) -> Boolean
   |                                 ^^^^^^^ not found in this scope
   |                                 help: perhaps you intended to use this type: `bool`

I’ve submitted suggestions for this sort of error message on other projects that get closed: “wontfix, just be smarter and don’t make mistakes”. That Rust is so willing to embrace additional code complexity to make it easier to use is one of the reasons I’ve come to like writing it – and one of the reasons I took the time to make the original suggestion.

This change will only save a few seconds at a time, but I’m still pleased it’s there. And when I inevitably make this mistake again, I’ll thank my past self for making it just a tiny bit easier to fix.