Skip to content

Commit 5ebbc08

Browse files
committed
More inline const expressions
1 parent 3774296 commit 5ebbc08

File tree

6 files changed

+11
-12
lines changed

6 files changed

+11
-12
lines changed

src/chunk.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ pub struct Compiler {
134134
#[cfg(any(feature = "luau", doc))]
135135
impl Default for Compiler {
136136
fn default() -> Self {
137-
Self::new()
137+
const { Self::new() }
138138
}
139139
}
140140

@@ -323,8 +323,8 @@ impl<'a> Chunk<'a> {
323323
/// necessary to populate the environment in order for scripts using custom environments to be
324324
/// useful.
325325
pub fn set_environment(mut self, env: impl IntoLua) -> Self {
326-
let lua = self.lua.lock();
327-
let lua = lua.lua();
326+
let guard = self.lua.lock();
327+
let lua = guard.lua();
328328
self.env = env
329329
.into_lua(lua)
330330
.and_then(|val| lua.unpack(val))
@@ -357,8 +357,7 @@ impl<'a> Chunk<'a> {
357357
///
358358
/// This is equivalent to calling the chunk function with no arguments and no return values.
359359
pub fn exec(self) -> Result<()> {
360-
self.call::<()>(())?;
361-
Ok(())
360+
self.call(())
362361
}
363362

364363
/// Asynchronously execute this chunk of code.

src/multi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ impl<T> Variadic<T> {
141141

142142
impl<T> Default for Variadic<T> {
143143
fn default() -> Variadic<T> {
144-
Variadic::new()
144+
const { Variadic::new() }
145145
}
146146
}
147147

src/serde/de.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ pub struct Options {
5151

5252
impl Default for Options {
5353
fn default() -> Self {
54-
Self::new()
54+
const { Self::new() }
5555
}
5656
}
5757

src/serde/ser.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ pub struct Options {
5252

5353
impl Default for Options {
5454
fn default() -> Self {
55-
Self::new()
55+
const { Self::new() }
5656
}
5757
}
5858

src/state.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ pub struct LuaOptions {
104104

105105
impl Default for LuaOptions {
106106
fn default() -> Self {
107-
LuaOptions::new()
107+
const { LuaOptions::new() }
108108
}
109109
}
110110

@@ -1251,7 +1251,7 @@ impl Lua {
12511251
///
12521252
/// This methods provides a way to add fields or methods to userdata objects of a type `T`.
12531253
pub fn register_userdata_type<T: 'static>(&self, f: impl FnOnce(&mut UserDataRegistry<T>)) -> Result<()> {
1254-
let mut registry = UserDataRegistry::new();
1254+
let mut registry = const { UserDataRegistry::new() };
12551255
f(&mut registry);
12561256

12571257
let lua = self.lock();

src/state/raw.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,7 @@ impl RawLua {
723723
}
724724

725725
// Create a new metatable from `UserData` definition
726-
let mut registry = UserDataRegistry::new();
726+
let mut registry = const { UserDataRegistry::new() };
727727
T::register(&mut registry);
728728

729729
self.register_userdata_metatable(registry)
@@ -742,7 +742,7 @@ impl RawLua {
742742
}
743743

744744
// Create an empty metatable
745-
let registry = UserDataRegistry::new();
745+
let registry = const { UserDataRegistry::new() };
746746
self.register_userdata_metatable::<T>(registry)
747747
})
748748
}

0 commit comments

Comments
 (0)