Skip to content

Ensure that we pass through spanned data where possible #637

Open
@ahayzen-kdab

Description

@ahayzen-kdab

Currently in various places we use quote! when we should be using quote_spanned!. (see #638 for syn::parse + quote_spanned! vs syn::parse_quote_spanned). A good first step would be to ensure we use quote_spanned in all relevant places.

This then means that errors do not point to the original code.

Before

[build] error: missing documentation for a method
[build]  --> examples/qml_features/rust/src/custom_parent_class.rs:9:1
[build]   |
[build] 9 | #[cxx_qt::bridge(cxx_file_stem = "custom_parent_class")]
[build]   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[build]   |
[build] note: the lint level is defined here
[build]  --> examples/qml_features/rust/src/lib.rs:8:9
[build]   |
[build] 8 | #![deny(missing_docs)]
[build]   |         ^^^^^^^^^^^^

After

[build] error: missing documentation for a method
[build]   --> examples/qml_features/rust/src/custom_parent_class.rs:65:9
[build]    |
[build] 65 |         fn update(self: Pin<&mut CustomParentClass>);
[build]    |         ^^
[build]    |
[build] note: the lint level is defined here
[build]   --> examples/qml_features/rust/src/lib.rs:8:9
[build]    |
[build] 8  | #![deny(missing_docs)]
[build]    |         ^^^^^^^^^^^^
[build] 

Diff

diff --git a/crates/cxx-qt-gen/src/generator/rust/inherit.rs b/crates/cxx-qt-gen/src/generator/rust/inherit.rs
index ec066b10..14d830ce 100644
--- a/crates/cxx-qt-gen/src/generator/rust/inherit.rs
+++ b/crates/cxx-qt-gen/src/generator/rust/inherit.rs
@@ -9,7 +9,7 @@ use crate::{
 };
 use proc_macro2::TokenStream;
 use quote::quote;
-use syn::{Item, Result};
+use syn::{spanned::Spanned, Item, Result};
 
 pub fn generate(
     qobject_ident: &QObjectName,
@@ -45,15 +45,16 @@ pub fn generate(
                 std::mem::swap(&mut unsafe_call, &mut unsafe_block);
             }
             let attrs = &method.method.attrs;
-            syn::parse2(quote! {
+            syn::parse_quote_spanned! {
+                method.method.span() =>
                 #unsafe_block extern "C++" {
                     #(#attrs)*
                     #[cxx_name = #cxx_name_string]
                     #unsafe_call fn #ident(#self_param, #(#parameters),*) #return_type;
                 }
-            })
+            }
         })
-        .collect::<Result<Vec<Item>>>()?;
+        .collect::<Vec<Item>>();

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions