Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiler warnings about bracket #20

Closed
szagi3891 opened this issue Jun 26, 2022 · 13 comments
Closed

Compiler warnings about bracket #20

szagi3891 opened this issue Jun 26, 2022 · 13 comments

Comments

@szagi3891
Copy link

Is it possible to disable these compiler warnings ?


warning: unnecessary braces around function argument
   --> demo/app/src/app/todo/mod.rs:256:37
    |
256 | ...                   { &comment.body }
    |                       ^^             ^^
    |
help: remove these braces
    |
256 -                                     { &comment.body }
256 +                                     &comment.body
    | 

warning: unnecessary braces around function argument
   --> demo/app/src/app/todo/mod.rs:270:25
    |
270 |                         { list_view }
    |                         ^^         ^^
    |
help: remove these braces
    |
270 -                         { list_view }
270 +                         list_view
    | 

warning: unnecessary braces around function argument
   --> demo/app/src/app/todo/mod.rs:278:25
    |
278 |                         { message }
    |                         ^^       ^^
    |
help: remove these braces
    |
278 -                         { message }
278 +                         message

@stoically
Copy link
Owner

Could you provide the code in question? Not sure what the context is.

@szagi3891
Copy link
Author

Sure.

I have this repository: https://github.com/vertigo-web/vertigo
Branch: "builder"

https://github.com/vertigo-web/vertigo/blob/d81013550607cf7341c3b2c840c0c29543779104/demo/app/src/app/todo/mod.rs#L278

            ResourceComputed::Error(message) => {
                dom! {
                    <div>
                        "Error = "
                        { message }
                    </div>
                }
            },

This part of the program is reporting warnings to me:

warning: unnecessary braces around function argument
   --> demo/app/src/app/todo/mod.rs:278:25
    |
278 |                         { message }
    |                         ^^       ^^
    |
help: remove these braces
    |
278 -                         { message }
278 +                         message
    | 

@stoically
Copy link
Owner

stoically commented Jun 26, 2022

Looks like this might be a false-positive from the nightly compiler, similar to rust-lang/rust#47775. Can't try with stable compiler since the crate depends on a nightly feature flag it seems.

Nice project, good luck with it!

@stoically
Copy link
Owner

Oh, and in terms of disabling those as a workaround, #[allow(unused_parens)] should do that trick, I guess.

@szagi3891
Copy link
Author

szagi3891 commented Jun 26, 2022

Nice project, good luck with it!

thank you :)

Can't try with stable compiler since the crate depends on a nightly feature flag it seems.

I tried to switch. The effect is the same.

I guess it must depend on the macro somehow. The previous html macro is built using https://crates.io/crates/percy and there this problem does not occur :/

@stoically
Copy link
Owner

stoically commented Jun 26, 2022

Ah, I see. It's probably your implementation of dom which generates unnecessary brackets around your generated code. I'd look at the expanded output with cargo-expand to see how exactly it looks like. Maybe it's just that you currently have a quote!{{ instead of just quote!{ somewhere.

syn-rsx itself doesn't generate code, so it can't generate unnecessary brackets either.

@szagi3891
Copy link
Author

I think you are right. I will try to solve the problem this way.

@stoically
Copy link
Owner

Sounds good. If it works out, feel free to close the issue. 👍

@szagi3891
Copy link
Author

        } else if child.node_type == NodeType::Block {
            // let block = child.value_as_block().unwrap();
            let block = child.value.unwrap();

            let stream = block.to_token_stream();
            println!("\n\n\nblock {stream}\n\n\n");

            out_child.push(quote! {
                .child(vertigo::EmbedDom::embed(#block))
            });

        } else {

It produces such a message:

block { message }

It appears that the variable block also contains these brackets:
let block = child.value.unwrap();

@stoically
Copy link
Owner

stoically commented Jun 26, 2022

Yep, value gives you an ExprBlock in this case, which itself contains the brackets. Using block.block.stmts instead might do the trick. Or if you want to keep the block fully intact, you could add an #[allow(unused_parens)] inside the quote!, since having unused brackets in this case seems ok.

@szagi3891
Copy link
Author

I had to clear this block of brackets. This solved the problem completely.

fn convert_expresion_without_brackets(span: Span, expr: Option<Expr>) -> Result<TokenStream2, ()> {
    match expr {
        Some(Expr::Block(expr)) => {
            let mut stmts = expr.block.stmts;
            
            let first = stmts.pop();

            if stmts.len() > 0 {
                emit_error!(span, format!("one Stmt was expected"));
                return Err(());
            }

            if let Some(first) = first {
                return Ok(first.to_token_stream());
            } else {
                emit_error!(span, format!("one Stmt was expected"));
                return Err(());
            }
        },
        _ => {
            emit_error!(span, format!("Block was expected"));
            Err(())
        }
    }
}

Thanks for your help :)

@stoically
Copy link
Owner

stoically commented Jun 26, 2022

Dirty but creative 😄 Personally I wouldnt operate directly on the stmts, but if it works for you, even better!

@szagi3891
Copy link
Author

In the worst case it will not compile :D

dezren39 pushed a commit to dezren39/syn-rsx that referenced this issue Jul 31, 2023
Allow wildcard close tag for block elements
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants