From f854364f6b0aa45eab1ee130f8572e51f4e4fd3b Mon Sep 17 00:00:00 2001 From: Ggiggle <47661277+Ggiggle@users.noreply.github.com> Date: Mon, 13 Nov 2023 12:11:30 +0800 Subject: [PATCH] fix: escape keyword when resolving path in workspace (#212) fix: escape keyword when resolving path in workspace mode Co-authored-by: $wangjie.wjdew <$wangjie.wjdew@bytedance.com> --- Cargo.lock | 2 +- pilota-build/Cargo.toml | 2 +- pilota-build/src/middle/resolver.rs | 11 ++++------- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 516ff5e0..c426c537 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -793,7 +793,7 @@ dependencies = [ [[package]] name = "pilota-build" -version = "0.9.6" +version = "0.9.7" dependencies = [ "anyhow", "criterion", diff --git a/pilota-build/Cargo.toml b/pilota-build/Cargo.toml index 2b23564b..ecdd6978 100644 --- a/pilota-build/Cargo.toml +++ b/pilota-build/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pilota-build" -version = "0.9.6" +version = "0.9.7" edition = "2021" description = "Compile thrift and protobuf idl into rust code at compile-time." documentation = "https://docs.rs/pilota-build" diff --git a/pilota-build/src/middle/resolver.rs b/pilota-build/src/middle/resolver.rs index f1cc5402..fb8956f7 100644 --- a/pilota-build/src/middle/resolver.rs +++ b/pilota-build/src/middle/resolver.rs @@ -84,12 +84,12 @@ impl PathResolver for DefaultPathResolver { #[derive(Debug)] enum Kind { Super, - Ident(FastStr), + Ident(Symbol), } let path = (0..p1.len() - i) .map(|_| Kind::Super) - .chain((i..p2.len()).map(|i| Kind::Ident(p2[i].clone().0))) + .chain((i..p2.len()).map(|i| Kind::Ident(p2[i].clone()))) .collect::>(); let _length = path.len(); @@ -97,7 +97,7 @@ impl PathResolver for DefaultPathResolver { for (_idx, k) in path.into_iter().enumerate() { segs.push(match k { Kind::Super => "super".into(), - Kind::Ident(ident) => Symbol::from(ident).to_string(), + Kind::Ident(ident) => ident.to_string(), }); } segs.into_iter().join("::").into() @@ -135,10 +135,7 @@ impl PathResolver for WorkspacePathResolver { if p2[0] == p1[0] { DefaultPathResolver.related_path(p1, p2) } else { - let mut segs = vec![]; - p2.iter().for_each(|s| segs.push(s.clone())); - - format!("::{}", segs.join("::")).into() + format!("::{}", p2.iter().map(|s| s.to_string()).join("::")).into() } } }