Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix warnings for rust 1.80 #5150

Merged
merged 8 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,7 @@ default-members = [

[workspace.lints.rust]
suspicious_double_ref_op = { level = "allow", priority = 2 }
unexpected_cfgs = { level = "allow", check-cfg = ['cfg(substrate_runtime)'] }
bkchr marked this conversation as resolved.
Show resolved Hide resolved

[workspace.lints.clippy]
all = { level = "allow", priority = 0 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ runtime-benchmarks = [
"polkadot-runtime-common/runtime-benchmarks",
"snowbridge-router-primitives/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
"sp-weights/runtime-benchmarks",
"xcm-builder/runtime-benchmarks",
"xcm-executor/runtime-benchmarks",
"xcm-runtime-apis/runtime-benchmarks",
Expand Down
5 changes: 4 additions & 1 deletion polkadot/parachain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,7 @@ std = [
"sp-runtime/std",
"sp-weights/std",
]
runtime-benchmarks = ["sp-runtime/runtime-benchmarks"]
runtime-benchmarks = [
"sp-runtime/runtime-benchmarks",
"sp-weights/runtime-benchmarks",
]
1 change: 1 addition & 0 deletions polkadot/xcm/xcm-builder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ runtime-benchmarks = [
"polkadot-runtime-parachains/runtime-benchmarks",
"polkadot-test-runtime/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
"sp-weights/runtime-benchmarks",
"xcm-executor/runtime-benchmarks",
]
std = [
Expand Down
1 change: 1 addition & 0 deletions polkadot/xcm/xcm-executor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
"sp-weights/runtime-benchmarks",
]
std = [
"codec/std",
Expand Down
1 change: 1 addition & 0 deletions polkadot/xcm/xcm-runtime-apis/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,5 @@ runtime-benchmarks = [
"pallet-xcm/runtime-benchmarks",
"xcm-builder/runtime-benchmarks",
"xcm-executor/runtime-benchmarks",
"sp-weights/runtime-benchmarks",
]
1 change: 1 addition & 0 deletions substrate/frame/message-queue/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ runtime-benchmarks = [
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
"sp-weights/runtime-benchmarks",
]
try-runtime = [
"frame-support/try-runtime",
Expand Down
1 change: 1 addition & 0 deletions substrate/frame/scheduler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ runtime-benchmarks = [
"frame-system/runtime-benchmarks",
"pallet-preimage/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
"sp-weights/runtime-benchmarks",
]
std = [
"codec/std",
Expand Down
1 change: 1 addition & 0 deletions substrate/frame/support/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ runtime-benchmarks = [
"frame-system/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
"sp-staking/runtime-benchmarks",
"sp-weights/runtime-benchmarks",
]
try-runtime = [
"frame-system/try-runtime",
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -869,7 +869,7 @@ macro_rules! hypothetically_ok {
pub use serde::{Deserialize, Serialize};

#[doc(hidden)]
#[cfg(not(no_std))]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This actually needed in both std and not std: #5150 (comment)

#[cfg(feature = "std")]
ggwpez marked this conversation as resolved.
Show resolved Hide resolved
pub use macro_magic;

/// Prelude to be used for pallet testing, for ease of use.
Expand Down
41 changes: 0 additions & 41 deletions substrate/frame/support/src/storage/generator/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,47 +74,6 @@ pub trait StorageMap<K: FullEncode, V: FullCodec> {
}
}

/// Utility to iterate through items in a storage map.
pub struct StorageMapIterator<K, V, Hasher> {
prefix: Vec<u8>,
previous_key: Vec<u8>,
drain: bool,
_phantom: ::core::marker::PhantomData<(K, V, Hasher)>,
}

impl<K: Decode + Sized, V: Decode + Sized, Hasher: ReversibleStorageHasher> Iterator
for StorageMapIterator<K, V, Hasher>
{
type Item = (K, V);

fn next(&mut self) -> Option<(K, V)> {
loop {
let maybe_next = sp_io::storage::next_key(&self.previous_key)
.filter(|n| n.starts_with(&self.prefix));
break match maybe_next {
Some(next) => {
self.previous_key = next;
match unhashed::get::<V>(&self.previous_key) {
Some(value) => {
if self.drain {
unhashed::kill(&self.previous_key)
}
let mut key_material =
Hasher::reverse(&self.previous_key[self.prefix.len()..]);
match K::decode(&mut key_material) {
Ok(key) => Some((key, value)),
Err(_) => continue,
}
},
None => continue,
}
},
None => None,
}
}
}
}

impl<K: FullCodec, V: FullCodec, G: StorageMap<K, V>> storage::IterableStorageMap<K, V> for G
where
G::Hasher: ReversibleStorageHasher,
Expand Down
1 change: 1 addition & 0 deletions substrate/frame/system/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ std = [
runtime-benchmarks = [
"frame-support/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
"sp-weights/runtime-benchmarks",
]
try-runtime = ["frame-support/try-runtime", "sp-runtime/try-runtime"]
experimental = ["frame-support/experimental"]
Expand Down
4 changes: 2 additions & 2 deletions substrate/primitives/panic-handler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use std::{
cell::Cell,
io::{self, Write},
marker::PhantomData,
panic::{self, PanicInfo},
panic::{self, PanicHookInfo},
thread,
};

Expand Down Expand Up @@ -145,7 +145,7 @@ fn strip_control_codes(input: &str) -> std::borrow::Cow<str> {
}

/// Function being called when a panic happens.
fn panic_hook(info: &PanicInfo, report_url: &str, version: &str) {
fn panic_hook(info: &PanicHookInfo, report_url: &str, version: &str) {
let location = info.location();
let file = location.as_ref().map(|l| l.file()).unwrap_or("<unknown>");
let line = location.as_ref().map(|l| l.line()).unwrap_or(0);
Expand Down
1 change: 0 additions & 1 deletion substrate/primitives/runtime-interface/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

// Custom inner attributes are unstable, so we need to faky disable the attribute.
// rustfmt still honors the attribute to not format the rustdocs below.
#![cfg_attr(feature = "never", rustfmt::skip)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you read the comment above? :D Not sure this is already fixed in rustfmt?

Copy link
Contributor Author

@gui1117 gui1117 Jul 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I missed it, but I did run cargo fmt -p sp-runtime-interface the file was unchanged so I thought it wasn't relevant anymore.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CI uses a specific nightly for formatting: cargo +nightly-2024-04-14 fmt.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also tested with this version, anyway CI should tell if the formatting of the crate is changing with this PR, in this case I'll revert this change.

//! Substrate runtime interface
//!
//! This crate provides types, traits and macros around runtime interfaces. A runtime interface is
Expand Down
4 changes: 3 additions & 1 deletion substrate/primitives/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ sp-tracing = { workspace = true, default-features = true }
substrate-test-runtime-client = { workspace = true }

[features]
runtime-benchmarks = []
runtime-benchmarks = [
"sp-weights/runtime-benchmarks",
]
try-runtime = []
default = ["std"]
std = [
Expand Down
1 change: 1 addition & 0 deletions substrate/primitives/weights/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ std = [
"sp-arithmetic/std",
"sp-debug-derive/std",
]
runtime-benchmarks = []
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there code in sp-weights that is guarded by the feature?

Copy link
Contributor Author

@gui1117 gui1117 Jul 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes this, we could also remove it IMO:

#[cfg(any(test, feature = "std", feature = "runtime-benchmarks"))]
impl From<u64> for Weight {
fn from(value: u64) -> Self {
Self::from_parts(value, value)
}
}
#[cfg(any(test, feature = "std", feature = "runtime-benchmarks"))]
impl From<(u64, u64)> for Weight {
fn from(value: (u64, u64)) -> Self {
Self::from_parts(value.0, value.1)
}
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it was never used, let's remove it.

# By default some types have documentation, `full-metadata-docs` allows to add documentation to
# more types in the metadata.
full-metadata-docs = ["scale-info/docs"]
Expand Down
1 change: 1 addition & 0 deletions umbrella/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ runtime-benchmarks = [
"snowbridge-runtime-test-common?/runtime-benchmarks",
"sp-runtime?/runtime-benchmarks",
"sp-staking?/runtime-benchmarks",
"sp-weights?/runtime-benchmarks",
"staging-node-inspect?/runtime-benchmarks",
"staging-xcm-builder?/runtime-benchmarks",
"staging-xcm-executor?/runtime-benchmarks",
Expand Down
Loading