Changed the span of parts of the proc_macro generated widget_new macros, to mitigate specific cases where some errors would have large spans that covered any text after it until it ended.
This commit is contained in:
parent
430bd9fbb1
commit
4973fd0b02
|
@ -1,8 +1,8 @@
|
||||||
error: cannot instantiate widget mix-ins
|
error: cannot instantiate widget mix-ins
|
||||||
--> $DIR/cannot_instantiate_widget_mixin.rs:3:1
|
--> $DIR/cannot_instantiate_widget_mixin.rs:4:9
|
||||||
|
|
|
|
||||||
3 | #[widget_mixin($crate::test_mixin)]
|
4 | pub mod test_mixin {}
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^
|
||||||
...
|
...
|
||||||
7 | let _ = test_mixin!();
|
7 | let _ = test_mixin!();
|
||||||
| ------------- in this macro invocation
|
| ------------- in this macro invocation
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
error: missing required property `foo`
|
error: missing required property `foo`
|
||||||
--> $DIR/capture_is_required_for_instance.rs:19:13
|
--> $DIR/capture_is_required_for_instance.rs:4:9
|
||||||
|
|
|
|
||||||
|
4 | pub mod test_widget {
|
||||||
|
| ^^^^^^^^^^^
|
||||||
|
...
|
||||||
19 | let _ = test_widget!();
|
19 | let _ = test_widget!();
|
||||||
| ^^^^^^^^^^^^^^
|
| -------------- in this macro invocation
|
||||||
|
|
|
|
||||||
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
error: missing required property `foo`
|
||||||
|
--> $DIR/capture_is_required_for_instance_inherited.rs:18:9
|
||||||
|
|
|
||||||
|
18 | pub mod test_widget {
|
||||||
|
| ^^^^^^^^^^^
|
||||||
|
...
|
||||||
|
23 | let _ = test_widget!();
|
||||||
|
| -------------- in this macro invocation
|
||||||
|
|
|
||||||
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
|
|
@ -1,11 +1,14 @@
|
||||||
error: missing required property `foo`
|
error: missing required property `foo`
|
||||||
--> $DIR/property_captured_required1.rs:29:17
|
--> $DIR/property_captured_required1.rs:4:9
|
||||||
|
|
|
|
||||||
|
4 | pub mod base_widget {
|
||||||
|
| ^^^^^^^^^^^
|
||||||
|
...
|
||||||
29 | let _base = base_widget! {
|
29 | let _base = base_widget! {
|
||||||
| _________________^
|
| _________________-
|
||||||
30 | | // expected missing required property error
|
30 | | // expected missing required property error
|
||||||
31 | | };
|
31 | | };
|
||||||
| |_____^
|
| |_____- in this macro invocation
|
||||||
|
|
|
|
||||||
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||||
|
|
||||||
|
|
|
@ -5,12 +5,15 @@ error: cannot unset required property `foo`
|
||||||
| ^^^^^
|
| ^^^^^
|
||||||
|
|
||||||
error: missing required property `foo`
|
error: missing required property `foo`
|
||||||
--> $DIR/cannot_unset_required1.rs:18:13
|
--> $DIR/cannot_unset_required1.rs:10:9
|
||||||
|
|
|
|
||||||
|
10 | pub mod test_widget {
|
||||||
|
| ^^^^^^^^^^^
|
||||||
|
...
|
||||||
18 | let _ = test_widget! {
|
18 | let _ = test_widget! {
|
||||||
| _____________^
|
| _____________-
|
||||||
19 | | foo = unset!;
|
19 | | foo = unset!;
|
||||||
20 | | };
|
20 | | };
|
||||||
| |_____^
|
| |_____- in this macro invocation
|
||||||
|
|
|
|
||||||
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||||
|
|
|
@ -5,12 +5,15 @@ error: cannot unset required property `foo`
|
||||||
| ^^^^^
|
| ^^^^^
|
||||||
|
|
||||||
error: missing required property `foo`
|
error: missing required property `foo`
|
||||||
--> $DIR/cannot_unset_required2.rs:19:13
|
--> $DIR/cannot_unset_required2.rs:4:9
|
||||||
|
|
|
|
||||||
|
4 | pub mod test_widget {
|
||||||
|
| ^^^^^^^^^^^
|
||||||
|
...
|
||||||
19 | let _ = test_widget! {
|
19 | let _ = test_widget! {
|
||||||
| _____________^
|
| _____________-
|
||||||
20 | | foo = unset!;
|
20 | | foo = unset!;
|
||||||
21 | | };
|
21 | | };
|
||||||
| |_____^
|
| |_____- in this macro invocation
|
||||||
|
|
|
|
||||||
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
error: missing required property `foo`
|
error: missing required property `foo`
|
||||||
--> $DIR/missing_captured1.rs:19:13
|
--> $DIR/missing_captured1.rs:4:9
|
||||||
|
|
|
|
||||||
|
4 | pub mod test_widget {
|
||||||
|
| ^^^^^^^^^^^
|
||||||
|
...
|
||||||
19 | let _ = test_widget! {
|
19 | let _ = test_widget! {
|
||||||
| _____________^
|
| _____________-
|
||||||
20 | | // foo = true;
|
20 | | // foo = true;
|
||||||
21 | | };
|
21 | | };
|
||||||
| |_____^
|
| |_____- in this macro invocation
|
||||||
|
|
|
|
||||||
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
error: missing required property `foo`
|
error: missing required property `foo`
|
||||||
--> $DIR/missing_captured2.rs:19:13
|
--> $DIR/missing_captured2.rs:4:9
|
||||||
|
|
|
|
||||||
|
4 | pub mod test_widget {
|
||||||
|
| ^^^^^^^^^^^
|
||||||
|
...
|
||||||
19 | let _ = test_widget! {
|
19 | let _ = test_widget! {
|
||||||
| _____________^
|
| _____________-
|
||||||
20 | | // foo = true;
|
20 | | // foo = true;
|
||||||
21 | | };
|
21 | | };
|
||||||
| |_____^
|
| |_____- in this macro invocation
|
||||||
|
|
|
|
||||||
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
error: missing required property `foo`
|
error: missing required property `foo`
|
||||||
--> $DIR/missing_required.rs:18:13
|
--> $DIR/missing_required.rs:10:9
|
||||||
|
|
|
|
||||||
|
10 | pub mod test_widget {
|
||||||
|
| ^^^^^^^^^^^
|
||||||
|
...
|
||||||
18 | let _ = test_widget! {
|
18 | let _ = test_widget! {
|
||||||
| _____________^
|
| _____________-
|
||||||
19 | | // foo = true;
|
19 | | // foo = true;
|
||||||
20 | | };
|
20 | | };
|
||||||
| |_____^
|
| |_____- in this macro invocation
|
||||||
|
|
|
|
||||||
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||||
|
|
|
@ -303,7 +303,6 @@ pub fn expand(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
|
||||||
if !captured_properties.contains(ident) {
|
if !captured_properties.contains(ident) {
|
||||||
// if no longer captured
|
// if no longer captured
|
||||||
if inherited_required.contains(ident) {
|
if inherited_required.contains(ident) {
|
||||||
println!("{} cannot remove", ident);
|
|
||||||
// but was explicitly marked required
|
// but was explicitly marked required
|
||||||
errors.push(
|
errors.push(
|
||||||
format_args!(
|
format_args!(
|
||||||
|
@ -314,7 +313,6 @@ pub fn expand(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
|
||||||
util::path_span(&inherited.inherit_use),
|
util::path_span(&inherited.inherit_use),
|
||||||
);
|
);
|
||||||
} else if inherited_properties.remove(ident).is_some() {
|
} else if inherited_properties.remove(ident).is_some() {
|
||||||
println!("{} removed", ident);
|
|
||||||
// remove property
|
// remove property
|
||||||
if let Some(i) = inherited_props_child.iter().position(|p| &p.ident == ident) {
|
if let Some(i) = inherited_props_child.iter().position(|p| &p.ident == ident) {
|
||||||
inherited_props_child.remove(i);
|
inherited_props_child.remove(i);
|
||||||
|
@ -891,13 +889,13 @@ pub fn expand(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
let new_macro = if mixin {
|
let new_macro = if mixin {
|
||||||
quote! {
|
quote_spanned! {ident.span()=>
|
||||||
($($invalid:tt)*) => {
|
($($invalid:tt)*) => {
|
||||||
std::compile_error!{"cannot instantiate widget mix-ins"}
|
std::compile_error!{"cannot instantiate widget mix-ins"}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
quote! {
|
quote_spanned! {ident.span()=>
|
||||||
($($tt:tt)*) => {
|
($($tt:tt)*) => {
|
||||||
#module::__core::widget_new! {
|
#module::__core::widget_new! {
|
||||||
widget {
|
widget {
|
||||||
|
|
|
@ -38,7 +38,7 @@ pub fn expand(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
|
||||||
Err(e) => non_user_error!(e),
|
Err(e) => non_user_error!(e),
|
||||||
};
|
};
|
||||||
|
|
||||||
let call_site = widget_data.call_site;
|
let call_site = user_input.call_site;
|
||||||
macro_rules! quote {
|
macro_rules! quote {
|
||||||
($($tt:tt)*) => {
|
($($tt:tt)*) => {
|
||||||
quote::quote_spanned! {call_site=>
|
quote::quote_spanned! {call_site=>
|
||||||
|
@ -856,7 +856,6 @@ impl Parse for Input {
|
||||||
}
|
}
|
||||||
|
|
||||||
struct WidgetData {
|
struct WidgetData {
|
||||||
call_site: Span,
|
|
||||||
module: TokenStream,
|
module: TokenStream,
|
||||||
properties_child: Vec<BuiltProperty>,
|
properties_child: Vec<BuiltProperty>,
|
||||||
properties: Vec<BuiltProperty>,
|
properties: Vec<BuiltProperty>,
|
||||||
|
@ -866,10 +865,8 @@ struct WidgetData {
|
||||||
}
|
}
|
||||||
impl Parse for WidgetData {
|
impl Parse for WidgetData {
|
||||||
fn parse(input: ParseStream) -> syn::Result<Self> {
|
fn parse(input: ParseStream) -> syn::Result<Self> {
|
||||||
let call_site = input.span();
|
|
||||||
let input = non_user_braced!(input, "widget");
|
let input = non_user_braced!(input, "widget");
|
||||||
let r = Ok(Self {
|
let r = Ok(Self {
|
||||||
call_site,
|
|
||||||
module: non_user_braced!(&input, "module").parse().unwrap(),
|
module: non_user_braced!(&input, "module").parse().unwrap(),
|
||||||
properties_child: parse_all(&non_user_braced!(&input, "properties_child")).unwrap_or_else(|e| non_user_error!(e)),
|
properties_child: parse_all(&non_user_braced!(&input, "properties_child")).unwrap_or_else(|e| non_user_error!(e)),
|
||||||
properties: parse_all(&non_user_braced!(&input, "properties")).unwrap_or_else(|e| non_user_error!(e)),
|
properties: parse_all(&non_user_braced!(&input, "properties")).unwrap_or_else(|e| non_user_error!(e)),
|
||||||
|
@ -960,12 +957,14 @@ impl Parse for BuiltWhenAssign {
|
||||||
|
|
||||||
/// The content of the widget macro call.
|
/// The content of the widget macro call.
|
||||||
struct UserInput {
|
struct UserInput {
|
||||||
|
call_site: Span,
|
||||||
errors: Errors,
|
errors: Errors,
|
||||||
properties: Vec<PropertyAssign>,
|
properties: Vec<PropertyAssign>,
|
||||||
whens: Vec<When>,
|
whens: Vec<When>,
|
||||||
}
|
}
|
||||||
impl Parse for UserInput {
|
impl Parse for UserInput {
|
||||||
fn parse(input: ParseStream) -> syn::Result<Self> {
|
fn parse(input: ParseStream) -> syn::Result<Self> {
|
||||||
|
let call_site = input.span();
|
||||||
let input = non_user_braced!(input, "user");
|
let input = non_user_braced!(input, "user");
|
||||||
|
|
||||||
let mut errors = Errors::default();
|
let mut errors = Errors::default();
|
||||||
|
@ -1009,7 +1008,12 @@ impl Parse for UserInput {
|
||||||
let _ = input.parse::<TokenStream>();
|
let _ = input.parse::<TokenStream>();
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(UserInput { errors, properties, whens })
|
Ok(UserInput {
|
||||||
|
call_site,
|
||||||
|
errors,
|
||||||
|
properties,
|
||||||
|
whens,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue