From 8d22e85e48bf46b3056b8e0173940a8bb4f69c31 Mon Sep 17 00:00:00 2001 From: topecongiro Date: Wed, 5 Apr 2017 06:28:47 +0900 Subject: [PATCH] Lookup the last element of 'subexpr_list' instead of the first one Closes #1217, #1236, #1389 and #1434. --- src/bin/cargo-fmt.rs | 3 ++- src/chains.rs | 2 +- tests/source/chains-visual.rs | 29 +++++++++++++++++++++++++++++ tests/target/chains-visual.rs | 34 ++++++++++++++++++++++++++++++++++ 4 files changed, 66 insertions(+), 2 deletions(-) diff --git a/src/bin/cargo-fmt.rs b/src/bin/cargo-fmt.rs index 0fcd0fd3f2d..ea747aa4702 100644 --- a/src/bin/cargo-fmt.rs +++ b/src/bin/cargo-fmt.rs @@ -199,7 +199,8 @@ fn get_targets(workspace_hitlist: WorkspaceHitlist) -> Result, std:: // is used inside a workspace. // To ensure backward compatability, we only use `cargo metadata` for workspaces. // TODO: Is it possible only use metadata or read-manifest - let output = Command::new("cargo").arg("metadata") + let output = Command::new("cargo") + .arg("metadata") .arg("--no-deps") .output()?; if output.status.success() { diff --git a/src/chains.rs b/src/chains.rs index 23085bb66e2..970278d12a1 100644 --- a/src/chains.rs +++ b/src/chains.rs @@ -217,7 +217,7 @@ pub fn rewrite_chain(expr: &ast::Expr, context: &RewriteContext, shape: Shape) - let first_connector = if extend || subexpr_list.is_empty() { "" - } else if let ast::ExprKind::Try(_) = subexpr_list[0].node { + } else if let ast::ExprKind::Try(_) = subexpr_list.last().unwrap().node { "" } else { &*connector diff --git a/tests/source/chains-visual.rs b/tests/source/chains-visual.rs index f0be8acdce9..198691d82b5 100644 --- a/tests/source/chains-visual.rs +++ b/tests/source/chains-visual.rs @@ -115,3 +115,32 @@ fn issue587() { std::mem::transmute(dl.symbol::<()>("init").unwrap()) } + +fn issue_1389() { + let names = String::from_utf8(names)?.split('|').map(str::to_owned).collect(); +} + +fn issue1217() -> Result { +let random_chars: String = OsRng::new()? + .gen_ascii_chars() + .take(self.bit_length) + .collect(); + + Ok(Mnemonic::new(&random_chars)) +} + +fn issue1236(options: Vec) -> Result> { +let process = Command::new("dmenu").stdin(Stdio::piped()) + .stdout(Stdio::piped()) + .spawn() + .chain_err(|| "failed to spawn dmenu")?; +} + +fn issue1434() { + for _ in 0..100 { + let prototype_id = PrototypeIdData::from_reader::<_, B>(&mut self.file_cursor).chain_err(|| { + format!("could not read prototype ID at offset {:#010x}", + current_offset) + })?; + } +} diff --git a/tests/target/chains-visual.rs b/tests/target/chains-visual.rs index 2795237d51b..2763b339084 100644 --- a/tests/target/chains-visual.rs +++ b/tests/target/chains-visual.rs @@ -134,3 +134,37 @@ fn issue587() { std::mem::transmute(dl.symbol::<()>("init").unwrap()) } + +fn issue_1389() { + let names = String::from_utf8(names)? + .split('|') + .map(str::to_owned) + .collect(); +} + +fn issue1217() -> Result { + let random_chars: String = OsRng::new()? + .gen_ascii_chars() + .take(self.bit_length) + .collect(); + + Ok(Mnemonic::new(&random_chars)) +} + +fn issue1236(options: Vec) -> Result> { + let process = Command::new("dmenu") + .stdin(Stdio::piped()) + .stdout(Stdio::piped()) + .spawn() + .chain_err(|| "failed to spawn dmenu")?; +} + +fn issue1434() { + for _ in 0..100 { + let prototype_id = PrototypeIdData::from_reader::<_, B>(&mut self.file_cursor) + .chain_err(|| { + format!("could not read prototype ID at offset {:#010x}", + current_offset) + })?; + } +}