Skip to content

Commit

Permalink
fix(rs): rust 1.83 clippy warnings (#710)
Browse files Browse the repository at this point in the history
  • Loading branch information
vobradovich authored Dec 4, 2024
1 parent 80e5e3c commit 08caaa4
Show file tree
Hide file tree
Showing 25 changed files with 43 additions and 29 deletions.
17 changes: 8 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ lalrpop = { version = "0.20", default-features = false }
lalrpop-util = "0.20"
logos = "0.13"
mockall = "0.12"
parity-scale-codec = { version = "3.7", default-features = false }
parity-scale-codec = { version = "=3.6.12", default-features = false }
prettyplease = "0.2"
proc-macro-error = "1.0"
proc-macro2 = { version = "1", default-features = false }
rustdoc-types = "=0.29.1"
rustdoc-types = "=0.31.0"
quote = "1.0"
scale-info = { version = "2.11", default-features = false }
serde = "1.0"
Expand Down
1 change: 1 addition & 0 deletions examples/demo/app/src/counter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ impl<'a> CounterService<'a> {

// Declare the service can emit events of type CounterEvents.
#[service(events = CounterEvents)]
#[allow(clippy::needless_lifetimes)]
impl<'a> CounterService<'a> {
/// Add a value to the counter
pub fn add(&mut self, value: u32) -> u32 {
Expand Down
1 change: 1 addition & 0 deletions examples/demo/app/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ mod value_fee;
static mut DOG_DATA: Option<RefCell<walker::WalkerData>> = None;
static mut REF_DATA: u8 = 42;

#[allow(static_mut_refs)]
fn dog_data() -> &'static RefCell<walker::WalkerData> {
unsafe {
DOG_DATA
Expand Down
3 changes: 3 additions & 0 deletions examples/demo/app/src/references/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,23 @@ impl<'t> ReferenceService<'t> {
}
}

#[allow(static_mut_refs)]
pub fn add<'a>(&mut self, v: u32) -> &'a u32 {
unsafe {
COUNTER.0 += v;
&COUNTER.0
}
}

#[allow(static_mut_refs)]
pub fn add_byte(&mut self, byte: u8) -> &'static [u8] {
unsafe {
BYTES.push(byte);
&*ptr::addr_of!(BYTES)
}
}

#[allow(static_mut_refs)]
pub async fn last_byte<'a>(&self) -> Option<&'a u8> {
unsafe { BYTES.last() }
}
Expand Down
2 changes: 2 additions & 0 deletions examples/rmrk/catalog/app/src/services/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,12 @@ where
Self { exec_context }
}

#[allow(static_mut_refs)]
fn data(&self) -> &CatalogData {
unsafe { CATALOG_DATA.as_ref().unwrap() }
}

#[allow(static_mut_refs)]
fn data_mut(&mut self) -> &mut CatalogData {
unsafe { CATALOG_DATA.as_mut().unwrap() }
}
Expand Down
2 changes: 2 additions & 0 deletions examples/rmrk/resource/app/src/services/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,12 @@ where
Ok(())
}

#[allow(static_mut_refs)]
fn data(&self) -> &'static ResourceStorageData {
unsafe { RESOURCE_STORAGE_DATA.as_ref().unwrap() }
}

#[allow(static_mut_refs)]
fn data_mut(&mut self) -> &'static mut ResourceStorageData {
unsafe { RESOURCE_STORAGE_DATA.as_mut().unwrap() }
}
Expand Down
7 changes: 3 additions & 4 deletions net/rs/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion net/rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ convert-case = { package = "convert_case", version = "0.6" }
genco = "0.17"
insta = "1.41"
itertools = "0.13"
parity-scale-codec = "3.7"
parity-scale-codec = "=3.6.12"
serde = { version = "1.0", features = ["derive"] }
serde-json = { package = "serde_json", version = "1.0" }
2 changes: 1 addition & 1 deletion rs/client-gen/src/ctor_generators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl<'a> CtorFactoryGenerator<'a> {
}
}

impl<'a, 'ast> Visitor<'ast> for CtorFactoryGenerator<'a> {
impl<'ast> Visitor<'ast> for CtorFactoryGenerator<'_> {
fn visit_ctor(&mut self, ctor: &'ast Ctor) {
quote_in! {self.tokens =>
pub struct $(self.service_name)Factory<R> {
Expand Down
2 changes: 1 addition & 1 deletion rs/client-gen/src/events_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl<'a> EventsModuleGenerator<'a> {
}
}

impl<'a, 'ast> Visitor<'ast> for EventsModuleGenerator<'a> {
impl<'ast> Visitor<'ast> for EventsModuleGenerator<'_> {
fn visit_service(&mut self, service: &'ast Service) {
let events_name = format!("{}Events", self.service_name);
let (service_path_bytes, _) = path_bytes(self.path);
Expand Down
2 changes: 1 addition & 1 deletion rs/client-gen/src/io_generators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl<'a> IoModuleGenerator<'a> {
}
}

impl<'a, 'ast> Visitor<'ast> for IoModuleGenerator<'a> {
impl<'ast> Visitor<'ast> for IoModuleGenerator<'_> {
fn visit_service(&mut self, service: &'ast Service) {
visitor::accept_service(service, self);
}
Expand Down
2 changes: 1 addition & 1 deletion rs/client-gen/src/mock_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl<'a> MockGenerator<'a> {
}
}

impl<'a, 'ast> Visitor<'ast> for MockGenerator<'a> {
impl<'ast> Visitor<'ast> for MockGenerator<'_> {
fn visit_service(&mut self, service: &'ast Service) {
visitor::accept_service(service, self);
}
Expand Down
2 changes: 1 addition & 1 deletion rs/client-gen/src/root_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ impl<'a> RootGenerator<'a> {
}
}

impl<'a, 'ast> Visitor<'ast> for RootGenerator<'a> {
impl<'ast> Visitor<'ast> for RootGenerator<'_> {
fn visit_ctor(&mut self, ctor: &'ast Ctor) {
let mut ctor_gen = CtorTraitGenerator::new(self.anonymous_service_name.to_owned());
ctor_gen.visit_ctor(ctor);
Expand Down
2 changes: 1 addition & 1 deletion rs/client-gen/src/type_generators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl<'a> TopLevelTypeGenerator<'a> {
}
}

impl<'a, 'ast> Visitor<'ast> for TopLevelTypeGenerator<'a> {
impl<'ast> Visitor<'ast> for TopLevelTypeGenerator<'_> {
fn visit_type(&mut self, r#type: &'ast Type) {
for doc in r#type.docs() {
quote_in! { self.tokens =>
Expand Down
2 changes: 1 addition & 1 deletion rs/idl-gen/src/meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ impl ExpandedProgramMeta {
pub fn types(&self) -> impl Iterator<Item = &PortableType> {
self.registry.types.iter().filter(|ty| {
!ty.ty.path.namespace().is_empty()
&& !self.ctors_type_id.is_some_and(|id| id == ty.id)
&& self.ctors_type_id.is_none_or(|id| id != ty.id)
&& !self.commands_type_ids().any(|id| id == ty.id)
&& !self.queries_type_ids().any(|id| id == ty.id)
&& !self.events_type_ids().any(|id| id == ty.id)
Expand Down
4 changes: 2 additions & 2 deletions rs/idl-parser/src/ffi/ast/visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ mod wrapper {
visitor: &'a Visitor,
}

impl<'a> VisitorWrapper<'a> {
impl VisitorWrapper<'_> {
pub fn new(context: *const (), visitor: *const Visitor) -> Result<Self, ErrorCode> {
if visitor.is_null() {
return Err(ErrorCode::NullPtr);
Expand All @@ -480,7 +480,7 @@ mod wrapper {
}
}

impl<'a, 'ast> RawVisitor<'ast> for VisitorWrapper<'a> {
impl<'ast> RawVisitor<'ast> for VisitorWrapper<'_> {
fn visit_ctor(&mut self, ctor: &'ast raw_ast::Ctor) {
if fn_ptr_addr!(self.visitor.visit_ctor).is_null() {
return raw_visitor::accept_ctor(ctor, self);
Expand Down
2 changes: 1 addition & 1 deletion rs/idl-parser/src/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl<'input> Lexer<'input> {
}
}

impl<'input> Iterator for Lexer<'input> {
impl Iterator for Lexer<'_> {
type Item = Spanned<Token, usize, ParseError>;

fn next(&mut self) -> Option<Self::Item> {
Expand Down
1 change: 1 addition & 0 deletions rs/macros/core/src/program/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ fn parse_gprogram_impl(program_impl_tokens: TokenStream2) -> ItemImpl {
})
}

#[allow(static_mut_refs)]
fn ensure_single_gprogram(program_impl: &ItemImpl) {
let crate_name = env::var("CARGO_CRATE_NAME").unwrap_or("crate".to_string());
if unsafe { PROGRAM_SPANS.get(&crate_name) }.is_some() {
Expand Down
2 changes: 2 additions & 0 deletions rs/macros/tests/gservice_with_extends_and_lifetimes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub(super) mod base {
}
}

#[allow(clippy::needless_lifetimes)]
#[service]
impl<'a> BaseWithLifetime<'a> {
pub fn base_name(&self) -> String {
Expand Down Expand Up @@ -46,6 +47,7 @@ pub(super) mod extended {
}
}

#[allow(clippy::needless_lifetimes)]
#[service(extends = base::BaseWithLifetime<'a>)]
impl<'a> ExtendedWithLifetime<'a> {
pub fn extended_name(&self) -> String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub(super) struct MyGenericService<'a, T> {
_a: PhantomData<&'a T>,
}

#[allow(clippy::needless_lifetimes)]
#[service]
impl<'a, T> MyGenericService<'a, T>
where
Expand Down
1 change: 1 addition & 0 deletions rs/macros/tests/gservice_with_lifetimes_and_events/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub enum MyEvents {
Event1,
}

#[allow(clippy::needless_lifetimes)]
#[service(events = MyEvents)]
impl<'l, T> MyGenericEventsService<'l, T>
where
Expand Down
1 change: 1 addition & 0 deletions rs/macros/tests/gservice_with_trait_bounds/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub(super) struct MyServiceWithTraitBounds<'a, T> {
_a: PhantomData<&'a T>,
}

#[allow(clippy::needless_lifetimes)]
#[service]
impl<'a, T: Into<u32>> MyServiceWithTraitBounds<'a, T> {
pub fn do_this(&mut self) -> u32 {
Expand Down
5 changes: 3 additions & 2 deletions rs/src/gstd/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ impl SysCalls {
}
}

#[allow(static_mut_refs)]
fn as_ref() -> Option<&'static SysCalls> {
unsafe { SYS_CALLS.as_ref() }
}
Expand Down Expand Up @@ -130,7 +131,7 @@ pub struct EventListenerGuard<'a> {
}

#[cfg(not(target_arch = "wasm32"))]
impl<'a> EventListenerGuard<'a> {
impl EventListenerGuard<'_> {
pub fn new(service_ptr: usize, listener_ptr: usize) -> Self {
let mut event_listeners = event_listeners().lock();
if event_listeners.contains_key(&service_ptr) {
Expand All @@ -147,7 +148,7 @@ impl<'a> EventListenerGuard<'a> {
}

#[cfg(not(target_arch = "wasm32"))]
impl<'a> Drop for EventListenerGuard<'a> {
impl Drop for EventListenerGuard<'_> {
fn drop(&mut self) {
let mut event_listeners = event_listeners().lock();
let listener_ptr = event_listeners.remove(&self.service_ptr);
Expand Down
2 changes: 1 addition & 1 deletion templates/set-vars.rhai
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ variable::set("mocks-feature-name", "mocks");

// Set versions of used crates
variable::set("mockall-version", "0.12");
variable::set("sails-rs-version", "0.7.0"); // NB: This version is updated autmatically by GH release workflow
variable::set("sails-rs-version", "0.6.3"); // NB: This version is updated autmatically by GH release workflow
variable::set("tokio-version", "1.41");

fn is_kebab_case(name) {
Expand Down

0 comments on commit 08caaa4

Please sign in to comment.