rustc_ast: Turn MutVisitor::token_visiting_enabled
into a constant
It's a visitor property rather than something that needs to be determined at runtime
This commit is contained in:
parent
8db8f48ea8
commit
d2470e74e1
@ -37,9 +37,7 @@ pub trait MutVisitor: Sized {
|
|||||||
/// Mutable token visiting only exists for the `macro_rules` token marker and should not be
|
/// Mutable token visiting only exists for the `macro_rules` token marker and should not be
|
||||||
/// used otherwise. Token visitor would be entirely separate from the regular visitor if
|
/// used otherwise. Token visitor would be entirely separate from the regular visitor if
|
||||||
/// the marker didn't have to visit AST fragments in nonterminal tokens.
|
/// the marker didn't have to visit AST fragments in nonterminal tokens.
|
||||||
fn token_visiting_enabled(&self) -> bool {
|
const VISIT_TOKENS: bool = false;
|
||||||
false
|
|
||||||
}
|
|
||||||
|
|
||||||
// Methods in this trait have one of three forms:
|
// Methods in this trait have one of three forms:
|
||||||
//
|
//
|
||||||
@ -363,7 +361,7 @@ pub fn visit_mac_args<T: MutVisitor>(args: &mut MacArgs, vis: &mut T) {
|
|||||||
}
|
}
|
||||||
MacArgs::Eq(eq_span, token) => {
|
MacArgs::Eq(eq_span, token) => {
|
||||||
vis.visit_span(eq_span);
|
vis.visit_span(eq_span);
|
||||||
if vis.token_visiting_enabled() {
|
if T::VISIT_TOKENS {
|
||||||
visit_token(token, vis);
|
visit_token(token, vis);
|
||||||
} else {
|
} else {
|
||||||
// The value in `#[key = VALUE]` must be visited as an expression for backward
|
// The value in `#[key = VALUE]` must be visited as an expression for backward
|
||||||
@ -682,7 +680,7 @@ pub fn visit_tt<T: MutVisitor>(tt: &mut TokenTree, vis: &mut T) {
|
|||||||
|
|
||||||
// No `noop_` prefix because there isn't a corresponding method in `MutVisitor`.
|
// No `noop_` prefix because there isn't a corresponding method in `MutVisitor`.
|
||||||
pub fn visit_tts<T: MutVisitor>(TokenStream(tts): &mut TokenStream, vis: &mut T) {
|
pub fn visit_tts<T: MutVisitor>(TokenStream(tts): &mut TokenStream, vis: &mut T) {
|
||||||
if vis.token_visiting_enabled() && !tts.is_empty() {
|
if T::VISIT_TOKENS && !tts.is_empty() {
|
||||||
let tts = Lrc::make_mut(tts);
|
let tts = Lrc::make_mut(tts);
|
||||||
visit_vec(tts, |(tree, _is_joint)| visit_tt(tree, vis));
|
visit_vec(tts, |(tree, _is_joint)| visit_tt(tree, vis));
|
||||||
}
|
}
|
||||||
@ -692,14 +690,14 @@ pub fn visit_attr_annotated_tts<T: MutVisitor>(
|
|||||||
AttrAnnotatedTokenStream(tts): &mut AttrAnnotatedTokenStream,
|
AttrAnnotatedTokenStream(tts): &mut AttrAnnotatedTokenStream,
|
||||||
vis: &mut T,
|
vis: &mut T,
|
||||||
) {
|
) {
|
||||||
if vis.token_visiting_enabled() && !tts.is_empty() {
|
if T::VISIT_TOKENS && !tts.is_empty() {
|
||||||
let tts = Lrc::make_mut(tts);
|
let tts = Lrc::make_mut(tts);
|
||||||
visit_vec(tts, |(tree, _is_joint)| visit_attr_annotated_tt(tree, vis));
|
visit_vec(tts, |(tree, _is_joint)| visit_attr_annotated_tt(tree, vis));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn visit_lazy_tts_opt_mut<T: MutVisitor>(lazy_tts: Option<&mut LazyTokenStream>, vis: &mut T) {
|
pub fn visit_lazy_tts_opt_mut<T: MutVisitor>(lazy_tts: Option<&mut LazyTokenStream>, vis: &mut T) {
|
||||||
if vis.token_visiting_enabled() {
|
if T::VISIT_TOKENS {
|
||||||
if let Some(lazy_tts) = lazy_tts {
|
if let Some(lazy_tts) = lazy_tts {
|
||||||
let mut tts = lazy_tts.create_token_stream();
|
let mut tts = lazy_tts.create_token_stream();
|
||||||
visit_attr_annotated_tts(&mut tts, vis);
|
visit_attr_annotated_tts(&mut tts, vis);
|
||||||
|
@ -19,9 +19,7 @@ use std::mem;
|
|||||||
struct Marker(LocalExpnId, Transparency);
|
struct Marker(LocalExpnId, Transparency);
|
||||||
|
|
||||||
impl MutVisitor for Marker {
|
impl MutVisitor for Marker {
|
||||||
fn token_visiting_enabled(&self) -> bool {
|
const VISIT_TOKENS: bool = true;
|
||||||
true
|
|
||||||
}
|
|
||||||
|
|
||||||
fn visit_span(&mut self, span: &mut Span) {
|
fn visit_span(&mut self, span: &mut Span) {
|
||||||
*span = span.apply_mark(self.0.to_expn_id(), self.1)
|
*span = span.apply_mark(self.0.to_expn_id(), self.1)
|
||||||
|
@ -15,9 +15,8 @@ fn print_crate_items(krate: &ast::Crate) -> String {
|
|||||||
struct ToZzIdentMutVisitor;
|
struct ToZzIdentMutVisitor;
|
||||||
|
|
||||||
impl MutVisitor for ToZzIdentMutVisitor {
|
impl MutVisitor for ToZzIdentMutVisitor {
|
||||||
fn token_visiting_enabled(&self) -> bool {
|
const VISIT_TOKENS: bool = true;
|
||||||
true
|
|
||||||
}
|
|
||||||
fn visit_ident(&mut self, ident: &mut Ident) {
|
fn visit_ident(&mut self, ident: &mut Ident) {
|
||||||
*ident = Ident::from_str("zz");
|
*ident = Ident::from_str("zz");
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user