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

Commit

Permalink
Update Cargo
Browse files Browse the repository at this point in the history
  • Loading branch information
ehuss committed Jan 12, 2020
1 parent 7c0489c commit d42a6a7
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 54 deletions.
40 changes: 23 additions & 17 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ rls-span = "0.5"
rls-vfs = "0.8"
rls-ipc = { version = "0.1.0", path = "rls-ipc", optional = true }

cargo = { git = "https://github.com/rust-lang/cargo", rev = "86134e7666a088682f20b76278c3ee096a315218" }
anyhow = "1.0.26"
cargo = { git = "https://github.com/rust-lang/cargo", rev = "735f648b35f5dd771a5b23a65bc465aee8639c56" }
cargo_metadata = "0.8"
clippy_lints = { git = "https://github.com/rust-lang/rust-clippy", rev = "05b46034ea734f2b4436b700452771652ecc0074", optional = true }
env_logger = "0.7"
failure = "0.1.1"
futures = { version = "0.1", optional = true }
home = "0.5.1"
itertools = "0.8"
Expand Down
1 change: 0 additions & 1 deletion rls-rustc/src/ipc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use std::collections::{HashMap, HashSet};
use std::io;
use std::path::{Path, PathBuf};

use failure::Fail;
use futures::Future;

use rls_ipc::client::{Client as JointClient, RpcChannel, RpcError};
Expand Down
26 changes: 20 additions & 6 deletions rls/src/actions/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
//! possibly running Rustfmt binary specified by the user.
use std::env::temp_dir;
use std::fmt;
use std::fs::File;
use std::io::Write;
use std::path::{Path, PathBuf};
Expand All @@ -24,21 +25,34 @@ pub enum Rustfmt {
}

/// Defines a formatting-related error.
#[derive(Fail, Debug)]
#[derive(Debug)]
pub enum Error {
/// Generic variant of `Error::Rustfmt` error.
#[fail(display = "Formatting could not be completed.")]
Failed,
#[fail(display = "Could not format source code: {}", _0)]
Rustfmt(rustfmt_nightly::ErrorKind),
#[fail(display = "Encountered I/O error: {}", _0)]
Io(std::io::Error),
#[fail(display = "Config couldn't be converted to TOML for Rustfmt purposes: {}", _0)]
ConfigTomlOutput(String),
#[fail(display = "Formatted output is not valid UTF-8 source: {}", _0)]
OutputNotUtf8(FromUtf8Error),
}

impl std::error::Error for Error {}

impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Error::Failed => write!(f, "Formatting could not be completed."),
Error::Rustfmt(err) => write!(f, "Could not format source code: {}", err),
Error::Io(err) => write!(f, "Encountered I/O error: {}", err),
Error::ConfigTomlOutput(err) => {
write!(f, "Config couldn't be converted to TOML for Rustfmt purposes: {}", err)
}
Error::OutputNotUtf8(err) => {
write!(f, "Formatted output is not valid UTF-8 source: {}", err)
}
}
}
}

impl From<std::io::Error> for Error {
fn from(err: std::io::Error) -> Error {
Error::Io(err)
Expand Down
2 changes: 1 addition & 1 deletion rls/src/actions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ impl InitActionContext {
*self.project_model.lock().unwrap() = None;
}

pub fn project_model(&self) -> Result<Arc<ProjectModel>, failure::Error> {
pub fn project_model(&self) -> Result<Arc<ProjectModel>, anyhow::Error> {
let cached: Option<Arc<ProjectModel>> = self.project_model.lock().unwrap().clone();
match cached {
Some(pm) => Ok(pm),
Expand Down
5 changes: 2 additions & 3 deletions rls/src/actions/post_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use crate::concurrency::JobToken;
use crate::config::CrateBlacklist;
use crate::lsp_data::{PublishDiagnosticsParams, Range};

use failure;
use itertools::Itertools;
use log::{trace, warn};
use lsp_types::DiagnosticSeverity;
Expand Down Expand Up @@ -108,7 +107,7 @@ impl PostBuildHandler {
&self,
manifest: PathBuf,
manifest_error_range: Option<Range>,
error: &failure::Error,
error: &anyhow::Error,
stdout: &str,
) {
use crate::lsp_data::Position;
Expand All @@ -125,7 +124,7 @@ impl PostBuildHandler {
.unwrap_or_else(|| Range { start: Position::new(0, 0), end: Position::new(9999, 0) });

let mut message = format!("{}", error);
for cause in error.iter_causes() {
for cause in error.chain().skip(1) {
write!(message, "\n{}", cause).unwrap();
}
if !stdout.trim().is_empty() {
Expand Down
35 changes: 17 additions & 18 deletions rls/src/build/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use cargo::util::{
config as cargo_config, errors::ManifestError, homedir, important_paths, CargoResult,
ConfigValue, ProcessBuilder,
};
use failure::{self, format_err, Fail};
use log::{debug, trace, warn};
use rls_data::Analysis;
use rls_vfs::Vfs;
Expand Down Expand Up @@ -75,7 +74,7 @@ pub(super) fn cargo(
}
});

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

if !reached_primary.load(Ordering::SeqCst) {
return Err(format_err!("error compiling dependent crate"));
return Err(anyhow::format_err!("error compiling dependent crate"));
}

Ok(compilation_cx
Expand Down Expand Up @@ -577,7 +576,7 @@ impl Executor for RlsExecutor {
}

if !success {
return Err(format_err!("Build error"));
return Err(anyhow::format_err!("Build error"));
}
}

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

impl ManifestAwareError {
fn new(cause: failure::Error, root_manifest: &Path, ws: Option<&Workspace<'_>>) -> Self {
fn new(cause: anyhow::Error, root_manifest: &Path, ws: Option<&Workspace<'_>>) -> Self {
let project_dir = root_manifest.parent().unwrap();
let mut err_path = root_manifest;
// Cover whole manifest if we haven't any better idea.
Expand All @@ -813,12 +812,16 @@ impl ManifestAwareError {
if is_project_manifest(last_cause.manifest_path()) {
// Manifest with the issue is inside the project.
err_path = last_cause.manifest_path().as_path();
if let Some((line, col)) = (last_cause as &dyn Fail)
.iter_chain()
.filter_map(|e| e.downcast_ref::<toml::de::Error>())
.next()
.and_then(|e| e.line_col())
{
// This can be replaced by Error::chain when it is stabilized.
fn find_toml_error(
err: &(dyn std::error::Error + 'static),
) -> Option<(usize, usize)> {
match err.downcast_ref::<toml::de::Error>() {
Some(toml_err) => toml_err.line_col(),
None => find_toml_error(err.source()?),
}
}
if let Some((line, col)) = find_toml_error(last_cause) {
// Use TOML deserializiation error position.
err_range.start = Position::new(line as _, col as _);
err_range.end = Position::new(line as _, col as u64 + 1);
Expand Down Expand Up @@ -862,11 +865,7 @@ impl fmt::Display for ManifestAwareError {
self.cause.fmt(f)
}
}
impl failure::Fail for ManifestAwareError {
fn cause(&self) -> Option<&dyn Fail> {
self.cause.as_fail().cause()
}
}
impl std::error::Error for ManifestAwareError {}

#[cfg(test)]
mod test {
Expand Down
3 changes: 1 addition & 2 deletions rls/src/build/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use std::sync::{Arc, Mutex, RwLock};
use std::thread;
use std::time::{Duration, Instant};

use failure;
use log::{debug, info, trace};
use rls_data::Analysis;
use rls_vfs::Vfs;
Expand Down Expand Up @@ -105,7 +104,7 @@ pub enum BuildResult {
Err(String, Option<String>),
/// Cargo failed.
CargoError {
error: failure::Error,
error: anyhow::Error,
stdout: String,
manifest_path: Option<PathBuf>,
manifest_error_range: Option<Range>,
Expand Down
3 changes: 0 additions & 3 deletions rls/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
#![warn(clippy::all, clippy::clone_on_ref_ptr)]
#![allow(clippy::cognitive_complexity, clippy::too_many_arguments, clippy::redundant_closure)]

#[macro_use]
extern crate failure;

pub use rls_analysis::{AnalysisHost, Target};
pub use rls_vfs::Vfs;

Expand Down
2 changes: 1 addition & 1 deletion rls/src/project_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub struct Dep {
}

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

0 comments on commit d42a6a7

Please sign in to comment.