Skip to content

Commit 9eedce5

Browse files
authored
Update rust to 1.65 (move-language#644)
* Update rust to 1.65 - Updated to 1.65.0 - Fixed clippy warnings
1 parent 8cc98cb commit 9eedce5

File tree

57 files changed

+499
-458
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+499
-458
lines changed

devtools/x-core/src/errors.rs

+18-18
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use serde::{de, ser};
88
use std::{borrow::Cow, error, fmt, io, process::ExitStatus, result, str::Utf8Error};
99

1010
/// Type alias for the return type for `run` methods.
11-
pub type Result<T, E = SystemError> = result::Result<T, E>;
11+
pub type Result<T, E = Box<SystemError>> = result::Result<T, E>;
1212

1313
/// A system error that happened while running a lint.
1414
#[derive(Debug)]
@@ -46,49 +46,49 @@ pub enum SystemError {
4646
}
4747

4848
impl SystemError {
49-
pub fn io(context: impl Into<Cow<'static, str>>, err: io::Error) -> Self {
50-
SystemError::Io {
49+
pub fn io(context: impl Into<Cow<'static, str>>, err: io::Error) -> Box<Self> {
50+
Box::new(SystemError::Io {
5151
context: context.into(),
5252
err,
53-
}
53+
})
5454
}
5555

56-
pub fn guppy(context: impl Into<Cow<'static, str>>, err: guppy::Error) -> Self {
57-
SystemError::Guppy {
56+
pub fn guppy(context: impl Into<Cow<'static, str>>, err: guppy::Error) -> Box<Self> {
57+
Box::new(SystemError::Guppy {
5858
context: context.into(),
5959
err,
60-
}
60+
})
6161
}
6262

63-
pub fn git_root(msg: impl Into<Cow<'static, str>>) -> Self {
64-
SystemError::GitRoot(msg.into())
63+
pub fn git_root(msg: impl Into<Cow<'static, str>>) -> Box<Self> {
64+
Box::new(SystemError::GitRoot(msg.into()))
6565
}
6666

67-
pub fn from_hex(context: impl Into<Cow<'static, str>>, err: FromHexError) -> Self {
68-
SystemError::FromHex {
67+
pub fn from_hex(context: impl Into<Cow<'static, str>>, err: FromHexError) -> Box<Self> {
68+
Box::new(SystemError::FromHex {
6969
context: context.into(),
7070
err,
71-
}
71+
})
7272
}
7373

7474
pub fn de(
7575
context: impl Into<Cow<'static, str>>,
7676
err: impl de::Error + Send + Sync + 'static,
77-
) -> Self {
78-
SystemError::Serde {
77+
) -> Box<Self> {
78+
Box::new(SystemError::Serde {
7979
context: context.into(),
8080
err: Box::new(err),
81-
}
81+
})
8282
}
8383

8484
pub fn ser(
8585
context: impl Into<Cow<'static, str>>,
8686
err: impl ser::Error + Send + Sync + 'static,
87-
) -> Self {
88-
SystemError::Serde {
87+
) -> Box<Self> {
88+
Box::new(SystemError::Serde {
8989
context: context.into(),
9090
err: Box::new(err),
91-
}
91+
})
9292
}
9393
}
9494

devtools/x-core/src/git.rs

+22-22
Original file line numberDiff line numberDiff line change
@@ -48,35 +48,35 @@ impl GitCli {
4848
let output = self
4949
.git_command()
5050
// The -z causes files to not be quoted, and to be separated by \0.
51-
.args(&["ls-files", "-z"])
51+
.args(["ls-files", "-z"])
5252
.output()
5353
.map_err(|err| SystemError::io("running git ls-files", err))?;
5454
if !output.status.success() {
55-
return Err(SystemError::Exec {
55+
return Err(Box::new(SystemError::Exec {
5656
cmd: "git ls-files",
5757
status: output.status,
58-
});
58+
}));
5959
}
6060

6161
Utf8Paths0::from_bytes(output.stdout)
62-
.map_err(|(path, err)| SystemError::NonUtf8Path { path, err })
62+
.map_err(|(path, err)| Box::new(SystemError::NonUtf8Path { path, err }))
6363
})
6464
}
6565

6666
/// Returns the merge base of the current commit (`HEAD`) with the specified commit.
6767
pub fn merge_base(&self, commit_ref: &str) -> Result<GitHash> {
6868
let output = self
6969
.git_command()
70-
.args(&["merge-base", "HEAD", commit_ref])
70+
.args(["merge-base", "HEAD", commit_ref])
7171
.output()
7272
.map_err(|err| {
7373
SystemError::io(format!("running git merge-base HEAD {}", commit_ref), err)
7474
})?;
7575
if !output.status.success() {
76-
return Err(SystemError::Exec {
76+
return Err(Box::new(SystemError::Exec {
7777
cmd: "git merge-base",
7878
status: output.status,
79-
});
79+
}));
8080
}
8181

8282
// The output is a hex-encoded hash followed by a newline.
@@ -96,7 +96,7 @@ impl GitCli {
9696
diff_filter: Option<&str>,
9797
) -> Result<Utf8Paths0> {
9898
let mut command = self.git_command();
99-
command.args(&["diff", "-z", "--name-only"]);
99+
command.args(["diff", "-z", "--name-only"]);
100100
if let Some(diff_filter) = diff_filter {
101101
command.arg(format!("--diff-filter={}", diff_filter));
102102
}
@@ -109,14 +109,14 @@ impl GitCli {
109109
.output()
110110
.map_err(|err| SystemError::io("running git diff", err))?;
111111
if !output.status.success() {
112-
return Err(SystemError::Exec {
112+
return Err(Box::new(SystemError::Exec {
113113
cmd: "git diff",
114114
status: output.status,
115-
});
115+
}));
116116
}
117117

118118
Utf8Paths0::from_bytes(output.stdout)
119-
.map_err(|(path, err)| SystemError::NonUtf8Path { path, err })
119+
.map_err(|(path, err)| Box::new(SystemError::NonUtf8Path { path, err }))
120120
}
121121

122122
/// Returns a package graph for the given commit, using a scratch repo if necessary.
@@ -139,7 +139,7 @@ impl GitCli {
139139
// Check that the project root and the Git root match.
140140
let output = self
141141
.git_command()
142-
.args(&["rev-parse", "--show-toplevel"])
142+
.args(["rev-parse", "--show-toplevel"])
143143
.stderr(Stdio::inherit())
144144
.output()
145145
.map_err(|err| SystemError::io("running git rev-parse --show-toplevel", err))?;
@@ -189,7 +189,7 @@ impl GitCli {
189189
/// performance reasons.
190190
fn get_or_init_scratch(&self, hash: &GitHash) -> Result<Utf8PathBuf> {
191191
let mut scratch_dir = self.root.join("target");
192-
scratch_dir.extend(&["x-scratch", "tree"]);
192+
scratch_dir.extend(["x-scratch", "tree"]);
193193

194194
if scratch_dir.is_dir() && self.is_git_repo(&scratch_dir)? {
195195
debug!("Using existing scratch worktree at {}", scratch_dir,);
@@ -199,14 +199,14 @@ impl GitCli {
199199
.git_command()
200200
.current_dir(&scratch_dir)
201201
// TODO: also git clean?
202-
.args(&["reset", &format!("{:x}", hash), "--hard"])
202+
.args(["reset", &format!("{:x}", hash), "--hard"])
203203
.output()
204204
.map_err(|err| SystemError::io("running git checkout in scratch tree", err))?;
205205
if !output.status.success() {
206-
return Err(SystemError::Exec {
206+
return Err(Box::new(SystemError::Exec {
207207
cmd: "git checkout",
208208
status: output.status,
209-
});
209+
}));
210210
}
211211
} else {
212212
if scratch_dir.is_dir() {
@@ -218,16 +218,16 @@ impl GitCli {
218218
info!("Setting up scratch worktree in {}", scratch_dir);
219219
let output = self
220220
.git_command()
221-
.args(&["worktree", "add"])
221+
.args(["worktree", "add"])
222222
.arg(&scratch_dir)
223-
.args(&[&format!("{:x}", hash), "--detach"])
223+
.args([&format!("{:x}", hash), "--detach"])
224224
.output()
225225
.map_err(|err| SystemError::io("running git worktree add", err))?;
226226
if !output.status.success() {
227-
return Err(SystemError::Exec {
227+
return Err(Box::new(SystemError::Exec {
228228
cmd: "git worktree add",
229229
status: output.status,
230-
});
230+
}));
231231
}
232232
}
233233

@@ -240,7 +240,7 @@ impl GitCli {
240240
let output = self
241241
.git_command()
242242
.current_dir(dir)
243-
.args(&["rev-parse", "--git-dir"])
243+
.args(["rev-parse", "--git-dir"])
244244
.output()
245245
.map_err(|err| SystemError::io("checking if a directory is a git repo", err))?;
246246

@@ -270,6 +270,6 @@ impl<'a, 'b> From<&'a GitHash> for Cow<'b, OsStr> {
270270

271271
impl fmt::LowerHex for GitHash {
272272
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
273-
write!(f, "{}", hex::encode(&self.0))
273+
write!(f, "{}", hex::encode(self.0))
274274
}
275275
}

devtools/x-core/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ impl XCoreContext {
3939
let current_rel_dir = match current_dir.strip_prefix(project_root) {
4040
Ok(rel_dir) => rel_dir.to_path_buf(),
4141
Err(_) => {
42-
return Err(SystemError::CwdNotInProjectRoot {
42+
return Err(Box::new(SystemError::CwdNotInProjectRoot {
4343
current_dir,
4444
project_root,
45-
})
45+
}))
4646
}
4747
};
4848
// TODO: The project root should be managed by this struct, not by the global project_root

devtools/x-core/src/workspace_subset.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ impl<'g> WorkspaceSubsets<'g> {
6363
WorkspaceSubset::new(&initial_packages, StandardFeatures::Default, &cargo_opts);
6464
Ok((name.clone(), subset))
6565
})
66-
.collect::<Result<_, _>>()?;
66+
.collect::<Result<_>>()?;
6767

6868
Ok(Self {
6969
default_members,

devtools/x/src/cargo.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,13 @@ impl Cargo {
104104
SelectedInclude::Workspace => {
105105
self.inner.arg("--workspace");
106106
for &e in &packages.excludes {
107-
self.inner.args(&["--exclude", e]);
107+
self.inner.args(["--exclude", e]);
108108
}
109109
}
110110
SelectedInclude::Includes(includes) => {
111111
for &p in includes {
112112
if !packages.excludes.contains(p) {
113-
self.inner.args(&["--package", p]);
113+
self.inner.args(["--package", p]);
114114
}
115115
}
116116
}
@@ -326,7 +326,7 @@ impl<'a> CargoCommand<'a> {
326326
Ok(vec![])
327327
} else {
328328
let mut cargo = self.prepare_cargo(packages);
329-
cargo.args(&["--message-format", "json-render-diagnostics"]);
329+
cargo.args(["--message-format", "json-render-diagnostics"]);
330330
Ok(cargo.run_with_output()?)
331331
}
332332
}

devtools/x/src/installer.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ impl Installer {
9090

9191
pub fn install_rustup_component_if_needed(name: &str) -> bool {
9292
let mut cmd = Command::new("rustup");
93-
cmd.args(&["component", "list", "--installed"]);
93+
cmd.args(["component", "list", "--installed"]);
9494
let result = cmd.output();
9595

9696
let installed = if let Ok(output) = result {
@@ -103,7 +103,7 @@ pub fn install_rustup_component_if_needed(name: &str) -> bool {
103103
if !installed {
104104
info!("installing rustup component: {}", name);
105105
let mut cmd = Command::new("rustup");
106-
cmd.args(&["component", "add", name]);
106+
cmd.args(["component", "add", name]);
107107
if cmd.output().is_ok() {
108108
info!("rustup component {} has been installed", name);
109109
} else {

devtools/x/src/test.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,13 @@ pub fn run(mut args: Args, xctx: XContext) -> Result<()> {
146146
}
147147

148148
if let Some(html_cov_dir) = &args.html_cov_dir {
149-
create_dir_all(&html_cov_dir)?;
149+
create_dir_all(html_cov_dir)?;
150150
let html_cov_path = &html_cov_dir.canonicalize()?;
151151
info!("created {}", &html_cov_path.to_string_lossy());
152152
exec_grcov(html_cov_path, llvm_profile_path)?;
153153
}
154154
if let Some(html_lcov_dir) = &args.html_lcov_dir {
155-
create_dir_all(&html_lcov_dir)?;
155+
create_dir_all(html_lcov_dir)?;
156156
let html_lcov_path = &html_lcov_dir.canonicalize()?;
157157
info!("created {}", &html_lcov_path.to_string_lossy());
158158
exec_lcov(html_lcov_path, llvm_profile_path)?;

language/documentation/examples/diem-framework/crates/crypto/src/ed25519.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ impl Ed25519PublicKey {
161161
bits
162162
};
163163
let mtg_point = curve25519_dalek::montgomery::MontgomeryPoint(key_bits);
164-
let sign = if negative { 1u8 } else { 0u8 };
164+
let sign = u8::from(negative);
165165
let ed_point = mtg_point
166166
.to_edwards(sign)
167167
.ok_or(CryptoMaterialError::DeserializationError)?;
@@ -341,7 +341,7 @@ impl VerifyingKey for Ed25519PublicKey {
341341

342342
impl fmt::Display for Ed25519PublicKey {
343343
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
344-
write!(f, "{}", hex::encode(&self.0.as_bytes()))
344+
write!(f, "{}", hex::encode(self.0.as_bytes()))
345345
}
346346
}
347347

language/documentation/examples/diem-framework/crates/crypto/src/unit_tests/ed25519_test.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,9 @@ proptest! {
100100
// Compute k = H(R∥A∥m) //
101101
//////////////////////////
102102
let mut h: Sha512 = Sha512::default();
103-
h.update(&mixed_r_point.compress().to_bytes());
104-
h.update(&mixed_pub_point.compress().to_bytes());
105-
h.update(&message);
103+
h.update(mixed_r_point.compress().to_bytes());
104+
h.update(mixed_pub_point.compress().to_bytes());
105+
h.update(message);
106106
// curve25519_dalek is stuck on an old digest version, so we can't do
107107
// Scalar::from_hash
108108
let mut output = [0u8; 64];
@@ -120,7 +120,7 @@ proptest! {
120120
let nonce = &expanded_priv_key[32..];
121121
let mut h: Sha512 = Sha512::default();
122122
h.update(nonce);
123-
h.update(&message);
123+
h.update(message);
124124
// curve25519_dalek is stuck on an old digest version, so we can't do
125125
// Scalar::from_hash
126126
let mut output = [0u8; 64];

language/documentation/examples/diem-framework/crates/crypto/src/unit_tests/hkdf_test.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ use sha2::{Sha256, Sha512};
1111
fn test_sha256_test_vectors() {
1212
let tests = test_vectors_sha256();
1313
for t in tests.iter() {
14-
let ikm = hex::decode(&t.ikm).unwrap();
15-
let salt = hex::decode(&t.salt).unwrap();
16-
let info = hex::decode(&t.info).unwrap();
14+
let ikm = hex::decode(t.ikm).unwrap();
15+
let salt = hex::decode(t.salt).unwrap();
16+
let info = hex::decode(t.info).unwrap();
1717

1818
let hkdf_extract = Hkdf::<Sha256>::extract(Option::from(&salt[..]), &ikm[..]).unwrap();
1919
let hkdf_expand = Hkdf::<Sha256>::expand(&hkdf_extract, Some(&info[..]), t.length);
@@ -29,9 +29,9 @@ fn test_sha256_test_vectors() {
2929
fn test_extract_then_expand() {
3030
let tests = test_vectors_sha256();
3131
for t in tests.iter() {
32-
let ikm = hex::decode(&t.ikm).unwrap();
33-
let salt = hex::decode(&t.salt).unwrap();
34-
let info = hex::decode(&t.info).unwrap();
32+
let ikm = hex::decode(t.ikm).unwrap();
33+
let salt = hex::decode(t.salt).unwrap();
34+
let info = hex::decode(t.info).unwrap();
3535

3636
let hkdf_full = Hkdf::<Sha256>::extract_then_expand(
3737
Option::from(&salt[..]),

language/documentation/examples/diem-framework/crates/crypto/src/validatable.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ impl Serialize for UnvalidatedEd25519PublicKey {
158158
S: serde::Serializer,
159159
{
160160
if serializer.is_human_readable() {
161-
let encoded = ::hex::encode(&self.0);
161+
let encoded = ::hex::encode(self.0);
162162
serializer.serialize_str(&encoded)
163163
} else {
164164
// See comment in deserialize_key.

language/documentation/examples/diem-framework/crates/crypto/src/x25519.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ impl traits::ValidCryptoMaterial for PublicKey {
250250

251251
impl std::fmt::Display for PublicKey {
252252
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
253-
write!(f, "{}", hex::encode(&self.0))
253+
write!(f, "{}", hex::encode(self.0))
254254
}
255255
}
256256

language/evm/exec-utils/src/compile.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,6 @@ pub fn solc_yul(source: &str, return_optimized_yul: bool) -> Result<(Vec<u8>, Op
121121
} else {
122122
None
123123
};
124-
let bin = hex::decode(&out_str[(start_of_hex.unwrap() + HEX_OUTPUT_MARKER.len())..].trim())?;
124+
let bin = hex::decode(out_str[(start_of_hex.unwrap() + HEX_OUTPUT_MARKER.len())..].trim())?;
125125
Ok((bin, yul))
126126
}

0 commit comments

Comments
 (0)