Skip to content
This repository was archived by the owner on Dec 29, 2022. It is now read-only.

Commit b27e117

Browse files
authored
Merge pull request #1613 from ehuss/update-cargo
Update Cargo
2 parents d8afef5 + d42a6a7 commit b27e117

File tree

10 files changed

+67
-54
lines changed

10 files changed

+67
-54
lines changed

Cargo.lock

Lines changed: 23 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ rls-span = "0.5"
2929
rls-vfs = "0.8"
3030
rls-ipc = { version = "0.1.0", path = "rls-ipc", optional = true }
3131

32-
cargo = { git = "https://github.com/rust-lang/cargo", rev = "86134e7666a088682f20b76278c3ee096a315218" }
32+
anyhow = "1.0.26"
33+
cargo = { git = "https://github.com/rust-lang/cargo", rev = "735f648b35f5dd771a5b23a65bc465aee8639c56" }
3334
cargo_metadata = "0.8"
3435
clippy_lints = { git = "https://github.com/rust-lang/rust-clippy", rev = "05b46034ea734f2b4436b700452771652ecc0074", optional = true }
3536
env_logger = "0.7"
36-
failure = "0.1.1"
3737
futures = { version = "0.1", optional = true }
3838
home = "0.5.1"
3939
itertools = "0.8"

rls-rustc/src/ipc.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use std::collections::{HashMap, HashSet};
22
use std::io;
33
use std::path::{Path, PathBuf};
44

5-
use failure::Fail;
65
use futures::Future;
76

87
use rls_ipc::client::{Client as JointClient, RpcChannel, RpcError};

rls/src/actions/format.rs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
//! possibly running Rustfmt binary specified by the user.
33
44
use std::env::temp_dir;
5+
use std::fmt;
56
use std::fs::File;
67
use std::io::Write;
78
use std::path::{Path, PathBuf};
@@ -24,21 +25,34 @@ pub enum Rustfmt {
2425
}
2526

2627
/// Defines a formatting-related error.
27-
#[derive(Fail, Debug)]
28+
#[derive(Debug)]
2829
pub enum Error {
2930
/// Generic variant of `Error::Rustfmt` error.
30-
#[fail(display = "Formatting could not be completed.")]
3131
Failed,
32-
#[fail(display = "Could not format source code: {}", _0)]
3332
Rustfmt(rustfmt_nightly::ErrorKind),
34-
#[fail(display = "Encountered I/O error: {}", _0)]
3533
Io(std::io::Error),
36-
#[fail(display = "Config couldn't be converted to TOML for Rustfmt purposes: {}", _0)]
3734
ConfigTomlOutput(String),
38-
#[fail(display = "Formatted output is not valid UTF-8 source: {}", _0)]
3935
OutputNotUtf8(FromUtf8Error),
4036
}
4137

38+
impl std::error::Error for Error {}
39+
40+
impl fmt::Display for Error {
41+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
42+
match self {
43+
Error::Failed => write!(f, "Formatting could not be completed."),
44+
Error::Rustfmt(err) => write!(f, "Could not format source code: {}", err),
45+
Error::Io(err) => write!(f, "Encountered I/O error: {}", err),
46+
Error::ConfigTomlOutput(err) => {
47+
write!(f, "Config couldn't be converted to TOML for Rustfmt purposes: {}", err)
48+
}
49+
Error::OutputNotUtf8(err) => {
50+
write!(f, "Formatted output is not valid UTF-8 source: {}", err)
51+
}
52+
}
53+
}
54+
}
55+
4256
impl From<std::io::Error> for Error {
4357
fn from(err: std::io::Error) -> Error {
4458
Error::Io(err)

rls/src/actions/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ impl InitActionContext {
219219
*self.project_model.lock().unwrap() = None;
220220
}
221221

222-
pub fn project_model(&self) -> Result<Arc<ProjectModel>, failure::Error> {
222+
pub fn project_model(&self) -> Result<Arc<ProjectModel>, anyhow::Error> {
223223
let cached: Option<Arc<ProjectModel>> = self.project_model.lock().unwrap().clone();
224224
match cached {
225225
Some(pm) => Ok(pm),

rls/src/actions/post_build.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use crate::concurrency::JobToken;
1919
use crate::config::CrateBlacklist;
2020
use crate::lsp_data::{PublishDiagnosticsParams, Range};
2121

22-
use failure;
2322
use itertools::Itertools;
2423
use log::{trace, warn};
2524
use lsp_types::DiagnosticSeverity;
@@ -108,7 +107,7 @@ impl PostBuildHandler {
108107
&self,
109108
manifest: PathBuf,
110109
manifest_error_range: Option<Range>,
111-
error: &failure::Error,
110+
error: &anyhow::Error,
112111
stdout: &str,
113112
) {
114113
use crate::lsp_data::Position;
@@ -125,7 +124,7 @@ impl PostBuildHandler {
125124
.unwrap_or_else(|| Range { start: Position::new(0, 0), end: Position::new(9999, 0) });
126125

127126
let mut message = format!("{}", error);
128-
for cause in error.iter_causes() {
127+
for cause in error.chain().skip(1) {
129128
write!(message, "\n{}", cause).unwrap();
130129
}
131130
if !stdout.trim().is_empty() {

rls/src/build/cargo.rs

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ use cargo::util::{
2020
config as cargo_config, errors::ManifestError, homedir, important_paths, CargoResult,
2121
ConfigValue, ProcessBuilder,
2222
};
23-
use failure::{self, format_err, Fail};
2423
use log::{debug, trace, warn};
2524
use rls_data::Analysis;
2625
use rls_vfs::Vfs;
@@ -75,7 +74,7 @@ pub(super) fn cargo(
7574
}
7675
});
7776

78-
match handle.join().map_err(|_| failure::err_msg("thread panicked")).and_then(|res| res) {
77+
match handle.join().map_err(|_| anyhow::Error::msg("thread panicked")).and_then(|res| res) {
7978
Ok(ref cwd) => {
8079
let diagnostics = Arc::try_unwrap(diagnostics).unwrap().into_inner().unwrap();
8180
let analysis = Arc::try_unwrap(analysis).unwrap().into_inner().unwrap();
@@ -105,7 +104,7 @@ fn run_cargo(
105104
input_files: Arc<Mutex<HashMap<PathBuf, HashSet<Crate>>>>,
106105
out: Arc<Mutex<Vec<u8>>>,
107106
progress_sender: Sender<ProgressUpdate>,
108-
) -> Result<PathBuf, failure::Error> {
107+
) -> Result<PathBuf, anyhow::Error> {
109108
// Lock early to guarantee synchronized access to env var for the scope of Cargo routine.
110109
// Additionally we need to pass inner lock to `RlsExecutor`, since it needs to hand it down
111110
// during `exec()` callback when calling linked compiler in parallel, for which we need to
@@ -281,7 +280,7 @@ fn run_cargo_ws(
281280
}
282281

283282
if !reached_primary.load(Ordering::SeqCst) {
284-
return Err(format_err!("error compiling dependent crate"));
283+
return Err(anyhow::format_err!("error compiling dependent crate"));
285284
}
286285

287286
Ok(compilation_cx
@@ -577,7 +576,7 @@ impl Executor for RlsExecutor {
577576
}
578577

579578
if !success {
580-
return Err(format_err!("Build error"));
579+
return Err(anyhow::format_err!("Build error"));
581580
}
582581
}
583582

@@ -791,14 +790,14 @@ fn filter_arg(args: &[OsString], key: &str) -> Vec<String> {
791790
/// Error wrapper that tries to figure out which manifest the cause best relates to in the project
792791
#[derive(Debug)]
793792
pub struct ManifestAwareError {
794-
cause: failure::Error,
793+
cause: anyhow::Error,
795794
/// The path to a manifest file within the project that seems the closest to the error's origin.
796795
nearest_project_manifest: PathBuf,
797796
manifest_error_range: Range,
798797
}
799798

800799
impl ManifestAwareError {
801-
fn new(cause: failure::Error, root_manifest: &Path, ws: Option<&Workspace<'_>>) -> Self {
800+
fn new(cause: anyhow::Error, root_manifest: &Path, ws: Option<&Workspace<'_>>) -> Self {
802801
let project_dir = root_manifest.parent().unwrap();
803802
let mut err_path = root_manifest;
804803
// Cover whole manifest if we haven't any better idea.
@@ -813,12 +812,16 @@ impl ManifestAwareError {
813812
if is_project_manifest(last_cause.manifest_path()) {
814813
// Manifest with the issue is inside the project.
815814
err_path = last_cause.manifest_path().as_path();
816-
if let Some((line, col)) = (last_cause as &dyn Fail)
817-
.iter_chain()
818-
.filter_map(|e| e.downcast_ref::<toml::de::Error>())
819-
.next()
820-
.and_then(|e| e.line_col())
821-
{
815+
// This can be replaced by Error::chain when it is stabilized.
816+
fn find_toml_error(
817+
err: &(dyn std::error::Error + 'static),
818+
) -> Option<(usize, usize)> {
819+
match err.downcast_ref::<toml::de::Error>() {
820+
Some(toml_err) => toml_err.line_col(),
821+
None => find_toml_error(err.source()?),
822+
}
823+
}
824+
if let Some((line, col)) = find_toml_error(last_cause) {
822825
// Use TOML deserializiation error position.
823826
err_range.start = Position::new(line as _, col as _);
824827
err_range.end = Position::new(line as _, col as u64 + 1);
@@ -862,11 +865,7 @@ impl fmt::Display for ManifestAwareError {
862865
self.cause.fmt(f)
863866
}
864867
}
865-
impl failure::Fail for ManifestAwareError {
866-
fn cause(&self) -> Option<&dyn Fail> {
867-
self.cause.as_fail().cause()
868-
}
869-
}
868+
impl std::error::Error for ManifestAwareError {}
870869

871870
#[cfg(test)]
872871
mod test {

rls/src/build/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use std::sync::{Arc, Mutex, RwLock};
1010
use std::thread;
1111
use std::time::{Duration, Instant};
1212

13-
use failure;
1413
use log::{debug, info, trace};
1514
use rls_data::Analysis;
1615
use rls_vfs::Vfs;
@@ -105,7 +104,7 @@ pub enum BuildResult {
105104
Err(String, Option<String>),
106105
/// Cargo failed.
107106
CargoError {
108-
error: failure::Error,
107+
error: anyhow::Error,
109108
stdout: String,
110109
manifest_path: Option<PathBuf>,
111110
manifest_error_range: Option<Range>,

rls/src/lib.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010
#![warn(clippy::all, clippy::clone_on_ref_ptr)]
1111
#![allow(clippy::cognitive_complexity, clippy::too_many_arguments, clippy::redundant_closure)]
1212

13-
#[macro_use]
14-
extern crate failure;
15-
1613
pub use rls_analysis::{AnalysisHost, Target};
1714
pub use rls_vfs::Vfs;
1815

rls/src/project_model.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub struct Dep {
4242
}
4343

4444
impl ProjectModel {
45-
pub fn load(ws_manifest: &Path, vfs: &Vfs) -> Result<ProjectModel, failure::Error> {
45+
pub fn load(ws_manifest: &Path, vfs: &Vfs) -> Result<ProjectModel, anyhow::Error> {
4646
assert!(ws_manifest.ends_with("Cargo.toml"));
4747
let mut config = Config::default()?;
4848
// Enable nightly flag for cargo(see #1043)

0 commit comments

Comments
 (0)