Skip to content

Commit

Permalink
rust: 1.77.0 (#10856)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mina86 authored Mar 25, 2024
1 parent 73b8827 commit 060016e
Show file tree
Hide file tree
Showing 15 changed files with 48 additions and 98 deletions.
34 changes: 17 additions & 17 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:
- uses: actions/checkout@v4

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

Expand Down Expand Up @@ -107,7 +107,7 @@ jobs:
with:
python-version: 3.11
cache: pip
- uses: taiki-e/install-action@91af8c38814c3998cb755869e5cbeffd3ab0e462
- uses: taiki-e/install-action@9b5b983efc779f85e5e5d11539f005e85ccb27ff
with:
tool: cargo-llvm-cov
- run: pip3 install --user -r pytest/requirements.txt
Expand All @@ -133,7 +133,7 @@ jobs:
with:
python-version: 3.11
cache: pip
- uses: taiki-e/install-action@91af8c38814c3998cb755869e5cbeffd3ab0e462
- uses: taiki-e/install-action@9b5b983efc779f85e5e5d11539f005e85ccb27ff
with:
tool: cargo-llvm-cov
- run: pip3 install --user -r pytest/requirements.txt
Expand Down Expand Up @@ -163,7 +163,7 @@ jobs:
with:
python-version: 3.11
cache: pip
- uses: taiki-e/install-action@91af8c38814c3998cb755869e5cbeffd3ab0e462
- uses: taiki-e/install-action@9b5b983efc779f85e5e5d11539f005e85ccb27ff
with:
tool: cargo-llvm-cov
- run: pip3 install --user -r pytest/requirements.txt
Expand Down Expand Up @@ -195,7 +195,7 @@ jobs:
with:
python-version: 3.11
cache: pip
- uses: taiki-e/install-action@91af8c38814c3998cb755869e5cbeffd3ab0e462
- uses: taiki-e/install-action@9b5b983efc779f85e5e5d11539f005e85ccb27ff
with:
tool: cargo-llvm-cov
- run: pip3 install --user -r pytest/requirements.txt
Expand All @@ -217,7 +217,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: taiki-e/install-action@91af8c38814c3998cb755869e5cbeffd3ab0e462
- uses: taiki-e/install-action@9b5b983efc779f85e5e5d11539f005e85ccb27ff
with:
tool: just
- uses: actions/setup-python@v4
Expand All @@ -236,7 +236,7 @@ jobs:
with:
python-version: 3.11
cache: pip
- uses: taiki-e/install-action@91af8c38814c3998cb755869e5cbeffd3ab0e462
- uses: taiki-e/install-action@9b5b983efc779f85e5e5d11539f005e85ccb27ff
with:
tool: cargo-llvm-cov
- run: pip3 install --user -r pytest/requirements.txt
Expand All @@ -258,7 +258,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: taiki-e/install-action@91af8c38814c3998cb755869e5cbeffd3ab0e462
- uses: taiki-e/install-action@9b5b983efc779f85e5e5d11539f005e85ccb27ff
with:
tool: just
- run: just check-rpc-errors-schema
Expand All @@ -277,7 +277,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: taiki-e/install-action@91af8c38814c3998cb755869e5cbeffd3ab0e462
- uses: taiki-e/install-action@9b5b983efc779f85e5e5d11539f005e85ccb27ff
with:
tool: just
- run: just check-cargo-fmt
Expand All @@ -287,7 +287,7 @@ jobs:
runs-on: ubuntu-22.04-8core
steps:
- uses: actions/checkout@v4
- uses: taiki-e/install-action@91af8c38814c3998cb755869e5cbeffd3ab0e462
- uses: taiki-e/install-action@9b5b983efc779f85e5e5d11539f005e85ccb27ff
with:
tool: just
- run: just check-cargo-clippy
Expand All @@ -297,7 +297,7 @@ jobs:
runs-on: ubuntu-22.04-8core
steps:
- uses: actions/checkout@v4
- uses: taiki-e/install-action@91af8c38814c3998cb755869e5cbeffd3ab0e462
- uses: taiki-e/install-action@9b5b983efc779f85e5e5d11539f005e85ccb27ff
with:
tool: just
- run: just doctests
Expand All @@ -307,7 +307,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: taiki-e/install-action@91af8c38814c3998cb755869e5cbeffd3ab0e462
- uses: taiki-e/install-action@9b5b983efc779f85e5e5d11539f005e85ccb27ff
with:
tool: just,cargo-deny
- run: just check-cargo-deny
Expand All @@ -317,7 +317,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: taiki-e/install-action@91af8c38814c3998cb755869e5cbeffd3ab0e462
- uses: taiki-e/install-action@9b5b983efc779f85e5e5d11539f005e85ccb27ff
with:
tool: just
- run: just check-themis
Expand All @@ -327,7 +327,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: taiki-e/install-action@91af8c38814c3998cb755869e5cbeffd3ab0e462
- uses: taiki-e/install-action@9b5b983efc779f85e5e5d11539f005e85ccb27ff
with:
tool: just
- run: just check-non-default
Expand All @@ -337,7 +337,7 @@ jobs:
runs-on: ubuntu-22.04-8core
steps:
- uses: actions/checkout@v4
- uses: taiki-e/install-action@91af8c38814c3998cb755869e5cbeffd3ab0e462
- uses: taiki-e/install-action@9b5b983efc779f85e5e5d11539f005e85ccb27ff
with:
tool: just,cargo-udeps
- run: just check-cargo-udeps
Expand All @@ -347,7 +347,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: taiki-e/install-action@91af8c38814c3998cb755869e5cbeffd3ab0e462
- uses: taiki-e/install-action@9b5b983efc779f85e5e5d11539f005e85ccb27ff
with:
tool: cargo-audit
- run: cargo audit -D warnings
Expand All @@ -373,7 +373,7 @@ jobs:
with:
name: coverage-profraw
path: coverage/profraw
- uses: taiki-e/install-action@91af8c38814c3998cb755869e5cbeffd3ab0e462
- uses: taiki-e/install-action@9b5b983efc779f85e5e5d11539f005e85ccb27ff
with:
tool: cargo-llvm-cov
- uses: actions/setup-python@v4
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
version = "0.0.0" # managed by cargo-workspaces, see below
authors = ["Near Inc <hello@nearprotocol.com>"]
edition = "2021"
rust-version = "1.76.0"
rust-version = "1.77.0"
repository = "https://github.com/near/nearcore"
license = "MIT OR Apache-2.0"

Expand Down
3 changes: 1 addition & 2 deletions chain/chain/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2772,8 +2772,7 @@ mod tests {
let mut chain = get_chain(Clock::real());
let genesis = chain.get_block_by_height(0).unwrap();
let signer = Arc::new(create_test_signer("test1"));
let short_fork =
vec![TestBlockBuilder::new(Clock::real(), &genesis, signer.clone()).build()];
let short_fork = [TestBlockBuilder::new(Clock::real(), &genesis, signer.clone()).build()];
let mut store_update = chain.mut_chain_store().store_update();
store_update.save_block_header(short_fork[0].header().clone()).unwrap();
store_update.commit().unwrap();
Expand Down
2 changes: 1 addition & 1 deletion chain/chain/src/tests/garbage_collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ fn test_fork_far_away_from_epoch_end() {
let max_changes = 1;
let fork_clean_step = 100;
let epoch_length = fork_clean_step + 10;
let simple_chains = vec![
let simple_chains = [
SimpleChain { from: 0, length: 5, is_removed: false },
SimpleChain { from: 5, length: 2, is_removed: true },
// We want the chain to end up exactly at the new epoch start.
Expand Down
24 changes: 0 additions & 24 deletions chain/client/src/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,6 @@ use crate::view_client::ViewClientActor;
use near_async::actix::AddrWithAutoSpanContextExt;
use near_async::messaging::IntoSender;
use near_network::client::ClientSenderForNetwork;
use near_network::types::{
PartialEncodedChunkForwardMsg, PartialEncodedChunkRequestMsg, PartialEncodedChunkResponseMsg,
};
use near_primitives::hash::CryptoHash;
use near_primitives::sharding::PartialEncodedChunk;

#[derive(actix::Message, Debug)]
#[rtype(result = "()")]
pub(crate) struct RecvPartialEncodedChunkForward(pub PartialEncodedChunkForwardMsg);

#[derive(actix::Message, Debug)]
#[rtype(result = "()")]
pub(crate) struct RecvPartialEncodedChunk(pub PartialEncodedChunk);

#[derive(actix::Message, Debug)]
#[rtype(result = "()")]
pub(crate) struct RecvPartialEncodedChunkResponse(
pub PartialEncodedChunkResponseMsg,
pub std::time::Instant,
);

#[derive(actix::Message, Debug)]
#[rtype(result = "()")]
pub(crate) struct RecvPartialEncodedChunkRequest(pub PartialEncodedChunkRequestMsg, pub CryptoHash);

pub fn client_sender_for_network(
client_addr: actix::Addr<ClientActor>,
Expand Down
6 changes: 5 additions & 1 deletion chain/client/src/sync/external.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,11 @@ impl ExternalConnection {
if let Some(parent_dir) = path.parent() {
std::fs::create_dir_all(parent_dir)?;
}
let mut file = std::fs::OpenOptions::new().write(true).create(true).open(&path)?;
let mut file = std::fs::OpenOptions::new()
.write(true)
.create(true)
.truncate(true)
.open(&path)?;
file.write_all(data)?;
tracing::debug!(target: "state_sync_dump", shard_id, part_length = data.len(), ?location, ?file_type, "Wrote a state part to a file");
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion chain/epoch-manager/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2296,7 +2296,7 @@ fn test_protocol_version_switch_with_shard_layout_change() {
}
epoch_manager.record_block_info(block_info, [0; 32]).unwrap();
}
let epochs = vec![EpochId::default(), EpochId(h[2]), EpochId(h[4])];
let epochs = [EpochId::default(), EpochId(h[2]), EpochId(h[4])];
assert_eq!(
epoch_manager.get_epoch_info(&epochs[1]).unwrap().protocol_version(),
new_protocol_version - 1
Expand Down
2 changes: 1 addition & 1 deletion chain/network/src/network_protocol/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ fn deduplicate_edges() {
let bc1 = data::make_edge(&b, &c, 1);
let mut want = vec![ab5.clone(), ac9.clone(), bc1.clone()];
want.sort_by_key(|e| e.key().clone());
let input = vec![ab1, ab3, ab5, ac7, ac9, bc1];
let input = [ab1, ab3, ab5, ac7, ac9, bc1];
for p in input.iter().permutations(input.len()) {
let mut got = Edge::deduplicate(p.into_iter().cloned().collect());
got.sort_by_key(|e| e.key().clone());
Expand Down
2 changes: 2 additions & 0 deletions chain/network/src/peer/peer_actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1795,6 +1795,7 @@ impl actix::Handler<WithSpanContext<Stop>> for PeerActor {
type InboundHandshakePermit = tokio::sync::OwnedSemaphorePermit;

#[derive(Debug)]
#[allow(dead_code)]
enum ConnectingStatus {
Inbound(InboundHandshakePermit),
Outbound { _permit: connection::OutboundHandshakePermit, handshake_spec: HandshakeSpec },
Expand All @@ -1813,6 +1814,7 @@ enum ConnectingStatus {
/// For the exact process of establishing a connection between peers,
/// see PoolSnapshot in chain/network/src/peer_manager/connection.rs.
#[derive(Debug)]
#[allow(dead_code)]
enum PeerStatus {
/// Handshake in progress.
Connecting(HandshakeSignalSender, ConnectingStatus),
Expand Down
2 changes: 1 addition & 1 deletion core/crypto/src/key_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl KeyFile {
#[cfg(unix)]
fn create(path: &Path) -> io::Result<File> {
use std::os::unix::fs::OpenOptionsExt;
std::fs::File::options().mode(0o600).write(true).create(true).open(path)
std::fs::File::options().mode(0o600).write(true).create(true).truncate(true).open(path)
}

#[cfg(not(unix))]
Expand Down
23 changes: 13 additions & 10 deletions core/store/src/db/refcount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,19 @@ use crate::DBCol;
/// In builds with debug assertions enabled, panics if `bytes` are non-empty but
/// too short to fit 64-bit reference count.
pub fn decode_value_with_rc(bytes: &[u8]) -> (Option<&[u8]>, i64) {
if bytes.len() < 8 {
debug_assert!(bytes.is_empty());
return (None, 0);
}
let (head, tail) = stdx::rsplit_slice::<8>(bytes);
let rc = i64::from_le_bytes(*tail);
if rc <= 0 {
(None, rc)
} else {
(Some(head), rc)
match bytes.split_last_chunk::<8>() {
None => {
debug_assert!(bytes.is_empty());
return (None, 0);
}
Some((head, tail)) => {
let rc = i64::from_le_bytes(*tail);
if rc <= 0 {
(None, rc)
} else {
(Some(head), rc)
}
}
}
}

Expand Down
6 changes: 3 additions & 3 deletions core/store/src/trie/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ pub struct ApplyStatePartResult {
}

enum NodeOrValue {
Node(Box<RawTrieNodeWithSize>),
Node,
Value(std::sync::Arc<[u8]>),
}

Expand Down Expand Up @@ -812,7 +812,7 @@ impl Trie {
to: &Option<&AccountId>,
) {
match self.debug_retrieve_raw_node_or_value(hash) {
Ok(NodeOrValue::Node(_)) => {
Ok(NodeOrValue::Node) => {
let mut prefix: Vec<u8> = Vec::new();
let mut limit = limit.unwrap_or(u32::MAX);
self.print_recursive_internal(
Expand Down Expand Up @@ -1115,7 +1115,7 @@ impl Trie {
) -> Result<NodeOrValue, StorageError> {
let bytes = self.internal_retrieve_trie_node(hash, true)?;
match RawTrieNodeWithSize::try_from_slice(&bytes) {
Ok(node) => Ok(NodeOrValue::Node(Box::new(node))),
Ok(_) => Ok(NodeOrValue::Node),
Err(_) => Ok(NodeOrValue::Value(bytes)),
}
}
Expand Down
1 change: 1 addition & 0 deletions runtime/near-vm-runner/src/instrument/stack_height/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ mod thunk;
///
/// This means that the module is invalid.
#[derive(Debug)]
#[allow(dead_code)]
pub struct Error(String);

pub(crate) struct Context {
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
# This specifies the version of Rust we use to build.
# Individual crates in the workspace may support a lower version, as indicated by `rust-version` field in each crate's `Cargo.toml`.
# The version specified below, should be at least as high as the maximum `rust-version` within the workspace.
channel = "1.76.0"
channel = "1.77.0"
components = [ "rustfmt", "clippy" ]
targets = [ "wasm32-unknown-unknown" ]
35 changes: 0 additions & 35 deletions utils/stdx/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,45 +27,10 @@ pub fn split_array_mut<const N: usize, const L: usize, const R: usize>(
(left.try_into().unwrap(), right.try_into().unwrap())
}

/// Splits `&[u8]` into `(&[u8; N], &[u8])`. **Panics** if slice is shorter
/// than `N`.
pub fn split_slice<const N: usize>(slice: &[u8]) -> (&[u8; N], &[u8]) {
let (head, tail) = slice.split_at(N);
(head.try_into().unwrap(), tail)
}

/// Splits `&[u8]` into `(&[u8], &[u8; N])`. **Panics** if slice is shorter
/// than `N`.
pub fn rsplit_slice<const N: usize>(slice: &[u8]) -> (&[u8], &[u8; N]) {
let index = slice.len().checked_sub(N).expect("len to be ≥ N");
let (head, tail) = slice.split_at(index);
(head, tail.try_into().unwrap())
}

/// Splits `&[u8]` into `(&[u8; N], &[u8])`. **Panics** if slice is shorter
/// than `N`.
pub fn split_slice_mut<const N: usize>(slice: &mut [u8]) -> (&mut [u8; N], &mut [u8]) {
let (head, tail) = slice.split_at_mut(N);
(head.try_into().unwrap(), tail)
}

/// Splits `&[u8]` into `(&[u8], &[u8; N])`. **Panics** if slice is shorter
/// than `N`.
pub fn rsplit_slice_mut<const N: usize>(slice: &mut [u8]) -> (&mut [u8], &mut [u8; N]) {
let index = slice.len().checked_sub(N).expect("len to be ≥ N");
let (head, tail) = slice.split_at_mut(index);
(head, tail.try_into().unwrap())
}

#[test]
fn test_split() {
assert_eq!((&[0, 1], &[2, 3, 4]), split_array(&[0, 1, 2, 3, 4]));
assert_eq!((&mut [0, 1], &mut [2, 3, 4]), split_array_mut(&mut [0, 1, 2, 3, 4]));

assert_eq!((&[0, 1], &[2, 3, 4][..]), split_slice(&[0, 1, 2, 3, 4]));
assert_eq!((&[0, 1][..], &[2, 3, 4]), rsplit_slice(&[0, 1, 2, 3, 4]));
assert_eq!((&mut [0, 1], &mut [2, 3, 4][..]), split_slice_mut(&mut [0, 1, 2, 3, 4]));
assert_eq!((&mut [0, 1][..], &mut [2, 3, 4]), rsplit_slice_mut(&mut [0, 1, 2, 3, 4]));
}

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

0 comments on commit 060016e

Please sign in to comment.