Skip to content

Commit

Permalink
[rust] upgrade to 1.51
Browse files Browse the repository at this point in the history
Upgrading Rust to 1.51 brings about the new resolver, along with a
number of lint changes.

Will switch over to the new resolver, and cleanup our current v2
resolver code, in a future PR.

Closes: diem#8017
  • Loading branch information
sunshowers authored and bors-libra committed Mar 25, 2021
1 parent 4aeb878 commit e34693b
Show file tree
Hide file tree
Showing 65 changed files with 176 additions and 189 deletions.
2 changes: 1 addition & 1 deletion common/bounded-executor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ mod test {
if completed == NUM_TASKS {
break;
} else {
::std::sync::atomic::spin_loop_hint();
std::hint::spin_loop()
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion common/logger/tests/derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ fn error_trait_object() {
}
}

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

let debug_error = ::std::io::Error::new(::std::io::ErrorKind::Other, "This is an error");
let display_error = OurError;
Expand Down
8 changes: 6 additions & 2 deletions config/management/genesis/src/swarm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ use anyhow::Result;
use diem_config::config::NodeConfig;
use diem_crypto::ed25519::Ed25519PrivateKey;
use diem_types::waypoint::Waypoint;
use std::{fs::File, io::Write, path::PathBuf};
use std::{
fs::File,
io::Write,
path::{Path, PathBuf},
};

pub trait BuildSwarm {
/// Generate the configs for a swarm
Expand All @@ -19,7 +23,7 @@ pub struct SwarmConfig {
}

impl SwarmConfig {
pub fn build<T: BuildSwarm>(config_builder: &T, output_dir: &PathBuf) -> Result<Self> {
pub fn build<T: BuildSwarm>(config_builder: &T, output_dir: &Path) -> Result<Self> {
let (mut configs, diem_root_key) = config_builder.build_swarm()?;
let mut config_files = vec![];

Expand Down
4 changes: 2 additions & 2 deletions config/management/genesis/src/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ fn write_waypoint(storage: &Storage, buffer: &mut String, key: &'static str) {
fn compare_genesis(
storage: Storage,
buffer: &mut String,
genesis_path: &PathBuf,
genesis_path: &Path,
) -> Result<(), Error> {
// Compute genesis and waypoint and compare to given waypoint
let db_path = TempPath::new();
Expand Down Expand Up @@ -203,7 +203,7 @@ fn compare_genesis(
/// Compute the ledger given a genesis writeset transaction and return access to that ledger and
/// the waypoint for that state.
fn compute_genesis(
genesis_path: &PathBuf,
genesis_path: &Path,
db_path: &Path,
) -> Result<(DbReaderWriter, Waypoint), Error> {
let diemdb = DiemDB::open(db_path, false, None, RocksdbConfig::default())
Expand Down
8 changes: 6 additions & 2 deletions config/management/operational/src/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@

use diem_management::{config::ConfigPath, error::Error, secure_backend::ValidatorBackend};
use serde::Serialize;
use std::{fs::File, io::Write, path::PathBuf};
use std::{
fs::File,
io::Write,
path::{Path, PathBuf},
};
use structopt::StructOpt;

#[derive(Debug, StructOpt)]
Expand Down Expand Up @@ -60,7 +64,7 @@ impl ExtractPrivateKey {
}
}

fn save_key<T: Serialize>(key: &T, key_name: &'static str, path: &PathBuf) -> Result<(), Error> {
fn save_key<T: Serialize>(key: &T, key_name: &'static str, path: &Path) -> Result<(), Error> {
let encoded = bcs::to_bytes(key).map_err(|e| Error::BCS(key_name.to_string(), e))?;
let mut file = File::create(path).map_err(|e| Error::IO(key_name.to_string(), e))?;
file.write_all(&encoded)
Expand Down
4 changes: 2 additions & 2 deletions config/management/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{error::Error, storage::StorageWrapper};
use diem_config::config;
use diem_types::chain_id::{self, ChainId};
use serde::{Deserialize, Serialize};
use std::path::PathBuf;
use std::path::{Path, PathBuf};
use structopt::StructOpt;

/// A config file for working with management tooling.
Expand Down Expand Up @@ -75,7 +75,7 @@ impl Default for Config {
}

impl Config {
pub fn load(path: &PathBuf) -> Result<Config, Error> {
pub fn load(path: &Path) -> Result<Config, Error> {
let reader = std::fs::File::open(path).map_err(|e| Error::ConfigError(e.to_string()))?;
serde_yaml::from_reader(reader).map_err(|e| Error::ConfigError(e.to_string()))
}
Expand Down
4 changes: 2 additions & 2 deletions config/management/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ macro_rules! execute_command {
}

use diem_crypto::ed25519::Ed25519PublicKey;
use std::{convert::TryInto, fs, path::PathBuf};
use std::{convert::TryInto, fs, path::Path};

/// Reads a given ed25519 public key from file. Attempts to read the key using
/// bcs encoding first. If this fails, attempts reading the key using hex.
pub fn read_key_from_file(path: &PathBuf) -> Result<Ed25519PublicKey, String> {
pub fn read_key_from_file(path: &Path) -> Result<Ed25519PublicKey, String> {
let bcs_bytes = fs::read(path).map_err(|e| e.to_string())?;
if let Ok(key) = bcs::from_bytes(&bcs_bytes) {
Ok(key)
Expand Down
5 changes: 2 additions & 3 deletions config/management/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,9 @@ impl StorageWrapper {
&self,
key_name: &'static str,
) -> Result<Ed25519PublicKey, Error> {
Ok(self
.storage
self.storage
.get_public_key_previous_version(key_name)
.map_err(|e| Error::StorageReadError(self.storage_name, key_name, e.to_string()))?)
.map_err(|e| Error::StorageReadError(self.storage_name, key_name, e.to_string()))
}

/// Retrieves public key from the stored private key
Expand Down
8 changes: 4 additions & 4 deletions config/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ impl fmt::Display for RoleType {
pub struct ParseRoleError(String);

impl NodeConfig {
pub fn data_dir(&self) -> &PathBuf {
pub fn data_dir(&self) -> &Path {
&self.base.data_dir
}

Expand All @@ -233,7 +233,7 @@ impl NodeConfig {
config.execution.load(&input_dir)?;

let mut config = config.validate_network_configs()?;
config.set_data_dir(config.data_dir().clone());
config.set_data_dir(config.data_dir().to_path_buf());
Ok(config)
}

Expand Down Expand Up @@ -414,11 +414,11 @@ impl RootPath {
}

/// This adds a full path when loading / storing if one is not specified
pub fn full_path(&self, file_path: &PathBuf) -> PathBuf {
pub fn full_path(&self, file_path: &Path) -> PathBuf {
if file_path.is_relative() {
self.root_path.join(file_path)
} else {
file_path.clone()
file_path.to_path_buf()
}
}
}
Expand Down
8 changes: 6 additions & 2 deletions config/src/config/secure_backend_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ use diem_secure_storage::{
GitHubStorage, InMemoryStorage, NamespacedStorage, OnDiskStorage, Storage, VaultStorage,
};
use serde::{Deserialize, Serialize};
use std::{fs::File, io::Read, path::PathBuf};
use std::{
fs::File,
io::Read,
path::{Path, PathBuf},
};

#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
#[serde(rename_all = "snake_case", tag = "type")]
Expand Down Expand Up @@ -136,7 +140,7 @@ impl OnDiskStorageConfig {
}
}

fn read_file(path: &PathBuf) -> Result<String, Error> {
fn read_file(path: &Path) -> Result<String, Error> {
let mut file =
File::open(path).map_err(|e| Error::IO(path.to_str().unwrap().to_string(), e))?;
let mut contents = String::new();
Expand Down
2 changes: 1 addition & 1 deletion consensus/consensus-types/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ impl<'de> Deserialize<'de> for Block {
struct BlockWithoutId {
block_data: BlockData,
signature: Option<Ed25519Signature>,
};
}

let BlockWithoutId {
block_data,
Expand Down
2 changes: 1 addition & 1 deletion consensus/src/block_storage/block_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,6 @@ impl BlockStore {
/// Helper function to insert the block with the qc together
pub fn insert_block_with_qc(&self, block: Block) -> anyhow::Result<Arc<ExecutedBlock>> {
self.insert_single_quorum_cert(block.quorum_cert().clone())?;
Ok(self.execute_and_insert_block(block)?)
self.execute_and_insert_block(block)
}
}
4 changes: 2 additions & 2 deletions consensus/src/consensusdb/schema/single_entry/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ impl KeyCodec<SingleEntrySchema> for SingleEntryKey {
.ok_or_else(|| format_err!("ToPrimitive failed."))?])
}

fn decode_key(data: &[u8]) -> Result<Self> {
fn decode_key(mut data: &[u8]) -> Result<Self> {
ensure_slice_len_eq(data, size_of::<u8>())?;
let key = (&data[..]).read_u8()?;
let key = data.read_u8()?;
SingleEntryKey::from_u8(key).ok_or_else(|| format_err!("FromPrimitive failed."))
}
}
Expand Down
2 changes: 1 addition & 1 deletion consensus/src/round_manager_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,7 @@ fn safety_rules_crash() {
let safety_rules =
MetricsSafetyRules::new(node.safety_rules_manager.client(), node.storage.clone());
node.round_manager.set_safety_rules(safety_rules);
};
}

timed_block_on(&mut runtime, async {
for _ in 0..2 {
Expand Down
2 changes: 1 addition & 1 deletion devtools/x-lint/src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl<'l> ProjectContext<'l> {

/// Returns the package graph, computing it for the first time if necessary.
pub fn package_graph(&self) -> Result<&'l PackageGraph> {
Ok(self.core.package_graph()?)
self.core.package_graph()
}

/// Returns the absolute path from the project root.
Expand Down
2 changes: 1 addition & 1 deletion devtools/x/src/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub struct Args {

pub fn run(args: Args, xctx: XContext) -> Result<()> {
// Hardcode that we want imports merged
let mut pass_through_args = vec!["--config".into(), "merge_imports=true".into()];
let mut pass_through_args = vec!["--config".into(), "imports_granularity=crate".into()];

if args.check {
pass_through_args.push("--check".into());
Expand Down
8 changes: 4 additions & 4 deletions devtools/x/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use log::info;
use std::{
ffi::OsString,
fs::create_dir_all,
path::PathBuf,
path::{Path, PathBuf},
process::{Command, Stdio},
};
use structopt::StructOpt;
Expand Down Expand Up @@ -121,7 +121,7 @@ pub fn run(mut args: Args, xctx: XContext) -> Result<()> {
cmd_result
}

fn exec_lcov_genhtml(html_lcov_path: &PathBuf) -> Result<()> {
fn exec_lcov_genhtml(html_lcov_path: &Path) -> Result<()> {
let mut genhtml = Command::new("genhtml");
let mut lcov_file_path = PathBuf::new();
lcov_file_path.push(html_lcov_path);
Expand All @@ -148,7 +148,7 @@ fn exec_lcov_genhtml(html_lcov_path: &PathBuf) -> Result<()> {
}
}

fn exec_lcov(html_lcov_path: &PathBuf) -> Result<()> {
fn exec_lcov(html_lcov_path: &Path) -> Result<()> {
let debug_dir = project_root().join("target/debug/");
let mut lcov_file_path = PathBuf::new();
lcov_file_path.push(html_lcov_path);
Expand Down Expand Up @@ -186,7 +186,7 @@ fn exec_lcov(html_lcov_path: &PathBuf) -> Result<()> {
}
}

fn exec_grcov(html_cov_path: &PathBuf) -> Result<()> {
fn exec_grcov(html_cov_path: &Path) -> Result<()> {
let debug_dir = project_root().join("target/debug/");
let mut grcov_html = Command::new("grcov");
grcov_html
Expand Down
8 changes: 6 additions & 2 deletions execution/db-bootstrapper/src/bin/db-bootstrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ use diem_types::{transaction::Transaction, waypoint::Waypoint};
use diem_vm::DiemVM;
use diemdb::DiemDB;
use executor::db_bootstrapper::calculate_genesis;
use std::{fs::File, io::Read, path::PathBuf};
use std::{
fs::File,
io::Read,
path::{Path, PathBuf},
};
use storage_interface::DbReaderWriter;
use structopt::StructOpt;

Expand Down Expand Up @@ -103,7 +107,7 @@ fn main() -> Result<()> {
Ok(())
}

fn load_genesis_txn(path: &PathBuf) -> Result<Transaction> {
fn load_genesis_txn(path: &Path) -> Result<Transaction> {
let mut file = File::open(&path)?;
let mut buffer = vec![];
file.read_to_end(&mut buffer)?;
Expand Down
17 changes: 6 additions & 11 deletions json-rpc/src/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ impl JsonRpcRequest {
T: TryFrom<String>,
{
let raw_str: String = self.parse_param(index, name)?;
Ok(T::try_from(raw_str).map_err(|_| invalid_param(index, name))?)
T::try_from(raw_str).map_err(|_| invalid_param(index, name))
}

/// Return native type of params[index] deserialized by from json value.
Expand All @@ -179,10 +179,7 @@ impl JsonRpcRequest {
where
T: DeserializeOwned,
{
Ok(
serde_json::from_value(self.get_param(index))
.map_err(|_| invalid_param(index, name))?,
)
serde_json::from_value(self.get_param(index)).map_err(|_| invalid_param(index, name))
}

fn parse_version_param(&self, index: usize, name: &str) -> Result<u64, JsonRpcError> {
Expand All @@ -205,15 +202,13 @@ impl JsonRpcRequest {
index: usize,
name: &str,
) -> Result<SignedTransaction, JsonRpcError> {
Ok(self
._parse_signed_transaction(self.get_param(index))
.map_err(|_| invalid_param(index, name))?)
self._parse_signed_transaction(self.get_param(index))
.map_err(|_| invalid_param(index, name))
}

fn parse_event_key(&self, index: usize, name: &str) -> Result<EventKey, JsonRpcError> {
Ok(self
._parse_event_key(self.get_param(index))
.map_err(|_| invalid_param(index, name))?)
self._parse_event_key(self.get_param(index))
.map_err(|_| invalid_param(index, name))
}

// the following methods should not be called directly as they return error causes internal error
Expand Down
2 changes: 1 addition & 1 deletion json-rpc/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ pub fn script_view_from_script(script: &Script) -> ScriptView {
// handle legacy fields, backward compatible
if name == "peer_to_peer_with_metadata" {
if let [TransactionArgument::Address(receiver), TransactionArgument::U64(amount), TransactionArgument::U8Vector(metadata), TransactionArgument::U8Vector(metadata_signature)] =
&script.args()[..]
script.args()
{
view.receiver = Some(*receiver);
view.amount = Some(*amount);
Expand Down
2 changes: 1 addition & 1 deletion language/compiler/ir-to-bytecode/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ impl<'a> Context<'a> {

/// Get the fake offset for the label. Labels will be fixed to real offsets after compilation
pub fn label_index(&mut self, label: BlockLabel) -> Result<CodeOffset> {
Ok(get_or_add_item(&mut self.labels, label)?)
get_or_add_item(&mut self.labels, label)
}

/// Get the identifier pool index, adds it if missing.
Expand Down
2 changes: 1 addition & 1 deletion language/compiler/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ fn do_verify_module(module: CompiledModule, dependencies: &[CompiledModule]) ->
module
}

fn write_output(path: &PathBuf, buf: &[u8]) {
fn write_output(path: &Path, buf: &[u8]) {
let mut f = fs::File::create(path)
.with_context(|| format!("Unable to open output file {:?}", path))
.unwrap();
Expand Down
2 changes: 1 addition & 1 deletion language/diem-framework/src/release.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ pub fn generate_script_builder(

std::process::Command::new("rustfmt")
.arg("--config")
.arg("merge_imports=true")
.arg("imports_granularity=crate")
.arg(output_path)
.status()
.expect("Failed to run rustfmt on generated code");
Expand Down
5 changes: 2 additions & 3 deletions language/diem-tools/transaction-replay/src/unit_tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,10 @@ impl DiemValidatorInterface for TestInterface {
account: AccountAddress,
version: Version,
) -> Result<Option<AccountState>> {
Ok(self
.state_db
self.state_db
.get(&(version, account))
.map(AccountState::try_from)
.transpose()?)
.transpose()
}

fn get_committed_transactions(&self, start: Version, limit: u64) -> Result<Vec<Transaction>> {
Expand Down
Loading

0 comments on commit e34693b

Please sign in to comment.