From 506fa435e63c97f80c448d0a86b07714018dbf9f Mon Sep 17 00:00:00 2001 From: Ed Page Date: Wed, 26 Jan 2022 16:01:24 -0600 Subject: [PATCH] chore: Upgrade cargo Cargo has switched exclusively to `toml_edit`, so when downcasting errors to get line and column, we need to downcast for those errors as well. This does not attempt to port rls to `toml_edit` and an analysis was not done to verify if the `find_toml_error` code path only needs to check for one toml library. The downside to this solution is its brittle. Any time cargo upgrades through a breaking `toml_edit` version, this test will break again and we'll have to upgrade rls to fix it. --- Cargo.lock | 49 +++++++++++++++++++++++++++++++++++------- Cargo.toml | 5 +++-- rls/src/build/cargo.rs | 11 +++++++--- 3 files changed, 52 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index efd70b2293..d6e1a78b85 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -125,13 +125,13 @@ dependencies = [ [[package]] name = "cargo" -version = "0.60.0" -source = "git+https://github.com/rust-lang/cargo?rev=06b9d31743210b788b130c8a484c2838afa6fc27#06b9d31743210b788b130c8a484c2838afa6fc27" +version = "0.61.0" +source = "git+https://github.com/rust-lang/cargo?rev=1c034752de0df744fcd7788fcbca158830b8bf85#1c034752de0df744fcd7788fcbca158830b8bf85" dependencies = [ "anyhow", "atty", "bytesize", - "cargo-platform 0.1.2 (git+https://github.com/rust-lang/cargo?rev=06b9d31743210b788b130c8a484c2838afa6fc27)", + "cargo-platform 0.1.2 (git+https://github.com/rust-lang/cargo?rev=1c034752de0df744fcd7788fcbca158830b8bf85)", "cargo-util", "clap 3.0.7", "crates-io", @@ -173,7 +173,7 @@ dependencies = [ "tar", "tempfile", "termcolor", - "toml", + "toml_edit", "unicode-width", "unicode-xid", "url 2.2.2", @@ -193,7 +193,7 @@ dependencies = [ [[package]] name = "cargo-platform" version = "0.1.2" -source = "git+https://github.com/rust-lang/cargo?rev=06b9d31743210b788b130c8a484c2838afa6fc27#06b9d31743210b788b130c8a484c2838afa6fc27" +source = "git+https://github.com/rust-lang/cargo?rev=1c034752de0df744fcd7788fcbca158830b8bf85#1c034752de0df744fcd7788fcbca158830b8bf85" dependencies = [ "serde", ] @@ -201,7 +201,7 @@ dependencies = [ [[package]] name = "cargo-util" version = "0.1.2" -source = "git+https://github.com/rust-lang/cargo?rev=06b9d31743210b788b130c8a484c2838afa6fc27#06b9d31743210b788b130c8a484c2838afa6fc27" +source = "git+https://github.com/rust-lang/cargo?rev=1c034752de0df744fcd7788fcbca158830b8bf85#1c034752de0df744fcd7788fcbca158830b8bf85" dependencies = [ "anyhow", "core-foundation", @@ -314,6 +314,16 @@ dependencies = [ "rustc-semver", ] +[[package]] +name = "combine" +version = "4.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50b727aacc797f9fc28e355d21f34709ac4fc9adecfe470ad07b8f4464f53062" +dependencies = [ + "bytes", + "memchr", +] + [[package]] name = "commoncrypto" version = "0.2.0" @@ -356,8 +366,8 @@ checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" [[package]] name = "crates-io" -version = "0.33.1" -source = "git+https://github.com/rust-lang/cargo?rev=06b9d31743210b788b130c8a484c2838afa6fc27#06b9d31743210b788b130c8a484c2838afa6fc27" +version = "0.34.0" +source = "git+https://github.com/rust-lang/cargo?rev=1c034752de0df744fcd7788fcbca158830b8bf85#1c034752de0df744fcd7788fcbca158830b8bf85" dependencies = [ "anyhow", "curl", @@ -1093,6 +1103,15 @@ dependencies = [ "unicase", ] +[[package]] +name = "kstring" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b310ccceade8121d7d77fee406160e457c2f4e7c7982d589da3499bc7ea4526" +dependencies = [ + "serde", +] + [[package]] name = "lazy_static" version = "1.4.0" @@ -1735,6 +1754,7 @@ dependencies = [ "tokio-stream", "tokio-util", "toml", + "toml_edit", "url 2.2.2", "walkdir", ] @@ -2257,6 +2277,19 @@ dependencies = [ "serde", ] +[[package]] +name = "toml_edit" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd43cf25c995eb155e5d692ba38185d68860674f54bb29cb458ee05d6de15561" +dependencies = [ + "combine", + "indexmap", + "itertools 0.10.1", + "kstring", + "serde", +] + [[package]] name = "tower-service" version = "0.3.1" diff --git a/Cargo.toml b/Cargo.toml index 15b79d4ca2..fbf71997c3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,8 +31,8 @@ rls-vfs = "0.8" rls-ipc = { version = "0.1.0", path = "rls-ipc", optional = true } anyhow = "1.0.26" -cargo = { git = "https://github.com/rust-lang/cargo", rev = "06b9d31743210b788b130c8a484c2838afa6fc27" } -cargo-util = { git = "https://github.com/rust-lang/cargo", rev = "06b9d31743210b788b130c8a484c2838afa6fc27" } +cargo = { git = "https://github.com/rust-lang/cargo", rev = "1c034752de0df744fcd7788fcbca158830b8bf85" } +cargo-util = { git = "https://github.com/rust-lang/cargo", rev = "1c034752de0df744fcd7788fcbca158830b8bf85" } cargo_metadata = "0.14" clippy_lints = { git = "https://github.com/rust-lang/rust-clippy", version = "0.1.60", optional = true } env_logger = "0.9" @@ -58,6 +58,7 @@ regex = "1" ordslice = "0.3" crossbeam-channel = "0.5" toml = "0.5" +toml_edit = { version = "0.13.1", features = ["easy"] } heck = "0.3" # A noop dependency that changes in the Rust repository, it's a bit of a hack. diff --git a/rls/src/build/cargo.rs b/rls/src/build/cargo.rs index 75a97b3a38..79a38260b0 100644 --- a/rls/src/build/cargo.rs +++ b/rls/src/build/cargo.rs @@ -828,9 +828,14 @@ impl ManifestAwareError { fn find_toml_error( err: &(dyn std::error::Error + 'static), ) -> Option<(usize, usize)> { - match err.downcast_ref::() { - Some(toml_err) => toml_err.line_col(), - None => find_toml_error(err.source()?), + if let Some(toml_err) = err.downcast_ref::() { + toml_err.line_col() + } else if let Some(toml_err) = err.downcast_ref::() { + toml_err.line_col() + } else if let Some(toml_err) = err.downcast_ref::() { + toml_err.line_col() + } else { + find_toml_error(err.source()?) } } if let Some((line, col)) = find_toml_error(last_cause) {