Skip to content

Commit

Permalink
fix some warnings with rust 1.83
Browse files Browse the repository at this point in the history
It's complaining about non-local impls and elided lifetimes
that have names.

I don't recall why I thought I needed these "dummy" enclosing
scopes, and they are most likely cargo-cult copypasta from
some other derive implementation that I used as inspiration.
  • Loading branch information
wez committed Nov 29, 2024
1 parent a7ff718 commit 74015a9
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 86 deletions.
23 changes: 8 additions & 15 deletions config/derive/src/configmeta.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{attr, bound};
use proc_macro2::{Span, TokenStream};
use quote::quote;
use syn::{parse_quote, Data, DataStruct, DeriveInput, Error, Fields, FieldsNamed, Ident, Result};
use syn::{parse_quote, Data, DataStruct, DeriveInput, Error, Fields, FieldsNamed, Result};

pub fn derive(input: DeriveInput) -> Result<TokenStream> {
match &input.data {
Expand All @@ -24,10 +24,6 @@ fn derive_struct(input: &DeriveInput, fields: &FieldsNamed) -> Result<TokenStrea
let info = attr::container_info(&input.attrs)?;
let ident = &input.ident;
let (impl_generics, ty_generics, _where_clause) = input.generics.split_for_impl();
let dummy = Ident::new(
&format!("_IMPL_CONFIGMETA_FOR_{}", ident),
Span::call_site(),
);

let options = fields
.named
Expand All @@ -44,17 +40,14 @@ fn derive_struct(input: &DeriveInput, fields: &FieldsNamed) -> Result<TokenStrea
let bounded_where_clause = bound::where_clause_with_bound(&input.generics, bound);

let tokens = quote! {
#[allow(non_upper_case_globals)]
const #dummy: () = {
impl #impl_generics crate::meta::ConfigMeta for #ident #ty_generics #bounded_where_clause {
fn get_config_options(&self) -> &'static [crate::meta::ConfigOption]
{
&[
#( #options, )*
]
}
impl #impl_generics crate::meta::ConfigMeta for #ident #ty_generics #bounded_where_clause {
fn get_config_options(&self) -> &'static [crate::meta::ConfigOption]
{
&[
#( #options, )*
]
}
};
}
};

if info.debug {
Expand Down
2 changes: 1 addition & 1 deletion lua-api-crates/serde-funcs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ fn toml_decode(lua: &Lua, text: String) -> mlua::Result<LuaValue> {
json_value_to_lua_value(lua, value)
}

fn json_value_to_lua_value<'lua>(lua: &'lua Lua, value: JValue) -> mlua::Result<LuaValue> {
fn json_value_to_lua_value<'lua>(lua: &'lua Lua, value: JValue) -> mlua::Result<LuaValue<'lua>> {
Ok(match value {
JValue::Null => LuaValue::Nil,
JValue::Bool(b) => LuaValue::Boolean(b),
Expand Down
2 changes: 1 addition & 1 deletion luahelper/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ macro_rules! impl_lua_conversion_dynamic {
pub fn dynamic_to_lua_value<'lua>(
lua: &'lua mlua::Lua,
value: DynValue,
) -> mlua::Result<mlua::Value> {
) -> mlua::Result<mlua::Value<'lua>> {
Ok(match value {
DynValue::Null => LuaValue::Nil,
DynValue::Bool(b) => LuaValue::Boolean(b),
Expand Down
60 changes: 23 additions & 37 deletions wezterm-dynamic/derive/src/fromdynamic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{attr, bound};
use proc_macro2::{Span, TokenStream};
use quote::quote;
use syn::{
parse_quote, Data, DataEnum, DataStruct, DeriveInput, Error, Fields, FieldsNamed, Ident, Result,
parse_quote, Data, DataEnum, DataStruct, DeriveInput, Error, Fields, FieldsNamed, Result,
};

pub fn derive(input: DeriveInput) -> Result<TokenStream> {
Expand All @@ -28,10 +28,6 @@ fn derive_struct(input: &DeriveInput, fields: &FieldsNamed) -> Result<TokenStrea
let ident = &input.ident;
let literal = ident.to_string();
let (impl_generics, ty_generics, _where_clause) = input.generics.split_for_impl();
let dummy = Ident::new(
&format!("_IMPL_FROMDYNAMIC_FOR_{}", ident),
Span::call_site(),
);

let placements = fields
.named
Expand Down Expand Up @@ -119,22 +115,19 @@ fn derive_struct(input: &DeriveInput, fields: &FieldsNamed) -> Result<TokenStrea
};

let tokens = quote! {
#[allow(non_upper_case_globals)]
const #dummy: () = {
impl #impl_generics wezterm_dynamic::FromDynamic for #ident #ty_generics #bounded_where_clause {
fn from_dynamic(value: &wezterm_dynamic::Value, options: wezterm_dynamic::FromDynamicOptions) -> std::result::Result<Self, wezterm_dynamic::Error> {
use wezterm_dynamic::{Value, BorrowedKey, ObjectKeyTrait};
#adjust_options
#from_dynamic
}

impl #impl_generics wezterm_dynamic::FromDynamic for #ident #ty_generics #bounded_where_clause {
fn from_dynamic(value: &wezterm_dynamic::Value, options: wezterm_dynamic::FromDynamicOptions) -> std::result::Result<Self, wezterm_dynamic::Error> {
use wezterm_dynamic::{Value, BorrowedKey, ObjectKeyTrait};
#adjust_options
#from_dynamic
}
impl #impl_generics #ident #ty_generics #bounded_where_clause {
pub const fn possible_field_names() -> &'static [&'static str] {
#field_names
}

}
impl #impl_generics #ident #ty_generics #bounded_where_clause {
pub const fn possible_field_names() -> &'static [&'static str] {
#field_names
}
};
}
};

if info.debug {
Expand All @@ -154,10 +147,6 @@ fn derive_enum(input: &DeriveInput, enumeration: &DataEnum) -> Result<TokenStrea

let ident = &input.ident;
let literal = ident.to_string();
let dummy = Ident::new(
&format!("_IMPL_FROMDYNAMIC_FOR_{}", ident),
Span::call_site(),
);

let variant_names = enumeration
.variants
Expand Down Expand Up @@ -321,23 +310,20 @@ fn derive_enum(input: &DeriveInput, enumeration: &DataEnum) -> Result<TokenStrea
};

let tokens = quote! {
#[allow(non_upper_case_globals)]
const #dummy: () = {
impl wezterm_dynamic::FromDynamic for #ident {
fn from_dynamic(value: &wezterm_dynamic::Value, options: wezterm_dynamic::FromDynamicOptions) -> std::result::Result<Self, wezterm_dynamic::Error> {
use wezterm_dynamic::{Value, BorrowedKey, ObjectKeyTrait};
#from_dynamic
}
impl wezterm_dynamic::FromDynamic for #ident {
fn from_dynamic(value: &wezterm_dynamic::Value, options: wezterm_dynamic::FromDynamicOptions) -> std::result::Result<Self, wezterm_dynamic::Error> {
use wezterm_dynamic::{Value, BorrowedKey, ObjectKeyTrait};
#from_dynamic
}
}

impl #ident {
pub fn variants() -> &'static [&'static str] {
&[
#( #variant_names, )*
]
}
impl #ident {
pub fn variants() -> &'static [&'static str] {
&[
#( #variant_names, )*
]
}
};
}
};

if info.debug {
Expand Down
45 changes: 13 additions & 32 deletions wezterm-dynamic/derive/src/todynamic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ fn derive_struct(input: &DeriveInput, fields: &FieldsNamed) -> Result<TokenStrea
let ident = &input.ident;
let info = attr::container_info(&input.attrs)?;
let (impl_generics, ty_generics, _where_clause) = input.generics.split_for_impl();
let dummy = Ident::new(
&format!("_IMPL_PLACEDYNAMIC_FOR_{}", ident),
Span::call_site(),
);

let placements = fields
.named
Expand All @@ -48,23 +44,16 @@ fn derive_struct(input: &DeriveInput, fields: &FieldsNamed) -> Result<TokenStrea
let tokens = match info.into {
Some(into) => {
quote!(

#[allow(non_upper_case_globals)]
const #dummy: () = {

impl #impl_generics wezterm_dynamic::ToDynamic for #ident #ty_generics #bounded_where_clause {
fn to_dynamic(&self) -> wezterm_dynamic::Value {
let target: #into = self.into();
target.to_dynamic()
}
}
};
)
}
None => {
quote!(
#[allow(non_upper_case_globals)]
const #dummy: () = {
impl #impl_generics wezterm_dynamic::PlaceDynamic for #ident #ty_generics #bounded_where_clause {
fn place_dynamic(&self, place: &mut wezterm_dynamic::Object) {
#(
Expand All @@ -82,7 +71,6 @@ fn derive_struct(input: &DeriveInput, fields: &FieldsNamed) -> Result<TokenStrea
wezterm_dynamic::Value::Object(object)
}
}
};
)
}
};
Expand All @@ -102,21 +90,17 @@ fn derive_enum(input: &DeriveInput, enumeration: &DataEnum) -> Result<TokenStrea
}

let ident = &input.ident;
let dummy = Ident::new(&format!("_IMPL_TODYNAMIC_FOR_{}", ident), Span::call_site());
let info = attr::container_info(&input.attrs)?;

let tokens = match info.into {
Some(into) => {
quote! {
#[allow(non_upper_case_globals)]
const #dummy: () = {
impl wezterm_dynamic::ToDynamic for #ident {
fn to_dynamic(&self) -> wezterm_dynamic::Value {
let target : #into = self.into();
target.to_dynamic()
}
impl wezterm_dynamic::ToDynamic for #ident {
fn to_dynamic(&self) -> wezterm_dynamic::Value {
let target : #into = self.into();
target.to_dynamic()
}
};
}
}
}
None => {
Expand Down Expand Up @@ -207,19 +191,16 @@ fn derive_enum(input: &DeriveInput, enumeration: &DataEnum) -> Result<TokenStrea
.collect::<Result<Vec<_>>>()?;

quote! {
#[allow(non_upper_case_globals)]
const #dummy: () = {
impl wezterm_dynamic::ToDynamic for #ident {
fn to_dynamic(&self) -> wezterm_dynamic::Value {
use wezterm_dynamic::Value;
match self {
#(
#variants
)*
}
impl wezterm_dynamic::ToDynamic for #ident {
fn to_dynamic(&self) -> wezterm_dynamic::Value {
use wezterm_dynamic::Value;
match self {
#(
#variants
)*
}
}
};
}
}
}
};
Expand Down

0 comments on commit 74015a9

Please sign in to comment.