Repository: actix/actix-web
File: actix-web-codegen/src/route.rs (Rust)

Code before:
    pub fn new(
        args: AttributeArgs,
        input: TokenStream,
        method: Option<MethodType>,
    ) -> syn::Result<Self> {
        if args.is_empty() {
            return Err(syn::Error::new(
                Span::call_site(),
                format!(
                    r#"invalid service definition, expected #[{}("<some path>")]"#,
                    method
                        .map(|it| it.as_str())
                        .unwrap_or("route")
                        .to_ascii_lowercase()
                ),
            ));
        }
        let ast: syn::ItemFn = syn::parse(input)?;
        let name = ast.sig.ident.clone();

        // Try and pull out the doc comments so that we can reapply them to the
        // generated struct.
        //
        // Note that multi line doc comments are converted to multiple doc
        // attributes.
        let mut doc_attribute = Vec::new();
        for attr in &ast.attrs {
            if let Some(ident) = attr.path.get_ident() {
                if ident == "doc" {
                    doc_attribute.push(attr.clone());
                }
            }
        }

        let args = Args::new(args, method)?;
        if args.methods.is_empty() {
            return Err(syn::Error::new(
                Span::call_site(),
                "The #[route(..)] macro requires at least one `method` attribute",
            ));
        }

        let resource_type = if ast.sig.asyncness.is_some() {
            ResourceType::Async
        } else {
            match ast.sig.output {
                syn::ReturnType::Default => {
                    return Err(syn::Error::new_spanned(
                        ast,
                        "Function has no return type. Cannot be used as handler",
                    ));

Review comment (suggestion):
```suggestion
        let mut doc_attributes = Vec::new();
```

then the return value can also use struct init shorthand for this.

Code after:
    pub fn new(
        args: AttributeArgs,
        input: TokenStream,
        method: Option<MethodType>,
    ) -> syn::Result<Self> {
        if args.is_empty() {
            return Err(syn::Error::new(
                Span::call_site(),
                format!(
                    r#"invalid service definition, expected #[{}("<some path>")]"#,
                    method
                        .map(|it| it.as_str())
                        .unwrap_or("route")
                        .to_ascii_lowercase()
                ),
            ));
        }
        let ast: syn::ItemFn = syn::parse(input)?;
        let name = ast.sig.ident.clone();

        // Try and pull out the doc comments so that we can reapply them to the
        // generated struct.
        //
        // Note that multi line doc comments are converted to multiple doc
        // attributes.
        let doc_attributes = ast
            .attrs
            .iter()
            .filter(|attr| attr.path.is_ident("doc"))
            .cloned()
            .collect();

        let args = Args::new(args, method)?;
        if args.methods.is_empty() {
            return Err(syn::Error::new(
                Span::call_site(),
                "The #[route(..)] macro requires at least one `method` attribute",
            ));
        }

        let resource_type = if ast.sig.asyncness.is_some() {
            ResourceType::Async
        } else {
            match ast.sig.output {
                syn::ReturnType::Default => {
                    return Err(syn::Error::new_spanned(
                        ast,
                        "Function has no return type. Cannot be used as handler",
                    ));
                }
                syn::ReturnType::Type(_, ref typ) => guess_resource_type(typ.as_ref()),