Skip to content

Commit 060016e

Browse files
authored
rust: 1.77.0 (#10856)
Release notes: https://blog.rust-lang.org/2024/03/21/Rust-1.77.0.html With split_last_chunk bunch of stdx code can now be deleted. \o/ As for other changes: - Rust now doesn’t consider Clone and Debug derives as using fields of a type. This lead to a handful of dead_code warnings. I’ve fixed them by either removing offending type or adding `allow(dead_code)`. - Cargo package id format has been stabilised¹ and krates crate stopped working. Why do we care about that crate? It’s a dependency of cargo-deny. To have CI pass I’ve updated taiki-e/install-action so that it fetches the newest cargo-deny. ¹ rust-lang/cargo#12914
1 parent 73b8827 commit 060016e

File tree

15 files changed

+48
-98
lines changed

15 files changed

+48
-98
lines changed

.github/workflows/ci.yml

+17-17
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ jobs:
5454
- uses: actions/checkout@v4
5555

5656
# Install all the required tools
57-
- uses: taiki-e/install-action@91af8c38814c3998cb755869e5cbeffd3ab0e462
57+
- uses: taiki-e/install-action@9b5b983efc779f85e5e5d11539f005e85ccb27ff
5858
with:
5959
tool: just,cargo-nextest,cargo-llvm-cov
6060

@@ -107,7 +107,7 @@ jobs:
107107
with:
108108
python-version: 3.11
109109
cache: pip
110-
- uses: taiki-e/install-action@91af8c38814c3998cb755869e5cbeffd3ab0e462
110+
- uses: taiki-e/install-action@9b5b983efc779f85e5e5d11539f005e85ccb27ff
111111
with:
112112
tool: cargo-llvm-cov
113113
- run: pip3 install --user -r pytest/requirements.txt
@@ -133,7 +133,7 @@ jobs:
133133
with:
134134
python-version: 3.11
135135
cache: pip
136-
- uses: taiki-e/install-action@91af8c38814c3998cb755869e5cbeffd3ab0e462
136+
- uses: taiki-e/install-action@9b5b983efc779f85e5e5d11539f005e85ccb27ff
137137
with:
138138
tool: cargo-llvm-cov
139139
- run: pip3 install --user -r pytest/requirements.txt
@@ -163,7 +163,7 @@ jobs:
163163
with:
164164
python-version: 3.11
165165
cache: pip
166-
- uses: taiki-e/install-action@91af8c38814c3998cb755869e5cbeffd3ab0e462
166+
- uses: taiki-e/install-action@9b5b983efc779f85e5e5d11539f005e85ccb27ff
167167
with:
168168
tool: cargo-llvm-cov
169169
- run: pip3 install --user -r pytest/requirements.txt
@@ -195,7 +195,7 @@ jobs:
195195
with:
196196
python-version: 3.11
197197
cache: pip
198-
- uses: taiki-e/install-action@91af8c38814c3998cb755869e5cbeffd3ab0e462
198+
- uses: taiki-e/install-action@9b5b983efc779f85e5e5d11539f005e85ccb27ff
199199
with:
200200
tool: cargo-llvm-cov
201201
- run: pip3 install --user -r pytest/requirements.txt
@@ -217,7 +217,7 @@ jobs:
217217
runs-on: ubuntu-latest
218218
steps:
219219
- uses: actions/checkout@v4
220-
- uses: taiki-e/install-action@91af8c38814c3998cb755869e5cbeffd3ab0e462
220+
- uses: taiki-e/install-action@9b5b983efc779f85e5e5d11539f005e85ccb27ff
221221
with:
222222
tool: just
223223
- uses: actions/setup-python@v4
@@ -236,7 +236,7 @@ jobs:
236236
with:
237237
python-version: 3.11
238238
cache: pip
239-
- uses: taiki-e/install-action@91af8c38814c3998cb755869e5cbeffd3ab0e462
239+
- uses: taiki-e/install-action@9b5b983efc779f85e5e5d11539f005e85ccb27ff
240240
with:
241241
tool: cargo-llvm-cov
242242
- run: pip3 install --user -r pytest/requirements.txt
@@ -258,7 +258,7 @@ jobs:
258258
runs-on: ubuntu-latest
259259
steps:
260260
- uses: actions/checkout@v4
261-
- uses: taiki-e/install-action@91af8c38814c3998cb755869e5cbeffd3ab0e462
261+
- uses: taiki-e/install-action@9b5b983efc779f85e5e5d11539f005e85ccb27ff
262262
with:
263263
tool: just
264264
- run: just check-rpc-errors-schema
@@ -277,7 +277,7 @@ jobs:
277277
runs-on: ubuntu-latest
278278
steps:
279279
- uses: actions/checkout@v4
280-
- uses: taiki-e/install-action@91af8c38814c3998cb755869e5cbeffd3ab0e462
280+
- uses: taiki-e/install-action@9b5b983efc779f85e5e5d11539f005e85ccb27ff
281281
with:
282282
tool: just
283283
- run: just check-cargo-fmt
@@ -287,7 +287,7 @@ jobs:
287287
runs-on: ubuntu-22.04-8core
288288
steps:
289289
- uses: actions/checkout@v4
290-
- uses: taiki-e/install-action@91af8c38814c3998cb755869e5cbeffd3ab0e462
290+
- uses: taiki-e/install-action@9b5b983efc779f85e5e5d11539f005e85ccb27ff
291291
with:
292292
tool: just
293293
- run: just check-cargo-clippy
@@ -297,7 +297,7 @@ jobs:
297297
runs-on: ubuntu-22.04-8core
298298
steps:
299299
- uses: actions/checkout@v4
300-
- uses: taiki-e/install-action@91af8c38814c3998cb755869e5cbeffd3ab0e462
300+
- uses: taiki-e/install-action@9b5b983efc779f85e5e5d11539f005e85ccb27ff
301301
with:
302302
tool: just
303303
- run: just doctests
@@ -307,7 +307,7 @@ jobs:
307307
runs-on: ubuntu-latest
308308
steps:
309309
- uses: actions/checkout@v4
310-
- uses: taiki-e/install-action@91af8c38814c3998cb755869e5cbeffd3ab0e462
310+
- uses: taiki-e/install-action@9b5b983efc779f85e5e5d11539f005e85ccb27ff
311311
with:
312312
tool: just,cargo-deny
313313
- run: just check-cargo-deny
@@ -317,7 +317,7 @@ jobs:
317317
runs-on: ubuntu-latest
318318
steps:
319319
- uses: actions/checkout@v4
320-
- uses: taiki-e/install-action@91af8c38814c3998cb755869e5cbeffd3ab0e462
320+
- uses: taiki-e/install-action@9b5b983efc779f85e5e5d11539f005e85ccb27ff
321321
with:
322322
tool: just
323323
- run: just check-themis
@@ -327,7 +327,7 @@ jobs:
327327
runs-on: ubuntu-latest
328328
steps:
329329
- uses: actions/checkout@v4
330-
- uses: taiki-e/install-action@91af8c38814c3998cb755869e5cbeffd3ab0e462
330+
- uses: taiki-e/install-action@9b5b983efc779f85e5e5d11539f005e85ccb27ff
331331
with:
332332
tool: just
333333
- run: just check-non-default
@@ -337,7 +337,7 @@ jobs:
337337
runs-on: ubuntu-22.04-8core
338338
steps:
339339
- uses: actions/checkout@v4
340-
- uses: taiki-e/install-action@91af8c38814c3998cb755869e5cbeffd3ab0e462
340+
- uses: taiki-e/install-action@9b5b983efc779f85e5e5d11539f005e85ccb27ff
341341
with:
342342
tool: just,cargo-udeps
343343
- run: just check-cargo-udeps
@@ -347,7 +347,7 @@ jobs:
347347
runs-on: ubuntu-latest
348348
steps:
349349
- uses: actions/checkout@v4
350-
- uses: taiki-e/install-action@91af8c38814c3998cb755869e5cbeffd3ab0e462
350+
- uses: taiki-e/install-action@9b5b983efc779f85e5e5d11539f005e85ccb27ff
351351
with:
352352
tool: cargo-audit
353353
- run: cargo audit -D warnings
@@ -373,7 +373,7 @@ jobs:
373373
with:
374374
name: coverage-profraw
375375
path: coverage/profraw
376-
- uses: taiki-e/install-action@91af8c38814c3998cb755869e5cbeffd3ab0e462
376+
- uses: taiki-e/install-action@9b5b983efc779f85e5e5d11539f005e85ccb27ff
377377
with:
378378
tool: cargo-llvm-cov
379379
- uses: actions/setup-python@v4

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
version = "0.0.0" # managed by cargo-workspaces, see below
33
authors = ["Near Inc <[email protected]>"]
44
edition = "2021"
5-
rust-version = "1.76.0"
5+
rust-version = "1.77.0"
66
repository = "https://github.com/near/nearcore"
77
license = "MIT OR Apache-2.0"
88

chain/chain/src/store.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -2772,8 +2772,7 @@ mod tests {
27722772
let mut chain = get_chain(Clock::real());
27732773
let genesis = chain.get_block_by_height(0).unwrap();
27742774
let signer = Arc::new(create_test_signer("test1"));
2775-
let short_fork =
2776-
vec![TestBlockBuilder::new(Clock::real(), &genesis, signer.clone()).build()];
2775+
let short_fork = [TestBlockBuilder::new(Clock::real(), &genesis, signer.clone()).build()];
27772776
let mut store_update = chain.mut_chain_store().store_update();
27782777
store_update.save_block_header(short_fork[0].header().clone()).unwrap();
27792778
store_update.commit().unwrap();

chain/chain/src/tests/garbage_collection.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@ fn test_fork_far_away_from_epoch_end() {
601601
let max_changes = 1;
602602
let fork_clean_step = 100;
603603
let epoch_length = fork_clean_step + 10;
604-
let simple_chains = vec![
604+
let simple_chains = [
605605
SimpleChain { from: 0, length: 5, is_removed: false },
606606
SimpleChain { from: 5, length: 2, is_removed: true },
607607
// We want the chain to end up exactly at the new epoch start.

chain/client/src/adapter.rs

-24
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,6 @@ use crate::view_client::ViewClientActor;
33
use near_async::actix::AddrWithAutoSpanContextExt;
44
use near_async::messaging::IntoSender;
55
use near_network::client::ClientSenderForNetwork;
6-
use near_network::types::{
7-
PartialEncodedChunkForwardMsg, PartialEncodedChunkRequestMsg, PartialEncodedChunkResponseMsg,
8-
};
9-
use near_primitives::hash::CryptoHash;
10-
use near_primitives::sharding::PartialEncodedChunk;
11-
12-
#[derive(actix::Message, Debug)]
13-
#[rtype(result = "()")]
14-
pub(crate) struct RecvPartialEncodedChunkForward(pub PartialEncodedChunkForwardMsg);
15-
16-
#[derive(actix::Message, Debug)]
17-
#[rtype(result = "()")]
18-
pub(crate) struct RecvPartialEncodedChunk(pub PartialEncodedChunk);
19-
20-
#[derive(actix::Message, Debug)]
21-
#[rtype(result = "()")]
22-
pub(crate) struct RecvPartialEncodedChunkResponse(
23-
pub PartialEncodedChunkResponseMsg,
24-
pub std::time::Instant,
25-
);
26-
27-
#[derive(actix::Message, Debug)]
28-
#[rtype(result = "()")]
29-
pub(crate) struct RecvPartialEncodedChunkRequest(pub PartialEncodedChunkRequestMsg, pub CryptoHash);
306

317
pub fn client_sender_for_network(
328
client_addr: actix::Addr<ClientActor>,

chain/client/src/sync/external.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,11 @@ impl ExternalConnection {
151151
if let Some(parent_dir) = path.parent() {
152152
std::fs::create_dir_all(parent_dir)?;
153153
}
154-
let mut file = std::fs::OpenOptions::new().write(true).create(true).open(&path)?;
154+
let mut file = std::fs::OpenOptions::new()
155+
.write(true)
156+
.create(true)
157+
.truncate(true)
158+
.open(&path)?;
155159
file.write_all(data)?;
156160
tracing::debug!(target: "state_sync_dump", shard_id, part_length = data.len(), ?location, ?file_type, "Wrote a state part to a file");
157161
Ok(())

chain/epoch-manager/src/tests/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2296,7 +2296,7 @@ fn test_protocol_version_switch_with_shard_layout_change() {
22962296
}
22972297
epoch_manager.record_block_info(block_info, [0; 32]).unwrap();
22982298
}
2299-
let epochs = vec![EpochId::default(), EpochId(h[2]), EpochId(h[4])];
2299+
let epochs = [EpochId::default(), EpochId(h[2]), EpochId(h[4])];
23002300
assert_eq!(
23012301
epoch_manager.get_epoch_info(&epochs[1]).unwrap().protocol_version(),
23022302
new_protocol_version - 1

chain/network/src/network_protocol/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ fn deduplicate_edges() {
2424
let bc1 = data::make_edge(&b, &c, 1);
2525
let mut want = vec![ab5.clone(), ac9.clone(), bc1.clone()];
2626
want.sort_by_key(|e| e.key().clone());
27-
let input = vec![ab1, ab3, ab5, ac7, ac9, bc1];
27+
let input = [ab1, ab3, ab5, ac7, ac9, bc1];
2828
for p in input.iter().permutations(input.len()) {
2929
let mut got = Edge::deduplicate(p.into_iter().cloned().collect());
3030
got.sort_by_key(|e| e.key().clone());

chain/network/src/peer/peer_actor.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1795,6 +1795,7 @@ impl actix::Handler<WithSpanContext<Stop>> for PeerActor {
17951795
type InboundHandshakePermit = tokio::sync::OwnedSemaphorePermit;
17961796

17971797
#[derive(Debug)]
1798+
#[allow(dead_code)]
17981799
enum ConnectingStatus {
17991800
Inbound(InboundHandshakePermit),
18001801
Outbound { _permit: connection::OutboundHandshakePermit, handshake_spec: HandshakeSpec },
@@ -1813,6 +1814,7 @@ enum ConnectingStatus {
18131814
/// For the exact process of establishing a connection between peers,
18141815
/// see PoolSnapshot in chain/network/src/peer_manager/connection.rs.
18151816
#[derive(Debug)]
1817+
#[allow(dead_code)]
18161818
enum PeerStatus {
18171819
/// Handshake in progress.
18181820
Connecting(HandshakeSignalSender, ConnectingStatus),

core/crypto/src/key_file.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ impl KeyFile {
2626
#[cfg(unix)]
2727
fn create(path: &Path) -> io::Result<File> {
2828
use std::os::unix::fs::OpenOptionsExt;
29-
std::fs::File::options().mode(0o600).write(true).create(true).open(path)
29+
std::fs::File::options().mode(0o600).write(true).create(true).truncate(true).open(path)
3030
}
3131

3232
#[cfg(not(unix))]

core/store/src/db/refcount.rs

+13-10
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,19 @@ use crate::DBCol;
3535
/// In builds with debug assertions enabled, panics if `bytes` are non-empty but
3636
/// too short to fit 64-bit reference count.
3737
pub fn decode_value_with_rc(bytes: &[u8]) -> (Option<&[u8]>, i64) {
38-
if bytes.len() < 8 {
39-
debug_assert!(bytes.is_empty());
40-
return (None, 0);
41-
}
42-
let (head, tail) = stdx::rsplit_slice::<8>(bytes);
43-
let rc = i64::from_le_bytes(*tail);
44-
if rc <= 0 {
45-
(None, rc)
46-
} else {
47-
(Some(head), rc)
38+
match bytes.split_last_chunk::<8>() {
39+
None => {
40+
debug_assert!(bytes.is_empty());
41+
return (None, 0);
42+
}
43+
Some((head, tail)) => {
44+
let rc = i64::from_le_bytes(*tail);
45+
if rc <= 0 {
46+
(None, rc)
47+
} else {
48+
(Some(head), rc)
49+
}
50+
}
4851
}
4952
}
5053

core/store/src/trie/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ pub struct ApplyStatePartResult {
563563
}
564564

565565
enum NodeOrValue {
566-
Node(Box<RawTrieNodeWithSize>),
566+
Node,
567567
Value(std::sync::Arc<[u8]>),
568568
}
569569

@@ -812,7 +812,7 @@ impl Trie {
812812
to: &Option<&AccountId>,
813813
) {
814814
match self.debug_retrieve_raw_node_or_value(hash) {
815-
Ok(NodeOrValue::Node(_)) => {
815+
Ok(NodeOrValue::Node) => {
816816
let mut prefix: Vec<u8> = Vec::new();
817817
let mut limit = limit.unwrap_or(u32::MAX);
818818
self.print_recursive_internal(
@@ -1115,7 +1115,7 @@ impl Trie {
11151115
) -> Result<NodeOrValue, StorageError> {
11161116
let bytes = self.internal_retrieve_trie_node(hash, true)?;
11171117
match RawTrieNodeWithSize::try_from_slice(&bytes) {
1118-
Ok(node) => Ok(NodeOrValue::Node(Box::new(node))),
1118+
Ok(_) => Ok(NodeOrValue::Node),
11191119
Err(_) => Ok(NodeOrValue::Value(bytes)),
11201120
}
11211121
}

runtime/near-vm-runner/src/instrument/stack_height/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ mod thunk;
9090
///
9191
/// This means that the module is invalid.
9292
#[derive(Debug)]
93+
#[allow(dead_code)]
9394
pub struct Error(String);
9495

9596
pub(crate) struct Context {

rust-toolchain.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
# This specifies the version of Rust we use to build.
33
# Individual crates in the workspace may support a lower version, as indicated by `rust-version` field in each crate's `Cargo.toml`.
44
# The version specified below, should be at least as high as the maximum `rust-version` within the workspace.
5-
channel = "1.76.0"
5+
channel = "1.77.0"
66
components = [ "rustfmt", "clippy" ]
77
targets = [ "wasm32-unknown-unknown" ]

utils/stdx/src/lib.rs

-35
Original file line numberDiff line numberDiff line change
@@ -27,45 +27,10 @@ pub fn split_array_mut<const N: usize, const L: usize, const R: usize>(
2727
(left.try_into().unwrap(), right.try_into().unwrap())
2828
}
2929

30-
/// Splits `&[u8]` into `(&[u8; N], &[u8])`. **Panics** if slice is shorter
31-
/// than `N`.
32-
pub fn split_slice<const N: usize>(slice: &[u8]) -> (&[u8; N], &[u8]) {
33-
let (head, tail) = slice.split_at(N);
34-
(head.try_into().unwrap(), tail)
35-
}
36-
37-
/// Splits `&[u8]` into `(&[u8], &[u8; N])`. **Panics** if slice is shorter
38-
/// than `N`.
39-
pub fn rsplit_slice<const N: usize>(slice: &[u8]) -> (&[u8], &[u8; N]) {
40-
let index = slice.len().checked_sub(N).expect("len to be ≥ N");
41-
let (head, tail) = slice.split_at(index);
42-
(head, tail.try_into().unwrap())
43-
}
44-
45-
/// Splits `&[u8]` into `(&[u8; N], &[u8])`. **Panics** if slice is shorter
46-
/// than `N`.
47-
pub fn split_slice_mut<const N: usize>(slice: &mut [u8]) -> (&mut [u8; N], &mut [u8]) {
48-
let (head, tail) = slice.split_at_mut(N);
49-
(head.try_into().unwrap(), tail)
50-
}
51-
52-
/// Splits `&[u8]` into `(&[u8], &[u8; N])`. **Panics** if slice is shorter
53-
/// than `N`.
54-
pub fn rsplit_slice_mut<const N: usize>(slice: &mut [u8]) -> (&mut [u8], &mut [u8; N]) {
55-
let index = slice.len().checked_sub(N).expect("len to be ≥ N");
56-
let (head, tail) = slice.split_at_mut(index);
57-
(head, tail.try_into().unwrap())
58-
}
59-
6030
#[test]
6131
fn test_split() {
6232
assert_eq!((&[0, 1], &[2, 3, 4]), split_array(&[0, 1, 2, 3, 4]));
6333
assert_eq!((&mut [0, 1], &mut [2, 3, 4]), split_array_mut(&mut [0, 1, 2, 3, 4]));
64-
65-
assert_eq!((&[0, 1], &[2, 3, 4][..]), split_slice(&[0, 1, 2, 3, 4]));
66-
assert_eq!((&[0, 1][..], &[2, 3, 4]), rsplit_slice(&[0, 1, 2, 3, 4]));
67-
assert_eq!((&mut [0, 1], &mut [2, 3, 4][..]), split_slice_mut(&mut [0, 1, 2, 3, 4]));
68-
assert_eq!((&mut [0, 1][..], &mut [2, 3, 4]), rsplit_slice_mut(&mut [0, 1, 2, 3, 4]));
6934
}
7035

7136
/// Joins `[u8; L]` and `[u8; R]` into `[u8; L + R]`.

0 commit comments

Comments
 (0)