Old crate of mine fails to compile on beta/nightly

While updating an old crate of mine, I noticed that the beta and nightly compiler is complaining about my use of .as_ref() on a String type.

herman@titan ~/projects/hal-rs !! rustup override set nightly
info: using existing install for 'nightly-x86_64-apple-darwin'
info: override toolchain for '/Users/herman/projects/hal-rs' set to 'nightly-x86_64-apple-darwin'

  nightly-x86_64-apple-darwin unchanged - rustc 1.13.0-nightly (aef6971ca 2016-08-17)

herman@titan ~/projects/hal-rs !! cargo test
   Compiling rustc-serialize v0.3.16
   Compiling hal v0.0.6 (file:///Users/herman/projects/hal-rs)
error[E0283]: type annotations required: cannot resolve `std::string::String: std::convert::AsRef<_>`
  --> src/resource.rs:47:52
   |
47 |                         resource.add_link(link_key.as_ref(), &link);
   |                                                    ^^^^^^

error: aborting due to previous error

error[E0283]: type annotations required: cannot resolve `std::string::String: std::convert::AsRef<_>`
  --> src/resource.rs:47:52
   |
47 |                         resource.add_link(link_key.as_ref(), &link);
   |                                                    ^^^^^^

Build failed, waiting for other jobs to finish...
error: aborting due to previous error

error: Could not compile `hal`.

Here is the line of code: https://github.com/hjr3/hal-rs/blob/9328a992a41d5a0239bd95282a7b4ecf17a3d2e3/src/resource.rs#L47

I know how to fix the error, but i am surprised to see code that compiles on stable not compiling on beta/nightly. Was there a PSA i missed? I see nothing on urlo.

2 Likes

Rust doesn't consider type inference changes to be breaking changes. If it did, implementing a trait would be a breaking change. The devs do often run changes that might affect type inference through crater (a system that compiles all of cargo against a version of rust) but that's only a "how bad is this" heuristic.

Regardless, this is really annoying and it would be nice if rust were to provide some sort of crate migration tool that adds type hints where appropriate. However, that's not the highest priority at the moment.

1 Like

Thank you for the great explanation. Annoying, but luckily this is an easy fix.