mirror of
https://gitee.com/openharmony/third_party_rust_syn
synced 2025-02-17 05:57:30 +00:00
Move path printing to a pub(crate) function
This commit is contained in:
parent
d5450934f8
commit
390e0c12f4
@ -3369,7 +3369,7 @@ pub(crate) mod printing {
|
||||
impl ToTokens for ExprPath {
|
||||
fn to_tokens(&self, tokens: &mut TokenStream) {
|
||||
outer_attrs_to_tokens(&self.attrs, tokens);
|
||||
private::print_path(tokens, &self.qself, &self.path);
|
||||
path::printing::print_path(tokens, &self.qself, &self.path);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -827,7 +827,7 @@ mod printing {
|
||||
impl ToTokens for PatPath {
|
||||
fn to_tokens(&self, tokens: &mut TokenStream) {
|
||||
tokens.append_all(self.attrs.outer());
|
||||
private::print_path(tokens, &self.qself, &self.path);
|
||||
path::printing::print_path(tokens, &self.qself, &self.path);
|
||||
}
|
||||
}
|
||||
|
||||
|
60
src/path.rs
60
src/path.rs
@ -684,7 +684,7 @@ pub mod parsing {
|
||||
}
|
||||
|
||||
#[cfg(feature = "printing")]
|
||||
mod printing {
|
||||
pub(crate) mod printing {
|
||||
use super::*;
|
||||
use crate::print::TokensOrDefault;
|
||||
use proc_macro2::TokenStream;
|
||||
@ -835,39 +835,37 @@ mod printing {
|
||||
}
|
||||
}
|
||||
|
||||
impl private {
|
||||
pub(crate) fn print_path(tokens: &mut TokenStream, qself: &Option<QSelf>, path: &Path) {
|
||||
let qself = match qself {
|
||||
Some(qself) => qself,
|
||||
None => {
|
||||
path.to_tokens(tokens);
|
||||
return;
|
||||
}
|
||||
};
|
||||
qself.lt_token.to_tokens(tokens);
|
||||
qself.ty.to_tokens(tokens);
|
||||
pub(crate) fn print_path(tokens: &mut TokenStream, qself: &Option<QSelf>, path: &Path) {
|
||||
let qself = match qself {
|
||||
Some(qself) => qself,
|
||||
None => {
|
||||
path.to_tokens(tokens);
|
||||
return;
|
||||
}
|
||||
};
|
||||
qself.lt_token.to_tokens(tokens);
|
||||
qself.ty.to_tokens(tokens);
|
||||
|
||||
let pos = cmp::min(qself.position, path.segments.len());
|
||||
let mut segments = path.segments.pairs();
|
||||
if pos > 0 {
|
||||
TokensOrDefault(&qself.as_token).to_tokens(tokens);
|
||||
path.leading_colon.to_tokens(tokens);
|
||||
for (i, segment) in segments.by_ref().take(pos).enumerate() {
|
||||
if i + 1 == pos {
|
||||
segment.value().to_tokens(tokens);
|
||||
qself.gt_token.to_tokens(tokens);
|
||||
segment.punct().to_tokens(tokens);
|
||||
} else {
|
||||
segment.to_tokens(tokens);
|
||||
}
|
||||
let pos = cmp::min(qself.position, path.segments.len());
|
||||
let mut segments = path.segments.pairs();
|
||||
if pos > 0 {
|
||||
TokensOrDefault(&qself.as_token).to_tokens(tokens);
|
||||
path.leading_colon.to_tokens(tokens);
|
||||
for (i, segment) in segments.by_ref().take(pos).enumerate() {
|
||||
if i + 1 == pos {
|
||||
segment.value().to_tokens(tokens);
|
||||
qself.gt_token.to_tokens(tokens);
|
||||
segment.punct().to_tokens(tokens);
|
||||
} else {
|
||||
segment.to_tokens(tokens);
|
||||
}
|
||||
} else {
|
||||
qself.gt_token.to_tokens(tokens);
|
||||
path.leading_colon.to_tokens(tokens);
|
||||
}
|
||||
for segment in segments {
|
||||
segment.to_tokens(tokens);
|
||||
}
|
||||
} else {
|
||||
qself.gt_token.to_tokens(tokens);
|
||||
path.leading_colon.to_tokens(tokens);
|
||||
}
|
||||
for segment in segments {
|
||||
segment.to_tokens(tokens);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1163,7 +1163,7 @@ mod printing {
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))]
|
||||
impl ToTokens for TypePath {
|
||||
fn to_tokens(&self, tokens: &mut TokenStream) {
|
||||
private::print_path(tokens, &self.qself, &self.path);
|
||||
path::printing::print_path(tokens, &self.qself, &self.path);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user