Skip to content

Commit ea5bdff

Browse files
committed
fix(arena): resolve clippy warnings for unsized types in Collect trait
Split static_collect! macro into two variants to handle sized vs unsized types: - static_collect_sized! for types that implement Sized (implements needs_trace) - static_collect! for potentially unsized types (skips needs_trace) This fixes clippy warnings about needs_trace() not being usable for unsized types like str, CStr, Path, and OsStr due to the Sized bound in the trait. Also removed needs_trace() implementations from: - &'static T (where T: ?Sized) - [T] (slice type is inherently unsized) The trait's default implementation handles the optimization check for sized types, while unsized types simply don't provide the method.
1 parent f20e08f commit ea5bdff

File tree

2 files changed

+36
-31
lines changed

2 files changed

+36
-31
lines changed

aiscript-arena/src/collect_impl.rs

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,19 @@ use crate::context::Collection;
1616
/// simple empty `Collect` implementation.
1717
#[macro_export]
1818
macro_rules! static_collect {
19+
($type:ty) => {
20+
unsafe impl Collect for $type
21+
where
22+
$type: 'static,
23+
{
24+
// Don't implement needs_trace for unsized types
25+
}
26+
};
27+
}
28+
29+
/// For sized static types, we can implement needs_trace
30+
#[macro_export]
31+
macro_rules! static_collect_sized {
1932
($type:ty) => {
2033
unsafe impl Collect for $type
2134
where
@@ -29,33 +42,33 @@ macro_rules! static_collect {
2942
};
3043
}
3144

32-
static_collect!(bool);
33-
static_collect!(char);
34-
static_collect!(u8);
35-
static_collect!(u16);
36-
static_collect!(u32);
37-
static_collect!(u64);
38-
static_collect!(usize);
39-
static_collect!(i8);
40-
static_collect!(i16);
41-
static_collect!(i32);
42-
static_collect!(i64);
43-
static_collect!(isize);
44-
static_collect!(f32);
45-
static_collect!(f64);
46-
static_collect!(String);
45+
static_collect_sized!(bool);
46+
static_collect_sized!(char);
47+
static_collect_sized!(u8);
48+
static_collect_sized!(u16);
49+
static_collect_sized!(u32);
50+
static_collect_sized!(u64);
51+
static_collect_sized!(usize);
52+
static_collect_sized!(i8);
53+
static_collect_sized!(i16);
54+
static_collect_sized!(i32);
55+
static_collect_sized!(i64);
56+
static_collect_sized!(isize);
57+
static_collect_sized!(f32);
58+
static_collect_sized!(f64);
59+
static_collect_sized!(String);
4760
static_collect!(str);
48-
static_collect!(alloc::ffi::CString);
61+
static_collect_sized!(alloc::ffi::CString);
4962
static_collect!(core::ffi::CStr);
50-
static_collect!(core::any::TypeId);
63+
static_collect_sized!(core::any::TypeId);
5164
#[cfg(feature = "std")]
5265
static_collect!(std::path::Path);
5366
#[cfg(feature = "std")]
54-
static_collect!(std::path::PathBuf);
67+
static_collect_sized!(std::path::PathBuf);
5568
#[cfg(feature = "std")]
5669
static_collect!(std::ffi::OsStr);
5770
#[cfg(feature = "std")]
58-
static_collect!(std::ffi::OsString);
71+
static_collect_sized!(std::ffi::OsString);
5972

6073
/// SAFETY: We know that a `&'static` reference cannot possibly point to `'gc` data, so it is safe
6174
/// to keep in a rooted objet and we do not have to trace through it.
@@ -84,10 +97,7 @@ static_collect!(std::ffi::OsString);
8497
///
8598
/// DO NOT REMOVE THIS EXTRA `T: 'static` BOUND
8699
unsafe impl<T: ?Sized + 'static> Collect for &'static T {
87-
#[inline]
88-
fn needs_trace() -> bool {
89-
false
90-
}
100+
// Don't implement needs_trace since T might be unsized
91101
}
92102

93103
unsafe impl<T: ?Sized + Collect> Collect for Box<T> {
@@ -98,10 +108,7 @@ unsafe impl<T: ?Sized + Collect> Collect for Box<T> {
98108
}
99109

100110
unsafe impl<T: Collect> Collect for [T] {
101-
#[inline]
102-
fn needs_trace() -> bool {
103-
T::needs_trace()
104-
}
111+
// Don't implement needs_trace since [T] is unsized
105112

106113
#[inline]
107114
fn trace(&self, cc: &Collection) {

aiscript-vm/src/compiler/codegen.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ pub struct CodeGen<'gc> {
7070

7171
impl<'gc> CodeGen<'gc> {
7272
pub fn new(ctx: Context<'gc>, fn_type: FunctionType, name: &str) -> Box<Self> {
73-
let generator = Box::new(CodeGen {
73+
Box::new(CodeGen {
7474
ctx,
7575
chunks: HashMap::new(),
7676
named_id_map: HashMap::new(),
@@ -107,9 +107,7 @@ impl<'gc> CodeGen<'gc> {
107107
enclosing: None,
108108
current_line: 0,
109109
error_reporter: ErrorReporter::new(),
110-
});
111-
112-
generator
110+
})
113111
}
114112

115113
pub fn register_enum(&mut self, name: &'gc str, enum_: GcRefLock<'gc, Enum<'gc>>) {

0 commit comments

Comments
 (0)