hydro_lang/deploy/
trybuild_rewriters.rs
1use syn::visit_mut::VisitMut;
2
3pub struct ReplaceCrateNameWithStaged {
4 pub crate_name: String,
5 pub is_test: bool,
6}
7
8impl VisitMut for ReplaceCrateNameWithStaged {
9 fn visit_type_path_mut(&mut self, i: &mut syn::TypePath) {
10 if let Some(first) = i.path.segments.first() {
11 if first.ident == self.crate_name {
12 let tail = i.path.segments.iter().skip(1).collect::<Vec<_>>();
13
14 if self.is_test {
15 *i = syn::parse_quote!(crate::__staged #(::#tail)*);
16 } else {
17 let crate_ident = syn::Ident::new(&self.crate_name, first.ident.span());
18 *i = syn::parse_quote!(#crate_ident::__staged #(::#tail)*);
19 }
20 }
21 }
22
23 syn::visit_mut::visit_type_path_mut(self, i);
24 }
25
26 fn visit_use_path_mut(&mut self, i: &mut syn::UsePath) {
27 if i.ident == "crate" && !self.is_test {
28 i.ident = syn::Ident::new(&self.crate_name, i.ident.span());
29 }
30 }
31}