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:
Well 2021-04-21 01:37:08 -03:00
parent 430bd9fbb1
commit 4973fd0b02
11 changed files with 65 additions and 32 deletions

View File

@ -1,8 +1,8 @@
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!();
| ------------- in this macro invocation

View File

@ -1,7 +1,10 @@
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!();
| ^^^^^^^^^^^^^^
| -------------- in this macro invocation
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

View File

@ -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)

View File

@ -1,11 +1,14 @@
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! {
| _________________^
| _________________-
30 | | // expected missing required property error
31 | | };
| |_____^
| |_____- in this macro invocation
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

View File

@ -5,12 +5,15 @@ error: cannot unset 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! {
| _____________^
| _____________-
19 | | foo = unset!;
20 | | };
| |_____^
| |_____- in this macro invocation
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

View File

@ -5,12 +5,15 @@ error: cannot unset 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! {
| _____________^
| _____________-
20 | | foo = unset!;
21 | | };
| |_____^
| |_____- in this macro invocation
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

View File

@ -1,10 +1,13 @@
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! {
| _____________^
| _____________-
20 | | // foo = true;
21 | | };
| |_____^
| |_____- in this macro invocation
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

View File

@ -1,10 +1,13 @@
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! {
| _____________^
| _____________-
20 | | // foo = true;
21 | | };
| |_____^
| |_____- in this macro invocation
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

View File

@ -1,10 +1,13 @@
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! {
| _____________^
| _____________-
19 | | // foo = true;
20 | | };
| |_____^
| |_____- in this macro invocation
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

View File

@ -303,7 +303,6 @@ pub fn expand(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
if !captured_properties.contains(ident) {
// if no longer captured
if inherited_required.contains(ident) {
println!("{} cannot remove", ident);
// but was explicitly marked required
errors.push(
format_args!(
@ -314,7 +313,6 @@ pub fn expand(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
util::path_span(&inherited.inherit_use),
);
} else if inherited_properties.remove(ident).is_some() {
println!("{} removed", ident);
// remove property
if let Some(i) = inherited_props_child.iter().position(|p| &p.ident == ident) {
inherited_props_child.remove(i);
@ -891,13 +889,13 @@ pub fn expand(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
};
};
let new_macro = if mixin {
quote! {
quote_spanned! {ident.span()=>
($($invalid:tt)*) => {
std::compile_error!{"cannot instantiate widget mix-ins"}
};
}
} else {
quote! {
quote_spanned! {ident.span()=>
($($tt:tt)*) => {
#module::__core::widget_new! {
widget {

View File

@ -38,7 +38,7 @@ pub fn expand(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
Err(e) => non_user_error!(e),
};
let call_site = widget_data.call_site;
let call_site = user_input.call_site;
macro_rules! quote {
($($tt:tt)*) => {
quote::quote_spanned! {call_site=>
@ -856,7 +856,6 @@ impl Parse for Input {
}
struct WidgetData {
call_site: Span,
module: TokenStream,
properties_child: Vec<BuiltProperty>,
properties: Vec<BuiltProperty>,
@ -866,10 +865,8 @@ struct WidgetData {
}
impl Parse for WidgetData {
fn parse(input: ParseStream) -> syn::Result<Self> {
let call_site = input.span();
let input = non_user_braced!(input, "widget");
let r = Ok(Self {
call_site,
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: 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.
struct UserInput {
call_site: Span,
errors: Errors,
properties: Vec<PropertyAssign>,
whens: Vec<When>,
}
impl Parse for UserInput {
fn parse(input: ParseStream) -> syn::Result<Self> {
let call_site = input.span();
let input = non_user_braced!(input, "user");
let mut errors = Errors::default();
@ -1009,7 +1008,12 @@ impl Parse for UserInput {
let _ = input.parse::<TokenStream>();
}
Ok(UserInput { errors, properties, whens })
Ok(UserInput {
call_site,
errors,
properties,
whens,
})
}
}