From 4c6da9aab3cc149cd49a4f3914db69dc1bdaada1 Mon Sep 17 00:00:00 2001 From: mc1098 Date: Tue, 7 Sep 2021 08:40:09 +0100 Subject: [PATCH] Add fully qualified primitives in proc macro (#2037) * Add primitive shadowing in macro tests * Fix primitive types to be fully qualified --- .../yew-macro/src/html_tree/html_element.rs | 10 ++-- packages/yew-macro/src/stringify.rs | 4 +- .../tests/classes_macro/classes-pass.rs | 38 +++++++++++- packages/yew-macro/tests/derive_props/pass.rs | 58 +++++++++++++++---- .../function_component_attr/generic-pass.rs | 42 +++++++++++++- .../with-props-pass.rs | 38 +++++++++++- .../without-props-pass.rs | 36 ++++++++++++ .../yew-macro/tests/html_macro/block-pass.rs | 36 ++++++++++++ .../tests/html_macro/component-pass.rs | 50 +++++++++++++--- .../tests/html_macro/dyn-element-pass.rs | 36 ++++++++++++ .../html_macro/generic-component-pass.rs | 40 ++++++++++++- .../tests/html_macro/html-element-pass.rs | 40 ++++++++++++- .../tests/html_macro/html-node-pass.rs | 38 +++++++++++- .../tests/html_macro/iterable-pass.rs | 36 ++++++++++++ .../yew-macro/tests/html_macro/list-pass.rs | 36 ++++++++++++ .../yew-macro/tests/html_macro/node-pass.rs | 36 ++++++++++++ .../yew-macro/tests/html_macro/svg-pass.rs | 36 ++++++++++++ .../yew-macro/tests/props_macro/props-pass.rs | 40 ++++++++++++- .../tests/props_macro/resolve-prop-pass.rs | 38 +++++++++++- 19 files changed, 650 insertions(+), 38 deletions(-) diff --git a/packages/yew-macro/src/html_tree/html_element.rs b/packages/yew-macro/src/html_tree/html_element.rs index af1aa8061d4..043d383b915 100644 --- a/packages/yew-macro/src/html_tree/html_element.rs +++ b/packages/yew-macro/src/html_tree/html_element.rs @@ -161,14 +161,14 @@ impl ToTokens for HtmlElement { return None; }), _ => Value::Dynamic(quote_spanned! {value.span()=> { - ::yew::utils::__ensure_type::(#value); + ::yew::utils::__ensure_type::<::std::primitive::bool>(#value); #key }}), }, expr => Value::Dynamic(quote_spanned! {expr.span()=> if #expr { ::std::option::Option::Some( - ::std::borrow::Cow::<'static, str>::Borrowed(#key) + ::std::borrow::Cow::<'static, ::std::primitive::str>::Borrowed(#key) ) } else { ::std::option::Option::None @@ -333,7 +333,7 @@ impl ToTokens for HtmlElement { #[allow(clippy::redundant_clone, unused_braces)] ::std::convert::Into::<::yew::virtual_dom::VNode>::into( ::yew::virtual_dom::VTag::__new_other( - ::std::borrow::Cow::<'static, str>::Borrowed(#name), + ::std::borrow::Cow::<'static, ::std::primitive::str>::Borrowed(#name), #node_ref, #key, #attributes, @@ -363,7 +363,7 @@ impl ToTokens for HtmlElement { // doesn't return a valid value quote_spanned! {expr.span()=> { let mut #vtag_name = ::std::convert::Into::< - ::std::borrow::Cow::<'static, str> + ::std::borrow::Cow::<'static, ::std::primitive::str> >::into(#expr); if !#vtag_name.is_ascii() { ::std::panic!( @@ -375,7 +375,7 @@ impl ToTokens for HtmlElement { #vtag_name.to_mut().make_ascii_lowercase(); #[allow(clippy::redundant_clone, unused_braces, clippy::let_and_return)] - let mut #vtag = match ::std::convert::AsRef::::as_ref(&#vtag_name) { + let mut #vtag = match ::std::convert::AsRef::<::std::primitive::str>::as_ref(&#vtag_name) { "input" => { ::yew::virtual_dom::VTag::__new_textarea( #value, diff --git a/packages/yew-macro/src/stringify.rs b/packages/yew-macro/src/stringify.rs index fa6a7b6b4ec..f6d3fad8f66 100644 --- a/packages/yew-macro/src/stringify.rs +++ b/packages/yew-macro/src/stringify.rs @@ -6,7 +6,7 @@ use syn::{Expr, Lit, LitStr}; /// Stringify a value at runtime. fn stringify_at_runtime(src: impl ToTokens) -> TokenStream { quote_spanned! {src.span()=> - ::std::convert::Into::<::std::borrow::Cow::<'static, str>>::into(#src) + ::std::convert::Into::<::std::borrow::Cow::<'static, ::std::primitive::str>>::into(#src) } } @@ -71,7 +71,7 @@ impl Stringify for LitStr { fn stringify(&self) -> TokenStream { quote_spanned! {self.span()=> - ::std::borrow::Cow::<'static, str>::Borrowed(#self) + ::std::borrow::Cow::<'static, ::std::primitive::str>::Borrowed(#self) } } } diff --git a/packages/yew-macro/tests/classes_macro/classes-pass.rs b/packages/yew-macro/tests/classes_macro/classes-pass.rs index 453b27c4f4f..4735e303d50 100644 --- a/packages/yew-macro/tests/classes_macro/classes-pass.rs +++ b/packages/yew-macro/tests/classes_macro/classes-pass.rs @@ -1,5 +1,41 @@ #![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; + fn compile_pass() { // multiple literals ::yew::classes!("one", "two"); @@ -16,7 +52,7 @@ fn compile_pass() { // optional classes ::yew::classes!( ::std::option::Option::Some("one"), - ::std::option::Option::None::<&'static str>, + ::std::option::Option::None::<&'static ::std::primitive::str>, ); // mixed types diff --git a/packages/yew-macro/tests/derive_props/pass.rs b/packages/yew-macro/tests/derive_props/pass.rs index 288234cd412..ce99ee6787d 100644 --- a/packages/yew-macro/tests/derive_props/pass.rs +++ b/packages/yew-macro/tests/derive_props/pass.rs @@ -1,6 +1,42 @@ #![no_implicit_prelude] #![recursion_limit = "128"] +// 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; + mod t1 { #[derive(::std::clone::Clone, ::yew::Properties, ::std::cmp::PartialEq)] pub struct Props { @@ -11,8 +47,8 @@ mod t1 { fn optional_prop_generics_should_work() { use ::yew::Properties; - Props::::builder().build(); - Props::::builder().value(true).build(); + Props::<::std::primitive::bool>::builder().build(); + Props::<::std::primitive::bool>::builder().value(true).build(); } } @@ -34,9 +70,9 @@ mod t2 { mod t3 { #[derive(::std::clone::Clone, ::yew::Properties, ::std::cmp::PartialEq)] pub struct Props { - b: i32, + b: ::std::primitive::i32, #[prop_or_default] - a: i32, + a: ::std::primitive::i32, } fn order_is_alphabetized() { @@ -60,8 +96,8 @@ mod t4 { fn optional_prop_generics_should_work() { use ::yew::Properties; - Props::::builder().build(); - Props::::builder().value(true).build(); + Props::<::std::primitive::bool>::builder().build(); + Props::<::std::primitive::bool>::builder().value(true).build(); } } @@ -72,7 +108,7 @@ mod t5 { T: ::std::clone::Clone + ::std::default::Default + ::std::cmp::PartialEq + 'a, > { #[prop_or_default] - static_value: &'static str, + static_value: &'static ::std::primitive::str, value: &'a T, } @@ -134,7 +170,7 @@ mod t8 { #[derive(::std::clone::Clone, ::yew::Properties, ::std::cmp::PartialEq)] pub struct Props { #[prop_or_else(|| 123)] - value: i32, + value: ::std::primitive::i32, } fn prop_or_else_closure_should_work() { @@ -169,7 +205,7 @@ mod t9 { use ::std::{assert_eq, result::Result::Ok}; use ::yew::Properties; - let props = Props::::builder().build(); + let props = Props::<::std::primitive::i32>::builder().build(); assert_eq!(props.value, Ok(123)); Props::::builder().value(Ok(456)).build(); } @@ -210,8 +246,8 @@ mod t12 { fn optional_prop_generics_should_work() { use ::yew::Properties; - Props::::builder().build(); - Props::::builder().value(true).build(); + Props::<::std::primitive::bool>::builder().build(); + Props::<::std::primitive::bool>::builder().value(true).build(); } } diff --git a/packages/yew-macro/tests/function_component_attr/generic-pass.rs b/packages/yew-macro/tests/function_component_attr/generic-pass.rs index 38985ccc833..29df3007d46 100644 --- a/packages/yew-macro/tests/function_component_attr/generic-pass.rs +++ b/packages/yew-macro/tests/function_component_attr/generic-pass.rs @@ -1,8 +1,44 @@ #![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; + #[derive(::std::clone::Clone, ::yew::Properties, ::std::cmp::PartialEq)] struct Props { - a: usize, + a: ::std::primitive::usize, } #[::yew::function_component(Comp)] @@ -23,7 +59,7 @@ fn comp1(_props: &()) -> ::yew::Html { } #[::yew::function_component(ConstGenerics)] -fn const_generics() -> ::yew::Html { +fn const_generics() -> ::yew::Html { ::yew::html! {
{ N } @@ -33,7 +69,7 @@ fn const_generics() -> ::yew::Html { fn compile_pass() { ::yew::html! { a=10 /> }; - ::yew::html! { /> }; + ::yew::html! { /> }; ::yew::html! { /> }; } diff --git a/packages/yew-macro/tests/function_component_attr/with-props-pass.rs b/packages/yew-macro/tests/function_component_attr/with-props-pass.rs index fec7dbd32b9..4ce8843d25d 100644 --- a/packages/yew-macro/tests/function_component_attr/with-props-pass.rs +++ b/packages/yew-macro/tests/function_component_attr/with-props-pass.rs @@ -1,8 +1,44 @@ #![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; + #[derive(Clone, ::yew::Properties, PartialEq)] struct Props { - a: usize, + a: ::std::primitive::usize, } #[::yew::function_component(Comp)] diff --git a/packages/yew-macro/tests/function_component_attr/without-props-pass.rs b/packages/yew-macro/tests/function_component_attr/without-props-pass.rs index 5bd778caa7b..61ccc468923 100644 --- a/packages/yew-macro/tests/function_component_attr/without-props-pass.rs +++ b/packages/yew-macro/tests/function_component_attr/without-props-pass.rs @@ -1,5 +1,41 @@ #![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; + #[::yew::function_component(Comp)] fn comp() -> ::yew::Html { ::yew::html! { diff --git a/packages/yew-macro/tests/html_macro/block-pass.rs b/packages/yew-macro/tests/html_macro/block-pass.rs index f10a0dac131..d8f527e6e46 100644 --- a/packages/yew-macro/tests/html_macro/block-pass.rs +++ b/packages/yew-macro/tests/html_macro/block-pass.rs @@ -1,5 +1,41 @@ #![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; + fn main() { ::yew::html! { <>{ "Hi" } }; ::yew::html! { <>{ ::std::format!("Hello") } }; diff --git a/packages/yew-macro/tests/html_macro/component-pass.rs b/packages/yew-macro/tests/html_macro/component-pass.rs index b07a5439454..f6dbe3c5359 100644 --- a/packages/yew-macro/tests/html_macro/component-pass.rs +++ b/packages/yew-macro/tests/html_macro/component-pass.rs @@ -1,10 +1,46 @@ #![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; + #[derive( ::std::clone::Clone, ::yew::Properties, ::std::default::Default, ::std::cmp::PartialEq, )] pub struct ContainerProperties { - pub int: i32, + pub int: ::std::primitive::i32, #[prop_or_default] pub children: ::yew::Children, } @@ -59,11 +95,11 @@ impl ::std::convert::Into<::yew::virtual_dom::VNode> for ChildrenVariants { pub struct ChildProperties { #[prop_or_default] pub string: ::std::string::String, - pub int: i32, + pub int: ::std::primitive::i32, #[prop_or_default] pub opt_str: ::std::option::Option<::std::string::String>, #[prop_or_default] - pub vec: ::std::vec::Vec, + pub vec: ::std::vec::Vec<::std::primitive::i32>, #[prop_or_default] pub optional_callback: ::std::option::Option<::yew::Callback<()>>, } @@ -98,7 +134,7 @@ impl ::yew::Component for AltChild { ::std::clone::Clone, ::yew::Properties, ::std::default::Default, ::std::cmp::PartialEq, )] pub struct ChildContainerProperties { - pub int: i32, + pub int: ::std::primitive::i32, #[prop_or_default] pub children: ::yew::html::ChildrenRenderer, } @@ -150,12 +186,12 @@ fn compile_pass() { - >::from("child")} int=1 /> + >::from("child")} int=1 /> - >::from("child")} int=1 /> + >::from("child")} int=1 /> - >::from("child"))} int=1 /> + >::from("child"))} int=1 /> }; diff --git a/packages/yew-macro/tests/html_macro/dyn-element-pass.rs b/packages/yew-macro/tests/html_macro/dyn-element-pass.rs index 8d85a86283c..e26369903ec 100644 --- a/packages/yew-macro/tests/html_macro/dyn-element-pass.rs +++ b/packages/yew-macro/tests/html_macro/dyn-element-pass.rs @@ -1,5 +1,41 @@ #![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; + fn main() { let dyn_tag = || ::std::string::ToString::to_string("test"); let mut next_extra_tag = { diff --git a/packages/yew-macro/tests/html_macro/generic-component-pass.rs b/packages/yew-macro/tests/html_macro/generic-component-pass.rs index 99f8239213e..49d88cb56b8 100644 --- a/packages/yew-macro/tests/html_macro/generic-component-pass.rs +++ b/packages/yew-macro/tests/html_macro/generic-component-pass.rs @@ -1,5 +1,41 @@ #![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 Generic { marker: ::std::marker::PhantomData, } @@ -46,8 +82,8 @@ fn compile_pass() { ::yew::html! { > /> }; ::yew::html! { >>>> }; - ::yew::html! { /> }; - ::yew::html! { >> }; + ::yew::html! { /> }; + ::yew::html! { >> }; ::yew::html! { /> }; ::yew::html! { >> }; diff --git a/packages/yew-macro/tests/html_macro/html-element-pass.rs b/packages/yew-macro/tests/html_macro/html-element-pass.rs index 14354e3d1b3..558281dbc95 100644 --- a/packages/yew-macro/tests/html_macro/html-element-pass.rs +++ b/packages/yew-macro/tests/html_macro/html-element-pass.rs @@ -1,15 +1,51 @@ #![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; + fn compile_pass() { let onclick = <::yew::Callback<::yew::MouseEvent> as ::std::convert::From<_>>::from( |_: ::yew::MouseEvent| (), ); let parent_ref = <::yew::NodeRef as ::std::default::Default>::default(); - let dyn_tag = || <::std::string::String as ::std::convert::From<&str>>::from("test"); + let dyn_tag = || <::std::string::String as ::std::convert::From<&::std::primitive::str>>::from("test"); let mut extra_tags_iter = ::std::iter::IntoIterator::into_iter(::std::vec!["a", "b"]); - let cow_none: ::std::option::Option<::std::borrow::Cow<'static, str>> = + let cow_none: ::std::option::Option<::std::borrow::Cow<'static, ::std::primitive::str>> = ::std::option::Option::None; ::yew::html! { diff --git a/packages/yew-macro/tests/html_macro/html-node-pass.rs b/packages/yew-macro/tests/html_macro/html-node-pass.rs index 74362e9feeb..a8c9dd1f7b3 100644 --- a/packages/yew-macro/tests/html_macro/html-node-pass.rs +++ b/packages/yew-macro/tests/html_macro/html-node-pass.rs @@ -1,5 +1,41 @@ #![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; + fn compile_pass() { ::yew::html! { "" }; ::yew::html! { 'a' }; @@ -14,7 +50,7 @@ fn compile_pass() { ::yew::html! { { 1.234 } }; ::yew::html! { ::std::format!("Hello") }; - ::yew::html! { {<::std::string::String as ::std::convert::From<&str>>::from("Hello") } }; + ::yew::html! { {<::std::string::String as ::std::convert::From<&::std::primitive::str>>::from("Hello") } }; let msg = "Hello"; ::yew::html! { msg }; diff --git a/packages/yew-macro/tests/html_macro/iterable-pass.rs b/packages/yew-macro/tests/html_macro/iterable-pass.rs index f2a8d5bb211..18eadf7b042 100644 --- a/packages/yew-macro/tests/html_macro/iterable-pass.rs +++ b/packages/yew-macro/tests/html_macro/iterable-pass.rs @@ -1,5 +1,41 @@ #![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; + fn empty_vec() -> ::std::vec::Vec<::yew::Html> { ::std::vec::Vec::<::yew::Html>::new() } diff --git a/packages/yew-macro/tests/html_macro/list-pass.rs b/packages/yew-macro/tests/html_macro/list-pass.rs index 0771865d8da..3cbe619eaeb 100644 --- a/packages/yew-macro/tests/html_macro/list-pass.rs +++ b/packages/yew-macro/tests/html_macro/list-pass.rs @@ -1,5 +1,41 @@ #![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; + fn main() { ::yew::html! {}; ::yew::html! { <> }; diff --git a/packages/yew-macro/tests/html_macro/node-pass.rs b/packages/yew-macro/tests/html_macro/node-pass.rs index cffe7db6f7e..1dfaea9c8a1 100644 --- a/packages/yew-macro/tests/html_macro/node-pass.rs +++ b/packages/yew-macro/tests/html_macro/node-pass.rs @@ -1,5 +1,41 @@ #![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; + fn main() { ::yew::html! { "" }; ::yew::html! { 'a' }; diff --git a/packages/yew-macro/tests/html_macro/svg-pass.rs b/packages/yew-macro/tests/html_macro/svg-pass.rs index 1da6a3c17f4..eb1bb3a0963 100644 --- a/packages/yew-macro/tests/html_macro/svg-pass.rs +++ b/packages/yew-macro/tests/html_macro/svg-pass.rs @@ -1,5 +1,41 @@ #![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; + fn main() { // Ensure Rust keywords can be used as element names. // See: #1771 diff --git a/packages/yew-macro/tests/props_macro/props-pass.rs b/packages/yew-macro/tests/props_macro/props-pass.rs index 9ffb083eaa9..1dd62c89dca 100644 --- a/packages/yew-macro/tests/props_macro/props-pass.rs +++ b/packages/yew-macro/tests/props_macro/props-pass.rs @@ -1,10 +1,46 @@ #![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; + #[derive(::std::clone::Clone, ::yew::Properties, ::std::cmp::PartialEq)] struct Props { - a: usize, + a: ::std::primitive::usize, #[prop_or_default] - b: usize, + b: ::std::primitive::usize, } fn compile_pass() { diff --git a/packages/yew-macro/tests/props_macro/resolve-prop-pass.rs b/packages/yew-macro/tests/props_macro/resolve-prop-pass.rs index eedbe3d586d..34ba0c83fd0 100644 --- a/packages/yew-macro/tests/props_macro/resolve-prop-pass.rs +++ b/packages/yew-macro/tests/props_macro/resolve-prop-pass.rs @@ -1,8 +1,44 @@ #![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; + #[derive(::std::clone::Clone, ::yew::Properties, ::std::cmp::PartialEq)] struct Props { - n: i32, + n: ::std::primitive::i32, } struct MyComp;