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 all commits
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
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,8 @@ default-members = [

[workspace.lints.rust]
suspicious_double_ref_op = { level = "allow", priority = 2 }
# `substrate_runtime` is a common `cfg` condition name used in the repo.
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
1 change: 0 additions & 1 deletion substrate/frame/support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -869,7 +869,6 @@ 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)

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
3 changes: 0 additions & 3 deletions substrate/primitives/runtime-interface/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// 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: 2 additions & 2 deletions substrate/primitives/weights/src/weight_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -401,14 +401,14 @@ where
}
}

#[cfg(any(test, feature = "std", feature = "runtime-benchmarks"))]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Better not to add some conditional code for runtime-benchmark here IMO.
This code was never generated, better not to start generating it.

Copy link
Member

@ggwpez ggwpez Jul 26, 2024

Choose a reason for hiding this comment

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

Yea feel free to delete in that case. I normally generate helpers on the fly if i need to.

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

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