• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

davidcole1340 / ext-php-rs / 18881635050

28 Oct 2025 04:18PM UTC coverage: 31.037% (-0.1%) from 31.138%
18881635050

Pull #566

github

web-flow
Merge 610ff3dd0 into a0387a4cd
Pull Request #566: chore(rust): bump Rust edition to 2024

10 of 91 new or added lines in 14 files covered. (10.99%)

1 existing line in 1 file now uncovered.

1356 of 4369 relevant lines covered (31.04%)

8.5 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/crates/macros/src/function.rs
1
use std::collections::HashMap;
2

3
use darling::{FromAttributes, ToTokens};
4
use proc_macro2::{Ident, Span, TokenStream};
5
use quote::{format_ident, quote};
6
use syn::spanned::Spanned as _;
7
use syn::{Expr, FnArg, GenericArgument, ItemFn, PatType, PathArguments, Type, TypePath};
8

9
use crate::helpers::get_docs;
10
use crate::parsing::{PhpRename, RenameRule, Visibility};
11
use crate::prelude::*;
12
use crate::syn_ext::DropLifetimes;
13

14
pub fn wrap(input: &syn::Path) -> Result<TokenStream> {
×
15
    let Some(func_name) = input.get_ident() else {
×
16
        bail!(input => "Pass a PHP function name into `wrap_function!()`.");
×
17
    };
18
    let builder_func = format_ident!("_internal_{func_name}");
×
19

20
    Ok(quote! {{
×
21
        (<#builder_func as ::ext_php_rs::internal::function::PhpFunction>::FUNCTION_ENTRY)()
×
22
    }})
23
}
24

25
#[derive(FromAttributes, Default, Debug)]
26
#[darling(default, attributes(php), forward_attrs(doc))]
27
struct PhpFunctionAttribute {
28
    #[darling(flatten)]
29
    rename: PhpRename,
30
    defaults: HashMap<Ident, Expr>,
31
    optional: Option<Ident>,
32
    vis: Option<Visibility>,
33
    attrs: Vec<syn::Attribute>,
34
}
35

36
pub fn parser(mut input: ItemFn) -> Result<TokenStream> {
×
37
    let php_attr = PhpFunctionAttribute::from_attributes(&input.attrs)?;
×
38
    input.attrs.retain(|attr| !attr.path().is_ident("php"));
×
39

40
    let args = Args::parse_from_fnargs(input.sig.inputs.iter(), php_attr.defaults)?;
×
41
    if let Some(ReceiverArg { span, .. }) = args.receiver {
×
42
        bail!(span => "Receiver arguments are invalid on PHP functions. See `#[php_impl]`.");
×
43
    }
44

45
    let docs = get_docs(&php_attr.attrs)?;
×
46

47
    let func = Function::new(
48
        &input.sig,
×
49
        php_attr
×
50
            .rename
×
51
            .rename(input.sig.ident.to_string(), RenameRule::Snake),
×
52
        args,
×
53
        php_attr.optional,
×
54
        docs,
×
55
    );
56
    let function_impl = func.php_function_impl();
×
57

58
    Ok(quote! {
×
59
        #input
×
60
        #function_impl
×
61
    })
62
}
63

64
#[derive(Debug)]
65
pub struct Function<'a> {
66
    /// Identifier of the Rust function associated with the function.
67
    pub ident: &'a Ident,
68
    /// Name of the function in PHP.
69
    pub name: String,
70
    /// Function arguments.
71
    pub args: Args<'a>,
72
    /// Function outputs.
73
    pub output: Option<&'a Type>,
74
    /// The first optional argument of the function.
75
    pub optional: Option<Ident>,
76
    /// Doc comments for the function.
77
    pub docs: Vec<String>,
78
}
79

80
#[derive(Debug)]
81
pub enum CallType<'a> {
82
    Function,
83
    Method {
84
        class: &'a syn::Path,
85
        receiver: MethodReceiver,
86
    },
87
}
88

89
/// Type of receiver on the method.
90
#[derive(Debug)]
91
pub enum MethodReceiver {
92
    /// Static method - has no receiver.
93
    Static,
94
    /// Class method, takes `&self` or `&mut self`.
95
    Class,
96
    /// Class method, takes `&mut ZendClassObject<Self>`.
97
    ZendClassObject,
98
}
99

100
impl<'a> Function<'a> {
101
    /// Parse a function.
102
    ///
103
    /// # Parameters
104
    ///
105
    /// * `sig` - Function signature.
106
    /// * `name` - Function name in PHP land.
107
    /// * `args` - Function arguments.
108
    /// * `optional` - The ident of the first optional argument.
109
    pub fn new(
×
110
        sig: &'a syn::Signature,
111
        name: String,
112
        args: Args<'a>,
113
        optional: Option<Ident>,
114
        docs: Vec<String>,
115
    ) -> Self {
116
        Self {
117
            ident: &sig.ident,
×
118
            name,
119
            args,
120
            output: match &sig.output {
×
121
                syn::ReturnType::Default => None,
122
                syn::ReturnType::Type(_, ty) => Some(&**ty),
123
            },
124
            optional,
125
            docs,
126
        }
127
    }
128

129
    /// Generates an internal identifier for the function.
130
    pub fn internal_ident(&self) -> Ident {
×
131
        format_ident!("_internal_{}", &self.ident)
×
132
    }
133

134
    /// Generates the function builder for the function.
135
    pub fn function_builder(&self, call_type: CallType) -> TokenStream {
×
136
        let name = &self.name;
×
137
        let (required, not_required) = self.args.split_args(self.optional.as_ref());
×
138

139
        // `handler` impl
140
        let arg_declarations = self
×
141
            .args
×
142
            .typed
×
143
            .iter()
144
            .map(TypedArg::arg_declaration)
×
145
            .collect::<Vec<_>>();
146

147
        // `entry` impl
148
        let required_args = required
×
149
            .iter()
150
            .map(TypedArg::arg_builder)
×
151
            .collect::<Vec<_>>();
152
        let not_required_args = not_required
×
153
            .iter()
154
            .map(TypedArg::arg_builder)
×
155
            .collect::<Vec<_>>();
156

157
        let returns = self.build_returns();
×
158
        let result = self.build_result(call_type, required, not_required);
×
159
        let docs = if self.docs.is_empty() {
×
160
            quote! {}
×
161
        } else {
162
            let docs = &self.docs;
×
163
            quote! {
×
164
                .docs(&[#(#docs),*])
×
165
            }
166
        };
167

168
        quote! {
×
169
            ::ext_php_rs::builders::FunctionBuilder::new(#name, {
×
170
                ::ext_php_rs::zend_fastcall! {
×
171
                    extern fn handler(
×
172
                        ex: &mut ::ext_php_rs::zend::ExecuteData,
×
173
                        retval: &mut ::ext_php_rs::types::Zval,
×
174
                    ) {
175
                        use ::ext_php_rs::convert::IntoZval;
×
176

177
                        #(#arg_declarations)*
×
178
                        let result = {
×
179
                            #result
×
180
                        };
181

182
                        if let Err(e) = result.set_zval(retval, false) {
×
183
                            let e: ::ext_php_rs::exception::PhpException = e.into();
×
184
                            e.throw().expect("Failed to throw PHP exception.");
×
185
                        }
186
                    }
187
                }
188
                handler
×
189
            })
190
            #(.arg(#required_args))*
×
191
            .not_required()
×
192
            #(.arg(#not_required_args))*
×
193
            #returns
×
194
            #docs
×
195
        }
196
    }
197

198
    fn build_returns(&self) -> Option<TokenStream> {
×
199
        self.output.cloned().map(|mut output| {
×
200
            output.drop_lifetimes();
×
201
            quote! {
×
202
                .returns(
×
203
                    <#output as ::ext_php_rs::convert::IntoZval>::TYPE,
×
204
                    false,
×
205
                    <#output as ::ext_php_rs::convert::IntoZval>::NULLABLE,
×
206
                )
207
            }
208
        })
209
    }
210

211
    fn build_result(
×
212
        &self,
213
        call_type: CallType,
214
        required: &[TypedArg<'_>],
215
        not_required: &[TypedArg<'_>],
216
    ) -> TokenStream {
217
        let ident = self.ident;
×
218
        let required_arg_names: Vec<_> = required.iter().map(|arg| arg.name).collect();
×
219
        let not_required_arg_names: Vec<_> = not_required.iter().map(|arg| arg.name).collect();
×
220

NEW
221
        let variadic_bindings = self.args.typed.iter().filter_map(|arg| {
×
NEW
222
            if arg.variadic {
×
NEW
223
                let name = arg.name;
×
NEW
224
                let variadic_name = format_ident!("__variadic_{}", name);
×
NEW
225
                let clean_ty = arg.clean_ty();
×
NEW
226
                Some(quote! {
×
NEW
227
                    let #variadic_name = #name.variadic_vals::<#clean_ty>();
×
228
                })
229
            } else {
NEW
230
                None
×
231
            }
232
        });
233

234
        let arg_accessors = self.args.typed.iter().map(|arg| {
×
235
            arg.accessor(|e| {
×
236
                quote! {
×
237
                    #e.throw().expect("Failed to throw PHP exception.");
×
238
                    return;
×
239
                }
240
            })
241
        });
242

243
        match call_type {
×
244
            CallType::Function => quote! {
×
245
                let parse = ex.parser()
×
246
                    #(.arg(&mut #required_arg_names))*
×
247
                    .not_required()
×
248
                    #(.arg(&mut #not_required_arg_names))*
×
249
                    .parse();
×
250
                if parse.is_err() {
×
251
                    return;
×
252
                }
NEW
253
                #(#variadic_bindings)*
×
254

255
                #ident(#({#arg_accessors}),*)
×
256
            },
257
            CallType::Method { class, receiver } => {
×
258
                let this = match receiver {
×
259
                    MethodReceiver::Static => quote! {
×
260
                        let parse = ex.parser();
×
261
                    },
262
                    MethodReceiver::ZendClassObject | MethodReceiver::Class => quote! {
×
263
                        let (parse, this) = ex.parser_method::<#class>();
×
264
                        let this = match this {
×
265
                            Some(this) => this,
×
266
                            None => {
×
267
                                ::ext_php_rs::exception::PhpException::default("Failed to retrieve reference to `$this`".into())
×
268
                                    .throw()
×
269
                                    .unwrap();
×
270
                                return;
×
271
                            }
272
                        };
273
                    },
274
                };
275
                let call = match receiver {
×
276
                    MethodReceiver::Static => {
×
277
                        quote! { #class::#ident(#({#arg_accessors}),*) }
×
278
                    }
279
                    MethodReceiver::Class => quote! { this.#ident(#({#arg_accessors}),*) },
×
280
                    MethodReceiver::ZendClassObject => {
×
281
                        quote! { #class::#ident(this, #({#arg_accessors}),*) }
×
282
                    }
283
                };
284
                quote! {
×
285
                    #this
×
286
                    let parse_result = parse
×
287
                        #(.arg(&mut #required_arg_names))*
×
288
                        .not_required()
×
289
                        #(.arg(&mut #not_required_arg_names))*
×
290
                        .parse();
×
291
                    if parse_result.is_err() {
×
292
                        return;
×
293
                    }
NEW
294
                    #(#variadic_bindings)*
×
295

296
                    #call
×
297
                }
298
            }
299
        }
300
    }
301

302
    /// Generates a struct and impl for the `PhpFunction` trait.
303
    pub fn php_function_impl(&self) -> TokenStream {
×
304
        let internal_ident = self.internal_ident();
×
305
        let builder = self.function_builder(CallType::Function);
×
306

307
        quote! {
×
308
            #[doc(hidden)]
×
309
            #[allow(non_camel_case_types)]
×
310
            struct #internal_ident;
×
311

312
            impl ::ext_php_rs::internal::function::PhpFunction for #internal_ident {
×
313
                const FUNCTION_ENTRY: fn() -> ::ext_php_rs::builders::FunctionBuilder<'static> = {
×
314
                    fn entry() -> ::ext_php_rs::builders::FunctionBuilder<'static>
×
315
                    {
316
                        #builder
×
317
                    }
318
                    entry
×
319
                };
320
            }
321
        }
322
    }
323

324
    /// Returns a constructor metadata object for this function. This doesn't
325
    /// check if the function is a constructor, however.
326
    pub fn constructor_meta(
×
327
        &self,
328
        class: &syn::Path,
329
        visibility: Option<&Visibility>,
330
    ) -> TokenStream {
331
        let ident = self.ident;
×
332
        let (required, not_required) = self.args.split_args(self.optional.as_ref());
×
333
        let required_args = required
×
334
            .iter()
335
            .map(TypedArg::arg_builder)
×
336
            .collect::<Vec<_>>();
337
        let not_required_args = not_required
×
338
            .iter()
339
            .map(TypedArg::arg_builder)
×
340
            .collect::<Vec<_>>();
341

342
        let required_arg_names: Vec<_> = required.iter().map(|arg| arg.name).collect();
×
343
        let not_required_arg_names: Vec<_> = not_required.iter().map(|arg| arg.name).collect();
×
344
        let arg_declarations = self
×
345
            .args
×
346
            .typed
×
347
            .iter()
348
            .map(TypedArg::arg_declaration)
×
349
            .collect::<Vec<_>>();
NEW
350
        let variadic_bindings = self.args.typed.iter().filter_map(|arg| {
×
NEW
351
            if arg.variadic {
×
NEW
352
                let name = arg.name;
×
NEW
353
                let variadic_name = format_ident!("__variadic_{}", name);
×
NEW
354
                let clean_ty = arg.clean_ty();
×
NEW
355
                Some(quote! {
×
NEW
356
                    let #variadic_name = #name.variadic_vals::<#clean_ty>();
×
357
                })
358
            } else {
NEW
359
                None
×
360
            }
361
        });
362
        let arg_accessors = self.args.typed.iter().map(|arg| {
×
363
            arg.accessor(
×
364
                |e| quote! { return ::ext_php_rs::class::ConstructorResult::Exception(#e); },
×
365
            )
366
        });
367
        let variadic = self.args.typed.iter().any(|arg| arg.variadic).then(|| {
×
368
            quote! {
×
369
                .variadic()
×
370
            }
371
        });
372
        let docs = &self.docs;
×
373
        let flags = visibility.option_tokens();
×
374

375
        quote! {
×
376
            ::ext_php_rs::class::ConstructorMeta {
×
377
                constructor: {
×
378
                    fn inner(ex: &mut ::ext_php_rs::zend::ExecuteData) -> ::ext_php_rs::class::ConstructorResult<#class> {
×
379
                        #(#arg_declarations)*
×
380
                        let parse = ex.parser()
×
381
                            #(.arg(&mut #required_arg_names))*
×
382
                            .not_required()
×
383
                            #(.arg(&mut #not_required_arg_names))*
×
384
                            #variadic
×
385
                            .parse();
×
386
                        if parse.is_err() {
×
387
                            return ::ext_php_rs::class::ConstructorResult::ArgError;
×
388
                        }
NEW
389
                        #(#variadic_bindings)*
×
UNCOV
390
                        #class::#ident(#({#arg_accessors}),*).into()
×
391
                    }
392
                    inner
×
393
                },
394
                build_fn: {
×
395
                    fn inner(func: ::ext_php_rs::builders::FunctionBuilder) -> ::ext_php_rs::builders::FunctionBuilder {
×
396
                        func
×
397
                            .docs(&[#(#docs),*])
×
398
                            #(.arg(#required_args))*
×
399
                            .not_required()
×
400
                            #(.arg(#not_required_args))*
×
401
                            #variadic
×
402
                    }
403
                    inner
×
404
                },
405
                flags: #flags
×
406
            }
407
        }
408
    }
409
}
410

411
#[derive(Debug)]
412
pub struct ReceiverArg {
413
    pub _mutable: bool,
414
    pub span: Span,
415
}
416

417
#[derive(Debug)]
418
pub struct TypedArg<'a> {
419
    pub name: &'a Ident,
420
    pub ty: Type,
421
    pub nullable: bool,
422
    pub default: Option<Expr>,
423
    pub as_ref: bool,
424
    pub variadic: bool,
425
}
426

427
#[derive(Debug)]
428
pub struct Args<'a> {
429
    pub receiver: Option<ReceiverArg>,
430
    pub typed: Vec<TypedArg<'a>>,
431
}
432

433
impl<'a> Args<'a> {
434
    pub fn parse_from_fnargs(
×
435
        args: impl Iterator<Item = &'a FnArg>,
436
        mut defaults: HashMap<Ident, Expr>,
437
    ) -> Result<Self> {
438
        let mut result = Self {
439
            receiver: None,
440
            typed: vec![],
×
441
        };
442
        for arg in args {
×
443
            match arg {
×
444
                FnArg::Receiver(receiver) => {
×
445
                    if receiver.reference.is_none() {
×
446
                        bail!(receiver => "PHP objects are heap-allocated and cannot be passed by value. Try using `&self` or `&mut self`.");
×
447
                    } else if result.receiver.is_some() {
×
448
                        bail!(receiver => "Too many receivers specified.")
×
449
                    }
450
                    result.receiver.replace(ReceiverArg {
×
451
                        _mutable: receiver.mutability.is_some(),
×
452
                        span: receiver.span(),
×
453
                    });
454
                }
455
                FnArg::Typed(PatType { pat, ty, .. }) => {
×
456
                    let syn::Pat::Ident(syn::PatIdent { ident, .. }) = &**pat else {
×
457
                        bail!(pat => "Unsupported argument.");
×
458
                    };
459

460
                    // If the variable is `&[&Zval]` treat it as the variadic argument.
461
                    let default = defaults.remove(ident);
×
462
                    let nullable = type_is_nullable(ty.as_ref(), default.is_some())?;
×
463
                    let (variadic, as_ref, ty) = Self::parse_typed(ty);
×
464
                    result.typed.push(TypedArg {
×
465
                        name: ident,
×
466
                        ty,
×
467
                        nullable,
×
468
                        default,
×
469
                        as_ref,
×
470
                        variadic,
×
471
                    });
472
                }
473
            }
474
        }
475
        Ok(result)
×
476
    }
477

478
    fn parse_typed(ty: &Type) -> (bool, bool, Type) {
×
479
        match ty {
×
480
            Type::Reference(ref_) => {
×
481
                let as_ref = ref_.mutability.is_some();
×
482
                match ref_.elem.as_ref() {
×
483
                    Type::Slice(slice) => (
×
484
                        // TODO: Allow specifying the variadic type.
485
                        slice.elem.to_token_stream().to_string() == "& Zval",
×
486
                        as_ref,
×
487
                        ty.clone(),
×
488
                    ),
489
                    _ => (false, as_ref, ty.clone()),
×
490
                }
491
            }
492
            Type::Path(TypePath { path, .. }) => {
×
493
                let mut as_ref = false;
×
494

495
                // For for types that are `Option<&mut T>` to turn them into
496
                // `Option<&T>`, marking the Arg as as "passed by reference".
497
                let ty = path
×
498
                    .segments
×
499
                    .last()
500
                    .filter(|seg| seg.ident == "Option")
×
501
                    .and_then(|seg| {
×
502
                        if let PathArguments::AngleBracketed(args) = &seg.arguments {
×
503
                            args.args
×
504
                                .iter()
×
505
                                .find(|arg| matches!(arg, GenericArgument::Type(_)))
×
506
                                .and_then(|ga| match ga {
×
507
                                    GenericArgument::Type(ty) => Some(match ty {
×
508
                                        Type::Reference(r) => {
×
509
                                            let mut new_ref = r.clone();
×
510
                                            new_ref.mutability = None;
×
511
                                            as_ref = true;
×
512
                                            Type::Reference(new_ref)
×
513
                                        }
514
                                        _ => ty.clone(),
×
515
                                    }),
516
                                    _ => None,
×
517
                                })
518
                        } else {
519
                            None
×
520
                        }
521
                    })
522
                    .unwrap_or_else(|| ty.clone());
×
523
                (false, as_ref, ty.clone())
×
524
            }
525
            _ => (false, false, ty.clone()),
×
526
        }
527
    }
528

529
    /// Splits the typed arguments into two slices:
530
    ///
531
    /// 1. Required arguments.
532
    /// 2. Non-required arguments.
533
    ///
534
    /// # Parameters
535
    ///
536
    /// * `optional` - The first optional argument. If [`None`], the optional
537
    ///   arguments will be from the first nullable argument after the last
538
    ///   non-nullable argument to the end of the arguments.
539
    pub fn split_args(&self, optional: Option<&Ident>) -> (&[TypedArg<'a>], &[TypedArg<'a>]) {
×
540
        let mut mid = None;
×
541
        for (i, arg) in self.typed.iter().enumerate() {
×
542
            if let Some(optional) = optional {
×
543
                if optional == arg.name {
×
544
                    mid.replace(i);
×
545
                }
546
            } else if mid.is_none() && arg.nullable {
×
547
                mid.replace(i);
×
548
            } else if !arg.nullable {
×
549
                mid.take();
×
550
            }
551
        }
552
        match mid {
×
553
            Some(mid) => (&self.typed[..mid], &self.typed[mid..]),
×
554
            None => (&self.typed[..], &self.typed[0..0]),
×
555
        }
556
    }
557
}
558

559
impl TypedArg<'_> {
560
    /// Returns a 'clean type' with the lifetimes removed. This allows the type
561
    /// to be used outside of the original function context.
562
    fn clean_ty(&self) -> Type {
×
563
        let mut ty = self.ty.clone();
×
564
        ty.drop_lifetimes();
×
565

566
        // Variadic arguments are passed as &[&Zval], so we need to extract the
567
        // inner type.
568
        if self.variadic {
×
569
            let Type::Reference(reference) = &ty else {
×
570
                return ty;
×
571
            };
572

573
            if let Type::Slice(inner) = &*reference.elem {
×
574
                return *inner.elem.clone();
×
575
            }
576
        }
577

578
        ty
×
579
    }
580

581
    /// Returns a token stream containing an argument declaration, where the
582
    /// name of the variable holding the arg is the name of the argument.
583
    fn arg_declaration(&self) -> TokenStream {
×
584
        let name = self.name;
×
585
        let val = self.arg_builder();
×
586
        quote! {
×
587
            let mut #name = #val;
588
        }
589
    }
590

591
    /// Returns a token stream containing the `Arg` definition to be passed to
592
    /// `ext-php-rs`.
593
    fn arg_builder(&self) -> TokenStream {
×
594
        let name = self.name.to_string();
×
595
        let ty = self.clean_ty();
×
596
        let null = if self.nullable {
×
597
            Some(quote! { .allow_null() })
×
598
        } else {
599
            None
×
600
        };
601
        let default = self.default.as_ref().map(|val| {
×
602
            let val = val.to_token_stream().to_string();
×
603
            quote! {
×
604
                .default(#val)
605
            }
606
        });
607
        let as_ref = if self.as_ref {
×
608
            Some(quote! { .as_ref() })
×
609
        } else {
610
            None
×
611
        };
612
        let variadic = self.variadic.then(|| quote! { .is_variadic() });
×
613
        quote! {
×
614
            ::ext_php_rs::args::Arg::new(#name, <#ty as ::ext_php_rs::convert::FromZvalMut>::TYPE)
615
                #null
616
                #default
617
                #as_ref
618
                #variadic
619
        }
620
    }
621

622
    /// Get the accessor used to access the value of the argument.
623
    fn accessor(&self, bail_fn: impl Fn(TokenStream) -> TokenStream) -> TokenStream {
×
624
        let name = self.name;
×
625
        if let Some(default) = &self.default {
×
626
            quote! {
×
627
                #name.val().unwrap_or(#default.into())
×
628
            }
629
        } else if self.variadic {
×
NEW
630
            let variadic_name = format_ident!("__variadic_{}", name);
×
631
            quote! {
×
NEW
632
                #variadic_name.as_slice()
×
633
            }
634
        } else if self.nullable {
×
635
            // Originally I thought we could just use the below case for `null` options, as
636
            // `val()` will return `Option<Option<T>>`, however, this isn't the case when
637
            // the argument isn't given, as the underlying zval is null.
638
            quote! {
×
639
                #name.val()
×
640
            }
641
        } else {
642
            let bail = bail_fn(quote! {
×
643
                ::ext_php_rs::exception::PhpException::default(
×
644
                    concat!("Invalid value given for argument `", stringify!(#name), "`.").into()
×
645
                )
646
            });
647
            quote! {
×
648
                match #name.val() {
×
649
                    Some(val) => val,
×
650
                    None => {
×
651
                        #bail;
×
652
                    }
653
                }
654
            }
655
        }
656
    }
657
}
658

659
/// Returns true of the given type is nullable in PHP.
660
// TODO(david): Eventually move to compile-time constants for this (similar to
661
// FromZval::NULLABLE).
662
pub fn type_is_nullable(ty: &Type, has_default: bool) -> Result<bool> {
×
663
    Ok(match ty {
×
664
        syn::Type::Path(path) => {
×
665
            has_default
×
666
                || path
×
667
                    .path
×
668
                    .segments
×
669
                    .iter()
×
670
                    .next_back()
×
671
                    .is_some_and(|seg| seg.ident == "Option")
×
672
        }
673
        syn::Type::Reference(_) => false, /* Reference cannot be nullable unless */
×
674
        // wrapped in `Option` (in that case it'd be a Path).
675
        _ => bail!(ty => "Unsupported argument type."),
×
676
    })
677
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc