From 58753d960799f9da22d509ce7f49efd471d534dc Mon Sep 17 00:00:00 2001 From: mc1098 Date: Sun, 5 Sep 2021 23:33:30 +0100 Subject: [PATCH] Add `no_implicit_prelude` to proc macro tests (#2033) * Add no_implicit_prelude to derive_props test * Add no_implicit_prelude to html_macro tests * Fix function_component macro tests function_component macro tests weren't being run by try build due to change in dir name. Imports corrected now that function_component is now in yew. Adds no_implicit_prelude to *-pass tests * Add no_implicit_prelude to props_macro tests * fix typo in comment --- packages/yew-macro/src/derive_props/field.rs | 56 ++++- .../yew-macro/src/html_tree/html_component.rs | 4 +- .../yew-macro/src/html_tree/html_element.rs | 2 +- packages/yew-macro/tests/derive_props/pass.rs | 120 +++++----- .../yew-macro/tests/function_attr_test.rs | 4 +- .../applied-to-non-fn-fail.rs | 1 - .../applied-to-non-fn-fail.stderr | 8 +- .../function_component_attr/async-fail.rs | 1 - .../function_component_attr/async-fail.stderr | 8 +- .../function_component_attr/bad-name-fail.rs | 1 - .../bad-name-fail.stderr | 16 +- .../bad-props-param-fail.rs | 1 - .../bad-props-param-fail.stderr | 8 +- .../bad-return-type-fail.rs | 1 - .../bad-return-type-fail.stderr | 14 +- .../function_component_attr/const-fail.rs | 1 - .../function_component_attr/const-fail.stderr | 8 +- .../function_component_attr/extern-fail.rs | 1 - .../extern-fail.stderr | 8 +- .../generic-lifetime-fail.rs | 2 - .../generic-lifetime-fail.stderr | 8 +- .../function_component_attr/generic-pass.rs | 12 +- .../generic-props-fail.rs | 1 - .../generic-props-fail.stderr | 45 ++-- .../lifetime-props-param-fail.rs | 1 - .../lifetime-props-param-fail.stderr | 8 +- .../multiple-param-fail.rs | 1 - .../multiple-param-fail.stderr | 12 +- .../mut-ref-props-param-fail.rs | 1 - .../mut-ref-props-param-fail.stderr | 8 +- .../function_component_attr/no-name-fail.rs | 1 - .../no-name-fail.stderr | 4 +- .../with-props-pass.rs | 4 +- .../with-receiver-fail.rs | 1 - .../with-receiver-fail.stderr | 4 +- .../without-props-pass.rs | 4 +- .../tests/html_macro/component-pass.rs | 218 +++++++++--------- .../html_macro/generic-component-pass.rs | 51 ++-- .../tests/html_macro/html-element-pass.rs | 46 ++-- .../tests/html_macro/html-node-pass.rs | 28 +-- .../yew-macro/tests/props_macro/props-pass.rs | 8 +- .../tests/props_macro/resolve-prop-pass.rs | 24 +- 42 files changed, 400 insertions(+), 355 deletions(-) diff --git a/packages/yew-macro/src/derive_props/field.rs b/packages/yew-macro/src/derive_props/field.rs index e24bc3b7a..54be0a4d5 100644 --- a/packages/yew-macro/src/derive_props/field.rs +++ b/packages/yew-macro/src/derive_props/field.rs @@ -5,7 +5,7 @@ use std::cmp::{Ord, Ordering, PartialEq, PartialOrd}; use std::convert::TryFrom; use syn::parse::Result; use syn::spanned::Spanned; -use syn::{Error, Expr, Field, Type, TypePath, Visibility}; +use syn::{Error, Expr, Field, Path, Type, TypePath, Visibility}; #[allow(clippy::large_enum_variant)] #[derive(PartialEq, Eq)] @@ -167,7 +167,7 @@ impl PropField { } else if matches!( &named_field.ty, Type::Path(TypePath { path, .. }) - if path.segments.len() == 1 && path.segments[0].ident == "Option" + if is_path_an_option(path) ) { Ok(PropAttr::Option) } else { @@ -178,6 +178,36 @@ impl PropField { } } +fn is_path_segments_an_option(path_segments: impl Iterator) -> bool { + fn is_option_path_seg(seg_index: usize, path: &str) -> u8 { + match (seg_index, path) { + (0, "core") => 0b001, + (0, "std") => 0b001, + (0, "Option") => 0b111, + (1, "option") => 0b010, + (2, "Option") => 0b100, + _ => 0, + } + } + + path_segments + .enumerate() + .fold(0, |flags, (i, ps)| flags | is_option_path_seg(i, &ps)) + == 0b111 +} + +/// Returns true when the [`Path`] seems like an [`Option`] type. +/// +/// This function considers the following paths as Options: +/// - core::option::Option +/// - std::option::Option +/// - Option::* +/// +/// Users can define their own [`Option`] type and this will return true - this is unavoidable. +fn is_path_an_option(path: &Path) -> bool { + is_path_segments_an_option(path.segments.iter().take(3).map(|ps| ps.ident.to_string())) +} + impl TryFrom for PropField { type Error = Error; @@ -223,3 +253,25 @@ impl PartialEq for PropField { self.name == other.name } } + +#[cfg(test)] +mod tests { + use crate::derive_props::field::is_path_segments_an_option; + + #[test] + fn all_std_and_core_option_path_seg_return_true() { + assert!(is_path_segments_an_option( + vec!["core".to_owned(), "option".to_owned(), "Option".to_owned()].into_iter() + )); + assert!(is_path_segments_an_option( + vec!["std".to_owned(), "option".to_owned(), "Option".to_owned()].into_iter() + )); + assert!(is_path_segments_an_option( + vec!["Option".to_owned()].into_iter() + )); + // why OR instead of XOR + assert!(is_path_segments_an_option( + vec!["Option".to_owned(), "Vec".to_owned(), "Option".to_owned()].into_iter() + )); + } +} diff --git a/packages/yew-macro/src/html_tree/html_component.rs b/packages/yew-macro/src/html_tree/html_component.rs index f2431ace4..f95a42327 100644 --- a/packages/yew-macro/src/html_tree/html_component.rs +++ b/packages/yew-macro/src/html_tree/html_component.rs @@ -108,7 +108,7 @@ impl ToTokens for HtmlComponent { let value = &node_ref.value; quote_spanned! {value.span()=> #value } } else { - quote! { ::yew::html::NodeRef::default() } + quote! { <::yew::html::NodeRef as ::std::default::Default>::default() } }; let key = if let Some(key) = &special_props.key { @@ -118,7 +118,7 @@ impl ToTokens for HtmlComponent { Some(::std::convert::Into::<::yew::virtual_dom::Key>::into(#value)) } } else { - quote! { None } + quote! { ::std::option::Option::None } }; tokens.extend(quote_spanned! {ty.span()=> diff --git a/packages/yew-macro/src/html_tree/html_element.rs b/packages/yew-macro/src/html_tree/html_element.rs index e3d792a13..af1aa8061 100644 --- a/packages/yew-macro/src/html_tree/html_element.rs +++ b/packages/yew-macro/src/html_tree/html_element.rs @@ -171,7 +171,7 @@ impl ToTokens for HtmlElement { ::std::borrow::Cow::<'static, str>::Borrowed(#key) ) } else { - None + ::std::option::Option::None } }), }, diff --git a/packages/yew-macro/tests/derive_props/pass.rs b/packages/yew-macro/tests/derive_props/pass.rs index bc4a9ef7a..288234cd4 100644 --- a/packages/yew-macro/tests/derive_props/pass.rs +++ b/packages/yew-macro/tests/derive_props/pass.rs @@ -1,41 +1,38 @@ +#![no_implicit_prelude] #![recursion_limit = "128"] -use yew::prelude::*; - mod t1 { - use super::*; - - #[derive(Clone, Properties, PartialEq)] - pub struct Props { + #[derive(::std::clone::Clone, ::yew::Properties, ::std::cmp::PartialEq)] + pub struct Props { #[prop_or_default] value: T, } fn optional_prop_generics_should_work() { + use ::yew::Properties; + Props::::builder().build(); Props::::builder().value(true).build(); } } mod t2 { - use super::*; - - #[derive(Clone, PartialEq)] + #[derive(::std::clone::Clone, ::std::cmp::PartialEq)] struct Value; - #[derive(Clone, Properties, PartialEq)] - pub struct Props { + #[derive(::std::clone::Clone, ::yew::Properties, ::std::cmp::PartialEq)] + pub struct Props { value: T, } fn required_prop_generics_should_work() { + use ::yew::Properties; + Props::::builder().value(Value).build(); } } mod t3 { - use super::*; - - #[derive(Clone, Properties, PartialEq)] + #[derive(::std::clone::Clone, ::yew::Properties, ::std::cmp::PartialEq)] pub struct Props { b: i32, #[prop_or_default] @@ -43,40 +40,46 @@ mod t3 { } fn order_is_alphabetized() { + use ::yew::Properties; + Props::builder().b(1).build(); Props::builder().a(1).b(2).build(); } } mod t4 { - use super::*; - - #[derive(Clone, Properties, PartialEq)] + #[derive(::std::clone::Clone, ::yew::Properties, ::std::cmp::PartialEq)] pub struct Props where - T: Clone + Default + PartialEq, + T: ::std::clone::Clone + ::std::default::Default + ::std::cmp::PartialEq, { #[prop_or_default] value: T, } fn optional_prop_generics_should_work() { + use ::yew::Properties; + Props::::builder().build(); Props::::builder().value(true).build(); } } mod t5 { - use super::*; - - #[derive(Clone, Properties, PartialEq)] - pub struct Props<'a, T: Clone + Default + PartialEq + 'a> { + #[derive(::std::clone::Clone, ::yew::Properties, ::std::cmp::PartialEq)] + pub struct Props< + 'a, + T: ::std::clone::Clone + ::std::default::Default + ::std::cmp::PartialEq + 'a, + > { #[prop_or_default] static_value: &'static str, value: &'a T, } fn optional_prop_generics_with_lifetime_should_work() { + use ::std::{convert::From, string::String}; + use ::yew::Properties; + Props::::builder().value(&String::from("")).build(); Props::::builder() .static_value("") @@ -86,18 +89,18 @@ mod t5 { } mod t6 { - use super::*; - use std::str::FromStr; - - #[derive(Properties, Clone, PartialEq)] - pub struct Props + #[derive(::yew::Properties, ::std::clone::Clone, ::std::cmp::PartialEq)] + pub struct Props where - ::Err: Clone + PartialEq, + ::Err: ::std::clone::Clone + ::std::cmp::PartialEq, { - value: Result::Err>, + value: ::std::result::Result::Err>, } fn required_prop_generics_with_where_clause_should_work() { + use ::std::{convert::From, result::Result::Ok, string::String}; + use ::yew::Properties; + Props::::builder() .value(Ok(String::from(""))) .build(); @@ -105,21 +108,22 @@ mod t6 { } mod t7 { - use super::*; - - #[derive(Clone, Debug, Eq, PartialEq)] + #[derive(::std::clone::Clone, Debug, Eq, ::std::cmp::PartialEq)] pub enum Foo { One, Two, } - #[derive(Clone, Properties, PartialEq)] + #[derive(::std::clone::Clone, ::yew::Properties, ::std::cmp::PartialEq)] pub struct Props { #[prop_or(Foo::One)] value: Foo, } fn prop_or_value_should_work() { + use ::std::assert_eq; + use ::yew::Properties; + let props = Props::builder().build(); assert_eq!(props.value, Foo::One); Props::builder().value(Foo::Two).build(); @@ -127,15 +131,16 @@ mod t7 { } mod t8 { - use super::*; - - #[derive(Clone, Properties, PartialEq)] + #[derive(::std::clone::Clone, ::yew::Properties, ::std::cmp::PartialEq)] pub struct Props { #[prop_or_else(|| 123)] value: i32, } fn prop_or_else_closure_should_work() { + use ::std::assert_eq; + use ::yew::Properties; + let props = Props::builder().build(); assert_eq!(props.value, 123); Props::builder().value(123).build(); @@ -143,26 +148,27 @@ mod t8 { } mod t9 { - use super::*; - use std::str::FromStr; - - #[derive(Clone, Properties, PartialEq)] - pub struct Props + #[derive(::std::clone::Clone, ::yew::Properties, ::std::cmp::PartialEq)] + pub struct Props where - ::Err: Clone + PartialEq, + ::Err: ::std::clone::Clone + ::std::cmp::PartialEq, { #[prop_or_else(default_value)] - value: Result::Err>, + value: ::std::result::Result::Err>, } - fn default_value() -> Result::Err> + fn default_value( + ) -> ::std::result::Result::Err> where - ::Err: Clone, + ::Err: ::std::clone::Clone, { "123".parse() } fn prop_or_else_function_with_generics_should_work() { + use ::std::{assert_eq, result::Result::Ok}; + use ::yew::Properties; + let props = Props::::builder().build(); assert_eq!(props.value, Ok(123)); Props::::builder().value(Ok(456)).build(); @@ -170,15 +176,13 @@ mod t9 { } mod t10 { - use super::*; - // this test makes sure that Yew handles generic params with default values properly. - #[derive(Clone, Properties, PartialEq)] + #[derive(::std::clone::Clone, ::yew::Properties, ::std::cmp::PartialEq)] pub struct Foo where - S: Clone + PartialEq, - M: Clone + PartialEq, + S: ::std::clone::Clone + ::std::cmp::PartialEq, + M: ::std::clone::Clone + ::std::cmp::PartialEq, { bar: S, baz: M, @@ -186,28 +190,26 @@ mod t10 { } mod t11 { - use super::*; - // this test makes sure that Yew handles generic params with const generics properly. - #[derive(Clone, Properties, PartialEq)] + #[derive(::std::clone::Clone, ::yew::Properties, ::std::cmp::PartialEq)] pub struct Foo where - T: Clone + PartialEq, + T: ::std::clone::Clone + ::std::cmp::PartialEq, { bar: [T; N], } } mod t12 { - use super::*; - - #[derive(Clone, Properties, PartialEq)] - pub struct Props { - value: Option, + #[derive(::std::clone::Clone, ::yew::Properties, ::std::cmp::PartialEq)] + pub struct Props { + value: ::std::option::Option, } fn optional_prop_generics_should_work() { + use ::yew::Properties; + Props::::builder().build(); Props::::builder().value(true).build(); } diff --git a/packages/yew-macro/tests/function_attr_test.rs b/packages/yew-macro/tests/function_attr_test.rs index 9747bc8d8..2c2d44178 100644 --- a/packages/yew-macro/tests/function_attr_test.rs +++ b/packages/yew-macro/tests/function_attr_test.rs @@ -2,6 +2,6 @@ #[rustversion::attr(stable(1.51), test)] fn tests() { let t = trybuild::TestCases::new(); - t.pass("tests/function_attr/*-pass.rs"); - t.compile_fail("tests/function_attr/*-fail.rs"); + t.pass("tests/function_component_attr/*-pass.rs"); + t.compile_fail("tests/function_component_attr/*-fail.rs"); } diff --git a/packages/yew-macro/tests/function_component_attr/applied-to-non-fn-fail.rs b/packages/yew-macro/tests/function_component_attr/applied-to-non-fn-fail.rs index 6d8fc0319..3f01c0c6d 100644 --- a/packages/yew-macro/tests/function_component_attr/applied-to-non-fn-fail.rs +++ b/packages/yew-macro/tests/function_component_attr/applied-to-non-fn-fail.rs @@ -1,5 +1,4 @@ use yew::prelude::*; -use yew_functional::function_component; #[derive(Clone, Properties, PartialEq)] struct Props { diff --git a/packages/yew-macro/tests/function_component_attr/applied-to-non-fn-fail.stderr b/packages/yew-macro/tests/function_component_attr/applied-to-non-fn-fail.stderr index ae0d9e552..59a2b4b2d 100644 --- a/packages/yew-macro/tests/function_component_attr/applied-to-non-fn-fail.stderr +++ b/packages/yew-macro/tests/function_component_attr/applied-to-non-fn-fail.stderr @@ -1,5 +1,5 @@ error: `function_component` attribute can only be applied to functions - --> $DIR/applied-to-non-fn-fail.rs:10:1 - | -10 | struct Test; - | ^^^^^^^^^^^^ + --> $DIR/applied-to-non-fn-fail.rs:9:1 + | +9 | struct Test; + | ^^^^^^^^^^^^ diff --git a/packages/yew-macro/tests/function_component_attr/async-fail.rs b/packages/yew-macro/tests/function_component_attr/async-fail.rs index 050f557a6..f8343a880 100644 --- a/packages/yew-macro/tests/function_component_attr/async-fail.rs +++ b/packages/yew-macro/tests/function_component_attr/async-fail.rs @@ -1,5 +1,4 @@ use yew::prelude::*; -use yew_functional::{function_component}; #[derive(Clone, Properties, PartialEq)] struct Props { diff --git a/packages/yew-macro/tests/function_component_attr/async-fail.stderr b/packages/yew-macro/tests/function_component_attr/async-fail.stderr index b4c082bdf..172deeb61 100644 --- a/packages/yew-macro/tests/function_component_attr/async-fail.stderr +++ b/packages/yew-macro/tests/function_component_attr/async-fail.stderr @@ -1,5 +1,5 @@ error: function components can't be async - --> $DIR/async-fail.rs:10:1 - | -10 | async fn comp(props: &Props) -> Html { - | ^^^^^ + --> $DIR/async-fail.rs:9:1 + | +9 | async fn comp(props: &Props) -> Html { + | ^^^^^ diff --git a/packages/yew-macro/tests/function_component_attr/bad-name-fail.rs b/packages/yew-macro/tests/function_component_attr/bad-name-fail.rs index 2218ab99e..ccac2be6c 100644 --- a/packages/yew-macro/tests/function_component_attr/bad-name-fail.rs +++ b/packages/yew-macro/tests/function_component_attr/bad-name-fail.rs @@ -1,5 +1,4 @@ use yew::prelude::*; -use yew_functional::function_component; #[derive(Clone, Properties, PartialEq)] struct Props { diff --git a/packages/yew-macro/tests/function_component_attr/bad-name-fail.stderr b/packages/yew-macro/tests/function_component_attr/bad-name-fail.stderr index 0354face6..f96cc1919 100644 --- a/packages/yew-macro/tests/function_component_attr/bad-name-fail.stderr +++ b/packages/yew-macro/tests/function_component_attr/bad-name-fail.stderr @@ -1,23 +1,23 @@ error: expected identifier - --> $DIR/bad-name-fail.rs:9:22 + --> $DIR/bad-name-fail.rs:8:22 | -9 | #[function_component(let)] +8 | #[function_component(let)] | ^^^ error: unexpected token - --> $DIR/bad-name-fail.rs:18:23 + --> $DIR/bad-name-fail.rs:17:23 | -18 | #[function_component(x, y, z)] +17 | #[function_component(x, y, z)] | ^ error: expected identifier - --> $DIR/bad-name-fail.rs:27:22 + --> $DIR/bad-name-fail.rs:26:22 | -27 | #[function_component(124)] +26 | #[function_component(124)] | ^^^ error: the component must not have the same name as the function - --> $DIR/bad-name-fail.rs:36:22 + --> $DIR/bad-name-fail.rs:35:22 | -36 | #[function_component(component)] +35 | #[function_component(component)] | ^^^^^^^^^ diff --git a/packages/yew-macro/tests/function_component_attr/bad-props-param-fail.rs b/packages/yew-macro/tests/function_component_attr/bad-props-param-fail.rs index e19c0cab5..1992f77df 100644 --- a/packages/yew-macro/tests/function_component_attr/bad-props-param-fail.rs +++ b/packages/yew-macro/tests/function_component_attr/bad-props-param-fail.rs @@ -1,5 +1,4 @@ use yew::prelude::*; -use yew_functional::function_component; #[derive(Clone, Properties, PartialEq)] struct Props { diff --git a/packages/yew-macro/tests/function_component_attr/bad-props-param-fail.stderr b/packages/yew-macro/tests/function_component_attr/bad-props-param-fail.stderr index ba89c1ca1..479b44a61 100644 --- a/packages/yew-macro/tests/function_component_attr/bad-props-param-fail.stderr +++ b/packages/yew-macro/tests/function_component_attr/bad-props-param-fail.stderr @@ -1,5 +1,5 @@ error: expected a reference to a `Properties` type (try: `&Props`) - --> $DIR/bad-props-param-fail.rs:10:16 - | -10 | fn comp(props: Props) -> Html { - | ^^^^^ + --> $DIR/bad-props-param-fail.rs:9:16 + | +9 | fn comp(props: Props) -> Html { + | ^^^^^ diff --git a/packages/yew-macro/tests/function_component_attr/bad-return-type-fail.rs b/packages/yew-macro/tests/function_component_attr/bad-return-type-fail.rs index 107e8ebf7..d680a9b2c 100644 --- a/packages/yew-macro/tests/function_component_attr/bad-return-type-fail.rs +++ b/packages/yew-macro/tests/function_component_attr/bad-return-type-fail.rs @@ -1,5 +1,4 @@ use yew::prelude::*; -use yew_functional::function_component; #[derive(Clone, Properties, PartialEq)] struct Props { diff --git a/packages/yew-macro/tests/function_component_attr/bad-return-type-fail.stderr b/packages/yew-macro/tests/function_component_attr/bad-return-type-fail.stderr index 283e09594..0a5d227dd 100644 --- a/packages/yew-macro/tests/function_component_attr/bad-return-type-fail.stderr +++ b/packages/yew-macro/tests/function_component_attr/bad-return-type-fail.stderr @@ -1,13 +1,13 @@ error: function components must return `yew::Html` - --> $DIR/bad-return-type-fail.rs:10:1 - | -10 | fn comp_1(_props: &Props) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^ + --> $DIR/bad-return-type-fail.rs:9:1 + | +9 | fn comp_1(_props: &Props) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/bad-return-type-fail.rs:14:5 + --> $DIR/bad-return-type-fail.rs:13:5 | -13 | fn comp(_props: &Props) -> u32 { +12 | fn comp(_props: &Props) -> u32 { | --- expected `VNode` because of return type -14 | 1 +13 | 1 | ^ expected enum `VNode`, found integer diff --git a/packages/yew-macro/tests/function_component_attr/const-fail.rs b/packages/yew-macro/tests/function_component_attr/const-fail.rs index 7bc778a2c..3d619b22d 100644 --- a/packages/yew-macro/tests/function_component_attr/const-fail.rs +++ b/packages/yew-macro/tests/function_component_attr/const-fail.rs @@ -1,5 +1,4 @@ use yew::prelude::*; -use yew_functional::function_component; #[derive(Clone, Properties, PartialEq)] struct Props { diff --git a/packages/yew-macro/tests/function_component_attr/const-fail.stderr b/packages/yew-macro/tests/function_component_attr/const-fail.stderr index 9788b7c47..5767abe40 100644 --- a/packages/yew-macro/tests/function_component_attr/const-fail.stderr +++ b/packages/yew-macro/tests/function_component_attr/const-fail.stderr @@ -1,5 +1,5 @@ error: const functions can't be function components - --> $DIR/const-fail.rs:10:1 - | -10 | const fn comp(props: &Props) -> Html { - | ^^^^^ + --> $DIR/const-fail.rs:9:1 + | +9 | const fn comp(props: &Props) -> Html { + | ^^^^^ diff --git a/packages/yew-macro/tests/function_component_attr/extern-fail.rs b/packages/yew-macro/tests/function_component_attr/extern-fail.rs index 12ba14eac..06a9d3e4e 100644 --- a/packages/yew-macro/tests/function_component_attr/extern-fail.rs +++ b/packages/yew-macro/tests/function_component_attr/extern-fail.rs @@ -1,5 +1,4 @@ use yew::prelude::*; -use yew_functional::function_component; #[derive(Clone, Properties, PartialEq)] struct Props { diff --git a/packages/yew-macro/tests/function_component_attr/extern-fail.stderr b/packages/yew-macro/tests/function_component_attr/extern-fail.stderr index 9e4afa22f..483c26095 100644 --- a/packages/yew-macro/tests/function_component_attr/extern-fail.stderr +++ b/packages/yew-macro/tests/function_component_attr/extern-fail.stderr @@ -1,5 +1,5 @@ error: extern functions can't be function components - --> $DIR/extern-fail.rs:10:1 - | -10 | extern "C" fn comp(props: &Props) -> Html { - | ^^^^^^^^^^ + --> $DIR/extern-fail.rs:9:1 + | +9 | extern "C" fn comp(props: &Props) -> Html { + | ^^^^^^^^^^ diff --git a/packages/yew-macro/tests/function_component_attr/generic-lifetime-fail.rs b/packages/yew-macro/tests/function_component_attr/generic-lifetime-fail.rs index cbf292125..bd559292b 100644 --- a/packages/yew-macro/tests/function_component_attr/generic-lifetime-fail.rs +++ b/packages/yew-macro/tests/function_component_attr/generic-lifetime-fail.rs @@ -1,5 +1,4 @@ use yew::prelude::*; -use yew_functional::function_component; #[derive(Clone, Properties, PartialEq)] struct Props { @@ -8,7 +7,6 @@ struct Props { #[function_component(Comp)] fn comp<'a>(props: &'a Props) -> Html { - html! {

{ props.a } diff --git a/packages/yew-macro/tests/function_component_attr/generic-lifetime-fail.stderr b/packages/yew-macro/tests/function_component_attr/generic-lifetime-fail.stderr index e934e01fe..b5bc4e2c7 100644 --- a/packages/yew-macro/tests/function_component_attr/generic-lifetime-fail.stderr +++ b/packages/yew-macro/tests/function_component_attr/generic-lifetime-fail.stderr @@ -1,5 +1,5 @@ error: function components can't have generic lifetime parameters - --> $DIR/generic-lifetime-fail.rs:10:8 - | -10 | fn comp<'a>(props: &'a Props) -> Html { - | ^^^^ + --> $DIR/generic-lifetime-fail.rs:9:8 + | +9 | fn comp<'a>(props: &'a Props) -> Html { + | ^^^^ 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 a43e4d240..38985ccc8 100644 --- a/packages/yew-macro/tests/function_component_attr/generic-pass.rs +++ b/packages/yew-macro/tests/function_component_attr/generic-pass.rs @@ -1,26 +1,28 @@ -#[derive(Clone, ::yew::Properties, PartialEq)] +#![no_implicit_prelude] + +#[derive(::std::clone::Clone, ::yew::Properties, ::std::cmp::PartialEq)] struct Props { a: usize, } -#[::yew_functional::function_component(Comp)] +#[::yew::function_component(Comp)] fn comp

(_props: &P) -> ::yew::Html where - P: ::yew::Properties + PartialEq, + P: ::yew::Properties + ::std::cmp::PartialEq, { ::yew::html! {

} } -#[::yew_functional::function_component(Comp1)] +#[::yew::function_component(Comp1)] fn comp1(_props: &()) -> ::yew::Html { ::yew::html! {

} } -#[::yew_functional::function_component(ConstGenerics)] +#[::yew::function_component(ConstGenerics)] fn const_generics() -> ::yew::Html { ::yew::html! {
diff --git a/packages/yew-macro/tests/function_component_attr/generic-props-fail.rs b/packages/yew-macro/tests/function_component_attr/generic-props-fail.rs index 96b7c0bcb..691faaf57 100644 --- a/packages/yew-macro/tests/function_component_attr/generic-props-fail.rs +++ b/packages/yew-macro/tests/function_component_attr/generic-props-fail.rs @@ -1,5 +1,4 @@ use yew::prelude::*; -use yew_functional::function_component; #[derive(Clone, Properties, PartialEq)] struct Props { diff --git a/packages/yew-macro/tests/function_component_attr/generic-props-fail.stderr b/packages/yew-macro/tests/function_component_attr/generic-props-fail.stderr index a3ff9cb6d..f7066e417 100644 --- a/packages/yew-macro/tests/function_component_attr/generic-props-fail.stderr +++ b/packages/yew-macro/tests/function_component_attr/generic-props-fail.stderr @@ -1,66 +1,57 @@ error[E0412]: cannot find type `INVALID` in this scope - --> $DIR/generic-props-fail.rs:26:19 + --> $DIR/generic-props-fail.rs:25:19 | -21 | fn compile_fail() { +20 | fn compile_fail() { | - help: you might be missing a type parameter: `` ... -26 | html! { /> }; +25 | html! { /> }; | ^^^^^^^ not found in this scope error[E0599]: no method named `build` found for struct `PropsBuilder` in the current scope - --> $DIR/generic-props-fail.rs:23:14 + --> $DIR/generic-props-fail.rs:22:14 | -4 | #[derive(Clone, Properties, PartialEq)] +3 | #[derive(Clone, Properties, PartialEq)] | ---------- method `build` not found for this ... -23 | html! { /> }; +22 | html! { /> }; | ^^^^ method not found in `PropsBuilder` error[E0599]: the function or associated item `new` exists for struct `VChild>>`, but its trait bounds were not satisfied - --> $DIR/generic-props-fail.rs:28:14 + --> $DIR/generic-props-fail.rs:27:14 | -28 | html! { /> }; +27 | html! { /> }; | ^^^^ function or associated item cannot be called on `VChild>>` due to unsatisfied trait bounds | - ::: $WORKSPACE/packages/yew-functional/src/lib.rs:73:1 + ::: $WORKSPACE/packages/yew/src/functional/mod.rs | -73 | pub struct FunctionComponent { + | pub struct FunctionComponent { | ----------------------------------------------------------- doesn't satisfy `_: yew::Component` | = note: the following trait bounds were not satisfied: `FunctionComponent>: yew::Component` error[E0277]: the trait bound `MissingTypeBounds: yew::Properties` is not satisfied - --> $DIR/generic-props-fail.rs:28:14 + --> $DIR/generic-props-fail.rs:27:14 | -28 | html! { /> }; +27 | html! { /> }; | ^^^^ the trait `yew::Properties` is not implemented for `MissingTypeBounds` | = note: required because of the requirements on the impl of `FunctionProvider` for `comp` -error[E0277]: can't compare `MissingTypeBounds` with `MissingTypeBounds` - --> $DIR/generic-props-fail.rs:28:14 - | -28 | html! { /> }; - | ^^^^ no implementation for `MissingTypeBounds == MissingTypeBounds` - | - = help: the trait `PartialEq` is not implemented for `MissingTypeBounds` - = note: required because of the requirements on the impl of `FunctionProvider` for `comp` - error[E0107]: missing generics for type alias `Comp` - --> $DIR/generic-props-fail.rs:31:14 + --> $DIR/generic-props-fail.rs:30:14 | -31 | html! { }; +30 | html! { }; | ^^^^ expected 1 type argument | note: type alias defined here, with 1 type parameter: `P` - --> $DIR/generic-props-fail.rs:9:22 + --> $DIR/generic-props-fail.rs:8:22 | -9 | #[function_component(Comp)] +8 | #[function_component(Comp)] | ^^^^ -10 | fn comp

(_props: &P) -> Html +9 | fn comp

(_props: &P) -> Html | - help: use angle brackets to add missing type argument | -31 | html! { /> }; +30 | html! { /> }; | ^^^ diff --git a/packages/yew-macro/tests/function_component_attr/lifetime-props-param-fail.rs b/packages/yew-macro/tests/function_component_attr/lifetime-props-param-fail.rs index 71f0d241b..0a1e3622d 100644 --- a/packages/yew-macro/tests/function_component_attr/lifetime-props-param-fail.rs +++ b/packages/yew-macro/tests/function_component_attr/lifetime-props-param-fail.rs @@ -1,5 +1,4 @@ use yew::prelude::*; -use yew_functional::function_component; #[derive(Clone, Properties, PartialEq)] struct Props { diff --git a/packages/yew-macro/tests/function_component_attr/lifetime-props-param-fail.stderr b/packages/yew-macro/tests/function_component_attr/lifetime-props-param-fail.stderr index 10343a7a3..d97e78148 100644 --- a/packages/yew-macro/tests/function_component_attr/lifetime-props-param-fail.stderr +++ b/packages/yew-macro/tests/function_component_attr/lifetime-props-param-fail.stderr @@ -1,5 +1,5 @@ error: reference must not have a lifetime - --> $DIR/lifetime-props-param-fail.rs:10:17 - | -10 | fn comp(props: &'static Props) -> Html { - | ^^^^^^^ + --> $DIR/lifetime-props-param-fail.rs:9:17 + | +9 | fn comp(props: &'static Props) -> Html { + | ^^^^^^^ diff --git a/packages/yew-macro/tests/function_component_attr/multiple-param-fail.rs b/packages/yew-macro/tests/function_component_attr/multiple-param-fail.rs index fef2f4eb0..37b0d7e1a 100644 --- a/packages/yew-macro/tests/function_component_attr/multiple-param-fail.rs +++ b/packages/yew-macro/tests/function_component_attr/multiple-param-fail.rs @@ -1,5 +1,4 @@ use yew::prelude::*; -use yew_functional::function_component; #[derive(Clone, Properties, PartialEq)] struct Props { diff --git a/packages/yew-macro/tests/function_component_attr/multiple-param-fail.stderr b/packages/yew-macro/tests/function_component_attr/multiple-param-fail.stderr index ce3251af8..ca8bc2ed2 100644 --- a/packages/yew-macro/tests/function_component_attr/multiple-param-fail.stderr +++ b/packages/yew-macro/tests/function_component_attr/multiple-param-fail.stderr @@ -1,11 +1,11 @@ error: function components can accept at most one parameter for the props - --> $DIR/multiple-param-fail.rs:10:24 - | -10 | fn comp(props: &Props, invalid: String) -> Html { - | ^^^^^^^^^^^^^^^ + --> $DIR/multiple-param-fail.rs:9:24 + | +9 | fn comp(props: &Props, invalid: String) -> Html { + | ^^^^^^^^^^^^^^^ error: function components can accept at most one parameter for the props - --> $DIR/multiple-param-fail.rs:20:25 + --> $DIR/multiple-param-fail.rs:19:25 | -20 | fn comp3(props: &Props, invalid: String, another_invalid: u32) -> Html { +19 | fn comp3(props: &Props, invalid: String, another_invalid: u32) -> Html { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/packages/yew-macro/tests/function_component_attr/mut-ref-props-param-fail.rs b/packages/yew-macro/tests/function_component_attr/mut-ref-props-param-fail.rs index 0f587e386..a5d9ec9d3 100644 --- a/packages/yew-macro/tests/function_component_attr/mut-ref-props-param-fail.rs +++ b/packages/yew-macro/tests/function_component_attr/mut-ref-props-param-fail.rs @@ -1,5 +1,4 @@ use yew::prelude::*; -use yew_functional::function_component; #[derive(Clone, Properties, PartialEq)] struct Props { diff --git a/packages/yew-macro/tests/function_component_attr/mut-ref-props-param-fail.stderr b/packages/yew-macro/tests/function_component_attr/mut-ref-props-param-fail.stderr index 6f6cb3cbb..28c0f64fc 100644 --- a/packages/yew-macro/tests/function_component_attr/mut-ref-props-param-fail.stderr +++ b/packages/yew-macro/tests/function_component_attr/mut-ref-props-param-fail.stderr @@ -1,5 +1,5 @@ error: reference must not be mutable - --> $DIR/mut-ref-props-param-fail.rs:10:17 - | -10 | fn comp(props: &mut Props) -> Html { - | ^^^ + --> $DIR/mut-ref-props-param-fail.rs:9:17 + | +9 | fn comp(props: &mut Props) -> Html { + | ^^^ diff --git a/packages/yew-macro/tests/function_component_attr/no-name-fail.rs b/packages/yew-macro/tests/function_component_attr/no-name-fail.rs index a2719376c..e648f0298 100644 --- a/packages/yew-macro/tests/function_component_attr/no-name-fail.rs +++ b/packages/yew-macro/tests/function_component_attr/no-name-fail.rs @@ -1,5 +1,4 @@ use yew::prelude::*; -use yew_functional::function_component; #[derive(Clone, Properties, PartialEq)] struct Props { diff --git a/packages/yew-macro/tests/function_component_attr/no-name-fail.stderr b/packages/yew-macro/tests/function_component_attr/no-name-fail.stderr index adc8d237c..fa9615bcb 100644 --- a/packages/yew-macro/tests/function_component_attr/no-name-fail.stderr +++ b/packages/yew-macro/tests/function_component_attr/no-name-fail.stderr @@ -1,7 +1,7 @@ error: unexpected end of input, expected identifier for the component - --> $DIR/no-name-fail.rs:9:1 + --> $DIR/no-name-fail.rs:8:1 | -9 | #[function_component()] +8 | #[function_component()] | ^^^^^^^^^^^^^^^^^^^^^^^ | = note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info) 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 9408bbdc6..fec7dbd32 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,9 +1,11 @@ +#![no_implicit_prelude] + #[derive(Clone, ::yew::Properties, PartialEq)] struct Props { a: usize, } -#[::yew_functional::function_component(Comp)] +#[::yew::function_component(Comp)] fn comp(props: &Props) -> ::yew::Html { ::yew::html! {

diff --git a/packages/yew-macro/tests/function_component_attr/with-receiver-fail.rs b/packages/yew-macro/tests/function_component_attr/with-receiver-fail.rs index d05a4fe3b..12ce13089 100644 --- a/packages/yew-macro/tests/function_component_attr/with-receiver-fail.rs +++ b/packages/yew-macro/tests/function_component_attr/with-receiver-fail.rs @@ -1,5 +1,4 @@ use yew::prelude::*; -use yew_functional::function_component; #[derive(Clone, Properties, PartialEq)] struct Props { diff --git a/packages/yew-macro/tests/function_component_attr/with-receiver-fail.stderr b/packages/yew-macro/tests/function_component_attr/with-receiver-fail.stderr index e0af10684..56999b9d9 100644 --- a/packages/yew-macro/tests/function_component_attr/with-receiver-fail.stderr +++ b/packages/yew-macro/tests/function_component_attr/with-receiver-fail.stderr @@ -1,5 +1,5 @@ error: function components can't accept a receiver - --> $DIR/with-receiver-fail.rs:13:13 + --> $DIR/with-receiver-fail.rs:12:13 | -13 | fn comp(self, props: &Props) -> Html { +12 | fn comp(self, props: &Props) -> Html { | ^^^^ 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 28bf1827a..5bd778caa 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,4 +1,6 @@ -#[::yew_functional::function_component(Comp)] +#![no_implicit_prelude] + +#[::yew::function_component(Comp)] fn comp() -> ::yew::Html { ::yew::html! {

diff --git a/packages/yew-macro/tests/html_macro/component-pass.rs b/packages/yew-macro/tests/html_macro/component-pass.rs index f6086f4bf..d585cba04 100644 --- a/packages/yew-macro/tests/html_macro/component-pass.rs +++ b/packages/yew-macro/tests/html_macro/component-pass.rs @@ -1,110 +1,108 @@ -use yew::html::ChildrenRenderer; -use yew::prelude::*; -use yew::virtual_dom::{VChild, VNode}; +#![no_implicit_prelude] -#[derive(Clone, Properties, Default, PartialEq)] +#[derive(::std::clone::Clone, ::yew::Properties, ::std::default::Default, ::std::cmp::PartialEq)] pub struct ContainerProperties { pub int: i32, #[prop_or_default] - pub children: Children, + pub children: ::yew::Children, } pub struct Container; -impl Component for Container { +impl ::yew::Component for Container { type Message = (); type Properties = ContainerProperties; - fn create(_ctx: &Context) -> Self { - unimplemented!() + fn create(_ctx: &::yew::Context) -> Self { + ::std::unimplemented!() } - fn view(&self, _ctx: &Context) -> Html { - unimplemented!() + fn view(&self, _ctx: &::yew::Context) -> ::yew::Html { + ::std::unimplemented!() } } -#[derive(Clone, PartialEq)] +#[derive(::std::clone::Clone, ::std::cmp::PartialEq)] pub enum ChildrenVariants { - Child(VChild), - AltChild(VChild), + Child(::yew::virtual_dom::VChild), + AltChild(::yew::virtual_dom::VChild), } -impl From> for ChildrenVariants { - fn from(comp: VChild) -> Self { +impl ::std::convert::From<::yew::virtual_dom::VChild> for ChildrenVariants { + fn from(comp: ::yew::virtual_dom::VChild) -> Self { ChildrenVariants::Child(comp) } } -impl From> for ChildrenVariants { - fn from(comp: VChild) -> Self { +impl ::std::convert::From<::yew::virtual_dom::VChild> for ChildrenVariants { + fn from(comp: ::yew::virtual_dom::VChild) -> Self { ChildrenVariants::AltChild(comp) } } -impl Into for ChildrenVariants { - fn into(self) -> VNode { +impl ::std::convert::Into<::yew::virtual_dom::VNode> for ChildrenVariants { + fn into(self) -> ::yew::virtual_dom::VNode { match self { - Self::Child(comp) => VNode::VComp(comp.into()), - Self::AltChild(comp) => VNode::VComp(comp.into()), + Self::Child(comp) => ::yew::virtual_dom::VNode::VComp(::std::convert::Into::<::yew::virtual_dom::VComp>::into(comp)), + Self::AltChild(comp) => ::yew::virtual_dom::VNode::VComp(::std::convert::Into::<::yew::virtual_dom::VComp>::into(comp)), } } } -#[derive(Clone, Properties, Default, PartialEq)] +#[derive(::std::clone::Clone, ::yew::Properties, ::std::default::Default, ::std::cmp::PartialEq)] pub struct ChildProperties { #[prop_or_default] - pub string: String, + pub string: ::std::string::String, pub int: i32, #[prop_or_default] - pub opt_str: Option, + pub opt_str: ::std::option::Option<::std::string::String>, #[prop_or_default] - pub vec: Vec, + pub vec: ::std::vec::Vec, #[prop_or_default] - pub optional_callback: Option>, + pub optional_callback: ::std::option::Option<::yew::Callback<()>>, } pub struct Child; -impl Component for Child { +impl ::yew::Component for Child { type Message = (); type Properties = ChildProperties; - fn create(_ctx: &Context) -> Self { - unimplemented!() + fn create(_ctx: &::yew::Context) -> Self { + ::std::unimplemented!() } - fn view(&self, _ctx: &Context) -> Html { - unimplemented!() + fn view(&self, _ctx: &::yew::Context) -> ::yew::Html { + ::std::unimplemented!() } } pub struct AltChild; -impl Component for AltChild { +impl ::yew::Component for AltChild { type Message = (); type Properties = (); - fn create(_ctx: &Context) -> Self { - unimplemented!() + fn create(_ctx: &::yew::Context) -> Self { + ::std::unimplemented!() } - fn view(&self, _ctx: &Context) -> Html { - unimplemented!() + fn view(&self, _ctx: &::yew::Context) -> ::yew::Html { + ::std::unimplemented!() } } -#[derive(Clone, Properties, Default, PartialEq)] +#[derive(::std::clone::Clone, ::yew::Properties, ::std::default::Default, ::std::cmp::PartialEq)] pub struct ChildContainerProperties { pub int: i32, #[prop_or_default] - pub children: ChildrenRenderer, + pub children: ::yew::html::ChildrenRenderer, } pub struct ChildContainer; -impl Component for ChildContainer { +impl ::yew::Component for ChildContainer { type Message = (); type Properties = ChildContainerProperties; - fn create(_ctx: &Context) -> Self { - unimplemented!() + fn create(_ctx: &::yew::Context) -> Self { + ::std::unimplemented!() } - fn view(&self, _ctx: &Context) -> Html { - unimplemented!() + fn view(&self, _ctx: &::yew::Context) -> ::yew::Html { + ::std::unimplemented!() } } @@ -114,78 +112,77 @@ mod scoped { } fn compile_pass() { - html! { }; + ::yew::html! { }; - html! { + ::yew::html! { <> }; - let props = ::Properties::default(); - let node_ref = NodeRef::default(); - html! { + let props = <::Properties as ::std::default::Default>::default(); + let node_ref = <::yew::NodeRef as ::std::default::Default>::default(); + ::yew::html! { <> - - ::Properties::default() ref={node_ref} /> + + ::Properties as ::std::default::Default>::default() ref={node_ref} /> }; - html! { + ::yew::html! { <> - - + + >::from("child")} int=1 /> - - - + >::from("child")} int=1 /> + + >::from("child"))} int=1 /> }; let name_expr = "child"; - html! { + ::yew::html! { }; let string = "child"; let int = 1; - html! { + ::yew::html! { }; - html! { + ::yew::html! { <> - - - >} /> + as ::std::convert::From<_>>::from(|_| ()))} /> + as ::std::convert::From<_>>::from(|_| ())} /> + >} /> }; - let node_ref = NodeRef::default(); - html! { + let node_ref = <::yew::NodeRef as ::std::default::Default>::default(); + ::yew::html! { <> }; let int = 1; - let node_ref = NodeRef::default(); - html! { + let node_ref = <::yew::NodeRef as ::std::default::Default>::default(); + ::yew::html! { <> }; - - let props = ::Properties::default(); - html! { + let props = <::Properties as ::std::default::Default>::default(); + ::yew::html! { <> @@ -202,13 +199,13 @@ fn compile_pass() { - }; - html! { + ::yew::html! { <> @@ -217,76 +214,85 @@ fn compile_pass() { }; - html! { + ::yew::html! { { - html_nested! { + ::yew::html_nested! { } } { - (0..2) - .map(|i| { html_nested! { } }) - .collect::>() + ::std::iter::Iterator::collect::<::std::vec::Vec<_>>( + ::std::iter::Iterator::map(0..2, + |i| { ::yew::html_nested! { } }) + ) } }; - let children = vec![ - html_nested! { }, - html_nested! { }, + let children = ::std::vec![ + ::yew::html_nested! { }, + ::yew::html_nested! { }, ]; - html! { + ::yew::html! { - { children.clone() } + { ::std::clone::Clone::clone(&children) } }; // https://github.com/yewstack/yew/issues/1527 - html! { + ::yew::html! { { for children } }; - let variants = || -> Vec { - vec![ - ChildrenVariants::Child(VChild::new( - ChildProperties::default(), - NodeRef::default(), - None, + let variants = || -> ::std::vec::Vec { + ::std::vec![ + ChildrenVariants::Child(::yew::virtual_dom::VChild::new( + ::default(), + <::yew::NodeRef as ::std::default::Default>::default(), + ::std::option::Option::None, + )), + ChildrenVariants::AltChild(::yew::virtual_dom::VChild::new( + (), + <::yew::NodeRef as ::std::default::Default>::default(), + ::std::option::Option::None )), - ChildrenVariants::AltChild(VChild::new((), NodeRef::default(), None)), ] }; - html! { + ::yew::html! { <> { - variants() - .into_iter() - .filter(|c| match c { - ChildrenVariants::Child(_) => true, - _ => false, - }) - .collect::() + ::std::iter::Iterator::collect::<::yew::virtual_dom::VNode>( + ::std::iter::Iterator::filter( + ::std::iter::IntoIterator::into_iter(variants()), + |c| match c { + ChildrenVariants::Child(_) => true, + _ => false, + } + ) + ) }

{ - variants() - .into_iter() - .filter(|c| match c { - ChildrenVariants::AltChild(_) => true, - _ => false, - }) - .collect::() + ::std::iter::Iterator::collect::<::yew::virtual_dom::VNode>( + ::std::iter::Iterator::filter( + ::std::iter::IntoIterator::into_iter(variants()), + |c| match c { + ChildrenVariants::AltChild(_) => true, + _ => false, + } + ) + ) }
}; - html_nested! { 1 }; + ::yew::html_nested! { 1 }; } fn main() {} 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 b13d6751f..99f823921 100644 --- a/packages/yew-macro/tests/html_macro/generic-component-pass.rs +++ b/packages/yew-macro/tests/html_macro/generic-component-pass.rs @@ -1,30 +1,29 @@ -use std::marker::PhantomData; -use yew::prelude::*; +#![no_implicit_prelude] pub struct Generic { - marker: PhantomData, + marker: ::std::marker::PhantomData, } -impl Component for Generic +impl ::yew::Component for Generic where T: 'static, { type Message = (); type Properties = (); - fn create(_ctx: &Context) -> Self { - unimplemented!() + fn create(_ctx: &::yew::Context) -> Self { + ::std::unimplemented!() } - fn view(&self, _ctx: &Context) -> Html { - unimplemented!() + fn view(&self, _ctx: &::yew::Context) -> ::yew::Html { + ::std::unimplemented!() } } pub struct Generic2 { - marker: PhantomData<(T1, T2)>, + marker: ::std::marker::PhantomData<(T1, T2)>, } -impl Component for Generic2 +impl ::yew::Component for Generic2 where T1: 'static, T2: 'static, @@ -32,31 +31,31 @@ where type Message = (); type Properties = (); - fn create(_ctx: &Context) -> Self { - unimplemented!() + fn create(_ctx: &::yew::Context) -> Self { + ::std::unimplemented!() } - fn view(&self, _ctx: &Context) -> Html { - unimplemented!() + fn view(&self, _ctx: &::yew::Context) -> ::yew::Html { + ::std::unimplemented!() } } fn compile_pass() { - html! { /> }; - html! { >> }; + ::yew::html! { /> }; + ::yew::html! { >> }; - html! { > /> }; - html! { >>>> }; + ::yew::html! { > /> }; + ::yew::html! { >>>> }; - html! { /> }; - html! { >> }; - html! { /> }; - html! { >> }; + ::yew::html! { /> }; + ::yew::html! { >> }; + ::yew::html! { /> }; + ::yew::html! { >> }; - html! { /> }; - html! { >> }; + ::yew::html! { /> }; + ::yew::html! { >> }; - html! { /> }; - html! { >> }; + ::yew::html! { /> }; + ::yew::html! { >> }; } fn main() {} 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 f929555d0..14354e3d1 100644 --- a/packages/yew-macro/tests/html_macro/html-element-pass.rs +++ b/packages/yew-macro/tests/html_macro/html-element-pass.rs @@ -1,16 +1,18 @@ -use std::borrow::Cow; -use yew::prelude::*; +#![no_implicit_prelude] fn compile_pass() { - let onclick = Callback::from(|_: MouseEvent| ()); - let parent_ref = NodeRef::default(); + 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 = || String::from("test"); - let mut extra_tags_iter = vec!["a", "b"].into_iter(); + let dyn_tag = || <::std::string::String as ::std::convert::From<&str>>::from("test"); + let mut extra_tags_iter = ::std::iter::IntoIterator::into_iter(::std::vec!["a", "b"]); - let cow_none: Option> = None; + let cow_none: ::std::option::Option<::std::borrow::Cow<'static, str>> = + ::std::option::Option::None; - html! { + ::yew::html! {
}; - let children = vec![ - html! { { "Hello" } }, - html! { { "World" } }, + let children = ::std::vec![ + ::yew::html! { { "Hello" } }, + ::yew::html! { { "World" } }, ]; - html! {
{children}
}; + ::yew::html! {
{children}
}; // handle misleading angle brackets - html! {
::default()}>
}; - html! {
}; + ::yew::html! {
::default()}>
}; + ::yew::html! {
}; } fn main() {} 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 eb06fae83..74362e9fe 100644 --- a/packages/yew-macro/tests/html_macro/html-node-pass.rs +++ b/packages/yew-macro/tests/html_macro/html-node-pass.rs @@ -1,23 +1,23 @@ -use yew::prelude::*; +#![no_implicit_prelude] fn compile_pass() { - html! { "" }; - html! { 'a' }; - html! { "hello" }; - html! { 42 }; - html! { 1.234 }; + ::yew::html! { "" }; + ::yew::html! { 'a' }; + ::yew::html! { "hello" }; + ::yew::html! { 42 }; + ::yew::html! { 1.234 }; - html! { { "" } }; - html! { { 'a' } }; - html! { { "hello" } }; - html! { { 42 } }; - html! { { 1.234 } }; + ::yew::html! { { "" } }; + ::yew::html! { { 'a' } }; + ::yew::html! { { "hello" } }; + ::yew::html! { { 42 } }; + ::yew::html! { { 1.234 } }; - html! { format!("Hello") }; - html! { String::from("Hello") }; + ::yew::html! { ::std::format!("Hello") }; + ::yew::html! { {<::std::string::String as ::std::convert::From<&str>>::from("Hello") } }; let msg = "Hello"; - html! { msg }; + ::yew::html! { msg }; } fn main() {} diff --git a/packages/yew-macro/tests/props_macro/props-pass.rs b/packages/yew-macro/tests/props_macro/props-pass.rs index 77434afaf..9ffb083ea 100644 --- a/packages/yew-macro/tests/props_macro/props-pass.rs +++ b/packages/yew-macro/tests/props_macro/props-pass.rs @@ -1,6 +1,6 @@ -use yew::prelude::*; +#![no_implicit_prelude] -#[derive(Clone, Properties, PartialEq)] +#[derive(::std::clone::Clone, ::yew::Properties, ::std::cmp::PartialEq)] struct Props { a: usize, #[prop_or_default] @@ -8,9 +8,9 @@ struct Props { } fn compile_pass() { - yew::props!(Props { a: 5 }); + ::yew::props!(Props { a: 5 }); let (a, b) = (3, 5); - yew::props!(Props { a, b }); + ::yew::props!(Props { a, b }); } fn main() {} 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 77e1dd527..eedbe3d58 100644 --- a/packages/yew-macro/tests/props_macro/resolve-prop-pass.rs +++ b/packages/yew-macro/tests/props_macro/resolve-prop-pass.rs @@ -1,29 +1,29 @@ -use yew::prelude::*; +#![no_implicit_prelude] -#[derive(Clone, Properties, PartialEq)] +#[derive(::std::clone::Clone, ::yew::Properties, ::std::cmp::PartialEq)] struct Props { n: i32, } struct MyComp; -impl Component for MyComp { +impl ::yew::Component for MyComp { type Message = (); type Properties = Props; - fn create(_ctx: &Context) -> Self { - unimplemented!() + fn create(_ctx: &::yew::Context) -> Self { + ::std::unimplemented!() } - fn view(&self, _ctx: &Context) -> Html { - unimplemented!() + fn view(&self, _ctx: &::yew::Context) -> ::yew::Html { + ::std::unimplemented!() } } fn compile_pass() { - yew::props!(Props { n: 1 }); - yew::props!(self::Props { n: 1 }); - yew::props!(MyComp::Properties { n: 2 }); - yew::props!(self::MyComp::Properties { n: 3 }); - yew::props!(::Properties { n: 5 }); + ::yew::props!(Props { n: 1 }); + ::yew::props!(self::Props { n: 1 }); + ::yew::props!(MyComp::Properties { n: 2 }); + ::yew::props!(self::MyComp::Properties { n: 3 }); + ::yew::props!(::Properties { n: 5}); } fn main() {}