mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-23 04:58:01 +00:00
Validate absolute path for substitute_type (#577)
* Remove commented code Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * Ensure substitue path is global absolute Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * Absolute path for build.rs Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * Add ui test that fails to compile Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
This commit is contained in:
+20
-1
@@ -23,7 +23,6 @@ use syn::{
|
||||
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub struct ItemMod {
|
||||
// attrs: Vec<syn::Attribute>,
|
||||
vis: syn::Visibility,
|
||||
mod_token: token::Mod,
|
||||
pub ident: syn::Ident,
|
||||
@@ -103,6 +102,26 @@ impl From<syn::Item> for Item {
|
||||
if let Some(attr) = substitute_attrs.get(0) {
|
||||
let use_path = &use_.tree;
|
||||
let substitute_with: syn::TypePath = syn::parse_quote!( #use_path );
|
||||
|
||||
let is_crate = substitute_with
|
||||
.path
|
||||
.segments
|
||||
.first()
|
||||
.map(|segment| segment.ident == "crate")
|
||||
.unwrap_or(false);
|
||||
|
||||
// Check if the substitute path is a global absolute path, meaning it
|
||||
// is prefixed with `::` or `crate`.
|
||||
//
|
||||
// Note: the leading colon is lost when parsing to `syn::TypePath` via
|
||||
// `syn::parse_quote!`. Therefore, inspect `use_`'s leading colon.
|
||||
if use_.leading_colon.is_none() && !is_crate {
|
||||
abort!(
|
||||
use_path.span(),
|
||||
"The substitute path must be a global absolute path; try prefixing with `::` or `crate`"
|
||||
)
|
||||
}
|
||||
|
||||
let type_substitute = SubxtItem::TypeSubstitute {
|
||||
generated_type_path: attr.substitute_type(),
|
||||
substitute_with,
|
||||
|
||||
Reference in New Issue
Block a user