I’ve been slowly updating my workspace one crate at a time. From what I’ve seen so far, cargo fix
works spectacularly well, far exceeding my expectations. It updated even some of my most macro-heavy crates without breaking a sweat.
So far, I’ve run into three issues, two of which were really not the fault of rust, but rather they were due to minor and temporary holes in the ecosystem. I’ll share them here to help others work around them (hopefully enabling users to discover more meaningful bugs in crates higher up the dependency chain!):
failure 0.1.1
uses an old version of syn
#[derive(Fail)]
panics on crate
syntax because it uses an old version of syn
. This is fixed on the master branch of failure
, but the next release currently seems to be in limbo.
For now, to resolve this, depend on the git repo:
# (note: make sure to include the version field to minimize breaking changes,
# as the repo actually contains two different versions of the crate!)
failure = { git = "https://github.com/rust-lang-nursery/failure", version = "0.1.2", rev = "9e1952de8e2" }
Try enabling proc-macro2
's nightly
feature if you use any custom derives (like serde
)
cargo fix
can get tripped up by errors in code generated by custom derives:
// output of 'cargo fix':
#[derive(Serialize, crate::Deserialize)] // <--- lol oops
pub struct Thing {
foo: ::module::Foo,
bar: ::module::Bar,
}
While the above is due to something that is an obvious bug in rustc (in that it gives the suggestion to write “crate::Deserialize”), you’re likely still going to have trouble even once that bug is fixed, because the core issue here is that the code generated by the macro has no span information.
Luckily, serde
already supports accurate span info, because it makes effective use of the proc-macro2
shim crate. All you need to do is add a direct dependency to your Cargo.toml, to enable the feature:
# note: you should check your Cargo.lock first to find out what version of
# proc-macro2 your dependencies depend on, and use that version number
proc-macro2 = { version = "0.4.9", features = ["nightly"] }
Be aware this won’t work for all custom derives (only ones that depend on the proc-macro2
crate and use it properly).