-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Remove extra braces in html_nested macro #2169
Changes from 4 commits
d647201
a1169dd
eca58be
444a6aa
bae3879
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -120,8 +120,8 @@ impl ToTokens for HtmlComponent { | |
|
||
tokens.extend(quote_spanned! {ty.span()=> | ||
{ | ||
#[allow(clippy::unit_arg)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Previously the now |
||
::yew::virtual_dom::VChild::<#ty>::new(#build_props, #node_ref, #key) | ||
let __yew_props = #build_props; | ||
::yew::virtual_dom::VChild::<#ty>::new(__yew_props, #node_ref, #key) | ||
} | ||
}); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -362,6 +362,10 @@ impl ToTokens for HtmlElement { | |
// this way we get a nice error message (with the correct span) when the expression | ||
// doesn't return a valid value | ||
quote_spanned! {expr.span()=> { | ||
#[allow(unused_braces)] | ||
// e.g. html!{<@{"div"}/>} will set `#expr` to `{"div"}` | ||
// (note the extra braces). Hence the need for the `allow`. | ||
// Anyways to remove the braces? | ||
let mut #vtag_name = ::std::convert::Into::< | ||
::std::borrow::Cow::<'static, ::std::primitive::str> | ||
>::into(#expr); | ||
Comment on lines
+364
to
370
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is where the misplaced |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -168,7 +168,7 @@ impl ToTokens for HtmlRootVNode { | |
fn to_tokens(&self, tokens: &mut TokenStream) { | ||
let new_tokens = self.0.to_token_stream(); | ||
tokens.extend(quote! {{ | ||
#[allow(clippy::useless_conversion, unused_braces)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this part is for the |
||
#[allow(clippy::useless_conversion)] | ||
<::yew::virtual_dom::VNode as ::std::convert::From<_>>::from(#new_tokens) | ||
}}); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#![no_implicit_prelude] | ||
|
||
// Shadow primitives | ||
#[allow(non_camel_case_types)] | ||
pub struct bool; | ||
#[allow(non_camel_case_types)] | ||
pub struct char; | ||
#[allow(non_camel_case_types)] | ||
pub struct f32; | ||
#[allow(non_camel_case_types)] | ||
pub struct f64; | ||
#[allow(non_camel_case_types)] | ||
pub struct i128; | ||
#[allow(non_camel_case_types)] | ||
pub struct i16; | ||
#[allow(non_camel_case_types)] | ||
pub struct i32; | ||
#[allow(non_camel_case_types)] | ||
pub struct i64; | ||
#[allow(non_camel_case_types)] | ||
pub struct i8; | ||
#[allow(non_camel_case_types)] | ||
pub struct isize; | ||
#[allow(non_camel_case_types)] | ||
pub struct str; | ||
#[allow(non_camel_case_types)] | ||
pub struct u128; | ||
#[allow(non_camel_case_types)] | ||
pub struct u16; | ||
#[allow(non_camel_case_types)] | ||
pub struct u32; | ||
#[allow(non_camel_case_types)] | ||
pub struct u64; | ||
#[allow(non_camel_case_types)] | ||
pub struct u8; | ||
#[allow(non_camel_case_types)] | ||
pub struct usize; | ||
|
||
pub struct MyComponent; | ||
impl ::yew::Component for MyComponent { | ||
type Message = (); | ||
type Properties = (); | ||
fn create(_ctx: &::yew::Context<Self>) -> Self { | ||
::std::unimplemented!() | ||
} | ||
fn view(&self, _ctx: &::yew::Context<Self>) -> ::yew::Html { | ||
::std::unimplemented!() | ||
} | ||
} | ||
|
||
// can test "unused braces" warning inside the macro | ||
// /~https://github.com/yewstack/yew/issues/2157 | ||
fn make_my_component()-> ::yew::virtual_dom::VChild<MyComponent>{ | ||
::yew::html_nested!{<MyComponent/>} | ||
} | ||
|
||
// can test "unused braces" warning inside the macro | ||
// /~https://github.com/yewstack/yew/issues/2157 | ||
fn make_my_component_html()-> ::yew::Html{ | ||
::yew::html!{<MyComponent/>} | ||
} | ||
Comment on lines
+51
to
+61
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. test for both |
||
|
||
fn main(){} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find this useful in development